14#include "CLHEP/Random/RandomEngine.h"
15#include "CLHEP/Random/RandFlat.h"
16#include "CLHEP/Random/RandGaussQ.h"
17#include "CLHEP/Random/RandPoissonQ.h"
20 const std::string& name,
21 const IInterface* parent) :
41 for(
int i=0; i<4; ++i){
42 for(
int j=0; j<4; ++j){
43 for(
int k=0; k<4; ++k){
51 for(
int i=0; i<16; ++i)
63 for(
int i=0; i<4; i++) {
64 for(
int j=0; j<4; j++) {
65 for(
int k=0; k<4; k++) {
87 return StatusCode::FAILURE;
91 return StatusCode::FAILURE;
118 return StatusCode::SUCCESS;
122StatusCode
AFP_PileUpTool::recoAll(
const EventContext& ctx, std::unique_ptr<AFP_TDDigiCollection>& digitCollection, std::unique_ptr<AFP_SiDigiCollection>& siDigiCollection)
const
127 return StatusCode::SUCCESS;
133 auto afpSiHits=std::make_unique<xAOD::AFPSiHitContainer>();
134 auto afpSiHitsAux=std::make_unique<xAOD::AFPSiHitAuxContainer>();
135 afpSiHits->setStore(afpSiHitsAux.get());
139 ATH_MSG_DEBUG(
"AFP_PileUpTool: after newXAODHitSi, simulated digi container size = "<<siDigiCollection->size()<<
", got afpSiHits with size "<<afpSiHits->size());
142 ATH_CHECK( siHitContainer.
record(std::move(afpSiHits), std::move(afpSiHitsAux)) );
144 return StatusCode::SUCCESS;
170 for (; it != itend; ++it) {
171 auto * xAODSiHit = siHitContainer->push_back(std::make_unique<xAOD::AFPSiHit>());
173 xAODSiHit->setStationID(it->m_nStationID);
174 xAODSiHit->setPixelLayerID(it->m_nDetectorID);
175 xAODSiHit->setPixelColIDChip(80-it->m_nPixelRow);
176 xAODSiHit->setPixelRowIDChip(336-it->m_nPixelCol);
177 xAODSiHit->setDepositedCharge( it->m_fADC );
179 tot = tot<16 ? tot : 16;
180 xAODSiHit->setTimeOverThreshold( tot );
187 auto afpToFHits=std::make_unique<xAOD::AFPToFHitContainer>();
188 auto afpToFHitsAux=std::make_unique<xAOD::AFPToFHitAuxContainer>();
189 afpToFHits->setStore(afpToFHitsAux.get());
193 ATH_MSG_DEBUG(
"AFP_PileUpTool: after recoToFHits, simulated TD digi container size = "<<digitCollection->size()<<
", got afpToFHits with size "<<afpToFHits->size());
196 ATH_CHECK(ToFHitsContainer.
record(std::move(afpToFHits),std::move(afpToFHitsAux)));
198 return StatusCode::SUCCESS;
207 for (; it != itend; ++it) {
208 auto * xAODToFHit = tofHitContainer->push_back(std::make_unique<xAOD::AFPToFHit>());
209 xAODToFHit->setStationID(it->m_nStationID);
210 xAODToFHit->setHptdcChannel(-1);
211 xAODToFHit->setBarInTrainID(it->m_nDetectorID%10-1);
212 xAODToFHit->setTrainID(it->m_nDetectorID/10-1);
213 xAODToFHit->setHptdcID(-1);
214 xAODToFHit->setPulseLength(it->m_fADC);
215 xAODToFHit->setTime(it->m_fTDC);
232 if (!hitCollection.
isValid()) {
233 ATH_MSG_ERROR(
"Could not get AFP_TDSimHitCollection container " << hitCollection.
name() <<
" from store " << hitCollection.
store());
234 return StatusCode::FAILURE;
239 thpcAFP_TDPmt.
insert(0, hitCollection.
cptr());
240 ATH_MSG_DEBUG(
"AFP_TDSimHitCollection found with " << hitCollection->size() <<
" hits");
243 TimedTDSimHitCollList TDSimHitCollList;
244 unsigned int numberOfTDSimHits{0};
247 return StatusCode::FAILURE;
251 TimedTDSimHitCollList::iterator iColl (TDSimHitCollList.begin());
252 TimedTDSimHitCollList::iterator endColl(TDSimHitCollList.end());
254 while (iColl != endColl) {
256 thpcAFP_TDPmt.
insert(iColl->first, tmpColl);
257 ATH_MSG_DEBUG (
" AFP_TDSimHitCollection found with " << tmpColl->
size() <<
" hits " << iColl->first );
264 if (!hitCollection.
isValid()) {
265 ATH_MSG_ERROR(
"Could not get AFP_SIDSimHitCollection container " << hitCollection.
name() <<
" from store " << hitCollection.
store());
266 return StatusCode::FAILURE;
271 thpcAFP_SiPmt.
insert(0, hitCollection.
cptr());
272 ATH_MSG_DEBUG(
"AFP_SIDSimHitCollection found with " << hitCollection->size() <<
" hits");
275 TimedSIDSimHitCollList SIDSimHitCollList;
276 unsigned int numberOfSIDSimHits{0};
279 return StatusCode::FAILURE;
283 TimedSIDSimHitCollList::iterator iSiColl (SIDSimHitCollList.begin());
284 TimedSIDSimHitCollList::iterator endSiColl(SIDSimHitCollList.end());
286 while (iSiColl != endSiColl) {
288 thpcAFP_SiPmt.
insert(iSiColl->first, tmpSiColl);
289 ATH_MSG_DEBUG (
" AFP_SIDSimHitCollection found with " << tmpSiColl->
size() <<
" hits " << iSiColl->first );
296 CLHEP::HepRandomEngine* rngEngine = rngWrapper->
getEngine(ctx);
298 std::unique_ptr<AFP_TDDigiCollection> digitCollection = std::make_unique<AFP_TDDigiCollection>();
299 std::unique_ptr<AFP_SiDigiCollection> siDigiCollection = std::make_unique<AFP_SiDigiCollection>();
312 return StatusCode::SUCCESS;
318 ATH_MSG_DEBUG (
"AFP_PileUpTool::prepareEvent() called for " << nInputEvents <<
" input events" );
326 return StatusCode::SUCCESS;
332 ATH_MSG_DEBUG (
"AFP_PileUpTool::processBunchXing() " << bunchXing );
334 for (; iEvt!=eSubEvents; ++iEvt) {
337 <<
" bunch crossing : " << bunchXing
338 <<
" time offset : " << iEvt->time()
339 <<
" event number : " << iEvt->ptr()->eventNumber()
340 <<
" run number : " << iEvt->ptr()->runNumber()
346 ATH_MSG_ERROR (
"SubEvent AFP_TDSimHitCollection not found in StoreGate " << seStore.name() );
347 return StatusCode::FAILURE;
350 ATH_MSG_DEBUG (
"AFP_TDSimHitCollection found with " << tmpColl->
size() <<
" hits" );
360 ATH_MSG_ERROR (
"SubEvent AFP_SIDSimHitCollection not found in StoreGate " << seStore.name() );
361 return StatusCode::FAILURE;
364 ATH_MSG_DEBUG (
"AFP_TDSimHitCollection found with " << tmpSiColl->
size() <<
" hits" );
372 return StatusCode::SUCCESS;
380 CLHEP::HepRandomEngine* rngEngine = rngWrapper->
getEngine(ctx);
391 return StatusCode::SUCCESS;
397 return StatusCode::SUCCESS;
403 for(
int i=0; i<4; i++) {
404 for(
int j=0; j<4; j++) {
405 for(
int k=0; k<4; k++) {
421 for (it = i; it != e; ++it) {
422 int Station = (*it)->m_nStationID;
423 int Detector = (*it)->m_nDetectorID;
424 int SensitiveElement = (*it)->m_nSensitiveElementID;
425 float GlobalTime = (*it)->m_fGlobalTime;
426 float WaveLength = (*it)->m_fWaveLength;
428 if(SensitiveElement%2 == 1)
createTDDigi(Station, Detector, SensitiveElement, GlobalTime, WaveLength, rndEngine);
433 return StatusCode::SUCCESS;
444 for (; it != itend; ++it) {
445 int Station = it->m_nStationID;
446 int Detector = it->m_nDetectorID;
447 int SensitiveElement = it->m_nSensitiveElementID;
448 float GlobalTime = it->m_fGlobalTime;
449 float WaveLength = it->m_fWaveLength;
451 if(SensitiveElement%2 == 1)
createTDDigi(Station, Detector, SensitiveElement, GlobalTime, WaveLength, rndEngine);
456 return StatusCode::SUCCESS;
468 for (it = i; it != e; ++it) {
469 int Station = (*it)->m_nStationID;
470 int Detector = (*it)->m_nDetectorID;
471 int PixelRow = (*it)->m_nPixelRow;
472 int PixelCol = (*it)->m_nPixelCol;
473 float PreStepX = (*it)->m_fPreStepX;
474 float PreStepY = (*it)->m_fPreStepY;
475 float PreStepZ = (*it)->m_fPreStepZ;
476 float PostStepX = (*it)->m_fPostStepX;
477 float PostStepY = (*it)->m_fPostStepY;
478 float PostStepZ = (*it)->m_fPostStepZ;
479 float DepEnergy = (*it)->m_fEnergyDeposit;
481 createSiDigi(ctx, Station, Detector, PixelRow, PixelCol, PreStepX, PreStepY, PreStepZ, PostStepX, PostStepY, PostStepZ, DepEnergy);
485 return StatusCode::SUCCESS;
496 for (; it != itend; ++it) {
497 int Station = it->m_nStationID;
498 int Detector = it->m_nDetectorID;
499 int PixelRow = it->m_nPixelRow;
500 int PixelCol = it->m_nPixelCol;
501 float PreStepX = it->m_fPreStepX;
502 float PreStepY = it->m_fPreStepY;
503 float PreStepZ = it->m_fPreStepZ;
504 float PostStepX = it->m_fPostStepX;
505 float PostStepY = it->m_fPostStepY;
506 float PostStepZ = it->m_fPostStepZ;
507 float DepEnergy = it->m_fEnergyDeposit;
509 createSiDigi(ctx, Station, Detector, PixelRow, PixelCol, PreStepX, PreStepY, PreStepZ, PostStepX, PostStepY, PostStepZ, DepEnergy);
512 return StatusCode::SUCCESS;
518 double qEff =
getQE( lambda );
519 return CLHEP::RandFlat::shoot(rndEngine, 0.0, 1.0) < qEff*
m_CollectionEff;
529void AFP_PileUpTool::createTDDigi(
int Station,
int Detector,
int SensitiveElement,
float GlobalTime,
float WaveLength, CLHEP::HepRandomEngine* rndEngine)
531 ATH_MSG_DEBUG (
" iterating Pmt " << Station <<
" " << Detector <<
" " << SensitiveElement <<
" " << GlobalTime <<
" " << WaveLength );
533 if ( Station >3 || Station < 0 || Detector >49 || Detector < 10 || (SensitiveElement-1)/2>1 || (SensitiveElement-1)/2<0) {
534 ATH_MSG_ERROR (
"Wrong station, detector or sensitive detector id" );
540 const int train = Detector/10 - 1;
541 const int bar = Detector%10-1;
543 if (train<0 or train >3 or bar<0 or bar>3){
544 ATH_MSG_ERROR (
"Wrong train or bar; allowed values are 0-3, actual values "<<train<<
", "<<bar);
558 TH1F hSignal_delayed(hSignal);
559 for(
int l = hSignal.GetNbinsX(); l>0; l-- ){
560 double val = l > nBinsDelay ? hSignal.GetBinContent(l-nBinsDelay) : 0;
561 hSignal_delayed.SetBinContent(l, val);
563 TH1F hSignal_forTDC(hSignal);
564 hSignal_forTDC.Add(&hSignal, &hSignal_delayed, -
m_CfdThr, 1);
566 const int bin = hSignal_forTDC.FindFirstBinAbove(0);
567 double TDC = hSignal_forTDC.GetBinCenter(
bin );
568 if(
bin-1 <= nBinsDelay )
576 int first = hSignal.FindFirstBinAbove(
threshold);
578 while( hSignal.GetBinContent(++last) >
threshold && last < hSignal.GetNbinsX() );
579 double ADC = last-first;
586 for(
int i=0; i<4; i++) {
587 for(
int j=0; j<4; j++) {
588 for(
int k=0; k<4; k++){
591 const double peakVal = hSignal.GetBinContent( hSignal.GetMaximumBin() );
595 const double TDC =
getTDC( hSignal );
596 const double ADC =
getADC( hSignal, 0.5*peakVal );
605 digitCollection->push_back(tddigi);
611 return StatusCode::SUCCESS;
624void AFP_PileUpTool::createSiDigi(
const EventContext& ctx,
int Station,
int Detector,
int PixelRow,
int PixelCol,
float PreStepX,
float PreStepY,
float PreStepZ,
float PostStepX,
float PostStepY,
float PostStepZ,
float DepEnergy)
626 ATH_MSG_DEBUG (
" iterating Pmt, station " << Station <<
", detector " << Detector <<
", pixel_col " << PixelCol <<
", pixel_row " << PixelRow <<
", dep_energy" << DepEnergy <<
" (x,y,z)_pre (" << PreStepX <<
"," << PreStepY <<
"," << PreStepZ <<
"), (x,y,z)_post (" << PostStepX <<
"," << PostStepY <<
"," << PostStepZ <<
")" );
630 CLHEP::HepRandomEngine* rngEngine = rngWrapper->
getEngine(ctx);
635 ATH_MSG_DEBUG (
"deposted charge for given hit " << depositedCharge );
637 if ((PixelCol>=336) || (PixelRow >= 80) || (Station >= 4) || (Detector >= 6 ) )
641 ATH_MSG_DEBUG (
"Hit in the vacuum layer in front of the station " << Station );
645 ATH_MSG_WARNING (
"WRONG NUMBER of PIXEL coordinates or station or detector !!!:" );
646 ATH_MSG_WARNING (
"station [max 4] " << Station <<
", detector [max 6]" << Detector <<
", pixel_col [max 336] " << PixelCol <<
", pixel_row [max 80] " << PixelRow );
651 m_deposited_charge[6*336*80*Station + 80*336*Detector + 80*PixelCol + PixelRow] += depositedCharge;
652 m_deposited_energy[6*336*80*Station + 80*336*Detector + 80*PixelCol + PixelRow] += DepEnergy;
666 CLHEP::HepRandomEngine* rngEngine = rngWrapper->
getEngine(ctx);
681 int station =
static_cast<int>(
index/(80*336*6));
682 int detector =
static_cast<int>((
index-station*80*336*6)/(80*336));
683 int column =
static_cast<int>((
index-station*80*336*6-detector*80*336)/80);
684 int row =
static_cast<int>(
index-station*80*336*6-detector*80*336-column*80);
686 ATH_MSG_DEBUG (
" reversed mapping, station " << station <<
", detector " << detector <<
", pixel_col " << column <<
", pixel_row " << row );
697 siDigiCollection->push_back(sidigi);
703 return StatusCode::SUCCESS;
709 int xDiscrete =
static_cast<int>(
x);
710 int iMin = xDiscrete;
711 int iMax =
h.GetNbinsX();
715 iMax =
h.GetNbinsX() + xDiscrete - 1;
717 for(
int i = iMin; i<=iMax; ++i){
718 h.SetBinContent(i,
h.GetBinContent(i) +
m_SignalVect[i-xDiscrete]);
725 int id = (
static_cast<int>(lambda)-200)/5;
726 if(
id > 81 ||
id < 0)
return 0;
735 if ( Time < 0)
return f;
736 double p = (FallTime-RiseTime*TMath::Log(1.+FallTime/RiseTime))/TMath::Log(10.);
737 f = TMath::Power(Time/p,RiseTime/p)*TMath::Exp(-(Time/p));
738 f /= (TMath::Power(RiseTime/p,RiseTime/p)*TMath::Exp(-(RiseTime/p)));
AtlasHitsVector< AFP_SIDSimHit >::const_iterator AFP_SIDSimHitConstIter
AtlasHitsVector< AFP_SIDSimHit > AFP_SIDSimHitCollection
AtlasHitsVector< AFP_SiDigi >::const_iterator AFP_SiDigiConstIter
AtlasHitsVector< AFP_TDDigi >::const_iterator AFP_TDDigiConstIter
AtlasHitsVector< AFP_TDSimHit > AFP_TDSimHitCollection
AtlasHitsVector< AFP_TDSimHit >::const_iterator AFP_TDSimHitConstIter
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
int m_nSensitiveElementID
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.
Header file for AthHistogramAlgorithm.
CONT::const_iterator const_iterator
const_iterator begin() const
const_iterator end() const
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.
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