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 \n" << elementId);
275 double stripCharge = 0.0;
276 double driftTime = 0.0;
277 const std::vector<float> samples = (*cscMap).second;
279 unsigned int samplingPhase =0;
280 double samplingTime =
m_pcalib->getSamplingTime();
281 m_pcalib->findCharge(samplingTime, samplingPhase, samples, stripCharge, driftTime);
282 driftTime +=
m_pcalib->getLatency();
291 int phisec =
m_idHelperSvc->cscIdHelper().stationPhi(digitId);
292 int istation =
m_idHelperSvc->cscIdHelper().stationName(digitId) - 49;
295 int measphi =
m_idHelperSvc->cscIdHelper().measuresPhi(digitId);
298 int sector = zsec*(2*phisec-istation+1);
300 auto depositsForHash = myDeposits.find(hashId);
301 if (depositsForHash != myDeposits.end() && !depositsForHash->second.empty()) {
302 depositsForHash->second[0].second.setCharge(stripCharge);
303 cscSimData->insert ( std::make_pair(digitId,
CscSimData(depositsForHash->second,0)) );
309 ATH_MSG_DEBUG (
"NEWDigit sec:measphi:wlay:istr:chg:t(w/latency) "
310 <<
m_idHelperSvc->cscIdHelper().show_to_string(digitId,&context)
311 <<
" hash:eleId = " << hashId <<
" " << elementId <<
" " << prevId <<
" "
312 << sector <<
" " << measphi <<
" " << wlay <<
" " << istrip <<
" "
313 <<
int(stripCharge+1) <<
" " <<
float(driftTime)
314 <<
" phase=" << phaseToSet
315 <<
" samps: " << samples[0] <<
" " << samples[1] <<
" "
316 << samples[2] <<
" " << samples[3]
319 if (prevId != elementId) {
320 if (coll_hash >= collections.size()) {
321 collections.resize (coll_hash+1);
323 collection = collections[coll_hash].
get();
324 if (
nullptr == collection) {
325 collections[coll_hash] = std::make_unique<CscDigitCollection>(elementId,coll_hash);
326 collection = collections[coll_hash].
get();
329 collection->
push_back (std::make_unique<CscDigit>(digitId, samples));
336 return StatusCode::FAILURE;
340 collection->
push_back (std::make_unique<CscDigit>(digitId, samples));
343 return StatusCode::SUCCESS;
355 csc_map::const_iterator cscMap = data_map.begin();
356 csc_map::const_iterator cscMapEnd = data_map.end();
357 for (; cscMap != cscMapEnd; ++cscMap) {
360 if (
m_idHelperSvc->cscIdHelper().get_id( hashId, digitId, &context ) ) {
361 ATH_MSG_ERROR (
"cannot get CSC channel identifier from hash " << hashId );
362 return StatusCode::FAILURE;
366 double stripCharge = 0.0;
367 stripCharge = ((*cscMap).second).second +
m_pedestal;
368 double driftTime =((*cscMap).second).first;
377 <<
" hash = " << hashId
378 <<
" charge = " << int (stripCharge+1) );
381 int phisec =
m_idHelperSvc->cscIdHelper().stationPhi(digitId);
382 int istation =
m_idHelperSvc->cscIdHelper().stationName(digitId) - 49;
385 int measphi =
m_idHelperSvc->cscIdHelper().measuresPhi(digitId);
388 int sector = zsec*(2*phisec-istation+1);
390 auto depositsForHash = myDeposits.find(hashId);
391 if (depositsForHash != myDeposits.end() && !depositsForHash->second.empty()) {
392 depositsForHash->second[0].second.setCharge(stripCharge);
393 cscSimData->insert ( std::make_pair(digitId,
CscSimData(depositsForHash->second,0)) );
399 auto newDigit = std::make_unique<CscDigit>(digitId,
int(stripCharge+1),
float(driftTime) );
402 ATH_MSG_DEBUG (
"CSC Digit sector:measphi:wlay:istrip:charge "
404 << measphi <<
" " << wlay <<
" " << istrip
405 <<
" " <<
int(stripCharge+1) <<
" " <<
float(driftTime) <<
" " << (newDigit->sampleCharges()).size());
409 if (
m_idHelperSvc->cscIdHelper().get_hash(elementId, coll_hash, &cscContext)) {
410 ATH_MSG_ERROR (
"Unable to get CSC hash id from CSC Digit collection "
411 <<
"context begin_index = " << cscContext.
begin_index()
412 <<
" context end_index = " << cscContext.
end_index()
413 <<
" the identifier is \n"<< elementId );
416 if (prevId != elementId) {
417 if (coll_hash >= collections.size()) {
418 collections.resize (coll_hash+1);
420 collection = collections[coll_hash].
get();
421 if (
nullptr == collection) {
422 collections[coll_hash] = std::make_unique<CscDigitCollection>(elementId,coll_hash);
423 collection = collections[coll_hash].
get();
425 collection->
push_back(std::move(newDigit));
430 collection->
push_back(std::move(newDigit));
432 ATH_MSG_ERROR(
"Trying to push back NULL CscDigitCollection");
433 return StatusCode::FAILURE;
437 return StatusCode::SUCCESS;
451 if (!hitCollection.
isValid()) {
452 ATH_MSG_ERROR(
"Could not get CSCSimHitCollection container " << hitCollection.
name() <<
" from store " << hitCollection.
store());
453 return StatusCode::FAILURE;
459 ATH_MSG_DEBUG(
"CSCSimHitCollection found with " << hitCollection->size() <<
" hits");
461 return StatusCode::SUCCESS;
465 TimedHitCollList hitCollList;
469 return StatusCode::FAILURE;
471 if (hitCollList.empty()) {
473 return StatusCode::FAILURE;
484 TimedHitCollList::iterator iColl(hitCollList.begin());
485 TimedHitCollList::iterator endColl(hitCollList.end());
486 while (iColl != endColl) {
488 m_thpcCSC->insert(iColl->first, p_collection);
490 << p_collection->
size() <<
" hits" );
493 return StatusCode::SUCCESS;
503 ATH_MSG_DEBUG(
"CscDigitizationTool::processBunchXing() " << bunchXing);
506 TimedHitCollList hitCollList;
509 bSubEvents, eSubEvents).isSuccess()) &&
510 hitCollList.empty()) {
512 return StatusCode::FAILURE;
514 ATH_MSG_VERBOSE(hitCollList.size() <<
" CSCSimHitCollection with key " <<
518 TimedHitCollList::iterator iColl(hitCollList.begin());
519 TimedHitCollList::iterator endColl(hitCollList.end());
522 for( ; iColl != endColl; ++iColl){
530 <<
" index: " << timeIndex.
index()
531 <<
" type: " << timeIndex.
type());
533 m_thpcCSC->insert(timeIndex, hitCollPtr);
538 return StatusCode::SUCCESS;
553 ATH_CHECK(cscSimData.
record(std::make_unique<CscSimDataCollection>()));
556 rngWrapper->
setSeed( name(), ctx );
560 for (
size_t coll_hash = 0; coll_hash < collections.size(); ++coll_hash) {
561 if (collections[coll_hash]) {
562 ATH_CHECK( cscDigits->addCollection (collections[coll_hash].release(), coll_hash) );
567 std::list<CSCSimHitCollection*>::iterator cscHitColl =
m_cscHitCollList.begin();
568 std::list<CSCSimHitCollection*>::iterator cscHitCollEnd =
m_cscHitCollList.end();
569 while(cscHitColl!=cscHitCollEnd)
571 delete (*cscHitColl);
576 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.
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