ATLAS Offline Software
HitWrapper.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include <cmath>
6 #include <iostream>
7 #include <cstdlib>
8 
9 #include "HitWrapper.h"
10 #include "G4Step.hh"
11 
12 #include "StoreGate/WriteHandle.h"
13 
21 
24 
25 
26 namespace G4UA
27 {
28 
29  //---------------------------------------------------------------------------
31  : AthMessaging(Gaudi::svcLocator()->service<IMessageSvc>("MessageSvc"),
32  "HitWrapper"),
33  m_evtStore("StoreGateSvc/StoreGateSvc","HitWrapper"),
34  m_detStore("StoreGateSvc/DetectorStore","HitWrapper"),
35  m_config(config)
36  {}
37 
38  //---------------------------------------------------------------------------
39  void HitWrapper::EndOfEventAction(const G4Event*)
40  {
41 
47  SG::WriteHandle<MMSimHitCollection> mmhits("MM_Hits");
48  SG::WriteHandle<sTGCSimHitCollection> stgc("sTGC_Hits");
49 
50  if (!csc.isValid() ) ATH_MSG_WARNING( " HitWrapper could not access csc hit collection" );
51  else {
52  // std::cout << "Working on a collection of size " << cscC->size() << std::endl;
53  //CSCSimHitCollection * csc = const_cast< CSCSimHitCollection * > (&(*cscC));
54  for (CSCSimHitCollection::iterator hit=csc->begin();hit!=csc->end();++hit){
55  //std::cout << "Wrapping CSC hit with time " << (*hit).globalTime() << std::endl;
56  (*hit).setGlobalTime( fmod( (*hit).globalTime() , m_config.time ) );
57  }
58  }
59 
60  if ( ! mdt.isValid() ) ATH_MSG_WARNING( " HitWrapper could not access mdt hit collection" );
61  else {
62  // std::cout << "Working on a collection of size " << mdtC->size() << std::endl;
63  //MDTSimHitCollection * mdt = const_cast< MDTSimHitCollection * > (&(*mdtC));
64  for (MDTSimHitCollection::iterator hit=mdt->begin();hit!=mdt->end();++hit){
65  //std::cout << "Wrapping MDT hit with time " << (*hit).globalTime() << std::endl;
66  (*hit).setGlobalTime( fmod( (*hit).globalTime() , m_config.time ) );
67  }
68  }
69 
70  if (! rpc.isValid() ) ATH_MSG_WARNING( " HitWrapper could not access rpc hit collection" );
71  else {
72  // std::cout << "Working on a collection of size " << rpcC->size() << std::endl;
73  //RPCSimHitCollection * rpc = const_cast< RPCSimHitCollection * > (&(*rpcC));
74  for (RPCSimHitCollection::iterator hit=rpc->begin();hit!=rpc->end();++hit){
75  //std::cout << "Wrapping RPC hit with time " << (*hit).globalTime() << std::endl;
76  (*hit).setGlobalTime( fmod( (*hit).globalTime() , m_config.time ) );
77  }
78  }
79 
80 
81  if (! tgc.isValid() ) ATH_MSG_WARNING( " HitWrapper could not access tgc hit collection" );
82  else {
83  // std::cout << "Working on a collection of size " << tgcC->size() << std::endl;
84  //TGCSimHitCollection * tgc = const_cast< TGCSimHitCollection * > (&(*tgcC));
85  for (TGCSimHitCollection::iterator hit=tgc->begin();hit!=tgc->end();++hit){
86  //std::cout << "Wrapping TGC hit with time " << (*hit).globalTime() << std::endl;
87  (*hit).setGlobalTime( fmod( (*hit).globalTime() , m_config.time ) );
88  }
89  }
90 
91 
93  if (! mmhits.isValid() ) ATH_MSG_WARNING( " HitWrapper could not access Micromegas hit collection" );
94  else {
95  // std::cout << "Working on a collection of size " << nswC->size() << std::endl;
96  //GenericMuonSimHitCollection *mm = const_cast< GenericMuonSimHitCollection * > (&(*mmC));
97  for (MMSimHitCollection::iterator hit=mmhits->begin();hit!=mmhits->end();++hit){
98  //std::cout << "Wrapping GenericMuon hit with time " << (*hit).globalTime() << std::endl;
99  (*hit).setGlobalTime( fmod( (*hit).globalTime() , m_config.time ) );
100  }
101  }
102 
103  if (! stgc.isValid() ) ATH_MSG_WARNING( " HitWrapper could not access sTGC hit collection" );
104  else {
105  // std::cout << "Working on a collection of size " << nswC->size() << std::endl;
106  //GenericMuonSimHitCollection *stgc = const_cast< GenericMuonSimHitCollection * > (&(*stgcC));
107  for (sTGCSimHitCollection::iterator hit=stgc->begin();hit!=stgc->end();++hit){
108  //std::cout << "Wrapping GenericMuon hit with time " << (*hit).globalTime() << std::endl;
109  (*hit).setGlobalTime( fmod( (*hit).globalTime() , m_config.time ) );
110  }
111  }
112 
113  // Handle the inner detector next
114  SG::WriteHandle<TRTUncompressedHitCollection> trt("TRTUncompressedHits");
116  SG::WriteHandle<SiHitCollection> sct("SCT_Hits");
117 
118  if (! trt.isValid() ) ATH_MSG_WARNING( " HitWrapper could not access trt hit collection" );
119  else {
120  //TRTUncompressedHitCollection * trt = const_cast< TRTUncompressedHitCollection * > (&*trtC);
121  for (TRTUncompressedHitCollection::iterator hit=trt->begin();hit!=trt->end();++hit){
122  //std::cout << "Wrapping TRT hit with time " << (*hit).globalTime() << std::endl;
123  (*hit).SetGlobalTime( std::fmod( (*hit).GetGlobalTime() , m_config.time ) );
124  }
125  }
126 
127  if (! pix.isValid()) ATH_MSG_WARNING( " HitWrapper could not access pix hit collection" );
128  else {
129  //SiHitCollection * pix = const_cast<SiHitCollection *> (&*pixC);
130  for (SiHitCollection::iterator hit=pix->begin();hit!=pix->end();++hit){
131  //std::cout << "Wrapping Pix hit with time " << (*hit).meanTime() << std::endl;
132  (*hit).setMeanTime( fmod( (*hit).meanTime() , m_config.time ) );
133  }
134  }
135 
136  if (! sct.isValid() ) ATH_MSG_WARNING( " HitWrapper could not access sct hit collection" );
137  else {
138  //SiHitCollection * sct = const_cast<SiHitCollection *> (&*sctC);
139  for (SiHitCollection::iterator hit=sct->begin();hit!=sct->end();++hit){
140  //std::cout << "Wrapping SCT hit with time " << (*hit).meanTime() << std::endl;
141  (*hit).setMeanTime( fmod( (*hit).meanTime() , m_config.time ) );
142  }
143  }
144 
145  }
146 
147 } // namespace G4UA
G4UA
for nSW
Definition: CalibrationDefaultProcessing.h:19
HitWrapper.h
CSCSimHitCollection.h
AtlasHitsVector::iterator
CONT::iterator iterator
Definition: AtlasHitsVector.h:42
sTGCSimHitCollection.h
G4UA::HitWrapper::EndOfEventAction
virtual void EndOfEventAction(const G4Event *) override
Definition: HitWrapper.cxx:39
AtlasHitsVector::begin
const_iterator begin() const
Definition: AtlasHitsVector.h:131
G4UA::HitWrapper::m_config
Config m_config
Definition: HitWrapper.h:38
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
WriteHandle.h
Handle class for recording to StoreGate.
G4UA::HitWrapper::Config
Definition: HitWrapper.h:23
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition: AthMessaging.h:55
G4UA::HitWrapper::HitWrapper
HitWrapper(const Config &config)
Definition: HitWrapper.cxx:30
RPCSimHitCollection.h
MDTSimHitCollection.h
SG::WriteHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
MMSimHitCollection.h
TGCSimHitCollection.h
G4UA::HitWrapper::Config::time
float time
Definition: HitWrapper.h:24
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
TRTUncompressedHitCollection.h
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
AtlasHitsVector::end
const_iterator end() const
Definition: AtlasHitsVector.h:134
Gaudi
=============================================================================
Definition: CaloGPUClusterAndCellDataMonitorOptions.h:273
pix
Definition: PixelMapping.cxx:16
SiHitCollection.h