ATLAS Offline Software
Public Member Functions | Private Member Functions | Private Attributes | List of all members
G4UA::MaterialStepRecorder Class Reference

#include <MaterialStepRecorder.h>

Inheritance diagram for G4UA::MaterialStepRecorder:
Collaboration diagram for G4UA::MaterialStepRecorder:

Public Member Functions

 MaterialStepRecorder ()
 
virtual void BeginOfEventAction (const G4Event *) override
 
virtual void EndOfEventAction (const G4Event *) override
 
virtual void BeginOfRunAction (const G4Run *) override
 
virtual void UserSteppingAction (const G4Step *) override
 
bool msgLvl (const MSG::Level lvl) const
 Test the output level. More...
 
MsgStream & msg () const
 The standard message stream. More...
 
MsgStream & msg (const MSG::Level lvl) const
 The standard message stream. More...
 
void setLevel (MSG::Level lvl)
 Change the current logging level. More...
 

Private Member Functions

void initMessaging () const
 Initialize our message level and MessageSvc. More...
 

Private Attributes

ServiceHandle< StoreGateSvcm_evtStore
 Pointer to StoreGate (event store by default) More...
 
Trk::MaterialStepCollectionm_matStepCollection
 
std::string m_matStepCollectionName
 
bool m_recordComposition
 
size_t m_totalSteps
 
size_t m_eventID
 
Trk::ElementTablem_elementTable
 
std::string m_elementTableName
 
Trk::ElementTablem_runElementTable
 
std::string m_nm
 Message source name. More...
 
boost::thread_specific_ptr< MsgStream > m_msg_tls
 MsgStream instance (a std::cout like with print-out levels) More...
 
std::atomic< IMessageSvc * > m_imsg { nullptr }
 MessageSvc pointer. More...
 
std::atomic< MSG::Level > m_lvl { MSG::NIL }
 Current logging level. More...
 
std::atomic_flag m_initialized ATLAS_THREAD_SAFE = ATOMIC_FLAG_INIT
 Messaging initialized (initMessaging) More...
 

Detailed Description

Definition at line 38 of file MaterialStepRecorder.h.

Constructor & Destructor Documentation

◆ MaterialStepRecorder()

MaterialStepRecorder::MaterialStepRecorder ( )

Definition at line 33 of file MaterialStepRecorder.cxx.

33  :
34  AthMessaging(Gaudi::svcLocator()->service< IMessageSvc >( "MessageSvc" ),"MaterialStepRecorder"),
35  m_evtStore("StoreGateSvc/StoreGateSvc","MaterialStepRecorder"), //FIXME name should be passed in via a Config struct rather than hardcoded.
36  m_matStepCollection(nullptr),
37  m_matStepCollectionName("MaterialStepRecords"), //FIXME should be passed in via a Config struct rather than hardcoded.
38  m_recordComposition(true), //FIXME should be passed in via a Config struct rather than hardcoded.
39  m_totalSteps(0),
40  m_eventID(0),
41  m_elementTable(nullptr),
42  m_elementTableName("ElementTable"),
43  m_runElementTable(nullptr)
44  {
45  }

Member Function Documentation

◆ BeginOfEventAction()

void MaterialStepRecorder::BeginOfEventAction ( const G4Event *  )
overridevirtual

Definition at line 47 of file MaterialStepRecorder.cxx.

48  {
49  ATH_MSG_DEBUG(" BeginOfEventAction");
50 
51  // create a new Collection
53  // m_eventStepLength = 0;
54  }

◆ BeginOfRunAction()

void MaterialStepRecorder::BeginOfRunAction ( const G4Run *  )
overridevirtual

Definition at line 75 of file MaterialStepRecorder.cxx.

76  {
77  ATH_MSG_DEBUG(" BeginOfRunAction");
78 
79  // initialize
80  m_totalSteps = 0;
81  m_eventID = 0;
82  }

◆ EndOfEventAction()

void MaterialStepRecorder::EndOfEventAction ( const G4Event *  )
overridevirtual

Definition at line 56 of file MaterialStepRecorder.cxx.

57  {
58  ATH_MSG_DEBUG(" EndOfEventAction");
59 
60  ++m_eventID;
61  // write the Collection to StoreGate
62  if(m_evtStore->record(m_matStepCollection, m_matStepCollectionName, false).isFailure())
63  {
64  ATH_MSG_ERROR("cannot record step collection to StoreGate");
65  }
66  // write out the ElementTable of this event
67  if ( m_evtStore->record(m_elementTable, m_elementTableName, false).isFailure() )
68  {
69  ATH_MSG_ERROR("EndOfEventAction : recording ElementTable in StoreGate FAILED");
70  delete m_elementTable;
71  }
72  m_elementTable = nullptr;
73  }

