ATLAS Offline Software
G4HitFilter.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "G4HitFilter.h"
6 
7 #include "G4RunManager.hh"
8 #include "G4Event.hh"
9 
20 
21 #include "StoreGate/ReadHandle.h"
22 
23 #include "GaudiKernel/Bootstrap.h"
24 #include "GaudiKernel/ISvcLocator.h"
25 #include "GaudiKernel/IMessageSvc.h"
26 
27 
28 namespace G4UA
29 {
30 
31  //----------------------------------------------------------------------------
33  : AthMessaging(Gaudi::svcLocator()->service< IMessageSvc >( "MessageSvc" ),
34  "G4HitFilter"),
35  m_config(config)
36  {}
37 
38  //----------------------------------------------------------------------------
39  void G4HitFilter::BeginOfRunAction(const G4Run*)
40  {
41  if(m_config.volumenames.size()==0){
42  ATH_MSG_ERROR("No hit containers declared");
43  }
44 
45  int hitType = 999;
46 
47  for(const auto& vol: m_config.volumenames){
48  if(vol == "BCMHits") hitType = SI;
49  else if(vol == "BLMHits") hitType = SI;
50  else if(vol == "CSC_Hits") hitType = CSC;
51  else if(vol == "LArCalibrationHitActive") hitType = CALOCALIB;
52  else if(vol == "LArCalibrationHitDeadMaterial") hitType = CALOCALIB;
53  else if(vol == "LArCalibrationHitInactive") hitType = CALOCALIB;
54  else if(vol == "LArHitEMB") hitType = LAR;
55  else if(vol == "LArHitEMEC") hitType = LAR;
56  else if(vol == "LArHitFCAL") hitType = LAR;
57  else if(vol == "LArHitHEC") hitType = LAR;
58  else if(vol == "LucidSimHitsVector") hitType = LUCID;
59  else if(vol == "MBTSHits") hitType = TILE;
60  else if(vol == "MDT_Hits") hitType = MDT;
61  else if(vol == "PixelHits") hitType = SI;
62  else if(vol == "RPC_Hits") hitType = RPC;
63  else if(vol == "SCT_Hits") hitType = SI;
64  else if(vol == "TGC_Hits") hitType = TGC;
65  else if(vol == "TRTUncompressedHits") hitType = TRT;
66  else if(vol == "TileHitVec") hitType = TILE;
67 
68  if(hitType == 999){
69  ATH_MSG_ERROR("unknown hit tipe" << vol);
70  }
71 
72  m_hitContainers.push_back( std::make_pair(hitType,vol) );
73  }
74  }
75 
76  //----------------------------------------------------------------------------
77  void G4HitFilter::EndOfEventAction(const G4Event*)
78  {
79  unsigned int counter = 0;
80 
81  m_report.ntot++;
82 
83  for(const auto& hitCont : m_hitContainers) {
84 
85  if(hitCont.first == CALOCALIB) {
87  if(! cont.isValid()) continue;
88  counter += cont->size();
89  }
90  else if(hitCont.first == CSC) {
91  SG::ReadHandle<CSCSimHitCollection> cont(hitCont.second);
92  if(! cont.isValid()) continue;
93  counter += cont->size();
94  }
95  else if(hitCont.first == LAR) {
96  SG::ReadHandle<LArHitContainer> cont(hitCont.second);
97  if(! cont.isValid()) continue;
98  counter += cont->size();
99  }
100  else if(hitCont.first == LUCID) {
101  SG::ReadHandle<LUCID_SimHitCollection> cont(hitCont.second);
102  if(! cont.isValid()) continue;
103  counter += cont->size();
104  }
105  else if(hitCont.first == MDT) {
106  SG::ReadHandle<MDTSimHitCollection> cont(hitCont.second);
107  if(! cont.isValid()) continue;
108  counter += cont->size();
109  }
110  else if(hitCont.first == RPC) {
111  SG::ReadHandle<RPCSimHitCollection> cont(hitCont.second);
112  if(! cont.isValid()) continue;
113  counter += cont->size();
114  }
115  else if(hitCont.first == SI) {
116  SG::ReadHandle<SiHitCollection> cont(hitCont.second);
117  if(! cont.isValid()) continue;
118  counter += cont->size();
119  }
120  else if(hitCont.first == TGC) {
121  SG::ReadHandle<TGCSimHitCollection> cont(hitCont.second);
122  if(! cont.isValid()) continue;
123  counter += cont->size();
124  }
125  else if(hitCont.first == TILE) {
126  SG::ReadHandle<TileHitVector> cont(hitCont.second);
127  if(! cont.isValid()) continue;
128  counter += cont->size();
129  }
130  else if(hitCont.first == TRT) {
132  if(! cont.isValid()) continue;
133  counter += cont->size();
134  }
135  else {
136  continue;
137  }
138 
139  // Require at least one hit from one selected detector volume.
140  if(counter>0) break;
141  }
142 
143  if (counter==0){
144  ATH_MSG_INFO("G4HitFilter: failing the event");
145  G4RunManager::GetRunManager()->AbortEvent();
146  }
147  else {
148  ATH_MSG_INFO("G4HitFilter: passing the event");
149  m_report.npass++;
150  }
151  }
152 
153 } // namespace G4UA
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
G4UA::G4HitFilter::Report::npass
int npass
Definition: G4HitFilter.h:39
G4UA
for nSW
Definition: CalibrationDefaultProcessing.h:19
G4HitFilter.h
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
CSCSimHitCollection.h
G4UA::G4HitFilter::m_config
Config m_config
Definition: G4HitFilter.h:66
G4UA::G4HitFilter::MDT
@ MDT
Definition: G4HitFilter.h:59
CaloCalibrationHitContainer.h
G4UA::G4HitFilter::EndOfEventAction
virtual void EndOfEventAction(const G4Event *) override
Definition: G4HitFilter.cxx:77
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
G4UA::G4HitFilter::LAR
@ LAR
Definition: G4HitFilter.h:57
G4UA::G4HitFilter::TILE
@ TILE
Definition: G4HitFilter.h:63
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
TRT
Definition: HitInfo.h:33
TGC
Definition: TgcBase.h:6
G4UA::G4HitFilter::Config
Definition: G4HitFilter.h:29
G4UA::G4HitFilter::SI
@ SI
Definition: G4HitFilter.h:61
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition: AthMessaging.h:55
RPCSimHitCollection.h
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
G4UA::G4HitFilter::RPC
@ RPC
Definition: G4HitFilter.h:60
G4UA::G4HitFilter::BeginOfRunAction
virtual void BeginOfRunAction(const G4Run *) override
Definition: G4HitFilter.cxx:39
LUCID_SimHitCollection.h
G4UA::G4HitFilter::TGC
@ TGC
Definition: G4HitFilter.h:62
G4UA::G4HitFilter::CALOCALIB
@ CALOCALIB
Definition: G4HitFilter.h:55
MDTSimHitCollection.h
TileHitVector.h
G4UA::G4HitFilter::G4HitFilter
G4HitFilter(const Config &config)
Constructor.
Definition: G4HitFilter.cxx:32
G4UA::G4HitFilter::CSC
@ CSC
Definition: G4HitFilter.h:56
G4UA::G4HitFilter::m_report
Report m_report
Definition: G4HitFilter.h:67
G4UA::G4HitFilter::Report::ntot
int ntot
Definition: G4HitFilter.h:38
TGCSimHitCollection.h
TRTUncompressedHitCollection.h
LArHitContainer.h
G4UA::G4HitFilter::Config::volumenames
std::vector< std::string > volumenames
Definition: G4HitFilter.h:30
Gaudi
=============================================================================
Definition: CaloGPUClusterAndCellDataMonitorOptions.h:273
AthenaHitsVector::size
size_type size() const
Definition: AthenaHitsVector.h:151
AtlasHitsVector::size
size_type size() const
Definition: AtlasHitsVector.h:143
ReadHandle.h
Handle class for reading from StoreGate.
G4UA::G4HitFilter::TRT
@ TRT
Definition: G4HitFilter.h:64
test_pyathena.counter
counter
Definition: test_pyathena.py:15
G4UA::G4HitFilter::m_hitContainers
std::vector< std::pair< int, std::string > > m_hitContainers
A list of (hitContainerTypes, volumeName) pairs, filled in BeginOfRunAction.
Definition: G4HitFilter.h:71
G4UA::G4HitFilter::LUCID
@ LUCID
Definition: G4HitFilter.h:58
SiHitCollection.h