30 #include "G4HCofThisEvent.hh" 31 #include "G4ProcessManager.hh" 32 #include "G4SDManager.hh" 35 #include "G4TransportationManager.hh" 36 #include "G4UserEventAction.hh" 37 #include "G4VProcess.hh" 38 #include "G4VTouchable.hh" 40 #include <CLHEP/Random/Randomize.h> 41 #include <CLHEP/Units/GlobalSystemOfUnits.h> 42 #include <CLHEP/Units/GlobalPhysicalConstants.h> 53 #include "TLorentzVector.h" 54 #include "TUnixSystem.h" 58 #include "TObjArray.h" 59 #include "TObjString.h" 68 TH1F*
getHisto(
const TObjString& histname);
71 TH2F*
getHisto2(
const TObjString& histname);
73 void writeToFile(
const TString& fOutputFile,
const TString& fRecreateFile);
80 const char*
name,
const char*
title, Int_t
nbinsx, Axis_t xlow, Axis_t xup, Int_t
nbinsy, Axis_t ylow, Axis_t yup);
91 public Observer<const BeginOfEvent*>,
92 public Observer<const BeginOfTrack*>,
114 int detLevels(
const G4VTouchable*)
const;
115 G4String
detName(
const G4VTouchable*,
int,
int)
const;
116 void detectorLevel(
const G4VTouchable*,
int&,
int*, G4String*)
const;
168 edm::LogVerbatim(
"FP420Test") <<
"============================================================================";
169 edm::LogVerbatim(
"FP420Test") <<
"FP420Testconstructor :: Initialized as observer";
183 double gapSupplane = 1.6;
186 double zKapton = 0.1;
190 double zSiElectr = 0.250;
191 double zCeramDet = 0.500;
197 double zSiStation = (
pn0 - 1) * (2 * (
zBlade +
gapBlade) + zKapton) + 2 * 6. + 0.0;
221 edm::LogVerbatim(
"FP420Test") <<
"FP420Test constructor :: Initialized Fp420AnalysisHistManager";
235 edm::LogVerbatim(
"FP420Test") <<
"FP420 output root file pointer has been deleted";
242 edm::LogVerbatim(
"FP420Test") << std::endl <<
"FP420Test Destructor --------> End of FP420Test : ";
257 TH1::AddDirectory(kFALSE);
284 histInit(
"PrimaryEta",
"Primary Eta", 100, 9., 12.);
285 histInit(
"PrimaryPhigrad",
"Primary Phigrad", 100, 0., 360.);
286 histInit(
"PrimaryTh",
"Primary Th", 100, 0., 180.);
287 histInit(
"PrimaryLastpoZ",
"Primary Lastpo Z", 100, -200., 430000.);
288 histInit(
"PrimaryLastpoX",
"Primary Lastpo X Z<z4", 100, -30., 30.);
289 histInit(
"PrimaryLastpoY",
"Primary Lastpo Y Z<z4", 100, -30., 30.);
290 histInit(
"XLastpoNumofpart",
"Primary Lastpo X n>10", 100, -30., 30.);
291 histInit(
"YLastpoNumofpart",
"Primary Lastpo Y n>10", 100, -30., 30.);
292 histInit(
"VtxX",
"Vtx X", 100, -50., 50.);
293 histInit(
"VtxY",
"Vtx Y", 100, -50., 50.);
294 histInit(
"VtxZ",
"Vtx Z", 100, -200., 430000.);
296 histInit(
"SumEDep",
"This is sum Energy deposited", 100, -1, 199.);
297 histInit(
"TrackL",
"This is TrackL", 100, 0., 12000.);
298 histInit(
"zHits",
"z Hits all events", 100, 400000., 430000.);
299 histInit(
"zHitsnoMI",
"z Hits no MI", 100, 400000., 430000.);
300 histInit(
"zHitsTrLoLe",
"z Hits TrLength bigger 8300", 100, 400000., 430000.);
301 histInit(
"NumberOfHits",
"NumberOfHits", 100, 0., 300.);
309 edm::LogVerbatim(
"FP420Test") <<
"================================================================";
310 edm::LogVerbatim(
"FP420Test") <<
" Write this Analysis to File " << fOutputFile;
311 edm::LogVerbatim(
"FP420Test") <<
"================================================================";
313 TFile*
file =
new TFile(fOutputFile, fRecreateFile);
324 strcpy(newtitle,
title);
325 strcat(newtitle,
" (");
327 strcat(newtitle,
") ");
334 const char*
name,
const char*
title, Int_t
nbinsx, Axis_t xlow, Axis_t xup, Int_t
nbinsy, Axis_t ylow, Axis_t yup) {
338 strcpy(newtitle,
title);
339 strcat(newtitle,
" (");
341 strcat(newtitle,
") ");
350 if (Number <= fHistArray->GetLast() &&
fHistArray->At(
Number) != (TObject*)
nullptr) {
354 edm::LogVerbatim(
"FP420Test") <<
"!!!!!!!!!!!!!!!!!!getHisto!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
356 edm::LogVerbatim(
"FP420Test") <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
366 if (Number <= fHistArray->GetLast() &&
fHistArray->At(
Number) != (TObject*)
nullptr) {
370 edm::LogVerbatim(
"FP420Test") <<
"!!!!!!!!!!!!!!!!getHisto2!!!!!!!!!!!!!!!!!!!!!!!!!!!";
372 edm::LogVerbatim(
"FP420Test") <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
420 edm::LogVerbatim(
"FP420Test") << std::endl <<
"FP420Test:: Begining of Run";
427 iev = (*evt)()->GetEventID();
436 itrk = (*trk)()->GetTrackID();
451 itrk = (*trk)()->GetTrackID();
456 G4double tracklength = (*trk)()->GetTrackLength();
462 G4ThreeVector vert_mom = (*trk)()->GetVertexMomentumDirection();
463 G4ThreeVector vert_pos = (*trk)()->GetVertexPosition();
492 if (tracklength <
z4) {
500 const G4Step* aStep = (*trk)()->GetStep();
504 G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
505 lastpo = preStepPoint->GetPosition();
554 G4int stepnumber = aStep->GetTrack()->GetCurrentStepNumber();
555 edm::LogVerbatim(
"FP420Test") <<
"FP420Test:update Step number = " << stepnumber;
558 G4Track* theTrack = aStep->GetTrack();
560 if (trkInfo ==
nullptr) {
561 edm::LogVerbatim(
"FP420Test") <<
"FP420Test on aStep: No trk info !!!! abort ";
563 G4int
id = theTrack->GetTrackID();
564 G4String
particleType = theTrack->GetDefinition()->GetParticleName();
565 G4int parentID = theTrack->GetParentID();
566 G4TrackStatus trackstatus = theTrack->GetTrackStatus();
567 G4double tracklength = theTrack->GetTrackLength();
568 G4ThreeVector trackmom = theTrack->GetMomentum();
569 G4double entot = theTrack->GetTotalEnergy();
570 G4int curstepnumber = theTrack->GetCurrentStepNumber();
587 G4double stepl = aStep->GetStepLength();
588 G4double EnerDeposit = aStep->GetTotalEnergyDeposit();
596 G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
597 const G4ThreeVector& preposition = preStepPoint->GetPosition();
598 G4ThreeVector prelocalpoint = theTrack->GetTouchable()->GetHistory()->GetTopTransform().TransformPoint(preposition);
599 G4VPhysicalVolume* currentPV = preStepPoint->GetPhysicalVolume();
600 const G4String& prename = currentPV->GetName();
602 const G4VTouchable* pre_touch = preStepPoint->GetTouchable();
607 for (
int i = 0;
i < 20; ++
i) {
611 if (pre_levels > 0) {
619 if (curstepnumber == 1) {
627 if (prename ==
"SBST") {
633 if (prename ==
"SBSTs") {
641 if (trackstatus != 2) {
643 if (prename ==
"SIDETL" || prename ==
"SIDETR") {
644 if (prename ==
"SIDETL") {
647 if (prename ==
"SIDETR") {
672 G4String posname = aStep->GetPostStepPoint()->GetPhysicalVolume()->GetName();
673 if ((prename ==
"SIDETL" && posname !=
"SIDETL") || (prename ==
"SIDETR" && posname !=
"SIDETR")) {
674 if (name1[2] ==
"SISTATION") {
677 if (name1[3] ==
"SIPLANE") {
681 if (prename ==
"SIDETL") {
684 if (copyno1[2] < 2) {
686 }
else if (copyno1[2] < 3) {
688 if (copyno1[3] < 2) {
689 }
else if (copyno1[3] < 3) {
691 }
else if (copyno1[3] < 4) {
693 }
else if (copyno1[3] < 5) {
695 }
else if (copyno1[3] < 6) {
697 }
else if (copyno1[3] < 7) {
699 }
else if (copyno1[3] < 8) {
701 }
else if (copyno1[3] < 9) {
703 }
else if (copyno1[3] < 10) {
706 }
else if (copyno1[2] < 4) {
708 }
else if (copyno1[2] < 5) {
712 if (prename ==
"SIDETR") {
715 if (copyno1[2] < 2) {
717 }
else if (copyno1[2] < 3) {
719 if (copyno1[3] < 2) {
720 }
else if (copyno1[3] < 3) {
722 }
else if (copyno1[3] < 4) {
724 }
else if (copyno1[3] < 5) {
726 }
else if (copyno1[3] < 6) {
728 }
else if (copyno1[3] < 7) {
730 }
else if (copyno1[3] < 8) {
732 }
else if (copyno1[3] < 9) {
734 }
else if (copyno1[3] < 10) {
737 }
else if (copyno1[2] < 4) {
739 }
else if (copyno1[2] < 5) {
769 if (trackstatus == 2) {
782 if (parentID == 1 && curstepnumber == 1) {
800 if (prename ==
"SBST") {
803 if (prename ==
"SBSTs") {
815 return ((touch->GetHistoryDepth()) + 1);
825 return touch->GetVolume(
ii)->GetName();
836 G4VPhysicalVolume*
pv = touch->GetVolume(
i);
841 copyno[
ii] = touch->GetReplicaNumber(
i);
852 iev = (*evt)()->GetEventID();
860 G4PrimaryParticle* thePrim =
nullptr;
863 G4int nvertex = (*evt)()->GetNumberOfPrimaryVertex();
865 edm::LogVerbatim(
"FP420Test") <<
"FP420Test: My warning: NumberOfPrimaryVertex != 1 --> = " << nvertex;
867 for (
int i = 0;
i < nvertex;
i++) {
868 G4PrimaryVertex* avertex = (*evt)()->GetPrimaryVertex(
i);
869 if (avertex ==
nullptr) {
870 edm::LogVerbatim(
"FP420Test") <<
"FP420Test End Of Event ERR: pointer to vertex = 0";
873 G4int
npart = avertex->GetNumberOfParticle();
877 edm::LogVerbatim(
"FP420Test") <<
"FP420Test End Of Event ERR: no NumberOfParticle";
880 if (thePrim ==
nullptr)
881 thePrim = avertex->GetPrimary(trackID);
883 if (thePrim !=
nullptr) {
885 G4double
vx = 0.,
vy = 0.,
vz = 0.;
886 vx = avertex->GetX0();
887 vy = avertex->GetY0();
888 vz = avertex->GetZ0();
900 if (thePrim !=
nullptr) {
922 G4ThreeVector mom = thePrim->GetMomentum();
924 double phi = atan2(mom.y(), mom.x());
927 double phigrad =
phi * 180. /
pi;
929 double th = mom.theta();
962 std::map<int, float, std::less<int> > themap;
963 std::map<int, float, std::less<int> > themap1;
965 std::map<int, float, std::less<int> > themapxy;
966 std::map<int, float, std::less<int> > themapz;
970 G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
976 int CAFIid = G4SDManager::GetSDMpointer()->GetCollectionID(
"FP420SI");
984 edm::LogVerbatim(
"FP420Test") <<
"FP420Test: theCAFI->entries = " << theCAFI->entries();
1016 int nhits = theCAFI->entries();
1019 G4ThreeVector hitPoint = aHit->
getEntry();
1020 double zz = hitPoint.z();
1035 double totallosenergy = 0.;
1041 G4ThreeVector hitPoint = aHit->
getEntry();
1046 unsigned int unitID = aHit->
getUnitID();
1076 double zz = hitPoint.z();
1092 themap[unitID] += losenergy;
1093 totallosenergy += losenergy;
1099 if (justlayer < 1 || justlayer > 2) {
1100 edm::LogVerbatim(
"FP420Test") <<
"FP420Test:WRONG justlayer= " << justlayer;
1115 G4ThreeVector middle = (hitExitLocalPoint - hitEntryLocalPoint) / 2.;
1116 themapz[unitID] = hitPoint.z() + fabs(middle.z());
1118 edm::LogVerbatim(
"FP420Test") <<
"1111111111111111111111111111111111111111111111111111111111111111111111111 ";
1122 edm::LogVerbatim(
"FP420Test") <<
"FP420Test: hitExitLocalPoint = " << hitExitLocalPoint;
1123 edm::LogVerbatim(
"FP420Test") <<
"FP420Test: hitEntryLocalPoint = " << hitEntryLocalPoint;
1125 edm::LogVerbatim(
"FP420Test") <<
"FP420Test: hitPoint.z()-419000.= " << hitPoint.z() - 419000.;
1127 edm::LogVerbatim(
"FP420Test") <<
"FP420Test:zHits-419000. = " << themapz[unitID] - 419000.;
1133 if (losenergy > 0.00003) {
1134 themap1[unitID] += 1.;
1140 if (losenergy > 0.00005) {
1141 themap1[unitID] += 1.;
1187 if (zz < z3 && zz >
z2) {
1192 if (zz < z4 && zz >
z3) {
1215 if (trackIDhit == 1) {
1224 if (zz < z3 && zz >
z2) {
1237 if (trackIDhit == 1) {
1245 if (zz < z4 && zz >
z3) {
1276 edm::LogVerbatim(
"FP420Test") <<
"22222222222222222222222222222222222222222222222222222222222222222222222222 ";
1279 int allplacesforsensors = 7;
1281 for (
int zmodule = 1; zmodule <
pn0; zmodule++) {
1282 for (
int zsideinorder = 1; zsideinorder < allplacesforsensors; zsideinorder++) {
1286 <<
" zsideinorder= " << zsideinorder <<
" zside= " <<
zside;
1290 if (justlayer < 1 || justlayer > 2) {
1291 edm::LogVerbatim(
"FP420Test") <<
"FP420Test:WRONG justlayer= " << justlayer;
1294 if (copyinlayer < 1 || copyinlayer > 3) {
1295 edm::LogVerbatim(
"FP420Test") <<
"FP420Test:WRONG copyinlayer= " << copyinlayer;
1298 if (orientation < 1 || orientation > 2) {
1299 edm::LogVerbatim(
"FP420Test") <<
"FP420Test:WRONG orientation= " << orientation;
1311 <<
"FP420Test: justlayer = " << justlayer <<
" copyinlayer = " << copyinlayer
1312 <<
" orientation = " << orientation <<
" ii= " <<
ii;
1314 double zdiststat = 0.;
1324 double kplane = -(
pn0 - 1) / 2 - 0.5 + (zmodule - 1);
1328 edm::LogVerbatim(
"FP420Test") <<
"FP420Test: Leftzcurrent-419000. = " << zcurrent - 419000.;
1331 if (justlayer == 1) {
1332 if (orientation == 1)
1334 if (orientation == 2)
1337 if (justlayer == 2) {
1338 if (orientation == 1)
1340 if (orientation == 2)
1346 zcurrent = -zcurrent;
1349 edm::LogVerbatim(
"FP420Test") <<
"FP420Test: zcurrent-419000. = " << zcurrent - 419000.;
1359 <<
"----------------------------------------------------------------------------- ";
1363 if (totallosenergy == 0.0) {
1364 edm::LogVerbatim(
"FP420Test") <<
"FP420Test: number of hits = " << theCAFI->entries();
1368 edm::LogVerbatim(
"FP420Test") <<
" j hits = " <<
j <<
"losenergy = " << losenergy;
1446 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