34 #include "G4HCofThisEvent.hh" 35 #include "G4ProcessManager.hh" 36 #include "G4SDManager.hh" 39 #include "G4TransportationManager.hh" 40 #include "G4UserEventAction.hh" 41 #include "G4VProcess.hh" 42 #include "G4VTouchable.hh" 44 #include <CLHEP/Random/Randomize.h> 45 #include <CLHEP/Units/GlobalSystemOfUnits.h> 46 #include <CLHEP/Units/GlobalPhysicalConstants.h> 57 #include "TLorentzVector.h" 58 #include "TUnixSystem.h" 62 #include "TObjArray.h" 63 #include "TObjString.h" 72 TH1F*
getHisto(
const TObjString& histname);
75 TH2F*
getHisto2(
const TObjString& histname);
77 void writeToFile(
const TString& fOutputFile,
const TString& fRecreateFile);
84 const char*
name,
const char*
title, Int_t
nbinsx, Axis_t xlow, Axis_t xup, Int_t
nbinsy, Axis_t ylow, Axis_t yup);
95 public Observer<const BeginOfEvent*>,
96 public Observer<const BeginOfTrack*>,
118 int detLevels(
const G4VTouchable*)
const;
119 G4String
detName(
const G4VTouchable*,
int,
int)
const;
120 void detectorLevel(
const G4VTouchable*,
int&,
int*, G4String*)
const;
172 edm::LogVerbatim(
"FP420Test") <<
"============================================================================";
173 edm::LogVerbatim(
"FP420Test") <<
"FP420Testconstructor :: Initialized as observer";
187 double gapSupplane = 1.6;
190 double zKapton = 0.1;
194 double zSiElectr = 0.250;
195 double zCeramDet = 0.500;
201 double zSiStation = (
pn0 - 1) * (2 * (
zBlade +
gapBlade) + zKapton) + 2 * 6. + 0.0;
225 edm::LogVerbatim(
"FP420Test") <<
"FP420Test constructor :: Initialized Fp420AnalysisHistManager";
239 edm::LogVerbatim(
"FP420Test") <<
"FP420 output root file pointer has been deleted";
246 edm::LogVerbatim(
"FP420Test") << std::endl <<
"FP420Test Destructor --------> End of FP420Test : ";
261 TH1::AddDirectory(kFALSE);
288 histInit(
"PrimaryEta",
"Primary Eta", 100, 9., 12.);
289 histInit(
"PrimaryPhigrad",
"Primary Phigrad", 100, 0., 360.);
290 histInit(
"PrimaryTh",
"Primary Th", 100, 0., 180.);
291 histInit(
"PrimaryLastpoZ",
"Primary Lastpo Z", 100, -200., 430000.);
292 histInit(
"PrimaryLastpoX",
"Primary Lastpo X Z<z4", 100, -30., 30.);
293 histInit(
"PrimaryLastpoY",
"Primary Lastpo Y Z<z4", 100, -30., 30.);
294 histInit(
"XLastpoNumofpart",
"Primary Lastpo X n>10", 100, -30., 30.);
295 histInit(
"YLastpoNumofpart",
"Primary Lastpo Y n>10", 100, -30., 30.);
296 histInit(
"VtxX",
"Vtx X", 100, -50., 50.);
297 histInit(
"VtxY",
"Vtx Y", 100, -50., 50.);
298 histInit(
"VtxZ",
"Vtx Z", 100, -200., 430000.);
300 histInit(
"SumEDep",
"This is sum Energy deposited", 100, -1, 199.);
301 histInit(
"TrackL",
"This is TrackL", 100, 0., 12000.);
302 histInit(
"zHits",
"z Hits all events", 100, 400000., 430000.);
303 histInit(
"zHitsnoMI",
"z Hits no MI", 100, 400000., 430000.);
304 histInit(
"zHitsTrLoLe",
"z Hits TrLength bigger 8300", 100, 400000., 430000.);
305 histInit(
"NumberOfHits",
"NumberOfHits", 100, 0., 300.);
313 edm::LogVerbatim(
"FP420Test") <<
"================================================================";
314 edm::LogVerbatim(
"FP420Test") <<
" Write this Analysis to File " << fOutputFile;
315 edm::LogVerbatim(
"FP420Test") <<
"================================================================";
317 TFile*
file =
new TFile(fOutputFile, fRecreateFile);
328 strcpy(newtitle,
title);
329 strcat(newtitle,
" (");
331 strcat(newtitle,
") ");
338 const char*
name,
const char*
title, Int_t
nbinsx, Axis_t xlow, Axis_t xup, Int_t
nbinsy, Axis_t ylow, Axis_t yup) {
342 strcpy(newtitle,
title);
343 strcat(newtitle,
" (");
345 strcat(newtitle,
") ");
354 if (Number <= fHistArray->GetLast() &&
fHistArray->At(
Number) != (TObject*)
nullptr) {
358 edm::LogVerbatim(
"FP420Test") <<
"!!!!!!!!!!!!!!!!!!getHisto!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
360 edm::LogVerbatim(
"FP420Test") <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
370 if (Number <= fHistArray->GetLast() &&
fHistArray->At(
Number) != (TObject*)
nullptr) {
374 edm::LogVerbatim(
"FP420Test") <<
"!!!!!!!!!!!!!!!!getHisto2!!!!!!!!!!!!!!!!!!!!!!!!!!!";
376 edm::LogVerbatim(
"FP420Test") <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
424 edm::LogVerbatim(
"FP420Test") << std::endl <<
"FP420Test:: Begining of Run";
431 iev = (*evt)()->GetEventID();
440 itrk = (*trk)()->GetTrackID();
455 itrk = (*trk)()->GetTrackID();
460 G4double tracklength = (*trk)()->GetTrackLength();
466 G4ThreeVector vert_mom = (*trk)()->GetVertexMomentumDirection();
467 G4ThreeVector vert_pos = (*trk)()->GetVertexPosition();
496 if (tracklength <
z4) {
504 const G4Step* aStep = (*trk)()->GetStep();
508 G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
509 lastpo = preStepPoint->GetPosition();
558 G4int stepnumber = aStep->GetTrack()->GetCurrentStepNumber();
559 edm::LogVerbatim(
"FP420Test") <<
"FP420Test:update Step number = " << stepnumber;
562 G4Track* theTrack = aStep->GetTrack();
564 if (trkInfo ==
nullptr) {
565 edm::LogVerbatim(
"FP420Test") <<
"FP420Test on aStep: No trk info !!!! abort ";
567 G4int
id = theTrack->GetTrackID();
568 G4String
particleType = theTrack->GetDefinition()->GetParticleName();
569 G4int parentID = theTrack->GetParentID();
570 G4TrackStatus trackstatus = theTrack->GetTrackStatus();
571 G4double tracklength = theTrack->GetTrackLength();
572 G4ThreeVector trackmom = theTrack->GetMomentum();
573 G4double entot = theTrack->GetTotalEnergy();
574 G4int curstepnumber = theTrack->GetCurrentStepNumber();
591 G4double stepl = aStep->GetStepLength();
592 G4double EnerDeposit = aStep->GetTotalEnergyDeposit();
600 G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
601 const G4ThreeVector& preposition = preStepPoint->GetPosition();
602 G4ThreeVector prelocalpoint = theTrack->GetTouchable()->GetHistory()->GetTopTransform().TransformPoint(preposition);
603 G4VPhysicalVolume* currentPV = preStepPoint->GetPhysicalVolume();
604 const G4String& prename = currentPV->GetName();
606 const G4VTouchable* pre_touch = preStepPoint->GetTouchable();
611 for (
int i = 0;
i < 20; ++
i) {
615 if (pre_levels > 0) {
623 if (curstepnumber == 1) {
631 if (prename ==
"SBST") {
637 if (prename ==
"SBSTs") {
645 if (trackstatus != 2) {
647 if (prename ==
"SIDETL" || prename ==
"SIDETR") {
648 if (prename ==
"SIDETL") {
651 if (prename ==
"SIDETR") {
676 G4String posname = aStep->GetPostStepPoint()->GetPhysicalVolume()->GetName();
677 if ((prename ==
"SIDETL" && posname !=
"SIDETL") || (prename ==
"SIDETR" && posname !=
"SIDETR")) {
678 if (name1[2] ==
"SISTATION") {
681 if (name1[3] ==
"SIPLANE") {
685 if (prename ==
"SIDETL") {
688 if (copyno1[2] < 2) {
690 }
else if (copyno1[2] < 3) {
692 if (copyno1[3] < 2) {
693 }
else if (copyno1[3] < 3) {
695 }
else if (copyno1[3] < 4) {
697 }
else if (copyno1[3] < 5) {
699 }
else if (copyno1[3] < 6) {
701 }
else if (copyno1[3] < 7) {
703 }
else if (copyno1[3] < 8) {
705 }
else if (copyno1[3] < 9) {
707 }
else if (copyno1[3] < 10) {
710 }
else if (copyno1[2] < 4) {
712 }
else if (copyno1[2] < 5) {
716 if (prename ==
"SIDETR") {
719 if (copyno1[2] < 2) {
721 }
else if (copyno1[2] < 3) {
723 if (copyno1[3] < 2) {
724 }
else if (copyno1[3] < 3) {
726 }
else if (copyno1[3] < 4) {
728 }
else if (copyno1[3] < 5) {
730 }
else if (copyno1[3] < 6) {
732 }
else if (copyno1[3] < 7) {
734 }
else if (copyno1[3] < 8) {
736 }
else if (copyno1[3] < 9) {
738 }
else if (copyno1[3] < 10) {
741 }
else if (copyno1[2] < 4) {
743 }
else if (copyno1[2] < 5) {
773 if (trackstatus == 2) {
786 if (parentID == 1 && curstepnumber == 1) {
804 if (prename ==
"SBST") {
807 if (prename ==
"SBSTs") {
819 return ((touch->GetHistoryDepth()) + 1);
829 return touch->GetVolume(
ii)->GetName();
840 G4VPhysicalVolume*
pv = touch->GetVolume(
i);
845 copyno[
ii] = touch->GetReplicaNumber(
i);
856 iev = (*evt)()->GetEventID();
864 G4PrimaryParticle* thePrim =
nullptr;
867 G4int nvertex = (*evt)()->GetNumberOfPrimaryVertex();
869 edm::LogVerbatim(
"FP420Test") <<
"FP420Test: My warning: NumberOfPrimaryVertex != 1 --> = " << nvertex;
871 for (
int i = 0;
i < nvertex;
i++) {
872 G4PrimaryVertex* avertex = (*evt)()->GetPrimaryVertex(
i);
873 if (avertex ==
nullptr) {
874 edm::LogVerbatim(
"FP420Test") <<
"FP420Test End Of Event ERR: pointer to vertex = 0";
877 G4int
npart = avertex->GetNumberOfParticle();
881 edm::LogVerbatim(
"FP420Test") <<
"FP420Test End Of Event ERR: no NumberOfParticle";
884 if (thePrim ==
nullptr)
885 thePrim = avertex->GetPrimary(trackID);
887 if (thePrim !=
nullptr) {
889 G4double vx = 0., vy = 0., vz = 0.;
890 vx = avertex->GetX0();
891 vy = avertex->GetY0();
892 vz = avertex->GetZ0();
904 if (thePrim !=
nullptr) {
926 G4ThreeVector mom = thePrim->GetMomentum();
928 double phi = atan2(mom.y(), mom.x());
931 double phigrad =
phi * 180. /
pi;
933 double th = mom.theta();
966 std::map<int, float, std::less<int> > themap;
967 std::map<int, float, std::less<int> > themap1;
969 std::map<int, float, std::less<int> > themapxy;
970 std::map<int, float, std::less<int> > themapz;
974 G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
980 int CAFIid = G4SDManager::GetSDMpointer()->GetCollectionID(
"FP420SI");
988 edm::LogVerbatim(
"FP420Test") <<
"FP420Test: theCAFI->entries = " << theCAFI->entries();
1020 int nhits = theCAFI->entries();
1023 G4ThreeVector hitPoint = aHit->
getEntry();
1024 double zz = hitPoint.z();
1039 double totallosenergy = 0.;
1045 G4ThreeVector hitPoint = aHit->
getEntry();
1050 unsigned int unitID = aHit->
getUnitID();
1080 double zz = hitPoint.z();
1096 themap[unitID] += losenergy;
1097 totallosenergy += losenergy;
1103 if (justlayer < 1 || justlayer > 2) {
1104 edm::LogVerbatim(
"FP420Test") <<
"FP420Test:WRONG justlayer= " << justlayer;
1119 G4ThreeVector middle = (hitExitLocalPoint - hitEntryLocalPoint) / 2.;
1120 themapz[unitID] = hitPoint.z() + fabs(middle.z());
1122 edm::LogVerbatim(
"FP420Test") <<
"1111111111111111111111111111111111111111111111111111111111111111111111111 ";
1126 edm::LogVerbatim(
"FP420Test") <<
"FP420Test: hitExitLocalPoint = " << hitExitLocalPoint;
1127 edm::LogVerbatim(
"FP420Test") <<
"FP420Test: hitEntryLocalPoint = " << hitEntryLocalPoint;
1129 edm::LogVerbatim(
"FP420Test") <<
"FP420Test: hitPoint.z()-419000.= " << hitPoint.z() - 419000.;
1131 edm::LogVerbatim(
"FP420Test") <<
"FP420Test:zHits-419000. = " << themapz[unitID] - 419000.;
1137 if (losenergy > 0.00003) {
1138 themap1[unitID] += 1.;
1144 if (losenergy > 0.00005) {
1145 themap1[unitID] += 1.;
1191 if (zz < z3 && zz >
z2) {
1196 if (zz < z4 && zz >
z3) {
1219 if (trackIDhit == 1) {
1228 if (zz < z3 && zz >
z2) {
1241 if (trackIDhit == 1) {
1249 if (zz < z4 && zz >
z3) {
1280 edm::LogVerbatim(
"FP420Test") <<
"22222222222222222222222222222222222222222222222222222222222222222222222222 ";
1283 int allplacesforsensors = 7;
1285 for (
int zmodule = 1; zmodule <
pn0; zmodule++) {
1286 for (
int zsideinorder = 1; zsideinorder < allplacesforsensors; zsideinorder++) {
1290 <<
" zsideinorder= " << zsideinorder <<
" zside= " <<
zside;
1294 if (justlayer < 1 || justlayer > 2) {
1295 edm::LogVerbatim(
"FP420Test") <<
"FP420Test:WRONG justlayer= " << justlayer;
1298 if (copyinlayer < 1 || copyinlayer > 3) {
1299 edm::LogVerbatim(
"FP420Test") <<
"FP420Test:WRONG copyinlayer= " << copyinlayer;
1302 if (orientation < 1 || orientation > 2) {
1303 edm::LogVerbatim(
"FP420Test") <<
"FP420Test:WRONG orientation= " << orientation;
1315 <<
"FP420Test: justlayer = " << justlayer <<
" copyinlayer = " << copyinlayer
1316 <<
" orientation = " << orientation <<
" ii= " <<
ii;
1318 double zdiststat = 0.;
1328 double kplane = -(
pn0 - 1) / 2 - 0.5 + (zmodule - 1);
1332 edm::LogVerbatim(
"FP420Test") <<
"FP420Test: Leftzcurrent-419000. = " << zcurrent - 419000.;
1335 if (justlayer == 1) {
1336 if (orientation == 1)
1338 if (orientation == 2)
1341 if (justlayer == 2) {
1342 if (orientation == 1)
1344 if (orientation == 2)
1350 zcurrent = -zcurrent;
1353 edm::LogVerbatim(
"FP420Test") <<
"FP420Test: zcurrent-419000. = " << zcurrent - 419000.;
1363 <<
"----------------------------------------------------------------------------- ";
1367 if (totallosenergy == 0.0) {
1368 edm::LogVerbatim(
"FP420Test") <<
"FP420Test: number of hits = " << theCAFI->entries();
1372 edm::LogVerbatim(
"FP420Test") <<
" j hits = " <<
j <<
"losenergy = " << losenergy;
1450 edm::LogVerbatim(
"FP420Test") <<
"FP420Test: END OF Event " << (*evt)()->GetEventID();
static int unpackCopyIndex(int rn0, int zside)
void update(const BeginOfJob *run) override
This routine will be called when the appropriate signal arrives.
Log< level::Info, true > LogVerbatim
#define DEFINE_SIMWATCHER(type)
T getParameter(std::string const &) const
void writeToFile(const TString &fOutputFile, const TString &fRecreateFile)
static int realzside(int rn0, int zsideinorder)
static void unpackFP420Index(const unsigned int &idx, int &det, int &zside, int &station, int &superplane)
FP420Test(const edm::ParameterSet &p)
static int unpackLayerIndex(int rn0, int zside)
std::string fRecreateFile
unsigned int getUnitID() const
static unsigned packMYIndex(int rn0, int pn0, int sn0, int det, int zside, int sector, int zmodule)
G4ThreeVector getEntry() const
Fp420AnalysisHistManager * theHistManager
unsigned int getTrackID() const
void detectorLevel(const G4VTouchable *, int &, int *, G4String *) const
Fp420AnalysisHistManager(const TString &managername)
Tan< T >::type tan(const T &t)
G4String detName(const G4VTouchable *, int, int) const
G4ThreeVector getEntryLocalP() const
Float_t fp420eventarray[1]
TH1F * getHisto(Int_t Number)
int detLevels(const G4VTouchable *) const
G4THitsCollection< FP420G4Hit > FP420G4HitCollection
void histInit(const char *name, const char *title, Int_t nbinsx, Axis_t xlow, Axis_t xup)
TH2F * getHisto2(Int_t Number)
float getEnergyLoss() const
static int unpackOrientation(int rn0, int zside)
TNtuple * fp420eventntuple
TObjArray * fHistNamesArray
G4ThreeVector getExitLocalP() const
~Fp420AnalysisHistManager() override