24 #include "G4SDManager.hh" 27 #include "G4VProcess.hh" 28 #include "G4HCofThisEvent.hh" 29 #include "G4UserEventAction.hh" 30 #include "G4TransportationManager.hh" 31 #include "G4ProcessManager.hh" 33 #include "CLHEP/Units/GlobalSystemOfUnits.h" 34 #include "CLHEP/Units/GlobalPhysicalConstants.h" 62 std::cout<<
"============================================================================"<<std::endl;
63 std::cout <<
"BscTestconstructor :: Initialized as observer"<< std::endl;
73 std::cout <<
"BscTest constructor :: Initialized BscAnalysisHistManager"<< std::endl;
82 std::cout <<
"Bsc output root file has been created";
85 bscOutputFile.Close();
88 std::cout <<
", and deleted" << std::endl;
95 std::cout << std::endl <<
"BscTest Destructor --------> End of BscTest : " << std::endl;
98 std::cout<<
"BscTest: End of process"<<std::endl;
109 fTypeTitle=managername;
110 fHistArray =
new TObjArray();
111 fHistNamesArray =
new TObjArray();
115 fHistArray->Compress();
116 fHistNamesArray->Compress();
125 fHistArray->Delete();
130 fHistNamesArray->Delete();
131 delete fHistNamesArray;
139 HistInit(
"TrackPhi",
"Primary Phi", 100, 0.,360. );
140 HistInit(
"TrackTheta",
"Primary Theta", 100, 0.,180. );
141 HistInit(
"TrackP",
"Track XY position Z+ ", 80, -80., 80., 80, -80., 80. );
142 HistInit(
"TrackM",
"Track XY position Z-", 80, -80., 80., 80, -80., 80. );
143 HistInit(
"DetIDs",
"Track DetId - vs +", 16, -0.5, 15.5,16, 15.5, 31.5 );
153 std::cout <<
"================================================================"<<std::endl;
154 std::cout <<
" Write this Analysis to File "<<fOutputFile<<std::endl;
155 std::cout <<
"================================================================"<<std::endl;
157 TFile*
file =
new TFile(fOutputFile, fRecreateFile);
168 char* newtitle =
new char[strlen(title)+strlen(fTypeTitle)+5];
169 strcpy(newtitle,title);
170 strcat(newtitle,
" (");
171 strcat(newtitle,fTypeTitle);
172 strcat(newtitle,
") ");
173 fHistArray->AddLast((
new TH1F(name, newtitle, nbinsx, xlow, xup)));
174 fHistNamesArray->AddLast(
new TObjString(name));
183 char* newtitle =
new char[strlen(title)+strlen(fTypeTitle)+5];
184 strcpy(newtitle,title);
185 strcat(newtitle,
" (");
186 strcat(newtitle,fTypeTitle);
187 strcat(newtitle,
") ");
188 fHistArray->AddLast((
new TH2F(name, newtitle, nbinsx, xlow, xup, nbinsy, ylow, yup)));
189 fHistNamesArray->AddLast(
new TObjString(name));
198 if (Number <= fHistArray->GetLast() && fHistArray->At(Number) != (TObject*)
nullptr){
200 return (TH1F*)(fHistArray->At(Number));
204 std::cout <<
"!!!!!!!!!!!!!!!!!!GetHisto!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
205 std::cout <<
" WARNING ERROR - HIST ID INCORRECT (TOO HIGH) - " << Number << std::endl;
206 std::cout <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
208 return (TH1F*)(fHistArray->At(0));
217 if (Number <= fHistArray->GetLast() && fHistArray->At(Number) != (TObject*)
nullptr){
219 return (TH2F*)(fHistArray->At(Number));
223 std::cout <<
"!!!!!!!!!!!!!!!!GetHisto2!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
224 std::cout <<
" WARNING ERROR - HIST ID INCORRECT (TOO HIGH) - " << Number << std::endl;
225 std::cout <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
227 return (TH2F*)(fHistArray->At(0));
236 Int_t
index = fHistNamesArray->IndexOf(&histname);
237 return GetHisto(index);
245 Int_t
index = fHistNamesArray->IndexOf(&histname);
246 return GetHisto2(index);
254 for(
int i = 0;
i < fHistArray->GetEntries();
i++){
255 ((TH1F*)(fHistArray->At(
i)))->Sumw2();
263 std::cout<<
"BscTest:beggining of job"<<std::endl;;
270 std::cout << std::endl <<
"BscTest:: Begining of Run"<< std::endl;
277 iev = (*evt)()->GetEventID();
279 std::cout <<
"BscTest:update Event number = " <<
iev << std::endl;
286 itrk = (*trk)()->GetTrackID();
288 std::cout <<
"BscTest:update BeginOfTrack number = " <<
itrk << std::endl;
301 itrk = (*trk)()->GetTrackID();
303 std::cout <<
"BscTest:update EndOfTrack number = " <<
itrk << std::endl;
306 G4double tracklength = (*trk)()->GetTrackLength();
312 G4ThreeVector vert_mom = (*trk)()->GetVertexMomentumDirection();
313 G4ThreeVector vert_pos = (*trk)()->GetVertexPosition();
316 const G4Step* aStep = (*trk)()->GetStep();
317 G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
318 lastpo = preStepPoint->GetPosition();
329 G4int stepnumber = aStep->GetTrack()->GetCurrentStepNumber();
330 std::cout <<
"BscTest:update Step number = " << stepnumber << std::endl;
333 G4Track* theTrack = aStep->GetTrack();
335 if (trkInfo ==
nullptr) {
336 std::cout <<
"BscTest on aStep: No trk info !!!! abort " << std::endl;
338 G4int
id = theTrack->GetTrackID();
339 G4String
particleType = theTrack->GetDefinition()->GetParticleName();
340 G4int parentID = theTrack->GetParentID();
341 G4TrackStatus trackstatus = theTrack->GetTrackStatus();
342 G4double tracklength = theTrack->GetTrackLength();
343 G4ThreeVector trackmom = theTrack->GetMomentum();
344 G4double entot = theTrack->GetTotalEnergy();
345 G4int curstepnumber = theTrack->GetCurrentStepNumber();
346 G4double stepl = aStep->GetStepLength();
347 G4double EnerDeposit = aStep->GetTotalEnergyDeposit();
348 G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
349 const G4ThreeVector& preposition = preStepPoint->GetPosition();
350 G4ThreeVector prelocalpoint = theTrack->GetTouchable()->GetHistory()->
351 GetTopTransform().TransformPoint(preposition);
352 G4VPhysicalVolume* currentPV = preStepPoint->GetPhysicalVolume();
353 const G4String& prename = currentPV->GetName();
355 const G4VTouchable* pre_touch = preStepPoint->GetTouchable();
357 G4String name1[20];
int copyno1[20];
358 for(
int i=0;
i<20; ++
i) {
362 if (pre_levels > 0) {
369 if (curstepnumber == 1 ) {
378 if(prename ==
"SBST" ) {
384 if(prename ==
"SBSTs" ) {
392 if (trackstatus != 2 ) {
394 if(prename ==
"SIDETL" || prename ==
"SIDETR" ) {
395 if(prename ==
"SIDETL") {
398 if(prename ==
"SIDETR") {
402 G4String posname = aStep->GetPostStepPoint()->GetPhysicalVolume()->GetName();
403 if((prename ==
"SIDETL" && posname !=
"SIDETL") || (prename ==
"SIDETR" && posname !=
"SIDETR")) {
404 if(name1[2] ==
"SISTATION" ) {
407 if(name1[3] ==
"SIPLANE" ) {
411 if(prename ==
"SIDETL") {
417 else if(copyno1[2]<3) {
421 else if(copyno1[3]<3) {
424 else if(copyno1[3]<4) {
427 else if(copyno1[3]<5) {
430 else if(copyno1[3]<6) {
433 else if(copyno1[3]<7) {
436 else if(copyno1[3]<8) {
439 else if(copyno1[3]<9) {
442 else if(copyno1[3]<10) {
446 else if(copyno1[2]<4) {
449 else if(copyno1[2]<5) {
453 if(prename ==
"SIDETR") {
459 else if(copyno1[2]<3) {
463 else if(copyno1[3]<3) {
466 else if(copyno1[3]<4) {
469 else if(copyno1[3]<5) {
472 else if(copyno1[3]<6) {
475 else if(copyno1[3]<7) {
478 else if(copyno1[3]<8) {
481 else if(copyno1[3]<9) {
484 else if(copyno1[3]<10) {
488 else if(copyno1[2]<4) {
491 else if(copyno1[2]<5) {
503 if (trackstatus == 2 ) {
512 if (parentID == 1 && curstepnumber == 1) {
515 if(prename ==
"SBST" ) {
518 if(prename ==
"SBSTs" ) {
530 return ((touch->GetHistoryDepth())+1);
537 int currentlevel)
const {
540 if (level > 0 && level >= currentlevel) {
541 int ii = level - currentlevel;
542 return touch->GetVolume(ii)->GetName();
549 int* copyno, G4String*
name)
const {
554 int i = level -
ii - 1;
555 G4VPhysicalVolume*
pv = touch->GetVolume(i);
557 name[
ii] = pv->GetName();
559 name[
ii] =
"Unknown";
560 copyno[
ii] = touch->GetReplicaNumber(i);
571 iev = (*evt)()->GetEventID();
572 std::cout <<
"BscTest:update EndOfEvent = " <<
iev << std::endl;
579 G4PrimaryParticle* thePrim=
nullptr;
583 G4int nvertex = (*evt)()->GetNumberOfPrimaryVertex();
585 std::cout <<
"BscTest: My warning: NumberOfPrimaryVertex != 1 --> = " << nvertex << std::endl;
587 for (
int i = 0 ;
i<nvertex;
i++) {
588 G4PrimaryVertex* avertex = (*evt)()->GetPrimaryVertex(
i);
589 if (avertex ==
nullptr)
590 std::cout <<
"BscTest End Of Event ERR: pointer to vertex = 0" 592 G4int
npart = avertex->GetNumberOfParticle();
594 std::cout <<
"BscTest: My warning: NumberOfPrimaryPart != 1 --> = " << npart << std::endl;
596 std::cout <<
"BscTest End Of Event ERR: no NumberOfParticle" << std::endl;
598 if (thePrim==
nullptr) thePrim=avertex->GetPrimary(trackID);
600 if (thePrim!=
nullptr) {
602 G4double vx=0.,vy=0.,vz=0.;
603 vx = avertex->GetX0();
604 vy = avertex->GetY0();
605 vz = avertex->GetZ0();
617 if (thePrim !=
nullptr) {
627 G4ThreeVector mom = thePrim->GetMomentum();
629 double phi = atan2(mom.y(),mom.x());
630 if (phi < 0.) phi += twopi;
631 double phigrad = phi*180./
pi;
633 double th = mom.theta();
654 std::map<int,float,std::less<int> > themap;
655 std::map<int,float,std::less<int> > themap1;
657 std::map<int,float,std::less<int> > themapxy;
658 std::map<int,float,std::less<int> > themapz;
662 G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
665 std::cout <<
"BscTest: accessed all HC" << std::endl;;
667 int CAFIid = G4SDManager::GetSDMpointer()->GetCollectionID(
"BSCHits");
671 std::cout <<
"BscTest: theCAFI->entries = " << theCAFI->entries() << std::endl;
681 for (
int j=0; j<theCAFI->entries(); j++) {
683 CLHEP::Hep3Vector hitPoint = aHit->
getEntry();
684 double zz = hitPoint.z();
690 int nhit11 = 0, nhit12 = 0, nhit13 = 0 ;
691 double totallosenergy= 0.;
692 for (
int j=0; j<theCAFI->entries(); j++) {
697 CLHEP::Hep3Vector hitPoint = aHit->
getEntry();
702 double zz = hitPoint.z();
707 std::cout <<
"BscTest:zHits = " << zz << std::endl;
710 themap[unitID] += losenergy;
711 totallosenergy += losenergy;
715 zside = (unitID&32)>>5;
720 G4ThreeVector middle = (hitExitLocalPoint+hitEntryLocalPoint)/2.;
721 themapz[unitID] = hitPoint.z()+middle.z();
726 if(losenergy > 0.00003) {
727 themap1[unitID] += 1.;
733 if(losenergy > 0.00005) {
734 themap1[unitID] += 1.;
765 if( zz < z3 && zz >
z2){
770 if( zz < z4 && zz >
z3){
804 if( zz < z3 && zz >
z2){
826 if( zz < z4 && zz >
z3){
836 if(totallosenergy == 0.0) {
837 std::cout <<
"BscTest: number of hits = " << theCAFI->entries() << std::endl;
838 for (
int j=0; j<theCAFI->entries(); j++) {
841 std::cout <<
" j hits = " << j <<
"losenergy = " << losenergy << std::endl;
845 double totalEnergy = 0.;
846 int nhitsX = 0, nhitsY = 0, nsumhit = 0 ;
847 for (
int sector=1; sector<4; sector++) {
848 int nhitsecX = 0, nhitsecY = 0;
849 for (
int zmodule=1; zmodule<11; zmodule++) {
854 double theTotalEnergy = themap[
index];
858 if(theTotalEnergy > 0.00003) {
867 if(theTotalEnergy > 0.00005) {
874 totalEnergy += themap[
index];
878 if(nhitsecX > 10 || nhitsecY > 10) {
894 std::cout <<
"BscTest: END OF Event " << (*evt)()->GetEventID() << std::endl;
T getParameter(std::string const &) const
G4ThreeVector getEntryLocalP() const
TH1F * GetHisto(Int_t Number)
int detLevels(const G4VTouchable *) const
TH2F * GetHisto2(Int_t Number)
unsigned int getUnitID() const
G4String detName(const G4VTouchable *, int, int) const
std::string fRecreateFile
void WriteToFile(const TString &fOutputFile, const TString &fRecreateFile)
void HistInit(const char *name, const char *title, Int_t nbinsx, Axis_t xlow, Axis_t xup)
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
static unsigned int packBscIndex(int det, int zside, int station)
G4ThreeVector getExitLocalP() const
G4ThreeVector getEntry() const
void detectorLevel(const G4VTouchable *, int &, int *, G4String *) const
G4THitsCollection< BscG4Hit > BscG4HitCollection
BscAnalysisHistManager(const TString &managername)
float getEnergyLoss() const
~BscAnalysisHistManager() override