12#include "CLHEP/Random/RandFlat.h"
42 ATH_CHECK(detStore()->retrieve(muDetMgr));
43 ATH_MSG_DEBUG (
"MuonDetectorManager retrieved from StoreGate.");
72 return StatusCode::FAILURE;
84 return StatusCode::SUCCESS;
96 return StatusCode::SUCCESS;
113 ATH_CHECK(cscSimData.
record(std::make_unique<CscSimDataCollection>()));
118 if (StatusCode::FAILURE ==
sc) {
125 rngWrapper->
setSeed( name(), ctx );
129 for (
size_t coll_hash = 0; coll_hash < collections.size(); ++coll_hash) {
130 if (collections[coll_hash]) {
131 ATH_CHECK( cscDigits->addCollection (collections[coll_hash].release(), coll_hash) );
135 return StatusCode::SUCCESS;
140 std::map <IdentifierHash,deposits> myDeposits;
142 csc_newmap data_SampleMap, data_SampleMapOddPhase;
149 return StatusCode::FAILURE;
153 while(
m_thpcCSC->nextDetectorElement(i, e) ) {
166 double globalHitTime(
hitTime(phit));
167 double bunchTime(globalHitTime - hit.
globalTime());
171 ATH_MSG_DEBUG (
"bunch time (ns) " << bunchTime <<
"globalHitTime (ns) " << globalHitTime <<
" hit Time (ns) " <<
hitTime(phit) );
174 std::vector<IdentifierHash> hashVec;
176 ?
m_cscDigitizer->digitize_hit(&hit, hashVec, data_SampleMap, data_SampleMapOddPhase, rndmEngine)
177 :
m_cscDigitizer->digitize_hit(&hit, hashVec, data_map, rndmEngine);
179 if (status.isFailure()) {
184 std::vector<IdentifierHash>::const_iterator vecBeg = hashVec.begin();
185 std::vector<IdentifierHash>::const_iterator vecEnd = hashVec.end();
189 float ypos = -99999.9;
200 if ( dx>0.0 && xi<=0.0 && xf>=0.0 ) {
211 const auto cscd =
CscMcData(energy, ypos, zpos);
212 for (; vecBeg != vecEnd; ++vecBeg) {
213 myDeposits[(*vecBeg)].emplace_back(trackLink,cscd);
228 double flat = CLHEP::RandFlat::shoot(rndmEngine, 0.0,1.0);
229 bool phaseToSet = flat<0.5;
242 std::map<IdentifierHash,deposits>& myDeposits,
253 csc_newmap::const_iterator cscMap = data_SampleMap.begin();
254 csc_newmap::const_iterator cscMapEnd = data_SampleMap.end();
256 for (; cscMap != cscMapEnd; ++cscMap) {
259 if (
m_idHelperSvc->cscIdHelper().get_id( hashId, digitId, &context ) ) {
260 ATH_MSG_ERROR (
"cannot get CSC channel identifier from hash " << hashId );
261 return StatusCode::FAILURE;
266 if (
m_idHelperSvc->cscIdHelper().get_hash(elementId, coll_hash, &cscContext)) {
267 ATH_MSG_ERROR (
"Unable to get CSC hash id from CSC Digit collection "
268 <<
"context begin_index = " << cscContext.
begin_index()
269 <<
" context end_index = " << cscContext.
end_index()
270 <<
" the identifier is " );
276 double stripCharge = 0.0;
277 double driftTime = 0.0;
278 const std::vector<float> samples = (*cscMap).second;
280 unsigned int samplingPhase =0;
281 double samplingTime =
m_pcalib->getSamplingTime();
282 m_pcalib->findCharge(samplingTime, samplingPhase, samples, stripCharge, driftTime);
283 driftTime +=
m_pcalib->getLatency();
292 int phisec =
m_idHelperSvc->cscIdHelper().stationPhi(digitId);
293 int istation =
m_idHelperSvc->cscIdHelper().stationName(digitId) - 49;
296 int measphi =
m_idHelperSvc->cscIdHelper().measuresPhi(digitId);
299 int sector = zsec*(2*phisec-istation+1);
301 auto depositsForHash = myDeposits.find(hashId);
302 if (depositsForHash != myDeposits.end() && !depositsForHash->second.empty()) {
303 depositsForHash->second[0].second.setCharge(stripCharge);
304 cscSimData->insert ( std::make_pair(digitId,
CscSimData(depositsForHash->second,0)) );
310 ATH_MSG_DEBUG (
"NEWDigit sec:measphi:wlay:istr:chg:t(w/latency) "
311 <<
m_idHelperSvc->cscIdHelper().show_to_string(digitId,&context)
312 <<
" hash:eleId = " << hashId <<
" " << elementId <<
" " << prevId <<
" "
313 << sector <<
" " << measphi <<
" " << wlay <<
" " << istrip <<
" "
314 <<
int(stripCharge+1) <<
" " <<
float(driftTime)
315 <<
" phase=" << phaseToSet
316 <<
" samps: " << samples[0] <<
" " << samples[1] <<
" "
317 << samples[2] <<
" " << samples[3]
320 if (prevId != elementId) {
321 if (coll_hash >= collections.size()) {
322 collections.resize (coll_hash+1);
324 collection = collections[coll_hash].
get();
325 if (
nullptr == collection) {
326 collections[coll_hash] = std::make_unique<CscDigitCollection>(elementId,coll_hash);
327 collection = collections[coll_hash].
get();
330 collection->
push_back (std::make_unique<CscDigit>(digitId, samples));
337 return StatusCode::FAILURE;
341 collection->
push_back (std::make_unique<CscDigit>(digitId, samples));
344 return StatusCode::SUCCESS;
356 csc_map::const_iterator cscMap = data_map.begin();
357 csc_map::const_iterator cscMapEnd = data_map.end();
358 for (; cscMap != cscMapEnd; ++cscMap) {
361 if (
m_idHelperSvc->cscIdHelper().get_id( hashId, digitId, &context ) ) {
362 ATH_MSG_ERROR (
"cannot get CSC channel identifier from hash " << hashId );
363 return StatusCode::FAILURE;
367 double stripCharge = 0.0;
368 stripCharge = ((*cscMap).second).second +
m_pedestal;
369 double driftTime =((*cscMap).second).first;
378 <<
" hash = " << hashId
379 <<
" charge = " << int (stripCharge+1) );
382 int phisec =
m_idHelperSvc->cscIdHelper().stationPhi(digitId);
383 int istation =
m_idHelperSvc->cscIdHelper().stationName(digitId) - 49;
386 int measphi =
m_idHelperSvc->cscIdHelper().measuresPhi(digitId);
389 int sector = zsec*(2*phisec-istation+1);
391 auto depositsForHash = myDeposits.find(hashId);
392 if (depositsForHash != myDeposits.end() && !depositsForHash->second.empty()) {
393 depositsForHash->second[0].second.setCharge(stripCharge);
394 cscSimData->insert ( std::make_pair(digitId,
CscSimData(depositsForHash->second,0)) );
400 auto newDigit = std::make_unique<CscDigit>(digitId,
int(stripCharge+1),
float(driftTime) );
403 ATH_MSG_DEBUG (
"CSC Digit sector:measphi:wlay:istrip:charge "
405 << measphi <<
" " << wlay <<
" " << istrip
406 <<
" " <<
int(stripCharge+1) <<
" " <<
float(driftTime) <<
" " << (newDigit->sampleCharges()).size());
410 if (
m_idHelperSvc->cscIdHelper().get_hash(elementId, coll_hash, &cscContext)) {
411 ATH_MSG_ERROR (
"Unable to get CSC hash id from CSC Digit collection "
412 <<
"context begin_index = " << cscContext.
begin_index()
413 <<
" context end_index = " << cscContext.
end_index()
414 <<
" the identifier is " );
418 if (prevId != elementId) {
419 if (coll_hash >= collections.size()) {
420 collections.resize (coll_hash+1);
422 collection = collections[coll_hash].
get();
423 if (
nullptr == collection) {
424 collections[coll_hash] = std::make_unique<CscDigitCollection>(elementId,coll_hash);
425 collection = collections[coll_hash].
get();
427 collection->
push_back(std::move(newDigit));
432 collection->
push_back(std::move(newDigit));
434 ATH_MSG_ERROR(
"Trying to push back NULL CscDigitCollection");
435 return StatusCode::FAILURE;
439 return StatusCode::SUCCESS;
453 if (!hitCollection.
isValid()) {
454 ATH_MSG_ERROR(
"Could not get CSCSimHitCollection container " << hitCollection.
name() <<
" from store " << hitCollection.
store());
455 return StatusCode::FAILURE;
461 ATH_MSG_DEBUG(
"CSCSimHitCollection found with " << hitCollection->size() <<
" hits");
463 return StatusCode::SUCCESS;
467 TimedHitCollList hitCollList;
471 return StatusCode::FAILURE;
473 if (hitCollList.empty()) {
475 return StatusCode::FAILURE;
486 TimedHitCollList::iterator iColl(hitCollList.begin());
487 TimedHitCollList::iterator endColl(hitCollList.end());
488 while (iColl != endColl) {
490 m_thpcCSC->insert(iColl->first, p_collection);
492 << p_collection->
size() <<
" hits" );
495 return StatusCode::SUCCESS;
505 ATH_MSG_DEBUG(
"CscDigitizationTool::processBunchXing() " << bunchXing);
508 TimedHitCollList hitCollList;
511 bSubEvents, eSubEvents).isSuccess()) &&
512 hitCollList.empty()) {
514 return StatusCode::FAILURE;
516 ATH_MSG_VERBOSE(hitCollList.size() <<
" CSCSimHitCollection with key " <<
520 TimedHitCollList::iterator iColl(hitCollList.begin());
521 TimedHitCollList::iterator endColl(hitCollList.end());
524 for( ; iColl != endColl; ++iColl){
532 <<
" index: " << timeIndex.
index()
533 <<
" type: " << timeIndex.
type());
535 m_thpcCSC->insert(timeIndex, hitCollPtr);
540 return StatusCode::SUCCESS;
555 ATH_CHECK(cscSimData.
record(std::make_unique<CscSimDataCollection>()));
558 rngWrapper->
setSeed( name(), ctx );
562 for (
size_t coll_hash = 0; coll_hash < collections.size(); ++coll_hash) {
563 if (collections[coll_hash]) {
564 ATH_CHECK( cscDigits->addCollection (collections[coll_hash].release(), coll_hash) );
569 std::list<CSCSimHitCollection*>::iterator cscHitColl =
m_cscHitCollList.begin();
570 std::list<CSCSimHitCollection*>::iterator cscHitCollEnd =
m_cscHitCollList.end();
571 while(cscHitColl!=cscHitCollEnd)
573 delete (*cscHitColl);
578 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
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(std::ostream &out=std::cout) 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