34 #include "G4SDManager.hh" 37 #include "G4VProcess.hh" 38 #include "G4HCofThisEvent.hh" 39 #include "G4UserEventAction.hh" 40 #include "G4TransportationManager.hh" 41 #include "G4ProcessManager.hh" 42 #include "G4VTouchable.hh" 44 #include <CLHEP/Vector/ThreeVector.h> 45 #include <CLHEP/Vector/LorentzVector.h> 46 #include <CLHEP/Random/Randomize.h> 47 #include <CLHEP/Units/SystemOfUnits.h> 48 #include <CLHEP/Units/GlobalPhysicalConstants.h> 60 #include "TLorentzVector.h" 61 #include "TUnixSystem.h" 65 #include "TObjArray.h" 66 #include "TObjString.h" 77 TH1F*
getHisto(
const TObjString& histname);
80 TH2F*
getHisto2(
const TObjString& histname);
82 void writeToFile(
const TString& fOutputFile,
const TString& fRecreateFile);
89 const char*
name,
const char*
title, Int_t
nbinsx, Axis_t xlow, Axis_t xup, Int_t
nbinsy, Axis_t ylow, Axis_t yup);
100 public Observer<const BeginOfEvent*>,
101 public Observer<const BeginOfTrack*>,
104 public Observer<const EndOfEvent*> {
126 int detLevels(
const G4VTouchable*)
const;
127 G4String
detName(
const G4VTouchable*,
int,
int)
const;
128 void detectorLevel(
const G4VTouchable*,
int&,
int*, G4String*)
const;
170 edm::LogVerbatim(
"BscTest") <<
"============================================================================";
171 edm::LogVerbatim(
"BscTest") <<
"BscTestconstructor :: Initialized as observer";
180 edm::LogVerbatim(
"BscTest") <<
"BscTest constructor :: Initialized BscAnalysisHistManager";
201 edm::LogVerbatim(
"BscTest") << std::endl <<
"BscTest Destructor --------> End of BscTest : ";
242 histInit(
"TrackPhi",
"Primary Phi", 100, 0., 360.);
243 histInit(
"TrackTheta",
"Primary Theta", 100, 0., 180.);
244 histInit(
"TrackP",
"Track XY position Z+ ", 80, -80., 80., 80, -80., 80.);
245 histInit(
"TrackM",
"Track XY position Z-", 80, -80., 80., 80, -80., 80.);
246 histInit(
"DetIDs",
"Track DetId - vs +", 16, -0.5, 15.5, 16, 15.5, 31.5);
254 edm::LogVerbatim(
"BscTest") <<
"================================================================";
255 edm::LogVerbatim(
"BscTest") <<
" Write this Analysis to File " << fOutputFile;
256 edm::LogVerbatim(
"BscTest") <<
"================================================================";
258 TFile*
file =
new TFile(fOutputFile, fRecreateFile);
269 strcpy(newtitle,
title);
270 strcat(newtitle,
" (");
272 strcat(newtitle,
") ");
279 const char*
name,
const char*
title, Int_t
nbinsx, Axis_t xlow, Axis_t xup, Int_t
nbinsy, Axis_t ylow, Axis_t yup) {
283 strcpy(newtitle,
title);
284 strcat(newtitle,
" (");
286 strcat(newtitle,
") ");
295 if (Number <= fHistArray->GetLast() &&
fHistArray->At(
Number) != (TObject*)
nullptr) {
299 edm::LogVerbatim(
"BscTest") <<
"!!!!!!!!!!!!!!!!!!getHisto!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
301 edm::LogVerbatim(
"BscTest") <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
311 if (Number <= fHistArray->GetLast() &&
fHistArray->At(
Number) != (TObject*)
nullptr) {
315 edm::LogVerbatim(
"BscTest") <<
"!!!!!!!!!!!!!!!!getHisto2!!!!!!!!!!!!!!!!!!!!!!!!!!!";
317 edm::LogVerbatim(
"BscTest") <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
366 iev = (*evt)()->GetEventID();
375 itrk = (*trk)()->GetTrackID();
390 itrk = (*trk)()->GetTrackID();
395 G4double tracklength = (*trk)()->GetTrackLength();
401 G4ThreeVector vert_mom = (*trk)()->GetVertexMomentumDirection();
402 G4ThreeVector vert_pos = (*trk)()->GetVertexPosition();
405 const G4Step* aStep = (*trk)()->GetStep();
406 G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
407 lastpo = preStepPoint->GetPosition();
418 G4int stepnumber = aStep->GetTrack()->GetCurrentStepNumber();
419 edm::LogVerbatim(
"BscTest") <<
"BscTest:update Step number = " << stepnumber;
422 G4Track* theTrack = aStep->GetTrack();
424 if (trkInfo ==
nullptr) {
427 G4int
id = theTrack->GetTrackID();
428 G4String
particleType = theTrack->GetDefinition()->GetParticleName();
429 G4int parentID = theTrack->GetParentID();
430 G4TrackStatus trackstatus = theTrack->GetTrackStatus();
431 G4double tracklength = theTrack->GetTrackLength();
432 G4ThreeVector trackmom = theTrack->GetMomentum();
433 G4double entot = theTrack->GetTotalEnergy();
434 G4int curstepnumber = theTrack->GetCurrentStepNumber();
435 G4double stepl = aStep->GetStepLength();
436 G4double EnerDeposit = aStep->GetTotalEnergyDeposit();
437 G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
438 const G4ThreeVector& preposition = preStepPoint->GetPosition();
439 G4ThreeVector prelocalpoint = theTrack->GetTouchable()->GetHistory()->GetTopTransform().TransformPoint(preposition);
440 G4VPhysicalVolume* currentPV = preStepPoint->GetPhysicalVolume();
441 const G4String& prename = currentPV->GetName();
443 const G4VTouchable* pre_touch = preStepPoint->GetTouchable();
447 for (
int i = 0;
i < 20; ++
i) {
451 if (pre_levels > 0) {
457 if (curstepnumber == 1) {
465 if (prename ==
"SBST") {
471 if (prename ==
"SBSTs") {
479 if (trackstatus != 2) {
481 if (prename ==
"SIDETL" || prename ==
"SIDETR") {
482 if (prename ==
"SIDETL") {
485 if (prename ==
"SIDETR") {
489 G4String posname = aStep->GetPostStepPoint()->GetPhysicalVolume()->GetName();
490 if ((prename ==
"SIDETL" && posname !=
"SIDETL") || (prename ==
"SIDETR" && posname !=
"SIDETR")) {
491 if (name1[2] ==
"SISTATION") {
494 if (name1[3] ==
"SIPLANE") {
498 if (prename ==
"SIDETL") {
501 if (copyno1[2] < 2) {
503 }
else if (copyno1[2] < 3) {
505 if (copyno1[3] < 2) {
506 }
else if (copyno1[3] < 3) {
508 }
else if (copyno1[3] < 4) {
510 }
else if (copyno1[3] < 5) {
512 }
else if (copyno1[3] < 6) {
514 }
else if (copyno1[3] < 7) {
516 }
else if (copyno1[3] < 8) {
518 }
else if (copyno1[3] < 9) {
520 }
else if (copyno1[3] < 10) {
523 }
else if (copyno1[2] < 4) {
525 }
else if (copyno1[2] < 5) {
529 if (prename ==
"SIDETR") {
532 if (copyno1[2] < 2) {
534 }
else if (copyno1[2] < 3) {
536 if (copyno1[3] < 2) {
537 }
else if (copyno1[3] < 3) {
539 }
else if (copyno1[3] < 4) {
541 }
else if (copyno1[3] < 5) {
543 }
else if (copyno1[3] < 6) {
545 }
else if (copyno1[3] < 7) {
547 }
else if (copyno1[3] < 8) {
549 }
else if (copyno1[3] < 9) {
551 }
else if (copyno1[3] < 10) {
554 }
else if (copyno1[2] < 4) {
556 }
else if (copyno1[2] < 5) {
567 if (trackstatus == 2) {
575 if (parentID == 1 && curstepnumber == 1) {
578 if (prename ==
"SBST") {
581 if (prename ==
"SBSTs") {
591 return ((touch->GetHistoryDepth()) + 1);
601 return touch->GetVolume(
ii)->GetName();
612 G4VPhysicalVolume*
pv = touch->GetVolume(
i);
617 copyno[
ii] = touch->GetReplicaNumber(
i);
628 iev = (*evt)()->GetEventID();
636 G4PrimaryParticle* thePrim =
nullptr;
639 G4int nvertex = (*evt)()->GetNumberOfPrimaryVertex();
641 edm::LogVerbatim(
"BscTest") <<
"BscTest: My warning: NumberOfPrimaryVertex != 1 --> = " << nvertex;
643 for (
int i = 0;
i < nvertex;
i++) {
644 G4PrimaryVertex* avertex = (*evt)()->GetPrimaryVertex(
i);
645 if (avertex ==
nullptr) {
646 edm::LogVerbatim(
"BscTest") <<
"BscTest End Of Event ERR: pointer to vertex = 0";
649 G4int
npart = avertex->GetNumberOfParticle();
653 edm::LogVerbatim(
"BscTest") <<
"BscTest End Of Event ERR: no NumberOfParticle";
655 if (thePrim ==
nullptr)
656 thePrim = avertex->GetPrimary(trackID);
658 if (thePrim !=
nullptr) {
660 G4double
vx = 0.,
vy = 0.,
vz = 0.;
661 vx = avertex->GetX0();
662 vy = avertex->GetY0();
663 vz = avertex->GetZ0();
675 if (thePrim !=
nullptr) {
685 G4ThreeVector mom = thePrim->GetMomentum();
687 double phi = atan2(mom.y(), mom.x());
690 double phigrad =
phi * 180. /
pi;
692 double th = mom.theta();
713 std::map<int, float, std::less<int> > themap;
714 std::map<int, float, std::less<int> > themap1;
716 std::map<int, float, std::less<int> > themapxy;
717 std::map<int, float, std::less<int> > themapz;
722 G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
730 int CAFIid = G4SDManager::GetSDMpointer()->GetCollectionID(
"BSCHits");
734 edm::LogVerbatim(
"BscTest") <<
"BscTest: theCAFI->entries = " << theCAFI->entries();
743 int nhits = theCAFI->entries();
746 const CLHEP::Hep3Vector& hitPoint = aHit->
getEntry();
747 double zz = hitPoint.z();
755 double totallosenergy = 0.;
759 const CLHEP::Hep3Vector& hitEntryLocalPoint = aHit->
getEntryLocalP();
760 const CLHEP::Hep3Vector& hitExitLocalPoint = aHit->
getExitLocalP();
761 const CLHEP::Hep3Vector& hitPoint = aHit->
getEntry();
766 double zz = hitPoint.z();
774 themap[unitID] += losenergy;
775 totallosenergy += losenergy;
780 zside = (unitID & 32) >> 5;
785 G4ThreeVector middle = (hitExitLocalPoint + hitEntryLocalPoint) / 2.;
786 themapz[unitID] = hitPoint.z() + middle.z();
791 if (losenergy > 0.00003) {
792 themap1[unitID] += 1.;
796 else if (
zside == 2) {
798 if (losenergy > 0.00005) {
799 themap1[unitID] += 1.;
900 if (totallosenergy == 0.0) {
901 edm::LogVerbatim(
"BscTest") <<
"BscTest: number of hits = " << theCAFI->entries();
958 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 unpackBscIndex(const unsigned int &idx)
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)
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