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) :
23 m_totToChargeTransformation (
"totToChargeTransformation",
"1909 + x*363 + x*x*141"),
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;
122 StatusCode 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 );
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;
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;
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>();
307 ATH_CHECK( digitWriteHandle.record(std::move(digitCollection)) );
310 ATH_CHECK( siDigiWriteHandle.record(std::move(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++) {
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;
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;
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;
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;
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" );
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 )
578 while( hSignal.GetBinContent(++last) >
threshold && last < hSignal.GetNbinsX() );
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 );
611 return StatusCode::SUCCESS;
624 void 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 );
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));
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){
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)));