27 #include "G4SDManager.hh"
30 #include "G4VProcess.hh"
31 #include "G4HCofThisEvent.hh"
32 #include "G4UserEventAction.hh"
33 #include "G4TransportationManager.hh"
34 #include "G4ProcessManager.hh"
37 #include "CLHEP/Units/GlobalSystemOfUnits.h"
38 #include "CLHEP/Units/GlobalPhysicalConstants.h"
69 std::cout<<
"============================================================================"<<std::endl;
70 std::cout <<
"BscTestconstructor :: Initialized as observer"<< std::endl;
80 std::cout <<
"BscTest constructor :: Initialized BscAnalysisHistManager"<< std::endl;
91 std::cout <<
"Bsc output root file has been created";
94 bscOutputFile.Close();
97 std::cout <<
", and deleted" << std::endl;
104 std::cout << std::endl <<
"BscTest Destructor --------> End of BscTest : "
108 std::cout<<
"BscTest: End of process"<<std::endl;
155 HistInit(
"TrackPhi",
"Primary Phi", 100, 0.,360. );
156 HistInit(
"TrackTheta",
"Primary Theta", 100, 0.,180. );
157 HistInit(
"TrackP",
"Track XY position Z+ ", 80, -80., 80., 80, -80., 80. );
158 HistInit(
"TrackM",
"Track XY position Z-", 80, -80., 80., 80, -80., 80. );
159 HistInit(
"DetIDs",
"Track DetId - vs +", 16, -0.5, 15.5,16, 15.5, 31.5 );
169 std::cout <<
"================================================================"<<std::endl;
170 std::cout <<
" Write this Analysis to File "<<fOutputFile<<std::endl;
171 std::cout <<
"================================================================"<<std::endl;
173 TFile*
file =
new TFile(fOutputFile, fRecreateFile);
184 char* newtitle =
new char[strlen(title)+strlen(
fTypeTitle)+5];
185 strcpy(newtitle,title);
186 strcat(newtitle,
" (");
188 strcat(newtitle,
") ");
189 fHistArray->AddLast((
new TH1F(name, newtitle, nbinsx, xlow, xup)));
199 char* newtitle =
new char[strlen(title)+strlen(
fTypeTitle)+5];
200 strcpy(newtitle,title);
201 strcat(newtitle,
" (");
203 strcat(newtitle,
") ");
204 fHistArray->AddLast((
new TH2F(name, newtitle, nbinsx, xlow, xup, nbinsy, ylow, yup)));
214 if (Number <= fHistArray->GetLast() &&
fHistArray->At(Number) != (TObject*)0){
220 std::cout <<
"!!!!!!!!!!!!!!!!!!GetHisto!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
221 std::cout <<
" WARNING ERROR - HIST ID INCORRECT (TOO HIGH) - " << Number << std::endl;
222 std::cout <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
233 if (Number <= fHistArray->GetLast() &&
fHistArray->At(Number) != (TObject*)0){
239 std::cout <<
"!!!!!!!!!!!!!!!!GetHisto2!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
240 std::cout <<
" WARNING ERROR - HIST ID INCORRECT (TOO HIGH) - " << Number << std::endl;
241 std::cout <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
279 std::cout<<
"BscTest:beggining of job"<<std::endl;;
287 std::cout << std::endl <<
"BscTest:: Begining of Run"<< std::endl;
297 iev = (*evt)()->GetEventID();
299 std::cout <<
"BscTest:update Event number = " <<
iev << std::endl;
306 itrk = (*trk)()->GetTrackID();
308 std::cout <<
"BscTest:update BeginOfTrack number = " <<
itrk << std::endl;
323 itrk = (*trk)()->GetTrackID();
325 std::cout <<
"BscTest:update EndOfTrack number = " <<
itrk << std::endl;
328 G4double tracklength = (*trk)()->GetTrackLength();
334 G4ThreeVector vert_mom = (*trk)()->GetVertexMomentumDirection();
335 G4ThreeVector vert_pos = (*trk)()->GetVertexPosition();
338 float phi = atan2(vert_mom.y(),vert_mom.x());
339 if (phi < 0.) phi += twopi;
340 if(tracklength <
z4) {
345 const G4Step* aStep = (*trk)()->GetStep();
346 G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
347 lastpo = preStepPoint->GetPosition();
362 G4int stepnumber = aStep->GetTrack()->GetCurrentStepNumber();
363 std::cout <<
"BscTest:update Step number = " << stepnumber << std::endl;
366 G4Track* theTrack = aStep->GetTrack();
369 std::cout <<
"BscTest on aStep: No trk info !!!! abort " << std::endl;
372 G4int
id = theTrack->GetTrackID();
373 G4String particleType = theTrack->GetDefinition()->GetParticleName();
374 G4int parentID = theTrack->GetParentID();
375 G4TrackStatus trackstatus = theTrack->GetTrackStatus();
376 G4double tracklength = theTrack->GetTrackLength();
377 G4ThreeVector trackmom = theTrack->GetMomentum();
378 G4double entot = theTrack->GetTotalEnergy();
379 G4int curstepnumber = theTrack->GetCurrentStepNumber();
380 G4ThreeVector vert_pos = theTrack->GetVertexPosition();
381 G4ThreeVector vert_mom = theTrack->GetVertexMomentumDirection();
382 G4double stepl = aStep->GetStepLength();
383 G4double EnerDeposit = aStep->GetTotalEnergyDeposit();
384 G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
385 G4ThreeVector preposition = preStepPoint->GetPosition();
386 G4ThreeVector prelocalpoint = theTrack->GetTouchable()->GetHistory()->
387 GetTopTransform().TransformPoint(preposition);
388 G4VPhysicalVolume* currentPV = preStepPoint->GetPhysicalVolume();
389 G4String prename = currentPV->GetName();
391 const G4VTouchable* pre_touch = preStepPoint->GetTouchable();
393 G4String name1[20];
int copyno1[20];
394 if (pre_levels > 0) {
401 if (curstepnumber == 1 ) {
410 if(prename ==
"SBST" ) {
416 if(prename ==
"SBSTs" ) {
424 if (trackstatus != 2 ) {
426 if(prename ==
"SIDETL" || prename ==
"SIDETR" ) {
427 if(prename ==
"SIDETL") {
430 if(prename ==
"SIDETR") {
434 G4String posname = aStep->GetPostStepPoint()->GetPhysicalVolume()->GetName();
435 if((prename ==
"SIDETL" && posname !=
"SIDETL") || (prename ==
"SIDETR" && posname !=
"SIDETR")) {
436 if(name1[2] ==
"SISTATION" ) {
439 if(name1[3] ==
"SIPLANE" ) {
443 if(prename ==
"SIDETL") {
449 else if(copyno1[2]<3) {
453 else if(copyno1[3]<3) {
456 else if(copyno1[3]<4) {
459 else if(copyno1[3]<5) {
462 else if(copyno1[3]<6) {
465 else if(copyno1[3]<7) {
468 else if(copyno1[3]<8) {
471 else if(copyno1[3]<9) {
474 else if(copyno1[3]<10) {
478 else if(copyno1[2]<4) {
481 else if(copyno1[2]<5) {
485 if(prename ==
"SIDETR") {
491 else if(copyno1[2]<3) {
495 else if(copyno1[3]<3) {
498 else if(copyno1[3]<4) {
501 else if(copyno1[3]<5) {
504 else if(copyno1[3]<6) {
507 else if(copyno1[3]<7) {
510 else if(copyno1[3]<8) {
513 else if(copyno1[3]<9) {
516 else if(copyno1[3]<10) {
520 else if(copyno1[2]<4) {
523 else if(copyno1[2]<5) {
535 if (trackstatus == 2 ) {
544 if (parentID == 1 && curstepnumber == 1) {
547 if(prename ==
"SBST" ) {
550 if(prename ==
"SBSTs" ) {
562 return ((touch->GetHistoryDepth())+1);
569 int currentlevel)
const {
572 if (level > 0 && level >= currentlevel) {
573 int ii = level - currentlevel;
574 return touch->GetVolume(ii)->GetName();
581 int* copyno, G4String*
name)
const {
586 int i = level -
ii - 1;
587 G4VPhysicalVolume* pv = touch->GetVolume(i);
589 name[
ii] = pv->GetName();
591 name[
ii] =
"Unknown";
592 copyno[
ii] = touch->GetReplicaNumber(i);
603 iev = (*evt)()->GetEventID();
604 std::cout <<
"BscTest:update EndOfEvent = " <<
iev << std::endl;
611 G4PrimaryParticle* thePrim=0;
615 G4int nvertex = (*evt)()->GetNumberOfPrimaryVertex();
617 std::cout <<
"BscTest: My warning: NumberOfPrimaryVertex != 1 --> = " << nvertex << std::endl;
619 for (
int i = 0 ;
i<nvertex;
i++) {
620 G4PrimaryVertex* avertex = (*evt)()->GetPrimaryVertex(
i);
622 std::cout <<
"BscTest End Of Event ERR: pointer to vertex = 0"
624 G4int
npart = avertex->GetNumberOfParticle();
626 std::cout <<
"BscTest: My warning: NumberOfPrimaryPart != 1 --> = " << npart << std::endl;
628 std::cout <<
"BscTest End Of Event ERR: no NumberOfParticle" << std::endl;
630 if (thePrim==0) thePrim=avertex->GetPrimary(trackID);
634 G4double vx=0.,vy=0.,vz=0.;
635 vx = avertex->GetX0();
636 vy = avertex->GetY0();
637 vz = avertex->GetZ0();
671 G4ThreeVector mom = thePrim->GetMomentum();
673 double phi = atan2(mom.y(),mom.x());
674 if (phi < 0.) phi += twopi;
675 double phigrad = phi*180./
pi;
677 double th = mom.theta();
698 std::map<int,float,std::less<int> > themap;
699 std::map<int,float,std::less<int> > themap1;
701 std::map<int,float,std::less<int> > themapxy;
702 std::map<int,float,std::less<int> > themapz;
706 G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
709 std::cout <<
"BscTest: accessed all HC" << std::endl;;
711 int CAFIid = G4SDManager::GetSDMpointer()->GetCollectionID(
"BSCHits");
715 std::cout <<
"BscTest: theCAFI->entries = " << theCAFI->entries() << std::endl;
726 for (
int j=0;
j<theCAFI->entries();
j++) {
728 CLHEP::Hep3Vector hitPoint = aHit->
getEntry();
729 double zz = hitPoint.z();
738 int nhit11 = 0, nhit12 = 0, nhit13 = 0 ;
739 double totallosenergy= 0.;
740 for (
int j=0;
j<theCAFI->entries();
j++) {
745 CLHEP::Hep3Vector hitPoint = aHit->
getEntry();
749 double phi_hit = hitPoint.phi();
750 if (phi_hit < 0.) phi_hit += twopi;
752 double zz = hitPoint.z();
757 std::cout <<
"BscTest:zHits = " << zz << std::endl;
760 themap[unitID] += losenergy;
761 totallosenergy += losenergy;
765 zside = (unitID&32)>>5;
770 G4ThreeVector middle = (hitExitLocalPoint+hitEntryLocalPoint)/2.;
771 themapz[unitID] = hitPoint.z()+middle.z();
776 if(losenergy > 0.00003) {
777 themap1[unitID] += 1.;
783 if(losenergy > 0.00005) {
784 themap1[unitID] += 1.;
815 if( zz < z3 && zz >
z2){
820 if( zz < z4 && zz >
z3){
854 if( zz < z3 && zz >
z2){
876 if( zz < z4 && zz >
z3){
886 if(totallosenergy == 0.0) {
887 std::cout <<
"BscTest: number of hits = " << theCAFI->entries() << std::endl;
888 for (
int j=0;
j<theCAFI->entries();
j++) {
891 std::cout <<
" j hits = " <<
j <<
"losenergy = " << losenergy << std::endl;
895 double totalEnergy = 0.;
896 int nhitsX = 0, nhitsY = 0, nsumhit = 0 ;
897 for (
int sector=1; sector<4; sector++) {
898 int nhitsecX = 0, nhitsecY = 0;
899 for (
int zmodule=1; zmodule<11; zmodule++) {
900 for (
int zside=1; zside<3; zside++) {
904 double theTotalEnergy = themap[
index];
908 if(theTotalEnergy > 0.00003) {
917 if(theTotalEnergy > 0.00005) {
924 totalEnergy += themap[
index];
928 if(nhitsecX > 10 || nhitsecY > 10) {
948 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)
TObjArray * fHistNamesArray
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)
BscTest(const edm::ParameterSet &p)
static void unpackBscIndex(const unsigned int &idx)
BscNumberingScheme * theBscNumberingScheme
static unsigned int packBscIndex(int det, int zside, int station)
~BscAnalysisHistManager()
G4ThreeVector getExitLocalP() const
G4ThreeVector getEntry() const
void detectorLevel(const G4VTouchable *, int &, int *, G4String *) const
void update(const BeginOfJob *run)
This routine will be called when the appropriate signal arrives.
G4THitsCollection< BscG4Hit > BscG4HitCollection
BscAnalysisHistManager(const TString &managername)
float getEnergyLoss() const