24 #include "G4SDManager.hh"
27 #include "G4VProcess.hh"
28 #include "G4HCofThisEvent.hh"
29 #include "G4UserEventAction.hh"
30 #include "G4TransportationManager.hh"
31 #include "G4ProcessManager.hh"
33 #include "CLHEP/Units/GlobalSystemOfUnits.h"
34 #include "CLHEP/Units/GlobalPhysicalConstants.h"
60 std::cout <<
"============================================================================" << std::endl;
61 std::cout <<
"BscTestconstructor :: Initialized as observer" << std::endl;
71 std::cout <<
"BscTest constructor :: Initialized BscAnalysisHistManager" << std::endl;
80 std::cout <<
"Bsc output root file has been created";
86 std::cout <<
", and deleted" << std::endl;
93 std::cout << std::endl <<
"BscTest Destructor --------> End of BscTest : " << std::endl;
96 std::cout <<
"BscTest: End of process" << std::endl;
134 HistInit(
"TrackPhi",
"Primary Phi", 100, 0., 360.);
135 HistInit(
"TrackTheta",
"Primary Theta", 100, 0., 180.);
136 HistInit(
"TrackP",
"Track XY position Z+ ", 80, -80., 80., 80, -80., 80.);
137 HistInit(
"TrackM",
"Track XY position Z-", 80, -80., 80., 80, -80., 80.);
138 HistInit(
"DetIDs",
"Track DetId - vs +", 16, -0.5, 15.5, 16, 15.5, 31.5);
146 std::cout <<
"================================================================" << std::endl;
147 std::cout <<
" Write this Analysis to File " << fOutputFile << std::endl;
148 std::cout <<
"================================================================" << std::endl;
150 TFile*
file =
new TFile(fOutputFile, fRecreateFile);
161 strcpy(newtitle,
title);
162 strcat(newtitle,
" (");
164 strcat(newtitle,
") ");
165 fHistArray->AddLast((
new TH1F(
name, newtitle, nbinsx, xlow, xup)));
171 const char*
name,
const char*
title, Int_t nbinsx, Axis_t xlow, Axis_t xup, Int_t nbinsy, Axis_t ylow, Axis_t yup) {
175 strcpy(newtitle,
title);
176 strcat(newtitle,
" (");
178 strcat(newtitle,
") ");
179 fHistArray->AddLast((
new TH2F(
name, newtitle, nbinsx, xlow, xup, nbinsy, ylow, yup)));
187 if (Number <= fHistArray->GetLast() &&
fHistArray->At(
Number) != (TObject*)
nullptr) {
191 std::cout <<
"!!!!!!!!!!!!!!!!!!GetHisto!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
192 std::cout <<
" WARNING ERROR - HIST ID INCORRECT (TOO HIGH) - " <<
Number << std::endl;
193 std::cout <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
203 if (Number <= fHistArray->GetLast() &&
fHistArray->At(
Number) != (TObject*)
nullptr) {
207 std::cout <<
"!!!!!!!!!!!!!!!!GetHisto2!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
208 std::cout <<
" WARNING ERROR - HIST ID INCORRECT (TOO HIGH) - " <<
Number << std::endl;
209 std::cout <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
243 std::cout <<
"BscTest:beggining of job" << std::endl;
251 std::cout << std::endl <<
"BscTest:: Begining of Run" << std::endl;
258 iev = (*evt)()->GetEventID();
260 std::cout <<
"BscTest:update Event number = " <<
iev << std::endl;
267 itrk = (*trk)()->GetTrackID();
269 std::cout <<
"BscTest:update BeginOfTrack number = " <<
itrk << std::endl;
282 itrk = (*trk)()->GetTrackID();
284 std::cout <<
"BscTest:update EndOfTrack number = " <<
itrk << std::endl;
287 G4double tracklength = (*trk)()->GetTrackLength();
293 G4ThreeVector vert_mom = (*trk)()->GetVertexMomentumDirection();
294 G4ThreeVector vert_pos = (*trk)()->GetVertexPosition();
297 const G4Step* aStep = (*trk)()->GetStep();
298 G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
299 lastpo = preStepPoint->GetPosition();
310 G4int stepnumber = aStep->GetTrack()->GetCurrentStepNumber();
311 std::cout <<
"BscTest:update Step number = " << stepnumber << std::endl;
314 G4Track* theTrack = aStep->GetTrack();
315 TrackInformation* trkInfo = dynamic_cast<TrackInformation*>(theTrack->GetUserInformation());
316 if (trkInfo ==
nullptr) {
317 std::cout <<
"BscTest on aStep: No trk info !!!! abort " << std::endl;
319 G4int
id = theTrack->GetTrackID();
320 G4String
particleType = theTrack->GetDefinition()->GetParticleName();
321 G4int parentID = theTrack->GetParentID();
322 G4TrackStatus trackstatus = theTrack->GetTrackStatus();
323 G4double tracklength = theTrack->GetTrackLength();
324 G4ThreeVector trackmom = theTrack->GetMomentum();
325 G4double entot = theTrack->GetTotalEnergy();
326 G4int curstepnumber = theTrack->GetCurrentStepNumber();
327 G4double stepl = aStep->GetStepLength();
328 G4double EnerDeposit = aStep->GetTotalEnergyDeposit();
329 G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
330 const G4ThreeVector& preposition = preStepPoint->GetPosition();
331 G4ThreeVector prelocalpoint = theTrack->GetTouchable()->GetHistory()->GetTopTransform().TransformPoint(preposition);
332 G4VPhysicalVolume* currentPV = preStepPoint->GetPhysicalVolume();
333 const G4String& prename = currentPV->GetName();
335 const G4VTouchable* pre_touch = preStepPoint->GetTouchable();
339 for (
int i = 0;
i < 20; ++
i) {
343 if (pre_levels > 0) {
349 if (curstepnumber == 1) {
357 if (prename ==
"SBST") {
363 if (prename ==
"SBSTs") {
371 if (trackstatus != 2) {
373 if (prename ==
"SIDETL" || prename ==
"SIDETR") {
374 if (prename ==
"SIDETL") {
377 if (prename ==
"SIDETR") {
381 G4String posname = aStep->GetPostStepPoint()->GetPhysicalVolume()->GetName();
382 if ((prename ==
"SIDETL" && posname !=
"SIDETL") || (prename ==
"SIDETR" && posname !=
"SIDETR")) {
383 if (name1[2] ==
"SISTATION") {
386 if (name1[3] ==
"SIPLANE") {
390 if (prename ==
"SIDETL") {
393 if (copyno1[2] < 2) {
395 }
else if (copyno1[2] < 3) {
397 if (copyno1[3] < 2) {
398 }
else if (copyno1[3] < 3) {
400 }
else if (copyno1[3] < 4) {
402 }
else if (copyno1[3] < 5) {
404 }
else if (copyno1[3] < 6) {
406 }
else if (copyno1[3] < 7) {
408 }
else if (copyno1[3] < 8) {
410 }
else if (copyno1[3] < 9) {
412 }
else if (copyno1[3] < 10) {
415 }
else if (copyno1[2] < 4) {
417 }
else if (copyno1[2] < 5) {
421 if (prename ==
"SIDETR") {
424 if (copyno1[2] < 2) {
426 }
else if (copyno1[2] < 3) {
428 if (copyno1[3] < 2) {
429 }
else if (copyno1[3] < 3) {
431 }
else if (copyno1[3] < 4) {
433 }
else if (copyno1[3] < 5) {
435 }
else if (copyno1[3] < 6) {
437 }
else if (copyno1[3] < 7) {
439 }
else if (copyno1[3] < 8) {
441 }
else if (copyno1[3] < 9) {
443 }
else if (copyno1[3] < 10) {
446 }
else if (copyno1[2] < 4) {
448 }
else if (copyno1[2] < 5) {
459 if (trackstatus == 2) {
467 if (parentID == 1 && curstepnumber == 1) {
470 if (prename ==
"SBST") {
473 if (prename ==
"SBSTs") {
483 return ((touch->GetHistoryDepth()) + 1);
493 return touch->GetVolume(
ii)->GetName();
504 G4VPhysicalVolume*
pv = touch->GetVolume(
i);
509 copyno[
ii] = touch->GetReplicaNumber(
i);
520 iev = (*evt)()->GetEventID();
521 std::cout <<
"BscTest:update EndOfEvent = " <<
iev << std::endl;
528 G4PrimaryParticle* thePrim =
nullptr;
531 G4int nvertex = (*evt)()->GetNumberOfPrimaryVertex();
533 std::cout <<
"BscTest: My warning: NumberOfPrimaryVertex != 1 --> = " << nvertex << std::endl;
535 for (
int i = 0;
i < nvertex;
i++) {
536 G4PrimaryVertex* avertex = (*evt)()->GetPrimaryVertex(
i);
537 if (avertex ==
nullptr)
538 std::cout <<
"BscTest End Of Event ERR: pointer to vertex = 0" << std::endl;
539 G4int
npart = avertex->GetNumberOfParticle();
541 std::cout <<
"BscTest: My warning: NumberOfPrimaryPart != 1 --> = " <<
npart << std::endl;
543 std::cout <<
"BscTest End Of Event ERR: no NumberOfParticle" << std::endl;
545 if (thePrim ==
nullptr)
546 thePrim = avertex->GetPrimary(trackID);
548 if (thePrim !=
nullptr) {
550 G4double vx = 0., vy = 0., vz = 0.;
551 vx = avertex->GetX0();
552 vy = avertex->GetY0();
553 vz = avertex->GetZ0();
565 if (thePrim !=
nullptr) {
575 G4ThreeVector mom = thePrim->GetMomentum();
577 double phi = atan2(mom.y(), mom.x());
580 double phigrad =
phi * 180. /
pi;
582 double th = mom.theta();
603 std::map<int, float, std::less<int> > themap;
604 std::map<int, float, std::less<int> > themap1;
606 std::map<int, float, std::less<int> > themapxy;
607 std::map<int, float, std::less<int> > themapz;
611 G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
614 std::cout <<
"BscTest: accessed all HC" << std::endl;
617 int CAFIid = G4SDManager::GetSDMpointer()->GetCollectionID(
"BSCHits");
621 std::cout <<
"BscTest: theCAFI->entries = " << theCAFI->entries() << std::endl;
630 int nhits = theCAFI->entries();
633 const CLHEP::Hep3Vector& hitPoint = aHit->
getEntry();
634 double zz = hitPoint.z();
641 int nhit11 = 0, nhit12 = 0, nhit13 = 0;
642 double totallosenergy = 0.;
646 const CLHEP::Hep3Vector& hitEntryLocalPoint = aHit->
getEntryLocalP();
647 const CLHEP::Hep3Vector& hitExitLocalPoint = aHit->
getExitLocalP();
648 const CLHEP::Hep3Vector& hitPoint = aHit->
getEntry();
653 double zz = hitPoint.z();
658 std::cout <<
"BscTest:zHits = " <<
zz << std::endl;
661 themap[unitID] += losenergy;
662 totallosenergy += losenergy;
666 zside = (unitID & 32) >> 5;
667 sector = (unitID & 7);
671 G4ThreeVector middle = (hitExitLocalPoint + hitEntryLocalPoint) / 2.;
672 themapz[unitID] = hitPoint.z() + middle.z();
677 if (losenergy > 0.00003) {
678 themap1[unitID] += 1.;
684 if (losenergy > 0.00005) {
685 themap1[unitID] += 1.;
716 if (zz < z3 && zz >
z2) {
721 if (zz < z4 && zz >
z3) {
744 if (trackIDhit == 1) {
753 if (zz < z3 && zz >
z2) {
766 if (trackIDhit == 1) {
774 if (zz < z4 && zz >
z3) {
784 if (totallosenergy == 0.0) {
785 std::cout <<
"BscTest: number of hits = " << theCAFI->entries() << std::endl;
789 std::cout <<
" j hits = " <<
j <<
"losenergy = " << losenergy << std::endl;
793 double totalEnergy = 0.;
794 int nhitsX = 0, nhitsY = 0, nsumhit = 0;
795 for (
int sector = 1; sector < 4; sector++) {
796 int nhitsecX = 0, nhitsecY = 0;
797 for (
int zmodule = 1; zmodule < 11; zmodule++) {
802 double theTotalEnergy = themap[
index];
806 if (theTotalEnergy > 0.00003) {
815 if (theTotalEnergy > 0.00005) {
822 totalEnergy += themap[
index];
826 if (nhitsecX > 10 || nhitsecY > 10) {
840 std::cout <<
"BscTest: END OF Event " << (*evt)()->GetEventID() << std::endl;