38 #include "G4SDManager.hh" 41 #include "G4VProcess.hh" 42 #include "G4HCofThisEvent.hh" 43 #include "G4UserEventAction.hh" 44 #include "G4TransportationManager.hh" 45 #include "G4ProcessManager.hh" 46 #include "G4VTouchable.hh" 48 #include <CLHEP/Vector/ThreeVector.h> 49 #include <CLHEP/Vector/LorentzVector.h> 50 #include <CLHEP/Random/Randomize.h> 51 #include <CLHEP/Units/GlobalSystemOfUnits.h> 52 #include <CLHEP/Units/GlobalPhysicalConstants.h> 64 #include "TLorentzVector.h" 65 #include "TUnixSystem.h" 69 #include "TObjArray.h" 70 #include "TObjString.h" 81 TH1F*
getHisto(
const TObjString& histname);
84 TH2F*
getHisto2(
const TObjString& histname);
86 void writeToFile(
const TString& fOutputFile,
const TString& fRecreateFile);
91 void histInit(
const char*
name,
const char*
title, Int_t nbinsx, Axis_t xlow, Axis_t xup);
93 const char*
name,
const char*
title, Int_t nbinsx, Axis_t xlow, Axis_t xup, Int_t nbinsy, Axis_t ylow, Axis_t yup);
104 public Observer<const BeginOfEvent*>,
105 public Observer<const BeginOfTrack*>,
108 public Observer<const EndOfEvent*> {
133 int detLevels(
const G4VTouchable*)
const;
134 G4String
detName(
const G4VTouchable*,
int,
int)
const;
135 void detectorLevel(
const G4VTouchable*,
int&,
int*, G4String*)
const;
177 edm::LogVerbatim(
"BscTest") <<
"============================================================================";
178 edm::LogVerbatim(
"BscTest") <<
"BscTestconstructor :: Initialized as observer";
188 edm::LogVerbatim(
"BscTest") <<
"BscTest constructor :: Initialized BscAnalysisHistManager";
210 edm::LogVerbatim(
"BscTest") << std::endl <<
"BscTest Destructor --------> End of BscTest : ";
251 histInit(
"TrackPhi",
"Primary Phi", 100, 0., 360.);
252 histInit(
"TrackTheta",
"Primary Theta", 100, 0., 180.);
253 histInit(
"TrackP",
"Track XY position Z+ ", 80, -80., 80., 80, -80., 80.);
254 histInit(
"TrackM",
"Track XY position Z-", 80, -80., 80., 80, -80., 80.);
255 histInit(
"DetIDs",
"Track DetId - vs +", 16, -0.5, 15.5, 16, 15.5, 31.5);
263 edm::LogVerbatim(
"BscTest") <<
"================================================================";
264 edm::LogVerbatim(
"BscTest") <<
" Write this Analysis to File " << fOutputFile;
265 edm::LogVerbatim(
"BscTest") <<
"================================================================";
267 TFile*
file =
new TFile(fOutputFile, fRecreateFile);
278 strcpy(newtitle,
title);
279 strcat(newtitle,
" (");
281 strcat(newtitle,
") ");
282 fHistArray->AddLast((
new TH1F(
name, newtitle, nbinsx, xlow, xup)));
288 const char*
name,
const char*
title, Int_t nbinsx, Axis_t xlow, Axis_t xup, Int_t nbinsy, Axis_t ylow, Axis_t yup) {
292 strcpy(newtitle,
title);
293 strcat(newtitle,
" (");
295 strcat(newtitle,
") ");
296 fHistArray->AddLast((
new TH2F(
name, newtitle, nbinsx, xlow, xup, nbinsy, ylow, yup)));
304 if (Number <= fHistArray->GetLast() &&
fHistArray->At(
Number) != (TObject*)
nullptr) {
308 edm::LogVerbatim(
"BscTest") <<
"!!!!!!!!!!!!!!!!!!getHisto!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
310 edm::LogVerbatim(
"BscTest") <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
320 if (Number <= fHistArray->GetLast() &&
fHistArray->At(
Number) != (TObject*)
nullptr) {
324 edm::LogVerbatim(
"BscTest") <<
"!!!!!!!!!!!!!!!!getHisto2!!!!!!!!!!!!!!!!!!!!!!!!!!!";
326 edm::LogVerbatim(
"BscTest") <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
375 iev = (*evt)()->GetEventID();
384 itrk = (*trk)()->GetTrackID();
399 itrk = (*trk)()->GetTrackID();
404 G4double tracklength = (*trk)()->GetTrackLength();
410 G4ThreeVector vert_mom = (*trk)()->GetVertexMomentumDirection();
411 G4ThreeVector vert_pos = (*trk)()->GetVertexPosition();
414 const G4Step* aStep = (*trk)()->GetStep();
415 G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
416 lastpo = preStepPoint->GetPosition();
427 G4int stepnumber = aStep->GetTrack()->GetCurrentStepNumber();
428 edm::LogVerbatim(
"BscTest") <<
"BscTest:update Step number = " << stepnumber;
431 G4Track* theTrack = aStep->GetTrack();
433 if (trkInfo ==
nullptr) {
436 G4int
id = theTrack->GetTrackID();
437 G4String
particleType = theTrack->GetDefinition()->GetParticleName();
438 G4int parentID = theTrack->GetParentID();
439 G4TrackStatus trackstatus = theTrack->GetTrackStatus();
440 G4double tracklength = theTrack->GetTrackLength();
441 G4ThreeVector trackmom = theTrack->GetMomentum();
442 G4double entot = theTrack->GetTotalEnergy();
443 G4int curstepnumber = theTrack->GetCurrentStepNumber();
444 G4double stepl = aStep->GetStepLength();
445 G4double EnerDeposit = aStep->GetTotalEnergyDeposit();
446 G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
447 const G4ThreeVector& preposition = preStepPoint->GetPosition();
448 G4ThreeVector prelocalpoint = theTrack->GetTouchable()->GetHistory()->GetTopTransform().TransformPoint(preposition);
449 G4VPhysicalVolume* currentPV = preStepPoint->GetPhysicalVolume();
450 const G4String& prename = currentPV->GetName();
452 const G4VTouchable* pre_touch = preStepPoint->GetTouchable();
456 for (
int i = 0;
i < 20; ++
i) {
460 if (pre_levels > 0) {
466 if (curstepnumber == 1) {
474 if (prename ==
"SBST") {
480 if (prename ==
"SBSTs") {
488 if (trackstatus != 2) {
490 if (prename ==
"SIDETL" || prename ==
"SIDETR") {
491 if (prename ==
"SIDETL") {
494 if (prename ==
"SIDETR") {
498 G4String posname = aStep->GetPostStepPoint()->GetPhysicalVolume()->GetName();
499 if ((prename ==
"SIDETL" && posname !=
"SIDETL") || (prename ==
"SIDETR" && posname !=
"SIDETR")) {
500 if (name1[2] ==
"SISTATION") {
503 if (name1[3] ==
"SIPLANE") {
507 if (prename ==
"SIDETL") {
510 if (copyno1[2] < 2) {
512 }
else if (copyno1[2] < 3) {
514 if (copyno1[3] < 2) {
515 }
else if (copyno1[3] < 3) {
517 }
else if (copyno1[3] < 4) {
519 }
else if (copyno1[3] < 5) {
521 }
else if (copyno1[3] < 6) {
523 }
else if (copyno1[3] < 7) {
525 }
else if (copyno1[3] < 8) {
527 }
else if (copyno1[3] < 9) {
529 }
else if (copyno1[3] < 10) {
532 }
else if (copyno1[2] < 4) {
534 }
else if (copyno1[2] < 5) {
538 if (prename ==
"SIDETR") {
541 if (copyno1[2] < 2) {
543 }
else if (copyno1[2] < 3) {
545 if (copyno1[3] < 2) {
546 }
else if (copyno1[3] < 3) {
548 }
else if (copyno1[3] < 4) {
550 }
else if (copyno1[3] < 5) {
552 }
else if (copyno1[3] < 6) {
554 }
else if (copyno1[3] < 7) {
556 }
else if (copyno1[3] < 8) {
558 }
else if (copyno1[3] < 9) {
560 }
else if (copyno1[3] < 10) {
563 }
else if (copyno1[2] < 4) {
565 }
else if (copyno1[2] < 5) {
576 if (trackstatus == 2) {
584 if (parentID == 1 && curstepnumber == 1) {
587 if (prename ==
"SBST") {
590 if (prename ==
"SBSTs") {
600 return ((touch->GetHistoryDepth()) + 1);
610 return touch->GetVolume(
ii)->GetName();
621 G4VPhysicalVolume*
pv = touch->GetVolume(
i);
626 copyno[
ii] = touch->GetReplicaNumber(
i);
637 iev = (*evt)()->GetEventID();
645 G4PrimaryParticle* thePrim =
nullptr;
648 G4int nvertex = (*evt)()->GetNumberOfPrimaryVertex();
650 edm::LogVerbatim(
"BscTest") <<
"BscTest: My warning: NumberOfPrimaryVertex != 1 --> = " << nvertex;
652 for (
int i = 0;
i < nvertex;
i++) {
653 G4PrimaryVertex* avertex = (*evt)()->GetPrimaryVertex(
i);
654 if (avertex ==
nullptr)
655 edm::LogVerbatim(
"BscTest") <<
"BscTest End Of Event ERR: pointer to vertex = 0";
656 G4int
npart = avertex->GetNumberOfParticle();
660 edm::LogVerbatim(
"BscTest") <<
"BscTest End Of Event ERR: no NumberOfParticle";
662 if (thePrim ==
nullptr)
663 thePrim = avertex->GetPrimary(trackID);
665 if (thePrim !=
nullptr) {
667 G4double vx = 0., vy = 0., vz = 0.;
668 vx = avertex->GetX0();
669 vy = avertex->GetY0();
670 vz = avertex->GetZ0();
682 if (thePrim !=
nullptr) {
692 G4ThreeVector mom = thePrim->GetMomentum();
694 double phi = atan2(mom.y(), mom.x());
697 double phigrad =
phi * 180. /
pi;
699 double th = mom.theta();
720 std::map<int, float, std::less<int> > themap;
721 std::map<int, float, std::less<int> > themap1;
723 std::map<int, float, std::less<int> > themapxy;
724 std::map<int, float, std::less<int> > themapz;
729 G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
737 int CAFIid = G4SDManager::GetSDMpointer()->GetCollectionID(
"BSCHits");
741 edm::LogVerbatim(
"BscTest") <<
"BscTest: theCAFI->entries = " << theCAFI->entries();
750 int nhits = theCAFI->entries();
753 const CLHEP::Hep3Vector& hitPoint = aHit->
getEntry();
754 double zz = hitPoint.z();
761 int nhit11 = 0, nhit12 = 0, nhit13 = 0;
762 double totallosenergy = 0.;
766 const CLHEP::Hep3Vector& hitEntryLocalPoint = aHit->
getEntryLocalP();
767 const CLHEP::Hep3Vector& hitExitLocalPoint = aHit->
getExitLocalP();
768 const CLHEP::Hep3Vector& hitPoint = aHit->
getEntry();
773 double zz = hitPoint.z();
781 themap[unitID] += losenergy;
782 totallosenergy += losenergy;
786 zside = (unitID & 32) >> 5;
787 sector = (unitID & 7);
791 G4ThreeVector middle = (hitExitLocalPoint + hitEntryLocalPoint) / 2.;
792 themapz[unitID] = hitPoint.z() + middle.z();
797 if (losenergy > 0.00003) {
798 themap1[unitID] += 1.;
804 if (losenergy > 0.00005) {
805 themap1[unitID] += 1.;
836 if (zz < z3 && zz >
z2) {
841 if (zz < z4 && zz >
z3) {
864 if (trackIDhit == 1) {
873 if (zz < z3 && zz >
z2) {
886 if (trackIDhit == 1) {
894 if (zz < z4 && zz >
z3) {
904 if (totallosenergy == 0.0) {
905 edm::LogVerbatim(
"BscTest") <<
"BscTest: number of hits = " << theCAFI->entries();
913 double totalEnergy = 0.;
914 int nhitsX = 0, nhitsY = 0, nsumhit = 0;
915 for (
int sector = 1; sector < 4; sector++) {
916 int nhitsecX = 0, nhitsecY = 0;
917 for (
int zmodule = 1; zmodule < 11; zmodule++) {
922 double theTotalEnergy = themap[
index];
926 if (theTotalEnergy > 0.00003) {
935 if (theTotalEnergy > 0.00005) {
942 totalEnergy += themap[
index];
946 if (nhitsecX > 10 || nhitsecY > 10) {
960 edm::LogVerbatim(
"BscTest") <<
"BscTest: END OF Event " << (*evt)()->GetEventID();
Log< level::Info, true > LogVerbatim
#define DEFINE_SIMWATCHER(type)
T getParameter(std::string const &) const
int detLevels(const G4VTouchable *) const
uint32_t getUnitID() const
TH1F * getHisto(Int_t Number)
TObjArray * fHistNamesArray
std::string fRecreateFile
G4String detName(const G4VTouchable *, int, int) const
void histInit(const char *name, const char *title, Int_t nbinsx, Axis_t xlow, Axis_t xup)
static unsigned int packBscIndex(int det, int zside, int station)
void detectorLevel(const G4VTouchable *, int &, int *, G4String *) const
BscAnalysisHistManager * TheHistManager
Tan< T >::type tan(const T &t)
void update(const BeginOfJob *run) override
This routine will be called when the appropriate signal arrives.
BscTest(const edm::ParameterSet &p)
static void unpackBscIndex(const unsigned int &idx)
BscNumberingScheme * theBscNumberingScheme
TH2F * getHisto2(Int_t Number)
float getEnergyLoss() const
const G4ThreeVector & getEntry() const
const G4ThreeVector & getExitLocalP() const
G4THitsCollection< BscG4Hit > BscG4HitCollection
BscAnalysisHistManager(const TString &managername)
const G4ThreeVector & getEntryLocalP() const
void writeToFile(const TString &fOutputFile, const TString &fRecreateFile)
~BscAnalysisHistManager() override