◆ initMessaging()

void AthMessaging::initMessaging ( ) const
privateinherited

Initialize our message level and MessageSvc.

This method should only be called once.

Definition at line 39 of file AthMessaging.cxx.

40 {
42  m_lvl = m_imsg ?
43  static_cast<MSG::Level>( m_imsg.load()->outputLevel(m_nm) ) :
44  MSG::INFO;
45 }

◆ msg() [1/2]

MsgStream & AthMessaging::msg ( ) const
inlineinherited

The standard message stream.

Returns a reference to the default message stream May not be invoked before sysInitialize() has been invoked.

Definition at line 164 of file AthMessaging.h.

165 {
166  MsgStream* ms = m_msg_tls.get();
167  if (!ms) {
168  if (!m_initialized.test_and_set()) initMessaging();
169  ms = new MsgStream(m_imsg,m_nm);
170  m_msg_tls.reset( ms );
171  }
172 
173  ms->setLevel (m_lvl);
174  return *ms;
175 }

◆ msg() [2/2]

MsgStream & AthMessaging::msg ( const MSG::Level  lvl) const
inlineinherited

The standard message stream.

Returns a reference to the default message stream May not be invoked before sysInitialize() has been invoked.

Definition at line 179 of file AthMessaging.h.

180 { return msg() << lvl; }

◆ msgLvl()

bool AthMessaging::msgLvl ( const MSG::Level  lvl) const
inlineinherited

Test the output level.

Parameters
lvlThe message level to test against
Returns
boolean Indicating if messages at given level will be printed
Return values
trueMessages at level "lvl" will be printed

Definition at line 151 of file AthMessaging.h.

152 {
153  if (!m_initialized.test_and_set()) initMessaging();
154  if (m_lvl <= lvl) {
155  msg() << lvl;
156  return true;
157  } else {
158  return false;
159  }
160 }

◆ setLevel()

void AthMessaging::setLevel ( MSG::Level  lvl)
inherited

Change the current logging level.

Use this rather than msg().setLevel() for proper operation with MT.

Definition at line 28 of file AthMessaging.cxx.

29 {
30  m_lvl = lvl;
31 }

◆ UserSteppingAction()

void MaterialStepRecorder::UserSteppingAction ( const G4Step *  aStep)
overridevirtual

Definition at line 84 of file MaterialStepRecorder.cxx.

