67 std::cout <<
"============================================================================" << std::endl;
68 std::cout <<
"CastorTestAnalysis:: Initialized as observer" << std::endl;
70 std::cout <<
" Step Ntuple will be created" << std::endl;
74 std::cout <<
" Event Ntuple will be created" << std::endl;
77 std::cout <<
"============================================================================" << std::endl;
82 new TNtuple(
"NTcastorstep",
"NTcastorstep",
"evt:trackid:charge:pdgcode:x:y:z:stepl:stepe:eta:phi:vpx:vpy:vpz");
86 "NTcastorevent",
"NTcastorevent",
"evt:ihit:detector:sector:module:enem:totalenergy:hitenergy:x:y:z");
94 std::cout << std::endl <<
"End of CastorTestAnalysis" << std::endl;
97 std::cout <<
"CastorTestAnalysis: End of process" << std::endl;
105 std::cout << std::endl <<
"CastorTestAnalysis: Starting Run" << std::endl;
107 std::cout <<
"CastorTestAnalysis: output step root file created" << std::endl;
113 std::cout <<
"CastorTestAnalysis: output event root file created" << std::endl;
131 G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
133 G4double stepL = aStep->GetStepLength();
134 G4double stepE = aStep->GetTotalEnergyDeposit();
137 std::cout <<
"Step " << stepL <<
", " << stepE << std::endl;
139 G4Track* theTrack = aStep->GetTrack();
140 G4int theTrackID = theTrack->GetTrackID();
141 G4double
theCharge = theTrack->GetDynamicParticle()->GetCharge();
143 G4int pdgcode = theTrack->GetDefinition()->GetPDGEncoding();
145 const G4ThreeVector& vert_mom = theTrack->GetVertexMomentumDirection();
146 G4double vpx = vert_mom.x();
147 G4double vpy = vert_mom.y();
148 G4double vpz = vert_mom.z();
149 double eta = 0.5 *
log((1. + vpz) / (1. - vpz));
150 double phi = atan2(vpy, vpx);
152 const G4ThreeVector& hitPoint = preStepPoint->GetPosition();
197 if (theTrack->GetNextVolume() != 0)
198 LogDebug(
"ForwardSim") <<
" NextVolume: " << theTrack->GetNextVolume()->GetName();
200 LogDebug(
"ForwardSim") <<
" NextVolume: OutOfWorld";
211 std::cout << std::endl <<
"CastorTest::update(EndOfEvent * evt) - event #" << (*evt)()->GetEventID() << std::endl;
214 G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
215 std::cout <<
"update(*evt) --> accessed all HC";
217 int CAFIid = G4SDManager::GetSDMpointer()->GetCollectionID(
"CastorFI");
241 if (theCAFI->entries() > 0)
247 G4PrimaryParticle* thePrim =
nullptr;
248 G4int nvertex = (*evt)()->GetNumberOfPrimaryVertex();
249 std::cout <<
"Event has " << nvertex <<
" vertex" << std::endl;
251 std::cout <<
"CASTORTest End Of Event ERROR: no vertex" << std::endl;
253 for (
int i = 0;
i < nvertex;
i++) {
254 G4PrimaryVertex* avertex = (*evt)()->GetPrimaryVertex(
i);
255 if (avertex ==
nullptr)
256 std::cout <<
"CASTORTest End Of Event ERR: pointer to vertex = 0" << std::endl;
257 std::cout <<
"Vertex number :" <<
i << std::endl;
258 int npart = avertex->GetNumberOfParticle();
260 std::cout <<
"CASTORTest End Of Event ERR: no primary!" << std::endl;
261 if (thePrim ==
nullptr)
262 thePrim = avertex->GetPrimary(trackID);
265 double px = 0.,
py = 0., pz = 0., pInit = 0;
266 double eta = 0.,
phi = 0.;
268 if (thePrim !=
nullptr) {
269 px = thePrim->GetPx();
270 py = thePrim->GetPy();
271 pz = thePrim->GetPz();
274 std::cout <<
"CASTORTest End Of Event ERR: primary has p=0 " << std::endl;
276 float costheta = pz / pInit;
285 std::cout <<
"CASTORTest End Of Event ERR: could not find primary " << std::endl;
287 LogDebug(
"ForwardSim") <<
"CastorTestAnalysis: Particle Type " <<
particleType <<
" p/eta/phi " << pInit <<
", "
291 int iEvt = (*evt)()->GetEventID();
293 std::cout <<
" CastorTest Event " << iEvt << std::endl;
294 else if ((iEvt < 100) && (iEvt % 10 == 0))
295 std::cout <<
" CastorTest Event " << iEvt << std::endl;
296 else if ((iEvt < 1000) && (iEvt % 100 == 0))
297 std::cout <<
" CastorTest Event " << iEvt << std::endl;
298 else if ((iEvt < 10000) && (iEvt % 1000 == 0))
299 std::cout <<
" CastorTest Event " << iEvt << std::endl;
301 std::cout << std::endl <<
"===>>> Done writing user histograms " << std::endl;
308 int nentries = hc->entries();
311 unsigned int volumeID = 0;
312 int det = 0,
zside, sector, zmodule;
313 std::map<int, float, std::less<int> > themap;
314 double totalEnergy = 0;
315 double hitEnergy = 0;
316 double en_in_sd = 0.;
318 for (
int ihit = 0; ihit < nentries; ihit++) {
323 for (
int ihit = 0; ihit < nentries; ihit++) {
366 std::cout <<
"CastorTestAnalysis: Ntuple step written" << std::endl;
368 std::cout <<
"CastorTestAnalysis: Step file closed" << std::endl;
374 std::cout <<
"CastorTestAnalysis: Ntuple event written" << std::endl;
376 std::cout <<
"CastorTestAnalysis: Event file closed" << std::endl;