5 #include "GaudiKernel/ConcurrencyFlags.h"
14 std::shared_ptr<PadOfflineData>
t_pad;
27 using PAD_MAP=std::map < Identifier,std::vector<PadHits> >;
36 declareInterface<NSWL1::IPadTdsTool>(
this);
49 ATH_MSG_DEBUG(
" " << std::setw(32) << std::setfill(
'.') << std::setiosflags(std::ios::left) <<
m_doNtuple.name() << ((
m_doNtuple)?
"[True]":
"[False]")<< std::setfill(
' ') << std::setiosflags(std::ios::right) );
55 const INamedInterface* pnamed =
dynamic_cast<const INamedInterface*
>(
parent);
56 const std::string& algo_name = pnamed->name();
59 if (Gaudi::Concurrency::ConcurrencyFlags::numConcurrentEvents() > 1) {
60 ATH_MSG_ERROR(
"DoNtuple is not possible in multi-threaded mode");
61 return StatusCode::FAILURE;
68 if ( algo_name==
"NSWL1Simulation" ) {
69 SmartIF<ITHistSvc> tHistSvc{service(
"THistSvc")};
72 TTree *
tree =
nullptr;
73 std::string
treename = algo_name+
"Tree";
88 return StatusCode::SUCCESS;
92 if( inc.type()==IncidentType::BeginEvent ) {
107 double localPosX(
d.second.firstEntry()), localPosY(
d.second.secondEntry());
110 s.localToGlobal(localPos, globalPos, globalPos);
115 float bin_offset = +0.;
116 for (
const std::vector<std::shared_ptr<PadData>>& pad : pad_cache) {
117 m_validation_tree->fill_num_pad_hits(pad.size());
118 for (
const std::shared_ptr<PadData> &
pd : pad) {
127 ATH_MSG_DEBUG(
"Pad at GposX " << pad_gpos.x() <<
" GposY " << pad_gpos.y() <<
" GposZ " << pad_gpos.z()
128 <<
" from multiplet "<<
pd->multipletId()<<
" and gasGapId "<<
pd->gasGapId() );
130 std::vector<MuonSimData::Deposit> deposits;
131 if(get_truth_hits_this_pad(Id, deposits)){
132 for(
const auto&
d : deposits) {
138 std::array<Amg::Vector2D, 4> local_pad_corners{make_array<Amg::Vector2D, 4>(
Amg::Vector2D::Zero())};
140 std::vector<Amg::Vector3D> global_pad_corners;
141 for(
const auto& local_corner : local_pad_corners) {
143 surface.
localToGlobal(local_corner, global_corner, global_corner);
144 global_pad_corners.push_back(global_corner);
146 m_validation_tree->fill_hit_global_corner_pos(global_pad_corners);
150 m_validation_tree->fill_hit_global_pos(pad_gpos);
151 m_validation_tree->fill_offlineid_info(*pad_offline, bin_offset);
154 return StatusCode::SUCCESS;
158 ATH_MSG_DEBUG(
"gather_pad_data: start gathering the PAD hits for side " <<
side <<
", sector " << sector );
160 if ( side <-1 || side >1 ) {
161 ATH_MSG_ERROR(
"requested side " <<
side <<
" is out of range: [-1==All, 0==side C, 1==side A]");
162 return StatusCode::FAILURE;
165 if ( sector <-1 || sector >15 ) {
166 ATH_MSG_ERROR(
"requested sector " << sector <<
" is out of range: [-1==All, 0 - 15]");
167 return StatusCode::FAILURE;
179 const bool anySide = (
side==-1);
180 const bool anySector = (sector==-1);
181 if (anySide && anySector) {
185 std::vector<std::shared_ptr<PadData>>& pad_sec = pad_cache.at(
i);
186 pads.insert( pads.end(), std::make_move_iterator(pad_sec.begin()), std::make_move_iterator(pad_sec.end()));
189 else if (anySector and not anySide) {
195 std::vector<std::shared_ptr<PadData>>& pad_sec = pad_cache.at(
i);
196 pads.insert( pads.end(), std::make_move_iterator(pad_sec.begin()), std::make_move_iterator(pad_sec.end()));
199 else if (anySide and not anySector) {
201 ATH_MSG_DEBUG(
"copying the PAD hit set of all trigger sector " << sector <<
" in both side" );
203 std::vector<std::shared_ptr<PadData>>& pad_secA = pad_cache.at(sectorA);
204 pads.insert( pads.end(), std::make_move_iterator(pad_secA.begin()), std::make_move_iterator(pad_secA.end()));
207 std::vector<std::shared_ptr<PadData>>& pad_secC = pad_cache.at(sectorC);
208 pads.insert( pads.end(), std::make_move_iterator(pad_secC.begin()), std::make_move_iterator(pad_secC.end()));
212 ATH_MSG_DEBUG(
"copying the PAD hit set of all trigger sector "<<sector
215 std::vector<std::shared_ptr<PadData>>& pad_secAorC = pad_cache.at(sectorAorC);
216 pads.insert( pads.end(), std::make_move_iterator(pad_secAorC.begin()), std::make_move_iterator(pad_secAorC.end()));
218 ATH_MSG_DEBUG(
"delivered n. " << pads.size() <<
" PAD hits." );
220 return StatusCode::SUCCESS;
225 if(!digit_container.
isValid()){
226 ATH_MSG_ERROR(
"could not retrieve the sTGC Digit container: cannot return the STRIP hits");
227 return StatusCode::FAILURE;
235 std::vector<PadHits> pad_hits;
236 uint16_t BC0 = 0, BCP1 = 1, BCP2 = 2, BCP3 = 3, BCP4 = 4, BCM1 = ~BCP1, BCM2 = ~BCP2, BCM3 = ~BCP3;
237 std::vector<uint16_t> bcWindow={BC0, BCP1, BCP2, BCP3, BCP4, BCM1, BCM2, BCM3};
239 for(;
it!=it_e; ++
it) {
247 if (
std::find(bcWindow.begin(), bcWindow.end(),
digit->bcTag()) != bcWindow.end()){
265 return StatusCode::SUCCESS;
276 double distance = std::sqrt( pad_gpos.x()*pad_gpos.x() +
277 pad_gpos.y()*pad_gpos.y() +
278 pad_gpos.z()*pad_gpos.z() );
284 CLHEP::HepRandomEngine * engine = rngWrapper->
getEngine(Gaudi::Hive::currentContext());
285 return CLHEP::RandGauss::shoot(engine, 0,
m_timeJitter);
292 for (
unsigned int i=0;
i<
h.size();
i++) {
295 if (
it!=channel_map.end() ) {
296 (*it).second.push_back(
h[
i]);
298 std::vector<PadHits>
tmp;
306 while (
it!=channel_map.end() ) {
307 std::vector<PadHits>&
hits = (*it).second;
310 while ( p_next!=
hits.end() ) {
311 if (std::fabs((*p_next).t_pad->time()-(*p).t_pad->time())<=
m_vmmDeadTime){
312 p_next =
hits.erase(p_next);
320 it = channel_map.begin();
321 while (
it!=channel_map.end() ) {
322 std::vector<PadHits>
hits = (*it).second;
336 int stationEta =
m_idHelperSvc->stgcIdHelper().stationEta(Id);
337 int stationPhi =
m_idHelperSvc->stgcIdHelper().stationPhi(Id);
339 int isSmall = stName[2] ==
'S';
340 int trigger_sector = (isSmall)? stationPhi*2-1 : stationPhi*2-2;
341 return (stationEta>0)? trigger_sector + 16 : trigger_sector;
347 double &delayed_time,
uint16_t &BCtag)
const
349 bool success =
false;
350 if(!
digit)
return success;
352 double arrival_time =
digit->time();
353 delayed_time = arrival_time;
357 if((delayed_time>200 || delayed_time<-200) ||
358 (capture_time>200 || capture_time<-200) ){
359 ATH_MSG_WARNING(
"sTGC Pad hit "<<pad_hit_number<<
" time outside of the range -200 ns / +200 ns,"
361 ATH_MSG_WARNING(
"sTGC Pad hit "<<pad_hit_number<<
": delayed time ["<<delayed_time<<
" ns]"
362 " capture time ["<<capture_time<<
" ns]");
365 for (
unsigned int i=0;
i<16;
i++) {
366 double bunch_start =
i*25;
367 double bunch_stop = (
i+1)*25;
368 double signal_start = delayed_time + 200;
369 double signal_stop = capture_time + 200;
370 if ((signal_start>=bunch_start && signal_start<bunch_stop) ||
371 (signal_stop>=bunch_start && signal_stop<bunch_stop) ){
372 BCtag = BCtag | (0x1<<
i);
375 if(bunch_start>=signal_start && bunch_stop<signal_stop){
376 BCtag = BCtag | (0x1<<
i);
379 std::string bctag =
"";
381 for(
unsigned int i=0;
i<16;
i++) {
382 if(BCtag & (last_bit>>
i)) bctag +=
"1";
385 ATH_MSG_DEBUG(
"sTGC Pad hit " << pad_hit_number <<
": arrival time [" << arrival_time <<
" ns]"
386 <<
" delayed time [" << delayed_time <<
" ns]"
387 <<
" capture time [" << capture_time <<
" ns]"
388 <<
" BC tag [" << bctag <<
"]" );
400 ATH_MSG_WARNING(
"could not retrieve the sTGC SDO container: it will not be possible to associate the MC truth");
403 ptrMuonSimDataCollection = sdo_container.
cptr();
413 for (
unsigned int i=0;
i<pad_hits.size();
i++) {
414 const std::vector<std::shared_ptr<PadData>>& pads = pad_cache.at(pad_hits[
i].t_cache_index);
415 bool fill = pads.empty();
416 for(
unsigned int p=0;
p<pads.size();
p++) {
418 if(Id==pad_hits[
i].t_id) {
420 ATH_MSG_WARNING(
"Pad Hits entered multiple times Discarding!!! Id:" << Id );
423 if(
fill ) pad_cache.at(pad_hits[
i].t_cache_index).push_back(pad_hits[
i].t_pad);
432 int stationEta =
m_idHelperSvc->stgcIdHelper().stationEta(Id);
433 int stationPhi =
m_idHelperSvc->stgcIdHelper().stationPhi(Id);
434 int multiplet =
m_idHelperSvc->stgcIdHelper().multilayer(Id);
443 <<
" Station Name [" <<stName <<
"]"
444 <<
" Station Eta [" <<stationEta <<
"]"
445 <<
" Station Phi [" <<stationPhi <<
"]"
446 <<
" Multiplet [" <<multiplet <<
"]"
447 <<
" GasGap [" <<gas_gap <<
"]"
450 <<
" Pad Eta [" <<pad_eta <<
"]"
451 <<
" Pad Phi [" <<pad_phi <<
"]"
452 <<
" BCTag [" <<
digit->bcTag() <<
"]"
453 <<
" Id Hash [" <<Id <<
"]");
458 for (
const auto &hit : pad_hits)
ATH_MSG_DEBUG(
"pad hit has time "<< hit.t_pad->time());
463 for (
const std::vector<std::shared_ptr<PadData>>& pad : pad_cache) {
464 for (
const auto &
padhit : pad)
466 <<
", trigger sector " <<
padhit->sectorId()
467 <<
", module " <<
padhit->moduleId()
468 <<
", multiplet " <<
padhit->multipletId()
469 <<
", gas gap " <<
padhit->gasGapId()
470 <<
", pad eta " <<
padhit->padEtaId()
471 <<
", pad phi " <<
padhit->padPhiId());