13#include "CLHEP/Random/RandFlat.h"
43 ATH_CHECK(detStore()->retrieve(muDetMgr));
44 ATH_MSG_DEBUG (
"MuonDetectorManager retrieved from StoreGate.");
73 return StatusCode::FAILURE;
85 return StatusCode::SUCCESS;
97 return StatusCode::SUCCESS;
114 ATH_CHECK(cscSimData.
record(std::make_unique<CscSimDataCollection>()));
119 if (StatusCode::FAILURE ==
sc) {
126 rngWrapper->
setSeed( name(), ctx );
130 for (
size_t coll_hash = 0; coll_hash < collections.size(); ++coll_hash) {
131 if (collections[coll_hash]) {
132 ATH_CHECK( cscDigits->addCollection (collections[coll_hash].release(), coll_hash) );
136 return StatusCode::SUCCESS;
141 std::map <IdentifierHash,deposits> myDeposits;
143 csc_newmap data_SampleMap, data_SampleMapOddPhase;
150 return StatusCode::FAILURE;
154 while(
m_thpcCSC->nextDetectorElement(i, e) ) {
167 double globalHitTime(
hitTime(phit));
168 double bunchTime(globalHitTime - hit.
globalTime());
172 ATH_MSG_DEBUG (
"bunch time (ns) " << bunchTime <<
"globalHitTime (ns) " << globalHitTime <<
" hit Time (ns) " <<
hitTime(phit) );
175 std::vector<IdentifierHash> hashVec;
177 ?
m_cscDigitizer->digitize_hit(&hit, hashVec, data_SampleMap, data_SampleMapOddPhase, rndmEngine)
178 :
m_cscDigitizer->digitize_hit(&hit, hashVec, data_map, rndmEngine);
180 if (status.isFailure()) {
185 std::vector<IdentifierHash>::const_iterator vecBeg = hashVec.begin();
186 std::vector<IdentifierHash>::const_iterator vecEnd = hashVec.end();
190 float ypos = -99999.9;
201 if ( dx>0.0 && xi<=0.0 && xf>=0.0 ) {
212 const auto cscd =
CscMcData(energy, ypos, zpos);
213 for (; vecBeg != vecEnd; ++vecBeg) {
214 myDeposits[(*vecBeg)].emplace_back(trackLink,cscd);
229 double flat = CLHEP::RandFlat::shoot(rndmEngine, 0.0,1.0);
230 bool phaseToSet = flat<0.5;
243 std::map<IdentifierHash,deposits>& myDeposits,
254 csc_newmap::const_iterator cscMap = data_SampleMap.begin();
255 csc_newmap::const_iterator cscMapEnd = data_SampleMap.end();
257 for (; cscMap != cscMapEnd; ++cscMap) {
260 if (
m_idHelperSvc->cscIdHelper().get_id( hashId, digitId, &context ) ) {
261 ATH_MSG_ERROR (
"cannot get CSC channel identifier from hash " << hashId );
262 return StatusCode::FAILURE;
267 if (
m_idHelperSvc->cscIdHelper().get_hash(elementId, coll_hash, &cscContext)) {
268 ATH_MSG_ERROR (
"Unable to get CSC hash id from CSC Digit collection "
269 <<
"context begin_index = " << cscContext.
begin_index()
270 <<
" context end_index = " << cscContext.
end_index()
271 <<
" the identifier is " );
277 double stripCharge = 0.0;
278 double driftTime = 0.0;
279 const std::vector<float> samples = (*cscMap).second;
281 unsigned int samplingPhase =0;
282 double samplingTime =
m_pcalib->getSamplingTime();
283 m_pcalib->findCharge(samplingTime, samplingPhase, samples, stripCharge, driftTime);
284 driftTime +=
m_pcalib->getLatency();
293 int phisec =
m_idHelperSvc->cscIdHelper().stationPhi(digitId);
294 int istation =
m_idHelperSvc->cscIdHelper().stationName(digitId) - 49;
297 int measphi =
m_idHelperSvc->cscIdHelper().measuresPhi(digitId);
300 int sector = zsec*(2*phisec-istation+1);
302 auto depositsForHash = myDeposits.find(hashId);
303 if (depositsForHash != myDeposits.end() && !depositsForHash->second.empty()) {
304 depositsForHash->second[0].second.setCharge(stripCharge);
305 cscSimData->insert ( std::make_pair(digitId,
CscSimData(depositsForHash->second,0)) );
311 ATH_MSG_DEBUG (
"NEWDigit sec:measphi:wlay:istr:chg:t(w/latency) "
312 <<
m_idHelperSvc->cscIdHelper().show_to_string(digitId,&context)
313 <<
" hash:eleId = " << hashId <<
" " << elementId <<
" " << prevId <<
" "
314 << sector <<
" " << measphi <<
" " << wlay <<
" " << istrip <<
" "
315 <<
int(stripCharge+1) <<
" " <<
float(driftTime)
316 <<
" phase=" << phaseToSet
317 <<
" samps: " << samples[0] <<
" " << samples[1] <<
" "
318 << samples[2] <<
" " << samples[3]
321 if (prevId != elementId) {
322 if (coll_hash >= collections.size()) {
323 collections.resize (coll_hash+1);
325 collection = collections[coll_hash].
get();
326 if (
nullptr == collection) {
327 collections[coll_hash] = std::make_unique<CscDigitCollection>(elementId,coll_hash);
328 collection = collections[coll_hash].
get();
331 collection->
push_back (std::make_unique<CscDigit>(digitId, samples));
338 return StatusCode::FAILURE;
342 collection->
push_back (std::make_unique<CscDigit>(digitId, samples));
345 return StatusCode::SUCCESS;
357 csc_map::const_iterator cscMap = data_map.begin();
358 csc_map::const_iterator cscMapEnd = data_map.end();
359 for (; cscMap != cscMapEnd; ++cscMap) {
362 if (
m_idHelperSvc->cscIdHelper().get_id( hashId, digitId, &context ) ) {
363 ATH_MSG_ERROR (
"cannot get CSC channel identifier from hash " << hashId );
364 return StatusCode::FAILURE;
368 double stripCharge = 0.0;
369 stripCharge = ((*cscMap).second).second +
m_pedestal;
370 double driftTime =((*cscMap).second).first;
379 <<
" hash = " << hashId
380 <<
" charge = " << int (stripCharge+1) );
383 int phisec =
m_idHelperSvc->cscIdHelper().stationPhi(digitId);
384 int istation =
m_idHelperSvc->cscIdHelper().stationName(digitId) - 49;
387 int measphi =
m_idHelperSvc->cscIdHelper().measuresPhi(digitId);
390 int sector = zsec*(2*phisec-istation+1);
392 auto depositsForHash = myDeposits.find(hashId);
393 if (depositsForHash != myDeposits.end() && !depositsForHash->second.empty()) {
394 depositsForHash->second[0].second.setCharge(stripCharge);
395 cscSimData->insert ( std::make_pair(digitId,
CscSimData(depositsForHash->second,0)) );
401 auto newDigit = std::make_unique<CscDigit>(digitId,
int(stripCharge+1),
float(driftTime) );
404 ATH_MSG_DEBUG (
"CSC Digit sector:measphi:wlay:istrip:charge "
406 << measphi <<
" " << wlay <<
" " << istrip
407 <<
" " <<
int(stripCharge+1) <<
" " <<
float(driftTime) <<
" " << (newDigit->sampleCharges()).size());
411 if (
m_idHelperSvc->cscIdHelper().get_hash(elementId, coll_hash, &cscContext)) {
412 ATH_MSG_ERROR (
"Unable to get CSC hash id from CSC Digit collection "
413 <<
"context begin_index = " << cscContext.
begin_index()
414 <<
" context end_index = " << cscContext.
end_index()
415 <<
" the identifier is " );
419 if (prevId != elementId) {
420 if (coll_hash >= collections.size()) {
421 collections.resize (coll_hash+1);
423 collection = collections[coll_hash].
get();
424 if (
nullptr == collection) {
425 collections[coll_hash] = std::make_unique<CscDigitCollection>(elementId,coll_hash);
426 collection = collections[coll_hash].
get();
428 collection->
push_back(std::move(newDigit));
433 collection->
push_back(std::move(newDigit));
435 ATH_MSG_ERROR(
"Trying to push back NULL CscDigitCollection");
436 return StatusCode::FAILURE;
440 return StatusCode::SUCCESS;
454 if (!hitCollection.
isValid()) {
455 ATH_MSG_ERROR(
"Could not get CSCSimHitCollection container " << hitCollection.
name() <<
" from store " << hitCollection.
store());
456 return StatusCode::FAILURE;
462 ATH_MSG_DEBUG(
"CSCSimHitCollection found with " << hitCollection->size() <<
" hits");
464 return StatusCode::SUCCESS;
468 TimedHitCollList hitCollList;
472 return StatusCode::FAILURE;
474 if (hitCollList.empty()) {
476 return StatusCode::FAILURE;
487 TimedHitCollList::iterator iColl(hitCollList.begin());
488 TimedHitCollList::iterator endColl(hitCollList.end());
489 while (iColl != endColl) {
491 m_thpcCSC->insert(iColl->first, p_collection);
493 << p_collection->
size() <<
" hits" );
496 return StatusCode::SUCCESS;
506 ATH_MSG_DEBUG(
"CscDigitizationTool::processBunchXing() " << bunchXing);
509 TimedHitCollList hitCollList;
512 bSubEvents, eSubEvents).isSuccess()) &&
513 hitCollList.empty()) {
515 return StatusCode::FAILURE;
517 ATH_MSG_VERBOSE(hitCollList.size() <<
" CSCSimHitCollection with key " <<
521 TimedHitCollList::iterator iColl(hitCollList.begin());
522 TimedHitCollList::iterator endColl(hitCollList.end());
525 for( ; iColl != endColl; ++iColl){
533 <<
" index: " << timeIndex.
index()
534 <<
" type: " << timeIndex.
type());
536 m_thpcCSC->insert(timeIndex, hitCollPtr);
541 return StatusCode::SUCCESS;
556 ATH_CHECK(cscSimData.
record(std::make_unique<CscSimDataCollection>()));
559 rngWrapper->
setSeed( name(), ctx );
563 for (
size_t coll_hash = 0; coll_hash < collections.size(); ++coll_hash) {
564 if (collections[coll_hash]) {
565 ATH_CHECK( cscDigits->addCollection (collections[coll_hash].release(), coll_hash) );
570 std::list<CSCSimHitCollection*>::iterator cscHitColl =
m_cscHitCollList.begin();
571 std::list<CSCSimHitCollection*>::iterator cscHitCollEnd =
m_cscHitCollList.end();
572 while(cscHitColl!=cscHitCollEnd)
574 delete (*cscHitColl);
579 return StatusCode::SUCCESS;
float hitTime(const AFP_SIDSimHit &hit)
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
AtlasHitsVector< CSCSimHit > CSCSimHitCollection
defines an "iterator" over instances of a given type in StoreGateSvc
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.
const Amg::Vector3D & getHitEnd() const
double globalTime() const
const Amg::Vector3D & getHitStart() const
double energyDeposit() const
std::string print() const
static const CscHitIdHelper * GetHelper()
const T * get(size_type n) const
Access an element, as an rvalue.
value_type push_back(value_type pElem)
Add an element to the end of the collection.
a link optimized in size for a GenParticle in a McEventCollection
static HepMcParticleLink getRedirectedLink(const HepMcParticleLink &particleLink, uint32_t eventIndex, const EventContext &ctx)
Return a HepMcParticleLink pointing at the same particle, but in a different GenEvent.
This class saves the "context" of an expanded identifier (ExpandedIdentifier) for compact or hash ver...
size_type begin_index() const
size_type end_index() const
This is a "hash" representation of an Identifier.
void show() const
Print out in hex form.
The MuonDetectorManager stores the transient representation of the Muon Spectrometer geometry and pro...
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
virtual const std::string & key() const override final
Return the StoreGate ID for the referenced object.
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.
TimedVector::const_iterator const_iterator
a smart pointer to a hit that also provides access to the extended timing info of the host event.
unsigned short eventId() const
the index of the component event in PileUpEventInfo.
bool ignoreTruthLink(const T &p, bool vetoPileUp)
Helper function for SDO creation in PileUpTools.
Ensure that the Athena extensions are properly loaded.
std::list< value_t > type
type of the collection of timed data object
a struct encapsulating the identifier of a pile-up event
index_type index() const
the index of the component event in PileUpEventInfo
PileUpType type() const
the pileup type - minbias, cavern, beam halo, signal?
time_type time() const
bunch xing time in ns