ATLAS Offline Software
G4AtlantisDumper.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 "G4AtlantisDumper.h"
6 
8 #include "StoreGate/ReadHandle.h"
9 
10 #include "G4Event.hh"
11 #include "G4Run.hh"
12 #include "G4Step.hh"
13 #include "G4VProcess.hh"
14 
15 #include <iostream>
16 
17 #include "GaudiKernel/Bootstrap.h"
18 #include "GaudiKernel/ISvcLocator.h"
19 #include "GaudiKernel/IMessageSvc.h"
20 
21 namespace G4UA
22 {
23 
25  AthMessaging(Gaudi::svcLocator()->service< IMessageSvc >( "MessageSvc" ),"G4AtlantisDumper"),
26  m_config(config),
27  m_evtStore("StoreGateSvc/StoreGateSvc","G4AtlantisDumper"),
28  m_detStore("StoreGateSvc/DetectorStore","G4AtlantisDumper"),
29  m_nsteps(0),
30  m_file(NULL)
31  {}
32 
33  void G4AtlantisDumper::UserSteppingAction(const G4Step* aStep)
34  {
35  const G4Track *t=aStep->GetTrack();
36  //if(m_nsteps>40) return;
37  if (!t) return;
38 
39  int id=t->GetTrackID();
40  int pid=t->GetParentID();
41 
42  int fs=aStep->IsFirstStepInVolume();
43  int ls=aStep->IsLastStepInVolume();
44  int stepn=t->GetCurrentStepNumber();
45 
46  const G4TrackVector *sec=aStep->GetSecondary();
47  int nsec=0; if (sec) nsec=sec->size();
48 
49  double tedep=aStep->GetTotalEnergyDeposit();
50  double tnedep=aStep->GetNonIonizingEnergyDeposit();
51  double length=aStep->GetStepLength();
52  int pdg=t->GetDefinition()->GetPDGEncoding();
53 
54  bool keep=false;
55  if (fs||ls) keep=true;
56  if (tedep>m_config.tedep_cut) keep=true;//default = 0.1 MeV
57  if (length>m_config.length_cut) keep=true;//default = 1.0 mm
58  if (aStep->GetPreStepPoint()->GetMomentum().mag()<m_config.p_cut) keep=false;//default = 10 MeV
59  if (aStep->GetPreStepPoint()->GetKineticEnergy()<m_config.ke_cut) keep=false;//default = 10 MeV
60  if (!keep) return;
61 
62  //const G4VPhysicalVolume *v =t->GetVolume();
63  //const G4Material *m =t->GetMaterial();
64 
65  const G4VProcess *p =t->GetCreatorProcess();
66  G4String pn="none"; if(p) pn=p->GetProcessName();
67 
68  G4ThreeVector pos1=aStep->GetPreStepPoint()->GetPosition();
69  double x1=pos1.x(); double y1=pos1.y(); double z1=pos1.z();
70  double t1=aStep->GetPreStepPoint()->GetGlobalTime();
71  G4ThreeVector pos2=aStep->GetPostStepPoint()->GetPosition();
72  double x2=pos2.x(); double y2=pos2.y(); double z2=pos2.z();
73  double t2=aStep->GetPostStepPoint()->GetGlobalTime();
74  G4ThreeVector p1=aStep->GetPreStepPoint()->GetMomentum();
75  double px1=p1.x(); double py1=p1.y(); double pz1=p1.z();
76  G4ThreeVector p2=aStep->GetPostStepPoint()->GetMomentum();
77  double px2=p2.x(); double py2=p2.y(); double pz2=p2.z();
78  double ke1=aStep->GetPreStepPoint()->GetKineticEnergy();
79  double ke2=aStep->GetPostStepPoint()->GetKineticEnergy();
80  //GetVelocity() //GetBeta() //GetGamma()
81  //GetSensitiveDetector() //GetPolarization()
82  double mass=aStep->GetPreStepPoint()->GetMass();
83  double charge=aStep->GetPreStepPoint()->GetCharge();
84  //GetMagneticMoment()
85 
86  (*m_file)<<"ACH_G4Step";
87  (*m_file)<<" "<<m_nsteps; (*m_file)<<" "<<id; (*m_file)<<" "<<pid; (*m_file)<<" "<<(int)fs; (*m_file)<<" "<<(int)ls; (*m_file)<<" "<<stepn;
88  (*m_file)<<" "<<pn; (*m_file)<<" "<<nsec;
89  (*m_file)<<" "<<tedep; (*m_file)<<" "<<tnedep; (*m_file)<<" "<<length; (*m_file)<<" "<<pdg; (*m_file)<<" "<<mass; (*m_file)<<" "<<charge;
90  (*m_file)<<" "<<x1; (*m_file)<<" "<<y1; (*m_file)<<" "<<z1; (*m_file)<<" "<<t1;
91  (*m_file)<<" "<<px1; (*m_file)<<" "<<py1; (*m_file)<<" "<<pz1; (*m_file)<<" "<<ke1;
92  (*m_file)<<" "<<x2; (*m_file)<<" "<<y2; (*m_file)<<" "<<z2; (*m_file)<<" "<<t2;
93  (*m_file)<<" "<<px2; (*m_file)<<" "<<py2; (*m_file)<<" "<<pz2; (*m_file)<<" "<<ke2;
94  (*m_file)<<std::endl;
95 
96  ++m_nsteps;
97  }
98 
100  {
101  ATH_MSG_INFO( "Goodbye from G4AtlantisDumper, event "<<event->GetEventID());
102  m_file->close();
103  delete m_file;
104 
105  ATH_MSG_INFO("G4AtlantisDumper: zipping "<<m_filename);
106  system(("zip -m "+m_filename+".zip "+m_filename).c_str());
107  }
108 
110  {
111  m_nsteps = 0;
112 
114  if(!evt.isValid()) {
115  ATH_MSG_INFO("G4AtlantisDumper could not get event info!");
116  return;
117  }
118 
119  int athevent = evt->eventNumber();
120  int athrun = evt->runNumber();
121  ATH_MSG_INFO("G4AtlantisDumper: Athena run event is "<<athrun<<" "<<athevent);
122  char buf[1000];
123  int length=snprintf(buf, 1000, "G4Atlantis_%d_%d.txt", athrun, athevent);
124  if(999<length) {
125  ATH_MSG_WARNING( "BeginOfEvent:: m_filename string (" << buf << ") was truncated" );
126  }
127  ATH_MSG_INFO( "G4AtlantisDumper: Opening m_file "<<buf);
128  m_file = new std::ofstream();
129  m_file->open(buf);
130  m_filename = buf;
131  }
132 
133 } // namespace G4UA
plotBeamSpotCompare.x1
x1
Definition: plotBeamSpotCompare.py:216
G4AtlantisDumper.h
G4UA::G4AtlantisDumper::Config
Definition: G4AtlantisDumper.h:29
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
G4UA::G4AtlantisDumper::Config::p_cut
double p_cut
Definition: G4AtlantisDumper.h:32
G4UA::G4AtlantisDumper::Config::tedep_cut
double tedep_cut
Definition: G4AtlantisDumper.h:30
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
G4UA
for nSW
Definition: CalibrationDefaultProcessing.h:19
G4UA::G4AtlantisDumper::m_filename
std::string m_filename
Definition: G4AtlantisDumper.h:50
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
G4UA::G4AtlantisDumper::BeginOfEventAction
virtual void BeginOfEventAction(const G4Event *) override
Definition: G4AtlantisDumper.cxx:109
G4UA::G4AtlantisDumper::m_config
Config m_config
Definition: G4AtlantisDumper.h:42
plotBeamSpotCompare.x2
x2
Definition: plotBeamSpotCompare.py:218
ALFA_EventTPCnv_Dict::t1
std::vector< ALFA_RawDataCollection_p1 > t1
Definition: ALFA_EventTPCnvDict.h:43
LArG4FSStartPointFilter.evt
evt
Definition: LArG4FSStartPointFilter.py:42
G4UA::G4AtlantisDumper::EndOfEventAction
virtual void EndOfEventAction(const G4Event *) override
Definition: G4AtlantisDumper.cxx:99
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
dqt_zlumi_pandas.mass
mass
Definition: dqt_zlumi_pandas.py:170
makeTRTBarrelCans.y1
tuple y1
Definition: makeTRTBarrelCans.py:15
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
m_file
std::unique_ptr< TFile > m_file
description: this is a custom writer for the old-school drivers that don't use an actual writer
Definition: OutputStreamData.cxx:52
python.ZdcRecConfig.pn
pn
Definition: ZdcRecConfig.py:357
G4UA::G4AtlantisDumper::Config::ke_cut
double ke_cut
Definition: G4AtlantisDumper.h:33
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
ReadCalibFromCool.keep
keep
Definition: ReadCalibFromCool.py:85
makeTRTBarrelCans.y2
tuple y2
Definition: makeTRTBarrelCans.py:18
ParticleGun_EoverP_Config.pid
pid
Definition: ParticleGun_EoverP_Config.py:62
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition: AthMessaging.h:55
G4UA::G4AtlantisDumper::m_file
std::ofstream * m_file
Definition: G4AtlantisDumper.h:49
G4UA::G4AtlantisDumper::Config::length_cut
double length_cut
Definition: G4AtlantisDumper.h:31
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:194
charge
double charge(const T &p)
Definition: AtlasPID.h:494
G4UA::G4AtlantisDumper::G4AtlantisDumper
G4AtlantisDumper(const Config &config)
Definition: G4AtlantisDumper.cxx:24
EventInfo.h
G4UA::G4AtlantisDumper::UserSteppingAction
virtual void UserSteppingAction(const G4Step *) override
Definition: G4AtlantisDumper.cxx:33
ALFA_EventTPCnv_Dict::t2
std::vector< ALFA_RawDataContainer_p1 > t2
Definition: ALFA_EventTPCnvDict.h:44
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
Herwig7_QED_EvtGen_ll.fs
dictionary fs
Definition: Herwig7_QED_EvtGen_ll.py:17
Gaudi
=============================================================================
Definition: CaloGPUClusterAndCellDataMonitorOptions.h:273
G4UA::G4AtlantisDumper::m_nsteps
int m_nsteps
Definition: G4AtlantisDumper.h:48
ReadHandle.h
Handle class for reading from StoreGate.
getReferenceRun.ls
def ls(fpath)
Definition: getReferenceRun.py:29
length
double length(const pvec &v)
Definition: FPGATrackSimLLPDoubletHoughTransformTool.cxx:26