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);
82 void histInit(
const char*
name,
const char*
title, Int_t nbinsx, Axis_t xlow, Axis_t xup);
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,
") ");
332 fHistArray->AddLast((
new TH1F(
name, newtitle, nbinsx, xlow, xup)));
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,
") ");
346 fHistArray->AddLast((
new TH2F(
name, newtitle, nbinsx, xlow, xup, nbinsy, ylow, yup)));
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";
875 G4int
npart = avertex->GetNumberOfParticle();
879 edm::LogVerbatim(
"FP420Test") <<
"FP420Test End Of Event ERR: no NumberOfParticle";
882 if (thePrim ==
nullptr)
883 thePrim = avertex->GetPrimary(trackID);
885 if (thePrim !=
nullptr) {
887 G4double vx = 0., vy = 0., vz = 0.;
888 vx = avertex->GetX0();
889 vy = avertex->GetY0();
890 vz = avertex->GetZ0();
902 if (thePrim !=
nullptr) {
924 G4ThreeVector mom = thePrim->GetMomentum();
926 double phi = atan2(mom.y(), mom.x());
929 double phigrad =
phi * 180. /
pi;
931 double th = mom.theta();
964 std::map<int, float, std::less<int> > themap;
965 std::map<int, float, std::less<int> > themap1;
967 std::map<int, float, std::less<int> > themapxy;
968 std::map<int, float, std::less<int> > themapz;
972 G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
978 int CAFIid = G4SDManager::GetSDMpointer()->GetCollectionID(
"FP420SI");
986 edm::LogVerbatim(
"FP420Test") <<
"FP420Test: theCAFI->entries = " << theCAFI->entries();
1018 int nhits = theCAFI->entries();
1021 G4ThreeVector hitPoint = aHit->
getEntry();
1022 double zz = hitPoint.z();
1036 int nhit11 = 0, nhit12 = 0, nhit13 = 0;
1037 double totallosenergy = 0.;
1043 G4ThreeVector hitPoint = aHit->
getEntry();
1048 unsigned int unitID = aHit->
getUnitID();
1078 double zz = hitPoint.z();
1094 themap[unitID] += losenergy;
1095 totallosenergy += losenergy;
1097 int det,
zside, sector, zmodule;
1101 if (justlayer < 1 || justlayer > 2) {
1102 edm::LogVerbatim(
"FP420Test") <<
"FP420Test:WRONG justlayer= " << justlayer;
1117 G4ThreeVector middle = (hitExitLocalPoint - hitEntryLocalPoint) / 2.;
1118 themapz[unitID] = hitPoint.z() + fabs(middle.z());
1120 edm::LogVerbatim(
"FP420Test") <<
"1111111111111111111111111111111111111111111111111111111111111111111111111 ";
1121 edm::LogVerbatim(
"FP420Test") <<
"FP420Test: det, zside, sector, zmodule = " << det <<
zside << sector
1124 edm::LogVerbatim(
"FP420Test") <<
"FP420Test: hitExitLocalPoint = " << hitExitLocalPoint;
1125 edm::LogVerbatim(
"FP420Test") <<
"FP420Test: hitEntryLocalPoint = " << hitEntryLocalPoint;
1127 edm::LogVerbatim(
"FP420Test") <<
"FP420Test: hitPoint.z()-419000.= " << hitPoint.z() - 419000.;
1129 edm::LogVerbatim(
"FP420Test") <<
"FP420Test:zHits-419000. = " << themapz[unitID] - 419000.;
1135 if (losenergy > 0.00003) {
1136 themap1[unitID] += 1.;
1142 if (losenergy > 0.00005) {
1143 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;
1280 for (
int sector = 1; sector <
sn0; sector++) {
1281 for (
int zmodule = 1; zmodule <
pn0; zmodule++) {
1282 for (
int zsideinorder = 1; zsideinorder < allplacesforsensors; zsideinorder++) {
1285 edm::LogVerbatim(
"FP420Test") <<
"FP420Test: sector= " << sector <<
" zmodule= " << zmodule
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;
1376 double totalEnergy = 0.;
1377 int nhitsX = 0, nhitsY = 0, nsumhit = 0;
1378 for (
int sector = 1; sector < 4; sector++) {
1379 int nhitsecX = 0, nhitsecY = 0;
1380 for (
int zmodule = 1; zmodule < 11; zmodule++) {
1386 double theTotalEnergy = themap[
index];
1390 if (theTotalEnergy > 0.00003) {
1399 if (theTotalEnergy > 0.00005) {
1412 totalEnergy += themap[
index];
1416 if (nhitsecX > 10 || nhitsecY > 10) {
1445 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]
static unsigned int packFP420Index(int det, int zside, int station, int superplane)
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