65 std::cout <<
"============================================================================" << std::endl;
66 std::cout <<
"ZdcTestAnalysis:: Initialized as observer" << std::endl;
68 std::cout <<
" Step Ntuple will be created" << std::endl;
72 std::cout <<
" Event Ntuple will be created" << std::endl;
75 std::cout <<
"============================================================================" << std::endl;
80 new TNtuple(
"NTzdcstep",
82 "evt:trackid:charge:pdgcode:x:y:z:stepl:stepe:eta:phi:vpx:vpy:vpz:idx:idl:pvtype:ncherphot");
86 new TNtuple(
"NTzdcevent",
88 "evt:ihit:fiberid:zside:subdet:layer:fiber:channel:enem:enhad:hitenergy:x:y:z:time:etot");
102 std::cout <<
"beggining of job" << std::endl;
110 std::cout << std::endl <<
"ZdcTestAnalysis: Begining of Run" << std::endl;
112 std::cout <<
"ZDCTestAnalysis: output step file created" << std::endl;
118 std::cout <<
"ZDCTestAnalysis: output event file created" << std::endl;
138 G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
140 G4double stepL = aStep->GetStepLength();
141 G4double stepE = aStep->GetTotalEnergyDeposit();
144 std::cout <<
"Step " << stepL <<
"," << stepE << std::endl;
146 G4Track* theTrack = aStep->GetTrack();
147 G4int theTrackID = theTrack->GetTrackID();
148 G4double
theCharge = theTrack->GetDynamicParticle()->GetCharge();
149 G4String
particleType = theTrack->GetDefinition()->GetParticleName();
150 G4int pdgcode = theTrack->GetDefinition()->GetPDGEncoding();
152 const G4ThreeVector& vert_mom = theTrack->GetVertexMomentumDirection();
153 G4double vpx = vert_mom.x();
154 G4double vpy = vert_mom.y();
155 G4double vpz = vert_mom.z();
156 double eta = 0.5 *
log((1. + vpz) / (1. - vpz));
157 double phi = atan2(vpy, vpx);
159 const G4ThreeVector& hitPoint = preStepPoint->GetPosition();
160 G4ThreeVector localPoint = theTrack->GetTouchable()->GetHistory()->GetTopTransform().TransformPoint(hitPoint);
162 const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
163 int idx = touch->GetReplicaNumber(0);
171 std::vector<G4VPhysicalVolume*> thePhysicalVolumes(
historyDepth);
173 std::vector<G4LogicalVolume*> theLogicalVolumes(
historyDepth);
179 theReplicaNumbers[
jj] = touch->GetReplicaNumber(
jj);
180 thePhysicalVolumes[
jj] = touch->GetVolume(
jj);
181 thePVnames[
jj] = thePhysicalVolumes[
jj]->GetName();
182 theLogicalVolumes[
jj] = thePhysicalVolumes[
jj]->GetLogicalVolume();
183 theLVnames[
jj] = theLogicalVolumes[
jj]->GetName();
184 theMaterials[
jj] = theLogicalVolumes[
jj]->GetMaterial();
185 theMaterialNames[
jj] = theMaterials[
jj]->GetName();
187 std::cout <<
" GHD " <<
jj <<
": " << theReplicaNumbers[
jj] <<
"," << thePVnames[
jj] <<
"," << theLVnames[
jj]
188 <<
"," << theMaterialNames[
jj] << std::endl;
191 idLayer = theReplicaNumbers[1];
192 if (thePVnames[0] ==
"ZDC_EMLayer")
194 else if (thePVnames[0] ==
"ZDC_EMAbsorber")
196 else if (thePVnames[0] ==
"ZDC_EMFiber")
198 else if (thePVnames[0] ==
"ZDC_HadLayer")
200 else if (thePVnames[0] ==
"ZDC_HadAbsorber")
202 else if (thePVnames[0] ==
"ZDC_HadFiber")
204 else if (thePVnames[0] ==
"ZDC_PhobosLayer")
206 else if (thePVnames[0] ==
"ZDC_PhobosAbsorber")
208 else if (thePVnames[0] ==
"ZDC_PhobosFiber")
213 std::cout <<
" pvtype=0 hd=" <<
historyDepth <<
" " << theReplicaNumbers[0] <<
"," << thePVnames[0] <<
","
214 << theLVnames[0] <<
"," << theMaterialNames[0] << std::endl;
217 int theReplicaNumber = touch->GetReplicaNumber(0);
218 G4VPhysicalVolume* thePhysicalVolume = touch->GetVolume(0);
219 const G4String& thePVname = thePhysicalVolume->GetName();
220 G4LogicalVolume* theLogicalVolume = thePhysicalVolume->GetLogicalVolume();
221 const G4String& theLVname = theLogicalVolume->GetName();
222 G4Material* theMaterial = theLogicalVolume->GetMaterial();
223 const G4String& theMaterialName = theMaterial->GetName();
225 std::cout <<
" hd=0 " << theReplicaNumber <<
"," << thePVname <<
"," << theLVname <<
"," << theMaterialName
231 double NCherPhot = -1;
259 <<
"ZdcTest::upDate(const EndOfEvent * evt) - event #" << (*evt)()->GetEventID() << std::endl
260 <<
" # of aSteps followed in event = " <<
stepIndex << std::endl;
263 G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
266 int theZDCHCid = G4SDManager::GetSDMpointer()->GetCollectionID(
"ZDCHITS");
267 std::cout <<
" - theZDCHCid = " << theZDCHCid;
270 std::cout <<
" - theZDCHC = " << theZDCHC << std::endl;
276 float ETot = 0., SEnergy = 0.;
279 unsigned int unsignedfiberID = 0;
280 std::map<int, float, std::less<int> > energyInFibers;
281 std::map<int, float, std::less<int> > primaries;
282 float totalEnergy = 0;
283 int nentries = theZDCHC->entries();
284 std::cout <<
" theZDCHC has " << nentries <<
" entries" << std::endl;
288 for (
int ihit = 0; ihit < nentries; ihit++) {
293 for (
int ihit = 0; ihit < nentries; ihit++) {
297 double enEm = aHit->
getEM();
298 double enHad = aHit->
getHadr();
302 std::cout <<
" entry #" << ihit <<
": fiberID=0x" << std::hex << fiberID <<
std::dec <<
"; enEm=" << enEm
303 <<
"; enHad=" << enHad <<
"; hitEnergy=" << hitEnergy <<
"z=" << hitPoint.z() << std::endl;
304 energyInFibers[fiberID] += enEm + enHad;
305 primaries[aHit->
getTrackID()] += enEm + enHad;
310 int thesubdet, thelayer, thefiber, thechannel, thez;
312 int unsignedsubdet, unsignedlayer, unsignedfiber, unsignedchannel, unsignedz;
314 unsignedfiberID, unsignedsubdet, unsignedlayer, unsignedfiber, unsignedchannel, unsignedz);
340 for (
std::map<
int,
float, std::less<int> >::iterator is = energyInFibers.begin(); is != energyInFibers.end();
348 G4PrimaryParticle* thePrim =
nullptr;
349 G4int nvertex = (*evt)()->GetNumberOfPrimaryVertex();
350 std::cout <<
"Event has " << nvertex <<
" vertex" << std::endl;
352 std::cout <<
"ZdcTest End Of Event ERROR: no vertex" << std::endl;
354 for (
int i = 0;
i < nvertex;
i++) {
355 G4PrimaryVertex* avertex = (*evt)()->GetPrimaryVertex(
i);
356 if (avertex ==
nullptr) {
357 std::cout <<
"ZdcTest End Of Event ERR: pointer to vertex = 0" << std::endl;
359 std::cout <<
"Vertex number :" <<
i << std::endl;
360 int npart = avertex->GetNumberOfParticle();
362 std::cout <<
"ZdcTest End Of Event ERR: no primary!" << std::endl;
363 if (thePrim ==
nullptr)
364 thePrim = avertex->GetPrimary(trackID);
368 double px = 0.,
py = 0., pz = 0.;
371 if (thePrim !=
nullptr) {
372 px = thePrim->GetPx();
373 py = thePrim->GetPy();
374 pz = thePrim->GetPz();
377 std::cout <<
"ZdcTest End Of Event ERR: primary has p=0 " << std::endl;
380 std::cout <<
"ZdcTest End Of Event ERR: could not find primary " << std::endl;
387 int iEvt = (*evt)()->GetEventID();
389 std::cout <<
" ZdcTest Event " << iEvt << std::endl;
390 else if ((iEvt < 100) && (iEvt % 10 == 0))
391 std::cout <<
" ZdcTest Event " << iEvt << std::endl;
392 else if ((iEvt < 1000) && (iEvt % 100 == 0))
393 std::cout <<
" ZdcTest Event " << iEvt << std::endl;
394 else if ((iEvt < 10000) && (iEvt % 1000 == 0))
395 std::cout <<
" ZdcTest Event " << iEvt << std::endl;
404 std::cout <<
"ZdcTestAnalysis: Ntuple step written for event: " <<
eventIndex << std::endl;
406 std::cout <<
"ZdcTestAnalysis: Step file closed" << std::endl;
412 std::cout <<
"ZdcTestAnalysis: Ntuple event written for event: " <<
eventIndex << std::endl;
414 std::cout <<
"ZdcTestAnalysis: Event file closed" << std::endl;