85  {
86  // kill secondaries
87  if (aStep->GetTrack()->GetParentID()) {
88  aStep->GetTrack()->SetTrackStatus(fStopAndKill);
89  return;
90  }
91 
92  // ElementTable preparation
96  }
97 
98  // the material information
99  const G4TouchableHistory* touchHist = static_cast<const G4TouchableHistory*>(aStep->GetPreStepPoint()->GetTouchable());
100  // G4LogicalVolume
101  const G4LogicalVolume *lv= touchHist ? touchHist->GetVolume()->GetLogicalVolume() : nullptr;
102  const G4Material *mat = lv ? lv->GetMaterial() : nullptr;
103 
104  std::vector<unsigned char> elements;
105  std::vector<unsigned char> fractions;
106 
107  // log the information // cut off air
108  if (mat && mat->GetRadlen() < 200000.) {
109 
110  ++m_totalSteps;
111 
112  // the step information
113  double steplength = aStep->GetStepLength();
114 
115  // the position information
116  G4ThreeVector pos = aStep->GetPreStepPoint()->GetPosition();
117 
118  double X0 = mat->GetRadlen();
119  double L0 = mat->GetNuclearInterLength();
120  double A = 0.;
121  double Z = 0.;
122  // double totAtoms = 0.;
123 
124  double rho = mat->GetDensity()*CLHEP::mm3/CLHEP::gram;
125 
126  // get the number of Elements
127  size_t elNumber = mat->GetNumberOfElements();
128  const G4ElementVector* elVector = mat->GetElementVector();
129  double totAtoms = mat->GetTotNbOfAtomsPerVolume();
130 
131  // reserve the right number of elements
132  elements.reserve(elNumber);
133  fractions.reserve(elNumber);
134 
135  if (1 == elNumber) {
136 
137  A = mat->GetA()/CLHEP::gram;
138  Z = mat->GetZ();
139 
140  unsigned int Zint = (unsigned int)Z;
141  // the element and fraction vector
142  elements.push_back(static_cast<unsigned char>(Z));
143  fractions.push_back(UCHAR_MAX);
144  // record the Element
146  // the element Material
147  Trk::Material elMat(X0,L0,A,Z,rho);
148  G4String elName = (*elVector)[0]->GetName();
149  // add it to the table
150  m_elementTable->addElement(elMat, elName);
151  m_runElementTable->addElement(elMat,elName);
152  }
153 
154 
155  } else {
156 
157  const G4double* atVector = mat->GetVecNbOfAtomsPerVolume();
158  double totalFrac = 0.;
159 
160  for (size_t iel = 0; iel < elNumber; ++iel) {
161 
162  const G4Element* currentEl = (*elVector)[iel];
163  double currentNum = atVector ? atVector[iel] : 1.;
164  double relNbAtoms = currentNum/totAtoms;
165 
166  double currentZ = currentEl->GetZ();
167 
168  A += relNbAtoms*currentEl->GetA()/CLHEP::gram;
169  Z += relNbAtoms*currentEl->GetZ();
170  unsigned int Zint = (unsigned int)(currentEl->GetZ());
171 
172  // the element and fraction vector
173  elements.push_back(int(currentZ));
174  // calculate the fraction with a accuracy of 1/256.
175  unsigned int relNbAtomsChar = (unsigned int)(relNbAtoms*(UCHAR_MAX));
176  relNbAtomsChar = relNbAtomsChar > UCHAR_MAX ? UCHAR_MAX : relNbAtomsChar;
177 
178  // smaller components than 0.5 % are automatically ignored
179  totalFrac += relNbAtoms;
180  if (relNbAtomsChar) {
181  fractions.push_back(relNbAtomsChar);
182  // record composition
184  double curA = currentEl->GetA()/CLHEP::gram;
185  double curZ = currentEl->GetZ();
186  // approximate formulas for X0 and L0
187  // X0 from : PH-EP-Tech-Note-2010-013 g/cm3 -> g/mm3
188  // L0 from :
189  double curX0 = 1432.8*curA/(curZ*(curZ+1)*(11.319-std::log(curZ)));
190  double curL0 = 0.;
191  double curRho = rho*relNbAtoms;
192  Trk::Material elMat(curX0,curL0,curA,curZ,curRho);
193  const G4String& elName = currentEl->GetName();
194  // add it to the table
195  m_elementTable->addElement(elMat, elName);
196  m_runElementTable->addElement(elMat,elName);
197  }
198  }
199  }
200  if ((totalFrac-1.)*(totalFrac-1.) > 10e-4 )
201  ATH_MSG_DEBUG("Total fractions do not add up to one at INPUT (" << totalFrac << ") !");
202  }
203 
204  // is it a Geantino?
205  if (aStep->GetTrack()->GetParticleDefinition()->GetPDGEncoding() == 0) {
207  m_matStepCollection->push_back(new Trk::MaterialStep(pos.x(), pos.y(), pos.z(), steplength, X0, L0, A, Z, rho, elements, fractions));
208  else
209  m_matStepCollection->push_back(new Trk::MaterialStep(pos.x(), pos.y(), pos.z(), steplength, X0, L0, A, Z, rho));
210  }
211  }
212  }

Member Data Documentation

◆ ATLAS_THREAD_SAFE

std::atomic_flag m_initialized AthMessaging::ATLAS_THREAD_SAFE = ATOMIC_FLAG_INIT
mutableprivateinherited

Messaging initialized (initMessaging)

Definition at line 141 of file AthMessaging.h.

◆ m_elementTable

Trk::ElementTable* G4UA::MaterialStepRecorder::m_elementTable
private

Definition at line 61 of file MaterialStepRecorder.h.

◆ m_elementTableName

std::string G4UA::MaterialStepRecorder::m_elementTableName
private

Definition at line 62 of file MaterialStepRecorder.h.

◆ m_eventID

size_t G4UA::MaterialStepRecorder::m_eventID
private

Definition at line 59 of file MaterialStepRecorder.h.

◆ m_evtStore

ServiceHandle<StoreGateSvc> G4UA::MaterialStepRecorder::m_evtStore
private

Pointer to StoreGate (event store by default)

Definition at line 51 of file MaterialStepRecorder.h.

◆ m_imsg

std::atomic<IMessageSvc*> AthMessaging::m_imsg { nullptr }
mutableprivateinherited

MessageSvc pointer.

Definition at line 135 of file AthMessaging.h.

◆ m_lvl

std::atomic<MSG::Level> AthMessaging::m_lvl { MSG::NIL }
mutableprivateinherited

Current logging level.

Definition at line 138 of file AthMessaging.h.

◆ m_matStepCollection

Trk::MaterialStepCollection* G4UA::MaterialStepRecorder::m_matStepCollection
private

Definition at line 53 of file MaterialStepRecorder.h.

◆ m_matStepCollectionName

