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"
62 std::cout <<
"============================================================================" << std::endl;
63 std::cout <<
"FP420Testconstructor :: Initialized as observer" << std::endl;
77 double gapSupplane = 1.6;
78 ZSiPlane = 2 * zBlade + gapBlade + gapSupplane;
81 ZSiStep = ZSiPlane + ZKapton;
83 double ZBoundDet = 0.020;
84 double ZSiElectr = 0.250;
85 double ZCeramDet = 0.500;
88 ZGapLDet = zBlade / 2 - (ZSiDet + ZSiElectr + ZBoundDet + ZCeramDet / 2);
91 double ZSiStation = (pn0 - 1) * (2 * (zBlade + gapBlade) + ZKapton) + 2 * 6. + 0.0;
96 zinibeg = (eee1 - eee2) / 2.;
98 z1 = zinibeg + (ZSiStation + 10.) / 2 +
z420;
104 fp420eventntuple =
new TNtuple(
"NTfp420event",
"NTfp420event",
"evt");
115 std::cout <<
"FP420Test constructor :: Initialized Fp420AnalysisHistManager" << std::endl;
122 TFile fp420OutputFile(
"newntfp420.root",
"RECREATE");
123 std::cout <<
"FP420 output root file has been created";
124 fp420eventntuple->Write();
126 fp420OutputFile.Close();
128 delete fp420eventntuple;
129 std::cout <<
", and deleted" << std::endl;
134 TheHistManager->WriteToFile(fOutputFile, fRecreateFile);
136 std::cout << std::endl <<
"FP420Test Destructor --------> End of FP420Test : " << std::endl;
147 fTypeTitle = managername;
148 fHistArray =
new TObjArray();
149 fHistNamesArray =
new TObjArray();
151 TH1::AddDirectory(kFALSE);
154 fHistArray->Compress();
155 fHistNamesArray->Compress();
165 fHistArray->Delete();
169 if (fHistNamesArray) {
170 fHistNamesArray->Delete();
171 delete fHistNamesArray;
178 HistInit(
"PrimaryEta",
"Primary Eta", 100, 9., 12.);
179 HistInit(
"PrimaryPhigrad",
"Primary Phigrad", 100, 0., 360.);
180 HistInit(
"PrimaryTh",
"Primary Th", 100, 0., 180.);
181 HistInit(
"PrimaryLastpoZ",
"Primary Lastpo Z", 100, -200., 430000.);
182 HistInit(
"PrimaryLastpoX",
"Primary Lastpo X Z<z4", 100, -30., 30.);
183 HistInit(
"PrimaryLastpoY",
"Primary Lastpo Y Z<z4", 100, -30., 30.);
184 HistInit(
"XLastpoNumofpart",
"Primary Lastpo X n>10", 100, -30., 30.);
185 HistInit(
"YLastpoNumofpart",
"Primary Lastpo Y n>10", 100, -30., 30.);
186 HistInit(
"VtxX",
"Vtx X", 100, -50., 50.);
187 HistInit(
"VtxY",
"Vtx Y", 100, -50., 50.);
188 HistInit(
"VtxZ",
"Vtx Z", 100, -200., 430000.);
190 HistInit(
"SumEDep",
"This is sum Energy deposited", 100, -1, 199.);
191 HistInit(
"TrackL",
"This is TrackL", 100, 0., 12000.);
192 HistInit(
"zHits",
"z Hits all events", 100, 400000., 430000.);
193 HistInit(
"zHitsnoMI",
"z Hits no MI", 100, 400000., 430000.);
194 HistInit(
"zHitsTrLoLe",
"z Hits TrLength bigger 8300", 100, 400000., 430000.);
195 HistInit(
"NumberOfHits",
"NumberOfHits", 100, 0., 300.);
203 std::cout <<
"================================================================" << std::endl;
204 std::cout <<
" Write this Analysis to File " << fOutputFile << std::endl;
205 std::cout <<
"================================================================" << std::endl;
207 TFile*
file =
new TFile(fOutputFile, fRecreateFile);
217 char* newtitle =
new char[strlen(
title) + strlen(fTypeTitle) + 5];
218 strcpy(newtitle,
title);
219 strcat(newtitle,
" (");
220 strcat(newtitle, fTypeTitle);
221 strcat(newtitle,
") ");
222 fHistArray->AddLast((
new TH1F(
name, newtitle, nbinsx, xlow, xup)));
223 fHistNamesArray->AddLast(
new TObjString(
name));
228 const char*
name,
const char*
title, Int_t nbinsx, Axis_t xlow, Axis_t xup, Int_t nbinsy, Axis_t ylow, Axis_t yup) {
231 char* newtitle =
new char[strlen(
title) + strlen(fTypeTitle) + 5];
232 strcpy(newtitle,
title);
233 strcat(newtitle,
" (");
234 strcat(newtitle, fTypeTitle);
235 strcat(newtitle,
") ");
236 fHistArray->AddLast((
new TH2F(
name, newtitle, nbinsx, xlow, xup, nbinsy, ylow, yup)));
237 fHistNamesArray->AddLast(
new TObjString(
name));
244 if (Number <= fHistArray->GetLast() && fHistArray->At(
Number) != (TObject*)
nullptr) {
245 return (TH1F*)(fHistArray->At(
Number));
248 std::cout <<
"!!!!!!!!!!!!!!!!!!GetHisto!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
249 std::cout <<
" WARNING ERROR - HIST ID INCORRECT (TOO HIGH) - " <<
Number << std::endl;
250 std::cout <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
252 return (TH1F*)(fHistArray->At(0));
260 if (Number <= fHistArray->GetLast() && fHistArray->At(
Number) != (TObject*)
nullptr) {
261 return (TH2F*)(fHistArray->At(
Number));
264 std::cout <<
"!!!!!!!!!!!!!!!!GetHisto2!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
265 std::cout <<
" WARNING ERROR - HIST ID INCORRECT (TOO HIGH) - " <<
Number << std::endl;
266 std::cout <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
268 return (TH2F*)(fHistArray->At(0));
276 Int_t
index = fHistNamesArray->IndexOf(&histname);
277 return GetHisto(
index);
284 Int_t
index = fHistNamesArray->IndexOf(&histname);
285 return GetHisto2(
index);
292 for (
int i = 0;
i < fHistArray->GetEntries();
i++) {
293 ((TH1F*)(fHistArray->At(
i)))->Sumw2();
306 std::cout <<
"FP420Test:beggining of job" << std::endl;
314 std::cout << std::endl <<
"FP420Test:: Begining of Run" << std::endl;
321 iev = (*evt)()->GetEventID();
323 std::cout <<
"FP420Test:update Event number = " << iev << std::endl;
330 itrk = (*trk)()->GetTrackID();
332 std::cout <<
"FP420Test:update BeginOfTrack number = " << itrk << std::endl;
345 itrk = (*trk)()->GetTrackID();
347 std::cout <<
"FP420Test:update EndOfTrack number = " << itrk << std::endl;
350 G4double tracklength = (*trk)()->GetTrackLength();
352 TheHistManager->GetHisto(
"SumEDep")->Fill(SumEnerDeposit);
353 TheHistManager->GetHisto(
"TrackL")->Fill(tracklength);
356 G4ThreeVector vert_mom = (*trk)()->GetVertexMomentumDirection();
357 G4ThreeVector vert_pos = (*trk)()->GetVertexPosition();
386 if (tracklength < z4) {
394 const G4Step* aStep = (*trk)()->GetStep();
398 G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
399 lastpo = preStepPoint->GetPosition();
402 if (lastpo.z() < z1 && lastpo.perp() < 100.) {
408 if ((lastpo.z() > z1 && lastpo.z() <
z2) && lastpo.perp() < 100.) {
414 if (lastpo.z() <
z2 && lastpo.perp() < 100.) {
423 if (lastpo.z() < z3 && lastpo.perp() < 100.) {
429 if (lastpo.z() < z4 && lastpo.perp() < 100.) {
448 G4int stepnumber = aStep->GetTrack()->GetCurrentStepNumber();
449 std::cout <<
"FP420Test:update Step number = " << stepnumber << std::endl;
452 G4Track* theTrack = aStep->GetTrack();
453 TrackInformation* trkInfo = dynamic_cast<TrackInformation*>(theTrack->GetUserInformation());
454 if (trkInfo ==
nullptr) {
455 std::cout <<
"FP420Test on aStep: No trk info !!!! abort " << std::endl;
457 G4int
id = theTrack->GetTrackID();
458 G4String
particleType = theTrack->GetDefinition()->GetParticleName();
459 G4int parentID = theTrack->GetParentID();
460 G4TrackStatus trackstatus = theTrack->GetTrackStatus();
461 G4double tracklength = theTrack->GetTrackLength();
462 G4ThreeVector trackmom = theTrack->GetMomentum();
463 G4double entot = theTrack->GetTotalEnergy();
464 G4int curstepnumber = theTrack->GetCurrentStepNumber();
481 G4double stepl = aStep->GetStepLength();
482 G4double EnerDeposit = aStep->GetTotalEnergyDeposit();
490 G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
491 const G4ThreeVector& preposition = preStepPoint->GetPosition();
492 G4ThreeVector prelocalpoint = theTrack->GetTouchable()->GetHistory()->GetTopTransform().TransformPoint(preposition);
493 G4VPhysicalVolume* currentPV = preStepPoint->GetPhysicalVolume();
494 const G4String& prename = currentPV->GetName();
496 const G4VTouchable* pre_touch = preStepPoint->GetTouchable();
497 int pre_levels = detLevels(pre_touch);
501 for (
int i = 0;
i < 20; ++
i) {
505 if (pre_levels > 0) {
506 detectorLevel(pre_touch, pre_levels, copyno1, name1);
561 if (curstepnumber == 1) {
569 if (prename ==
"SBST") {
575 if (prename ==
"SBSTs") {
583 if (trackstatus != 2) {
585 if (prename ==
"SIDETL" || prename ==
"SIDETR") {
586 if (prename ==
"SIDETL") {
589 if (prename ==
"SIDETR") {
614 G4String posname = aStep->GetPostStepPoint()->GetPhysicalVolume()->GetName();
615 if ((prename ==
"SIDETL" && posname !=
"SIDETL") || (prename ==
"SIDETR" && posname !=
"SIDETR")) {
616 if (name1[2] ==
"SISTATION") {
619 if (name1[3] ==
"SIPLANE") {
623 if (prename ==
"SIDETL") {
626 if (copyno1[2] < 2) {
628 }
else if (copyno1[2] < 3) {
630 if (copyno1[3] < 2) {
631 }
else if (copyno1[3] < 3) {
633 }
else if (copyno1[3] < 4) {
635 }
else if (copyno1[3] < 5) {
637 }
else if (copyno1[3] < 6) {
639 }
else if (copyno1[3] < 7) {
641 }
else if (copyno1[3] < 8) {
643 }
else if (copyno1[3] < 9) {
645 }
else if (copyno1[3] < 10) {
648 }
else if (copyno1[2] < 4) {
650 }
else if (copyno1[2] < 5) {
654 if (prename ==
"SIDETR") {
657 if (copyno1[2] < 2) {
659 }
else if (copyno1[2] < 3) {
661 if (copyno1[3] < 2) {
662 }
else if (copyno1[3] < 3) {
664 }
else if (copyno1[3] < 4) {
666 }
else if (copyno1[3] < 5) {
668 }
else if (copyno1[3] < 6) {
670 }
else if (copyno1[3] < 7) {
672 }
else if (copyno1[3] < 8) {
674 }
else if (copyno1[3] < 9) {
676 }
else if (copyno1[3] < 10) {
679 }
else if (copyno1[2] < 4) {
681 }
else if (copyno1[2] < 5) {
694 SumEnerDeposit += EnerDeposit;
711 if (trackstatus == 2) {
714 tracklength0 = tracklength;
724 if (parentID == 1 && curstepnumber == 1) {
742 if (prename ==
"SBST") {
745 if (prename ==
"SBSTs") {
757 return ((touch->GetHistoryDepth()) + 1);
767 return touch->GetVolume(
ii)->GetName();
778 G4VPhysicalVolume*
pv = touch->GetVolume(
i);
783 copyno[
ii] = touch->GetReplicaNumber(
i);
794 iev = (*evt)()->GetEventID();
795 std::cout <<
"FP420Test:update EndOfEvent = " << iev << std::endl;
802 G4PrimaryParticle* thePrim =
nullptr;
805 G4int nvertex = (*evt)()->GetNumberOfPrimaryVertex();
807 std::cout <<
"FP420Test: My warning: NumberOfPrimaryVertex != 1 --> = " << nvertex << std::endl;
809 for (
int i = 0;
i < nvertex;
i++) {
810 G4PrimaryVertex* avertex = (*evt)()->GetPrimaryVertex(
i);
811 if (avertex ==
nullptr)
812 std::cout <<
"FP420Test End Of Event ERR: pointer to vertex = 0" << std::endl;
813 G4int
npart = avertex->GetNumberOfParticle();
815 std::cout <<
"FP420Test: My warning: NumberOfPrimaryPart != 1 --> = " <<
npart << std::endl;
817 std::cout <<
"FP420Test End Of Event ERR: no NumberOfParticle" << std::endl;
820 if (thePrim ==
nullptr)
821 thePrim = avertex->GetPrimary(trackID);
823 if (thePrim !=
nullptr) {
825 G4double vx = 0., vy = 0., vz = 0.;
826 vx = avertex->GetX0();
827 vy = avertex->GetY0();
828 vz = avertex->GetZ0();
832 TheHistManager->GetHisto(
"VtxX")->Fill(vx);
833 TheHistManager->GetHisto(
"VtxY")->Fill(vy);
834 TheHistManager->GetHisto(
"VtxZ")->Fill(vz);
840 if (thePrim !=
nullptr) {
856 if (lastpo.z() < z4 && lastpo.perp() < 100.) {
862 G4ThreeVector mom = thePrim->GetMomentum();
864 double phi = atan2(mom.y(), mom.x());
867 double phigrad = phi * 180. /
pi;
869 double th = mom.theta();
883 TheHistManager->GetHisto(
"PrimaryEta")->Fill(
eta);
884 TheHistManager->GetHisto(
"PrimaryPhigrad")->Fill(phigrad);
885 TheHistManager->GetHisto(
"PrimaryTh")->Fill(th * 180. /
pi);
887 TheHistManager->GetHisto(
"PrimaryLastpoZ")->Fill(lastpo.z());
888 if (lastpo.z() < z4) {
889 TheHistManager->GetHisto(
"PrimaryLastpoX")->Fill(lastpo.x());
890 TheHistManager->GetHisto(
"PrimaryLastpoY")->Fill(lastpo.y());
893 TheHistManager->GetHisto(
"XLastpoNumofpart")->Fill(lastpo.x());
894 TheHistManager->GetHisto(
"YLastpoNumofpart")->Fill(lastpo.y());
902 map<int, float, less<int> > themap;
903 map<int, float, less<int> > themap1;
905 map<int, float, less<int> > themapxy;
906 map<int, float, less<int> > themapz;
910 G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
913 std::cout <<
"FP420Test: accessed all HC" << std::endl;
916 int CAFIid = G4SDManager::GetSDMpointer()->GetCollectionID(
"FP420SI");
924 std::cout <<
"FP420Test: theCAFI->entries = " << theCAFI->entries() << std::endl;
927 TheHistManager->GetHisto(
"NumberOfHits")->Fill(theCAFI->entries());
945 if (lastpo.z() < z4) {
956 int nhits = theCAFI->entries();
959 G4ThreeVector hitPoint = aHit->
getEntry();
960 double zz = hitPoint.z();
961 TheHistManager->GetHisto(
"zHits")->Fill(
zz);
962 if (tracklength0 > 8300.)
963 TheHistManager->GetHisto(
"zHitsTrLoLe")->Fill(
zz);
974 int nhit11 = 0, nhit12 = 0, nhit13 = 0;
975 double totallosenergy = 0.;
981 G4ThreeVector hitPoint = aHit->
getEntry();
1016 double zz = hitPoint.z();
1018 TheHistManager->GetHisto(
"zHitsnoMI")->Fill(
zz);
1021 std::cout <<
"FP420Test:zHits = " <<
zz << std::endl;
1032 themap[unitID] += losenergy;
1033 totallosenergy += losenergy;
1035 int det,
zside, sector, zmodule;
1039 if (justlayer < 1 || justlayer > 2) {
1040 std::cout <<
"FP420Test:WRONG justlayer= " << justlayer << std::endl;
1055 G4ThreeVector middle = (hitExitLocalPoint - hitEntryLocalPoint) / 2.;
1056 themapz[unitID] = hitPoint.z() + fabs(middle.z());
1058 std::cout <<
"1111111111111111111111111111111111111111111111111111111111111111111111111 " << std::endl;
1059 std::cout <<
"FP420Test: det, zside, sector, zmodule = " << det <<
zside << sector << zmodule << std::endl;
1060 std::cout <<
"FP420Test: justlayer = " << justlayer << std::endl;
1061 std::cout <<
"FP420Test: hitExitLocalPoint = " << hitExitLocalPoint << std::endl;
1062 std::cout <<
"FP420Test: hitEntryLocalPoint = " << hitEntryLocalPoint << std::endl;
1063 std::cout <<
"FP420Test: middle= " << middle << std::endl;
1064 std::cout <<
"FP420Test: hitPoint.z()-419000.= " << hitPoint.z() - 419000. << std::endl;
1066 std::cout <<
"FP420Test:zHits-419000. = " << themapz[unitID] - 419000. << std::endl;
1072 if (losenergy > 0.00003) {
1073 themap1[unitID] += 1.;
1079 if (losenergy > 0.00005) {
1080 themap1[unitID] += 1.;
1114 if (lastpo.z() < z4 && lastpo.perp() < 120.) {
1124 if (zz < z3 && zz >
z2) {
1129 if (zz < z4 && zz > z3) {
1152 if (trackIDhit == 1) {
1161 if (zz < z3 && zz >
z2) {
1174 if (trackIDhit == 1) {
1182 if (zz < z4 && zz > z3) {
1213 std::cout <<
"22222222222222222222222222222222222222222222222222222222222222222222222222 " << std::endl;
1216 int allplacesforsensors = 7;
1217 for (
int sector = 1; sector < sn0; sector++) {
1218 for (
int zmodule = 1; zmodule < pn0; zmodule++) {
1219 for (
int zsideinorder = 1; zsideinorder < allplacesforsensors; zsideinorder++) {
1222 std::cout <<
"FP420Test: sector= " << sector <<
" zmodule= " << zmodule
1223 <<
" zsideinorder= " << zsideinorder <<
" zside= " <<
zside << std::endl;
1227 if (justlayer < 1 || justlayer > 2) {
1228 std::cout <<
"FP420Test:WRONG justlayer= " << justlayer << std::endl;
1231 if (copyinlayer < 1 || copyinlayer > 3) {
1232 std::cout <<
"FP420Test:WRONG copyinlayer= " << copyinlayer << std::endl;
1235 if (orientation < 1 || orientation > 2) {
1236 std::cout <<
"FP420Test:WRONG orientation= " << orientation << std::endl;
1247 std::cout <<
"FP420Test: justlayer = " << justlayer <<
" copyinlayer = " << copyinlayer
1248 <<
" orientation = " << orientation <<
" ii= " <<
ii << std::endl;
1250 double zdiststat = 0.;
1260 double kplane = -(pn0 - 1) / 2 - 0.5 + (zmodule - 1);
1261 double zcurrent = zinibeg +
z420 + (ZSiStep - ZSiPlane) / 2 + kplane * ZSiStep + zdiststat;
1264 std::cout <<
"FP420Test: Leftzcurrent-419000. = " << zcurrent - 419000. << std::endl;
1265 std::cout <<
"FP420Test: ZGapLDet = " << ZGapLDet << std::endl;
1267 if (justlayer == 1) {
1268 if (orientation == 1)
1269 zcurrent += (ZGapLDet + ZSiDet / 2);
1270 if (orientation == 2)
1271 zcurrent += zBlade - (ZGapLDet + ZSiDet / 2);
1273 if (justlayer == 2) {
1274 if (orientation == 1)
1275 zcurrent += (ZGapLDet + ZSiDet / 2) + zBlade + gapBlade;
1276 if (orientation == 2)
1277 zcurrent += 2 * zBlade + gapBlade - (ZGapLDet + ZSiDet / 2);
1282 zcurrent = -zcurrent;
1285 std::cout <<
"FP420Test: zcurrent-419000. = " << zcurrent - 419000. << std::endl;
1294 std::cout <<
"----------------------------------------------------------------------------- " << std::endl;
1298 if (totallosenergy == 0.0) {
1299 std::cout <<
"FP420Test: number of hits = " << theCAFI->entries() << std::endl;
1303 std::cout <<
" j hits = " <<
j <<
"losenergy = " << losenergy << std::endl;
1311 double totalEnergy = 0.;
1312 int nhitsX = 0, nhitsY = 0, nsumhit = 0;
1313 for (
int sector = 1; sector < 4; sector++) {
1314 int nhitsecX = 0, nhitsecY = 0;
1315 for (
int zmodule = 1; zmodule < 11; zmodule++) {
1321 double theTotalEnergy = themap[
index];
1325 if (theTotalEnergy > 0.00003) {
1334 if (theTotalEnergy > 0.00005) {
1347 totalEnergy += themap[
index];
1351 if (nhitsecX > 10 || nhitsecY > 10) {
1380 std::cout <<
"FP420Test: END OF Event " << (*evt)()->GetEventID() << std::endl;