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/GlobalSystemOfUnits.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*> {
129 int detLevels(
const G4VTouchable*)
const;
130 G4String
detName(
const G4VTouchable*,
int,
int)
const;
131 void detectorLevel(
const G4VTouchable*,
int&,
int*, G4String*)
const;
173 edm::LogVerbatim(
"BscTest") <<
"============================================================================";
174 edm::LogVerbatim(
"BscTest") <<
"BscTestconstructor :: Initialized as observer";
184 edm::LogVerbatim(
"BscTest") <<
"BscTest constructor :: Initialized BscAnalysisHistManager";
206 edm::LogVerbatim(
"BscTest") << std::endl <<
"BscTest Destructor --------> End of BscTest : ";
247 histInit(
"TrackPhi",
"Primary Phi", 100, 0., 360.);
248 histInit(
"TrackTheta",
"Primary Theta", 100, 0., 180.);
249 histInit(
"TrackP",
"Track XY position Z+ ", 80, -80., 80., 80, -80., 80.);
250 histInit(
"TrackM",
"Track XY position Z-", 80, -80., 80., 80, -80., 80.);
251 histInit(
"DetIDs",
"Track DetId - vs +", 16, -0.5, 15.5, 16, 15.5, 31.5);
259 edm::LogVerbatim(
"BscTest") <<
"================================================================";
260 edm::LogVerbatim(
"BscTest") <<
" Write this Analysis to File " << fOutputFile;
261 edm::LogVerbatim(
"BscTest") <<
"================================================================";
263 TFile*
file =
new TFile(fOutputFile, fRecreateFile);
274 strcpy(newtitle,
title);
275 strcat(newtitle,
" (");
277 strcat(newtitle,
") ");
284 const char*
name,
const char*
title, Int_t
nbinsx, Axis_t xlow, Axis_t xup, Int_t
nbinsy, Axis_t ylow, Axis_t yup) {
288 strcpy(newtitle,
title);
289 strcat(newtitle,
" (");
291 strcat(newtitle,
") ");
300 if (Number <= fHistArray->GetLast() &&
fHistArray->At(
Number) != (TObject*)
nullptr) {
304 edm::LogVerbatim(
"BscTest") <<
"!!!!!!!!!!!!!!!!!!getHisto!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
306 edm::LogVerbatim(
"BscTest") <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
316 if (Number <= fHistArray->GetLast() &&
fHistArray->At(
Number) != (TObject*)
nullptr) {
320 edm::LogVerbatim(
"BscTest") <<
"!!!!!!!!!!!!!!!!getHisto2!!!!!!!!!!!!!!!!!!!!!!!!!!!";
322 edm::LogVerbatim(
"BscTest") <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
371 iev = (*evt)()->GetEventID();
380 itrk = (*trk)()->GetTrackID();
395 itrk = (*trk)()->GetTrackID();
400 G4double tracklength = (*trk)()->GetTrackLength();
406 G4ThreeVector vert_mom = (*trk)()->GetVertexMomentumDirection();
407 G4ThreeVector vert_pos = (*trk)()->GetVertexPosition();
410 const G4Step* aStep = (*trk)()->GetStep();
411 G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
412 lastpo = preStepPoint->GetPosition();
423 G4int stepnumber = aStep->GetTrack()->GetCurrentStepNumber();
424 edm::LogVerbatim(
"BscTest") <<
"BscTest:update Step number = " << stepnumber;
427 G4Track* theTrack = aStep->GetTrack();
429 if (trkInfo ==
nullptr) {
432 G4int
id = theTrack->GetTrackID();
433 G4String
particleType = theTrack->GetDefinition()->GetParticleName();
434 G4int parentID = theTrack->GetParentID();
435 G4TrackStatus trackstatus = theTrack->GetTrackStatus();
436 G4double tracklength = theTrack->GetTrackLength();
437 G4ThreeVector trackmom = theTrack->GetMomentum();
438 G4double entot = theTrack->GetTotalEnergy();
439 G4int curstepnumber = theTrack->GetCurrentStepNumber();
440 G4double stepl = aStep->GetStepLength();
441 G4double EnerDeposit = aStep->GetTotalEnergyDeposit();
442 G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
443 const G4ThreeVector& preposition = preStepPoint->GetPosition();
444 G4ThreeVector prelocalpoint = theTrack->GetTouchable()->GetHistory()->GetTopTransform().TransformPoint(preposition);
445 G4VPhysicalVolume* currentPV = preStepPoint->GetPhysicalVolume();
446 const G4String& prename = currentPV->GetName();
448 const G4VTouchable* pre_touch = preStepPoint->GetTouchable();
452 for (
int i = 0;
i < 20; ++
i) {
456 if (pre_levels > 0) {
462 if (curstepnumber == 1) {
470 if (prename ==
"SBST") {
476 if (prename ==
"SBSTs") {
484 if (trackstatus != 2) {
486 if (prename ==
"SIDETL" || prename ==
"SIDETR") {
487 if (prename ==
"SIDETL") {
490 if (prename ==
"SIDETR") {
494 G4String posname = aStep->GetPostStepPoint()->GetPhysicalVolume()->GetName();
495 if ((prename ==
"SIDETL" && posname !=
"SIDETL") || (prename ==
"SIDETR" && posname !=
"SIDETR")) {
496 if (name1[2] ==
"SISTATION") {
499 if (name1[3] ==
"SIPLANE") {
503 if (prename ==
"SIDETL") {
506 if (copyno1[2] < 2) {
508 }
else if (copyno1[2] < 3) {
510 if (copyno1[3] < 2) {
511 }
else if (copyno1[3] < 3) {
513 }
else if (copyno1[3] < 4) {
515 }
else if (copyno1[3] < 5) {
517 }
else if (copyno1[3] < 6) {
519 }
else if (copyno1[3] < 7) {
521 }
else if (copyno1[3] < 8) {
523 }
else if (copyno1[3] < 9) {
525 }
else if (copyno1[3] < 10) {
528 }
else if (copyno1[2] < 4) {
530 }
else if (copyno1[2] < 5) {
534 if (prename ==
"SIDETR") {
537 if (copyno1[2] < 2) {
539 }
else if (copyno1[2] < 3) {
541 if (copyno1[3] < 2) {
542 }
else if (copyno1[3] < 3) {
544 }
else if (copyno1[3] < 4) {
546 }
else if (copyno1[3] < 5) {
548 }
else if (copyno1[3] < 6) {
550 }
else if (copyno1[3] < 7) {
552 }
else if (copyno1[3] < 8) {
554 }
else if (copyno1[3] < 9) {
556 }
else if (copyno1[3] < 10) {
559 }
else if (copyno1[2] < 4) {
561 }
else if (copyno1[2] < 5) {
572 if (trackstatus == 2) {
580 if (parentID == 1 && curstepnumber == 1) {
583 if (prename ==
"SBST") {
586 if (prename ==
"SBSTs") {
596 return ((touch->GetHistoryDepth()) + 1);
606 return touch->GetVolume(
ii)->GetName();
617 G4VPhysicalVolume*
pv = touch->GetVolume(
i);
622 copyno[
ii] = touch->GetReplicaNumber(
i);
633 iev = (*evt)()->GetEventID();
641 G4PrimaryParticle* thePrim =
nullptr;
644 G4int nvertex = (*evt)()->GetNumberOfPrimaryVertex();
646 edm::LogVerbatim(
"BscTest") <<
"BscTest: My warning: NumberOfPrimaryVertex != 1 --> = " << nvertex;
648 for (
int i = 0;
i < nvertex;
i++) {
649 G4PrimaryVertex* avertex = (*evt)()->GetPrimaryVertex(
i);
650 if (avertex ==
nullptr) {
651 edm::LogVerbatim(
"BscTest") <<
"BscTest End Of Event ERR: pointer to vertex = 0";
654 G4int
npart = avertex->GetNumberOfParticle();
658 edm::LogVerbatim(
"BscTest") <<
"BscTest End Of Event ERR: no NumberOfParticle";
660 if (thePrim ==
nullptr)
661 thePrim = avertex->GetPrimary(trackID);
663 if (thePrim !=
nullptr) {
665 G4double vx = 0., vy = 0., vz = 0.;
666 vx = avertex->GetX0();
667 vy = avertex->GetY0();
668 vz = avertex->GetZ0();
680 if (thePrim !=
nullptr) {
690 G4ThreeVector mom = thePrim->GetMomentum();
692 double phi = atan2(mom.y(), mom.x());
695 double phigrad =
phi * 180. /
pi;
697 double th = mom.theta();
718 std::map<int, float, std::less<int> > themap;
719 std::map<int, float, std::less<int> > themap1;
721 std::map<int, float, std::less<int> > themapxy;
722 std::map<int, float, std::less<int> > themapz;
727 G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
735 int CAFIid = G4SDManager::GetSDMpointer()->GetCollectionID(
"BSCHits");
739 edm::LogVerbatim(
"BscTest") <<
"BscTest: theCAFI->entries = " << theCAFI->entries();
748 int nhits = theCAFI->entries();
751 const CLHEP::Hep3Vector& hitPoint = aHit->
getEntry();
752 double zz = hitPoint.z();
760 double totallosenergy = 0.;
764 const CLHEP::Hep3Vector& hitEntryLocalPoint = aHit->
getEntryLocalP();
765 const CLHEP::Hep3Vector& hitExitLocalPoint = aHit->
getExitLocalP();
766 const CLHEP::Hep3Vector& hitPoint = aHit->
getEntry();
771 double zz = hitPoint.z();
779 themap[unitID] += losenergy;
780 totallosenergy += losenergy;
785 zside = (unitID & 32) >> 5;
790 G4ThreeVector middle = (hitExitLocalPoint + hitEntryLocalPoint) / 2.;
791 themapz[unitID] = hitPoint.z() + middle.z();
796 if (losenergy > 0.00003) {
797 themap1[unitID] += 1.;
801 else if (
zside == 2) {
803 if (losenergy > 0.00005) {
804 themap1[unitID] += 1.;
905 if (totallosenergy == 0.0) {
906 edm::LogVerbatim(
"BscTest") <<
"BscTest: number of hits = " << theCAFI->entries();
963 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