std::string G4UA::MaterialStepRecorder::m_matStepCollectionName
private

Definition at line 54 of file MaterialStepRecorder.h.

◆ m_msg_tls

boost::thread_specific_ptr<MsgStream> AthMessaging::m_msg_tls
mutableprivateinherited

MsgStream instance (a std::cout like with print-out levels)

Definition at line 132 of file AthMessaging.h.

◆ m_nm

std::string AthMessaging::m_nm
privateinherited

Message source name.

Definition at line 129 of file AthMessaging.h.

◆ m_recordComposition

bool G4UA::MaterialStepRecorder::m_recordComposition
private

Definition at line 56 of file MaterialStepRecorder.h.

◆ m_runElementTable

Trk::ElementTable* G4UA::MaterialStepRecorder::m_runElementTable
private

Definition at line 64 of file MaterialStepRecorder.h.

◆ m_totalSteps

size_t G4UA::MaterialStepRecorder::m_totalSteps
private

Definition at line 58 of file MaterialStepRecorder.h.


The documentation for this class was generated from the following files:
G4UA::MaterialStepRecorder::m_eventID
size_t m_eventID
Definition: MaterialStepRecorder.h:59
AthMessaging::m_lvl
std::atomic< MSG::Level > m_lvl
Current logging level.
Definition: AthMessaging.h:138
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
G4UA::MaterialStepRecorder::m_matStepCollectionName
std::string m_matStepCollectionName
Definition: MaterialStepRecorder.h:54
Monitored::Z
@ Z
Definition: HistogramFillerUtils.h:24
mat
GeoMaterial * mat
Definition: LArDetectorConstructionTBEC.cxx:55
Trk::ElementTable::contains
bool contains(unsigned int Z) const
quick check
Definition: ElementTable.h:93
Trk::MaterialStepCollection
DataVector< Trk::MaterialStep > MaterialStepCollection
Definition: MaterialStepCollection.h:17
python.SystemOfUnits.gram
int gram
Definition: SystemOfUnits.py:165
G4UA::MaterialStepRecorder::m_matStepCollection
Trk::MaterialStepCollection * m_matStepCollection
Definition: MaterialStepRecorder.h:53
AthMessaging::m_imsg
std::atomic< IMessageSvc * > m_imsg
MessageSvc pointer.
Definition: AthMessaging.h:135
python.SystemOfUnits.ms
int ms
Definition: SystemOfUnits.py:132
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
python.SystemOfUnits.mm3
int mm3
Definition: SystemOfUnits.py:85
pdg_comparison.X0
X0
Definition: pdg_comparison.py:314
Trk::MaterialStep
Definition: MaterialStep.h:34
AthMessaging::AthMessaging
AthMessaging()
Default constructor:
A
TrigConf::MSGTC::Level
Level
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:21
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
G4UA::MaterialStepRecorder::m_recordComposition
bool m_recordComposition
Definition: MaterialStepRecorder.h:56
AthMessaging::msg
MsgStream & msg() const
The standard message stream.
Definition: AthMessaging.h:164
G4UA::MaterialStepRecorder::m_elementTable
Trk::ElementTable * m_elementTable
Definition: MaterialStepRecorder.h:61
G4UA::MaterialStepRecorder::m_runElementTable
Trk::ElementTable * m_runElementTable
Definition: MaterialStepRecorder.h:64
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
G4UA::MaterialStepRecorder::m_evtStore
ServiceHandle< StoreGateSvc > m_evtStore
Pointer to StoreGate (event store by default)
Definition: MaterialStepRecorder.h:51
Trk::ElementTable
Definition: ElementTable.h:24
G4UA::MaterialStepRecorder::m_elementTableName
std::string m_elementTableName
Definition: MaterialStepRecorder.h:62
AthMessaging::m_nm
std::string m_nm
Message source name.
Definition: AthMessaging.h:129
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
Trk::Material
Definition: Material.h:116
AthMessaging::initMessaging
void initMessaging() const
Initialize our message level and MessageSvc.
Definition: AthMessaging.cxx:39
AthMessaging::m_msg_tls
boost::thread_specific_ptr< MsgStream > m_msg_tls
MsgStream instance (a std::cout like with print-out levels)
Definition: AthMessaging.h:132
fitman.rho
rho
Definition: fitman.py:532
Trk::L0
@ L0
Definition: AlignModuleList.h:32
G4UA::MaterialStepRecorder::m_totalSteps
size_t m_totalSteps
Definition: MaterialStepRecorder.h:58
Trk::ElementTable::addElement
void addElement(const Material &mat, const std::string &mname="")
Add material to the Table - if the elment is already filled ignore.
Definition: ElementTable.h:75