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);
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,
") ");
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,
") ");
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";
658 G4int
npart = avertex->GetNumberOfParticle();
662 edm::LogVerbatim(
"BscTest") <<
"BscTest End Of Event ERR: no NumberOfParticle";
664 if (thePrim ==
nullptr)
665 thePrim = avertex->GetPrimary(trackID);
667 if (thePrim !=
nullptr) {
669 G4double vx = 0., vy = 0., vz = 0.;
670 vx = avertex->GetX0();
671 vy = avertex->GetY0();
672 vz = avertex->GetZ0();
684 if (thePrim !=
nullptr) {
694 G4ThreeVector mom = thePrim->GetMomentum();
696 double phi = atan2(mom.y(), mom.x());
699 double phigrad =
phi * 180. /
pi;
701 double th = mom.theta();
722 std::map<int, float, std::less<int> > themap;
723 std::map<int, float, std::less<int> > themap1;
725 std::map<int, float, std::less<int> > themapxy;
726 std::map<int, float, std::less<int> > themapz;
731 G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
739 int CAFIid = G4SDManager::GetSDMpointer()->GetCollectionID(
"BSCHits");
743 edm::LogVerbatim(
"BscTest") <<
"BscTest: theCAFI->entries = " << theCAFI->entries();
752 int nhits = theCAFI->entries();
755 const CLHEP::Hep3Vector& hitPoint = aHit->
getEntry();
756 double zz = hitPoint.z();
764 double totallosenergy = 0.;
768 const CLHEP::Hep3Vector& hitEntryLocalPoint = aHit->
getEntryLocalP();
769 const CLHEP::Hep3Vector& hitExitLocalPoint = aHit->
getExitLocalP();
770 const CLHEP::Hep3Vector& hitPoint = aHit->
getEntry();
775 double zz = hitPoint.z();
783 themap[unitID] += losenergy;
784 totallosenergy += losenergy;
789 zside = (unitID & 32) >> 5;
794 G4ThreeVector middle = (hitExitLocalPoint + hitEntryLocalPoint) / 2.;
795 themapz[unitID] = hitPoint.z() + middle.z();
800 if (losenergy > 0.00003) {
801 themap1[unitID] += 1.;
805 else if (
zside == 2) {
807 if (losenergy > 0.00005) {
808 themap1[unitID] += 1.;
909 if (totallosenergy == 0.0) {
910 edm::LogVerbatim(
"BscTest") <<
"BscTest: number of hits = " << theCAFI->entries();
967 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)
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