File indexing completed on 2025-01-18 09:17:01
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031 #include "RunAction.hh"
0032 #include "G4AnalysisManager.hh"
0033 #include "G4AutoLock.hh"
0034
0035 namespace
0036 {
0037 G4Mutex aMutex = G4MUTEX_INITIALIZER;
0038 }
0039
0040 using namespace std;
0041
0042
0043
0044 RunAction::RunAction(DetectorConstruction* det, PrimaryGeneratorAction* pri)
0045 :fDetector(det),fPrimary(pri)
0046 {}
0047
0048
0049
0050 RunAction::~RunAction()
0051 {}
0052
0053
0054
0055 void RunAction::BeginOfRunAction(const G4Run* )
0056 {
0057
0058
0059 fRow=0;
0060
0061 fXVector = CLHEP::HepVector(32);
0062 fYVector = CLHEP::HepVector(32);
0063 fThetaVector = CLHEP::HepVector(32);
0064 fPhiVector = CLHEP::HepVector(32);
0065
0066
0067
0068
0069 G4cout << "##### Create analysis manager " << " " << this << G4endl;
0070
0071 G4AnalysisManager* man = G4AnalysisManager::Instance();
0072 man->SetDefaultFileType("root");
0073
0074 G4cout << "Using " << man->GetType() << " analysis manager" << G4endl;
0075
0076
0077 man->OpenFile("nanobeam");
0078 man->SetFirstHistoId(1);
0079 man->SetFirstNtupleId(1);
0080
0081
0082 man->CreateNtuple("ntuple0", "BeamProfile");
0083 man->CreateNtupleDColumn("xIn");
0084 man->CreateNtupleDColumn("yIn");
0085 man->CreateNtupleDColumn("zIn");
0086 man->FinishNtuple();
0087 G4cout << "Ntuple-1 created" << G4endl;
0088
0089
0090 man->CreateNtuple("ntuple1","Grid");
0091 man->CreateNtupleDColumn("xIn");
0092 man->CreateNtupleDColumn("yIn");
0093 man->CreateNtupleDColumn("e");
0094 man->FinishNtuple();
0095 G4cout << "Ntuple-2 created" << G4endl;
0096
0097
0098 man->CreateNtuple("ntuple2","Coef");
0099 man->CreateNtupleDColumn("xIn");
0100 man->CreateNtupleDColumn("yIn");
0101 man->CreateNtupleDColumn("thetaIn");
0102 man->CreateNtupleDColumn("phiIn");
0103 man->FinishNtuple();
0104 G4cout << "Ntuple-3 created" << G4endl;
0105
0106 return;
0107
0108 }
0109
0110
0111
0112 void RunAction::EndOfRunAction(const G4Run* )
0113 {
0114
0115 if (fDetector->GetCoef()==1)
0116 {
0117
0118
0119
0120
0121
0122 G4AutoLock l(&aMutex);
0123
0124
0125 CLHEP::HepMatrix m;
0126
0127
0128
0129
0130 m = CLHEP::HepMatrix(32,32);
0131 m = fPrimary->GetMatrix();
0132
0133 G4cout << G4endl;
0134 G4cout << "===> NANOBEAM LINE INTRINSIC ABERRATION COEFFICIENTS (units of micrometer and mrad) :" << G4endl;
0135 G4cout << G4endl;
0136
0137 int inv;
0138
0139 m.invert(inv);
0140 CLHEP::HepVector tmp(32,0);
0141 tmp=m*fXVector;
0142 CLHEP::HepVector b;
0143 b=tmp.sub(2,2); G4cout << "<x|theta>=" << b << G4endl;
0144 b=tmp.sub(8,8); G4cout << "<x|theta*delta>=" << b << G4endl;
0145 b=tmp.sub(10,10); G4cout << "<x|theta^3>=" << b << G4endl;
0146 b=tmp.sub(12,12); G4cout << "<x|theta*phi^2>=" << b << G4endl;
0147 m.invert(inv);
0148
0149 m.invert(inv);
0150 tmp = m*fThetaVector;
0151 m.invert(inv);
0152 b=tmp.sub(2,2); G4cout << "<x|x>=" << b << G4endl;
0153
0154 m.invert(inv);
0155 tmp=m*fYVector;
0156 b=tmp.sub(3,3); G4cout << "<y|phi>=" << b << G4endl;
0157 b=tmp.sub(9,9); G4cout << "<y|phi*delta>=" << b << G4endl;
0158 b=tmp.sub(11,11); G4cout << "<y|theta^2*phi>=" << b << G4endl;
0159 b=tmp.sub(13,13); G4cout << "<y|phi^3>=" << b << G4endl;
0160 m.invert(inv);
0161
0162 m.invert(inv);
0163 tmp = m*fPhiVector;
0164 m.invert(inv);
0165 b=tmp.sub(3,3); G4cout << "<y|y>=" << b << G4endl;
0166
0167 }
0168
0169
0170
0171 G4AnalysisManager* man = G4AnalysisManager::Instance();
0172 man->Write();
0173 man->CloseFile();
0174
0175
0176 man->Clear();
0177 }