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 : " << std::endl;
107 std::cout<<
"BscTest: End of process"<<std::endl;
154 HistInit(
"TrackPhi",
"Primary Phi", 100, 0.,360. );
155 HistInit(
"TrackTheta",
"Primary Theta", 100, 0.,180. );
156 HistInit(
"TrackP",
"Track XY position Z+ ", 80, -80., 80., 80, -80., 80. );
157 HistInit(
"TrackM",
"Track XY position Z-", 80, -80., 80., 80, -80., 80. );
158 HistInit(
"DetIDs",
"Track DetId - vs +", 16, -0.5, 15.5,16, 15.5, 31.5 );
168 std::cout <<
"================================================================"<<std::endl;
169 std::cout <<
" Write this Analysis to File "<<fOutputFile<<std::endl;
170 std::cout <<
"================================================================"<<std::endl;
172 TFile*
file =
new TFile(fOutputFile, fRecreateFile);
183 char* newtitle =
new char[strlen(title)+strlen(
fTypeTitle)+5];
184 strcpy(newtitle,title);
185 strcat(newtitle,
" (");
187 strcat(newtitle,
") ");
188 fHistArray->AddLast((
new TH1F(name, newtitle, nbinsx, xlow, xup)));
198 char* newtitle =
new char[strlen(title)+strlen(
fTypeTitle)+5];
199 strcpy(newtitle,title);
200 strcat(newtitle,
" (");
202 strcat(newtitle,
") ");
203 fHistArray->AddLast((
new TH2F(name, newtitle, nbinsx, xlow, xup, nbinsy, ylow, yup)));
213 if (Number <= fHistArray->GetLast() &&
fHistArray->At(Number) != (TObject*)0){
219 std::cout <<
"!!!!!!!!!!!!!!!!!!GetHisto!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
220 std::cout <<
" WARNING ERROR - HIST ID INCORRECT (TOO HIGH) - " << Number << std::endl;
221 std::cout <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
232 if (Number <= fHistArray->GetLast() &&
fHistArray->At(Number) != (TObject*)0){
238 std::cout <<
"!!!!!!!!!!!!!!!!GetHisto2!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
239 std::cout <<
" WARNING ERROR - HIST ID INCORRECT (TOO HIGH) - " << Number << std::endl;
240 std::cout <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
278 std::cout<<
"BscTest:beggining of job"<<std::endl;;
286 std::cout << std::endl <<
"BscTest:: Begining of Run"<< std::endl;
296 iev = (*evt)()->GetEventID();
298 std::cout <<
"BscTest:update Event number = " <<
iev << std::endl;
305 itrk = (*trk)()->GetTrackID();
307 std::cout <<
"BscTest:update BeginOfTrack number = " <<
itrk << std::endl;
322 itrk = (*trk)()->GetTrackID();
324 std::cout <<
"BscTest:update EndOfTrack number = " <<
itrk << std::endl;
327 G4double tracklength = (*trk)()->GetTrackLength();
333 G4ThreeVector vert_mom = (*trk)()->GetVertexMomentumDirection();
334 G4ThreeVector vert_pos = (*trk)()->GetVertexPosition();
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;
725 for (
int j=0;
j<theCAFI->entries();
j++) {
727 CLHEP::Hep3Vector hitPoint = aHit->
getEntry();
728 double zz = hitPoint.z();
737 int nhit11 = 0, nhit12 = 0, nhit13 = 0 ;
738 double totallosenergy= 0.;
739 for (
int j=0;
j<theCAFI->entries();
j++) {
744 CLHEP::Hep3Vector hitPoint = aHit->
getEntry();
751 double zz = hitPoint.z();
756 std::cout <<
"BscTest:zHits = " << zz << std::endl;
759 themap[unitID] += losenergy;
760 totallosenergy += losenergy;
764 zside = (unitID&32)>>5;
769 G4ThreeVector middle = (hitExitLocalPoint+hitEntryLocalPoint)/2.;
770 themapz[unitID] = hitPoint.z()+middle.z();
775 if(losenergy > 0.00003) {
776 themap1[unitID] += 1.;
782 if(losenergy > 0.00005) {
783 themap1[unitID] += 1.;
814 if( zz < z3 && zz >
z2){
819 if( zz < z4 && zz >
z3){
853 if( zz < z3 && zz >
z2){
875 if( zz < z4 && zz >
z3){
885 if(totallosenergy == 0.0) {
886 std::cout <<
"BscTest: number of hits = " << theCAFI->entries() << std::endl;
887 for (
int j=0;
j<theCAFI->entries();
j++) {
890 std::cout <<
" j hits = " <<
j <<
"losenergy = " << losenergy << std::endl;
894 double totalEnergy = 0.;
895 int nhitsX = 0, nhitsY = 0, nsumhit = 0 ;
896 for (
int sector=1; sector<4; sector++) {
897 int nhitsecX = 0, nhitsecY = 0;
898 for (
int zmodule=1; zmodule<11; zmodule++) {
903 double theTotalEnergy = themap[
index];
907 if(theTotalEnergy > 0.00003) {
916 if(theTotalEnergy > 0.00005) {
923 totalEnergy += themap[
index];
927 if(nhitsecX > 10 || nhitsecY > 10) {
943 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