107 G4Track* currentTrack = currentStep->GetTrack();
110 cout<<
"Can't get currentTrack"<<endl;
113 G4TrackStatus currentTrackStatus = currentTrack->GetTrackStatus();
115 int stepNumber = currentTrack->GetCurrentStepNumber();
116 if(msgFlag) cout<<
"STEP "<<stepNumber<<
":"<<endl;
119 Hep3Vector currentPosition = currentTrack->GetPosition();
120 Hep3Vector currentMomentum = currentTrack->GetMomentum();
124 G4VPhysicalVolume* oldVolume;
125 G4VPhysicalVolume* newVolume;
126 if(!currentTrack->GetTouchableHandle()) cout<<
"Can't get currentTrack->GetTouchableHandle()"<<endl;
127 else oldVolume= currentTrack->GetTouchableHandle()->GetVolume();
128 if(!currentTrack->GetNextTouchableHandle()) cout<<
"Can't get currentTrack->GetNextTouchableHandle()"<<endl;
129 else newVolume= currentTrack->GetNextTouchableHandle()->GetVolume();
130 if(!oldVolume) cout<<
"Can't get oldVolume!"<<endl;
133 if(stepNumber>50000) {
134 cout<<
"infinite steps in the track "<<endl;
135 currentTrack->SetTrackStatus(fStopAndKill); m_trackstop =
true;
138 G4String ParticleName = currentTrack->GetDefinition()->GetParticleName();
139 double x_ = currentPosition.x();
140 double y_ = currentPosition.y();
141 double z_ = currentPosition.z();
142 bool inner = (oldVolume!=newVolume)&&(!( (fabs(x_)>=myMucR) || (fabs(y_)>=myMucR) || ((fabs(x_-y_)/sqrt(2.))>=myMucR) || ((fabs(x_+y_)/sqrt(2.))>=myMucR) || (fabs(z_)>=myMucZ)) );
143 bool mucdec = (fabs(x_)>=myMucR) || (fabs(y_)>=myMucR) || ((fabs(x_-y_)/sqrt(2.))>=myMucR) || ((fabs(x_+y_)/sqrt(2.))>=myMucR) || (fabs(z_)>=myMucZ);
146 if(currentTrackStatus == fAlive)
152 double currentPoint[3]={currentPosition.x(),currentPosition.y(),currentPosition.z()};
153 double currentBfield[3]={0.0,0.0,0.0};
154 Hep3Vector currentB(0.0,0.0,1.0);
155 if(G4TransportationManager::GetTransportationManager())
157 G4FieldManager* fieldManager=G4TransportationManager::GetTransportationManager()->GetFieldManager();
160 if(fieldManager->GetDetectorField())
162 fieldManager->GetDetectorField()->GetFieldValue(currentPoint,currentBfield);
163 currentB.set(currentBfield[0]/tesla,currentBfield[1]/tesla,currentBfield[2]/tesla);
164 if(msgFlag) cout<<
"B:"<<currentB.x()<<
","<<currentB.y()<<
","<<currentB.z()<<endl;
170 G4Material* oldMaterial = oldVolume->GetLogicalVolume()->GetMaterial();
171 if(!oldMaterial) std::cout<<
"Can't get oldMaterial"<<std::endl;
172 else CalculateChicc(oldMaterial);
175 if(!(extXpErr->
move(currentPosition,currentMomentum,currentB,1,chicc)))
176 if(msgFlag) cout<<
"can not update Error Matrix!!"<<endl;
181 cout<<
"Volume name:"<<newVolume->GetName()<<endl;
182 cout<<
"Volume number:"<<newVolume->GetCopyNo()<<endl;
183 cout<<
"x:"<<currentPoint[0]<<
"//y:"<<currentPoint[1]<<
"//z:"<<currentPoint[2]
184 <<
"||px:"<<currentMomentum.x()<<
"//py:"<<currentMomentum.y()<<
"//pz:"
185 <<currentMomentum.z()<<endl;
186 cout<<
"Error matrix is:"<<extXpErr->
get_err()<<endl;
187 cout<<
"phi:"<<atan(currentPoint[1]/currentPoint[0])<<endl;
188 Hep3Vector nz(0.,0.,1.);
189 cout<<
"Projected z error:"<<extXpErr->
get_plane_err(currentMomentum.unit(),nz)
195 Hep3Vector nt(-y/R,
x/R,0.);
196 cout<<
"Projected phi error:"<<(extXpErr->
get_plane_err(currentMomentum.unit(),nt))/R
201 Hep3Vector xVector(1.0,0,0);
202 Hep3Vector yVector(0,1.0,0);
203 Hep3Vector zVector(0,0,1.0);
205 tzVector.setRThetaPhi(1.0,
M_PI/2.0,currentPosition.phi());
206 double r = currentPosition.perp();
207 double x = currentPosition.x();
208 double y = currentPosition.y();
209 double z = currentPosition.z();
210 G4String newVolumeName = newVolume->GetName();
211 G4String oldVolumeName = oldVolume->GetName();
212 G4StepPoint* postStepPoint = currentStep->GetPostStepPoint();
213 G4TouchableHistory* theTouchable = (G4TouchableHistory*)(postStepPoint->GetTouchable());
214 int newVolumeNumber=newVolume->GetCopyNo();
228 if( (!myTofFlag) && (!myTof1Flag) && (newVolumeName.contains(
"Tof") ))
230 newVolumeNumber = -2;
231 double currentTrackLength = currentTrack->GetTrackLength();
232 double totalTrackLength = currentTrackLength + initialPath;
236 double localTime = currentTrack->GetLocalTime();
238 double totalTOF = localTime + initialTof;
245 double xError = extXpErr->
get_plane_err(currentMomentum.unit(),xVector);
246 double yError = extXpErr->
get_plane_err(currentMomentum.unit(),yVector);
247 double zError = extXpErr->
get_plane_err(currentMomentum.unit(),zVector);
248 double tzError= extXpErr->
get_plane_err(currentMomentum.unit(),tzVector);
249 myExtTrack->
SetTof1Data(currentPosition/10.0,currentMomentum/1000.0,newVolumeName,newVolumeNumber,totalTOF,totalTrackLength/10,myOutputSymMatrix(extXpErr->
get_err()),zError/10,tzError/10,xError/10,yError/10);
262 if( (!myTof1Flag) && (newVolumeName==
"logicalScinBr1" || newVolumeName.contains(
"ScinEc") ||
263 newVolumeName.contains(
"logical_sensitive_detector_east") || newVolumeName.contains(
"logical_sensitive_detector_west") ) )
265 double currentTrackLength = currentTrack->GetTrackLength();
266 double totalTrackLength = currentTrackLength+initialPath;
268 double localTime = currentTrack->GetLocalTime();
269 double totalTOF = localTime + initialTof;
271 myPathIntoTof1 = currentTrackLength;
272 if(msgFlag) cout <<
"myPathIntoTof1 = " << myPathIntoTof1 << endl;
276 newVolumeNumber=theTouchable->GetReplicaNumber(2);
277 help_mrpc_nb = theTouchable->GetReplicaNumber(3);
279 if(newVolumeName.contains(
"ScinEc")) {
280 newVolumeNumber=(95-newVolumeNumber)/2;
281 newVolumeNumber=newVolumeNumber+176;
283 if(newVolumeName.contains(
"East")) newVolumeNumber=newVolumeNumber+48;
287 else if( newVolumeName.contains(
"_west_1"))
290 newVolumeNumber = (help_mrpc_nb)*(-0.5)+18.5;
314 else if(newVolumeName.contains(
"_east_1") )
317 newVolumeNumber = (help_mrpc_nb)*(0.5)+0.5;
342 else if( newVolumeName.contains(
"_west_2"))
344 newVolumeNumber = (help_mrpc_nb)*(-0.5)+18;
368 else if(newVolumeName.contains(
"_east_2") )
370 newVolumeNumber = (help_mrpc_nb)*(0.5)+1;
394 else{ newVolumeNumber=(527-newVolumeNumber)/3;}
400 double xError = extXpErr->
get_plane_err(currentMomentum.unit(),xVector);
401 double yError = extXpErr->
get_plane_err(currentMomentum.unit(),yVector);
402 double zError = extXpErr->
get_plane_err(currentMomentum.unit(),zVector);
403 double tzError= extXpErr->
get_plane_err(currentMomentum.unit(),tzVector);
404 myExtTrack->
SetTof1Data(currentPosition/10,currentMomentum/1000,newVolumeName,newVolumeNumber,totalTOF,totalTrackLength/10,myOutputSymMatrix(extXpErr->
get_err()),zError/10,tzError/10,xError/10,yError/10);
413 if( myInTof1 && ( oldVolumeName==
"logicalScinBr1" || oldVolumeName.contains(
"ScinEc") ||
414 newVolumeName.contains(
"logical_sensitive_detector_east") || newVolumeName.contains(
"logical_sensitive_detector_west")) ) {
417 myPathOutTof1 = currentTrack->GetTrackLength();
418 myPathInTof1.push_back(myPathOutTof1 - myPathIntoTof1);
419 if(msgFlag) cout <<
"myPathOutTof1 = " << myPathOutTof1 << endl;
422 if( myOutTof1 && ( newVolumeName==
"logicalScinBr1" || newVolumeName.contains(
"ScinEc") ||
423 newVolumeName.contains(
"logical_sensitive_detector_east") || newVolumeName.contains(
"logical_sensitive_detector_west")) ) {
426 myPathIntoTof1 = currentTrack->GetTrackLength();
427 if(msgFlag) cout <<
"myPathIntoTof1 = " << myPathIntoTof1 << endl;
433 if( (!myTof2Flag) && newVolumeName==
"logicalScinBr2" )
435 double currentTrackLength = currentTrack->GetTrackLength();
436 double totalTrackLength = currentTrackLength+initialPath;
438 double localTime = currentTrack->GetLocalTime();
439 double totalTOF = localTime + initialTof;
440 newVolumeNumber=(527-theTouchable->GetReplicaNumber(2))/3;
443 myPathIntoTof2 = currentTrackLength;
444 if(msgFlag) cout <<
"myPathIntoTof2 = " << myPathIntoTof2 << endl;
448 double xError = extXpErr->
get_plane_err(currentMomentum.unit(),xVector);
449 double yError = extXpErr->
get_plane_err(currentMomentum.unit(),yVector);
450 double zError = extXpErr->
get_plane_err(currentMomentum.unit(),zVector);
451 double tzError= extXpErr->
get_plane_err(currentMomentum.unit(),tzVector);
452 myExtTrack->
SetTof2Data(currentPosition/10,currentMomentum/1000,newVolumeName,newVolumeNumber,totalTOF,totalTrackLength/10,myOutputSymMatrix(extXpErr->
get_err()),zError/10,tzError/10,xError/10,yError/10);
458 if( myInTof2 && oldVolumeName==
"logicalScinBr2" ) {
461 myPathOutTof2 = currentTrack->GetTrackLength();
462 myPathInTof2.push_back(myPathOutTof2 - myPathIntoTof2);
463 if(msgFlag) cout <<
"myPathOutTof2 = " << myPathOutTof2 << endl;
466 if( myOutTof2 && newVolumeName==
"logicalScinBr2" ) {
469 myPathIntoTof2 = currentTrack->GetTrackLength();
470 if(msgFlag) cout <<
"myPathIntoTof2 = " << myPathIntoTof2 << endl;
474 if( (!myPhyEmcFlag) && (!myEmcFlag) && (newVolumeName==
"EMC" || newVolumeName.contains(
"BSC") || newVolumeName==
"EndPhi"))
476 newVolumeNumber = -2;
480 Hep3Vector
nPhi(-y/r,
x/r,0.);
483 Hep3Vector aPosition = currentPosition;
484 double R = aPosition.r();
485 double aTheta = aPosition.theta();
486 aPosition.setTheta(aTheta + M_PI_2);
488 errorTheta =(extXpErr->
get_plane_err(currentMomentum.unit(),aPosition.unit()))/R;
489 if(msgFlag) cout<<
"Theta direction: "<<aPosition<<endl;
490 myExtTrack->
SetEmcData(currentPosition/10,currentMomentum/1000,newVolumeName,newVolumeNumber,errorTheta,errorPhi,myOutputSymMatrix(extXpErr->
get_err()));
497 if(!myEmcPathFlag && newVolumeName.contains(
"Crystal") )
499 myPathIntoCrystal = currentTrack->GetTrackLength();
501 myEmcPathFlag =
true;
505 if( (!myEmcFlag) && newVolumeName.contains(
"Crystal") )
510 int npart,ntheta,nphi;
511 if(currentTrack->GetNextTouchableHandle()->GetVolume(1)->GetName().contains(
"BSC")) {
513 std::istringstream thetaBuf((currentTrack->GetNextTouchableHandle()->GetVolume(1)->GetName()).substr(16,2));
515 nphi = 308-currentTrack->GetNextTouchableHandle()->GetCopyNumber(2);
517 npart=2-2*currentTrack->GetNextTouchableHandle()->GetCopyNumber(3);
518 int endSector=currentTrack->GetNextTouchableHandle()->GetCopyNumber(2);
520 std::istringstream thetaBuf((currentTrack->GetNextTouchableHandle()->GetVolume(0)->GetName()).substr(20,2));
526 ostringstream strEmc;
528 strEmc<<
"EmcPart"<<npart<<
"Theta0"<<ntheta<<
"Phi"<<nphi;
530 strEmc<<
"EmcPart"<<npart<<
"Theta"<<ntheta<<
"Phi"<<nphi;
534 Hep3Vector
nPhi(-y/r,
x/r,0.);
537 Hep3Vector aPosition = currentPosition;
538 double R = aPosition.r();
539 double aTheta = aPosition.theta();
540 aPosition.setTheta(aTheta + M_PI_2);
542 errorTheta =(extXpErr->
get_plane_err(currentMomentum.unit(),aPosition.unit()))/R;
543 if(msgFlag) cout<<
"Theta direction: "<<aPosition<<endl;
544 myExtTrack->
SetEmcData(currentPosition/10,currentMomentum/1000,strEmc.str(),
546 newVolumeNumber,errorTheta,errorPhi,myOutputSymMatrix(extXpErr->
get_err()));
553 if(myEmcPathFlag && oldVolumeName.contains(
"Crystal") )
555 myPathOutCrystal = currentTrack->GetTrackLength();
556 myPathInCrystal = myPathInCrystal+myPathOutCrystal-myPathIntoCrystal;
563 if( (!myMucFlag) && ( (fabs(
x)>=myMucR) || (fabs(y)>=myMucR) || ((fabs(
x-y)/sqrt(2.))>=myMucR) || ((fabs(
x+y)/sqrt(2.))>=myMucR) || (fabs(z)>=myMucZ) ) )
565 int newVolumeNumber = newVolume->GetCopyNo();
568 Hep3Vector xVector(1.0,0,0);
569 Hep3Vector yVector(0,1.0,0);
570 Hep3Vector zVector(0,0,1.0);
571 double xError = extXpErr->
get_plane_err(currentMomentum.unit(),xVector);
572 double yError = extXpErr->
get_plane_err(currentMomentum.unit(),yVector);
573 double zError = extXpErr->
get_plane_err(currentMomentum.unit(),zVector);
575 double phi = currentPosition.phi();
576 if(phi<0.) phi+=
M_PI;
577 int i = int(8.0*phi/
M_PI);
578 if( i==0 || i==7 || i==8 )
584 Hep3Vector tzVector(-1.0,1.0,0.);
585 tzError =extXpErr->
get_plane_err(currentMomentum.unit(),tzVector.unit());
593 Hep3Vector tzVector(1.0,1.0,0.);
594 tzError =extXpErr->
get_plane_err(currentMomentum.unit(),tzVector.unit());
596 myExtTrack->
SetMucData(currentPosition/10,currentMomentum/1000,newVolumeName,newVolumeNumber,myOutputSymMatrix(extXpErr->
get_err()),zError/10,tzError/10,xError/10,yError/10);
599 if(!(ParticleName.contains(
"mu")&&myUseMucKalFlag))
602 currentStep->GetTrack()->SetTrackStatus(fStopAndKill);
611 HepSymMatrix XpErr = extXpErr->
get_err();
612 int namesize = oldVolumeName.size();
613 bool Flag1(
false),Flag2(
false),Flag3(
false),Flag4(
false),Flag5(
false);
614 Flag1 = m_mucdigicol->size()>0;
615 Flag2 = myUseMucKalFlag;
616 Flag3 = ParticleName.contains(
"mu")&&oldVolumeName.contains(
"lMuc")&&oldVolumeName.contains(
"P")&&oldVolumeName.contains(
"S")&&(oldVolumeName.contains(
"G")||oldVolumeName.contains(
"Ab"));
617 Flag4 = oldVolumeName.contains(
"lMuc")&&oldVolumeName.contains(
"P")&&oldVolumeName.contains(
"S")&&((namesize==10&&oldVolumeName.contains(
"G"))||(namesize==11&&oldVolumeName.contains(
"Ab")));
618 Flag5 = !((RemID[0]==1&&RemID[2]==9)||((RemID[0]==0||RemID[0]==2)&&RemID[2]==8));
620 if(Flag1&&Flag2&&Flag3&&Flag5)
623 double depth = currentStep-> GetStepLength();
624 if(oldVolumeName.contains(
"Ab"))
625 RemDepth = RemDepth+ depth;
626 if(RemStep==0&&Flag4)
628 Hep3Vector ID_1 =
GetGapID(oldVolumeName);
631 bool LastLay = (ID_1[0]==1&&ID_1[2]<9)||((ID_1[0]==0||ID_1[0]==2)&&ID_1[2]<8);
632 if(RememberID[2]!=ID_1[2]&&LastLay)
635 double dist = fabs(pos_loc.z());
636 RemPositon = currentPosition;
637 RemMomentum = currentMomentum;
645 bool WillFilter =
false;
646 bool LastLay_ =
false;
647 double dist_b = 99999.;
652 LastLay_ =(ID_2[0]==1&&ID_2[2]<9)||((ID_2[0]==0||ID_2[0]==2)&&ID_2[2]<8);
653 if(LastLay_)dist_b=fabs(
MucGeoGeneral::Instance()->GetGap(ID_2[0],ID_2[1],ID_2[2])->TransformToGap(currentPosition).z());
660 double dist = fabs(pos_loc.z());
662 if(!WillFilter&&RemDist>dist)
664 RemPositon = currentPosition;
665 RemMomentum = currentMomentum;
668 RemVol = oldVolumeName;
680 vector<MucRecHit*> tmp = muckal->
TrackHit();
683 double chi2 = muckal->
GetChi2();
690 myMucchisq_ = myMucchisq_+chi2;
691 muckal->
XPmod(m_pos_mod,m_mom_mod,m_err_mod);
693 if(RememberID[0]==1)myMucbrLastLay_=RememberID[2];
694 if(RememberID[0]==0||RememberID[0]==2)myMucecLastLay_=RememberID[2];
695 if(oldVolumeName.contains(
"Ab"))
696 RemDepth = RemDepth-depth;
698 myMucdepth_ = RemDepth;
700 myMucdepth_=myMucdepth_+RemDepth;
708 currentStep->GetTrack()->SetTrackStatus(fStopAndKill);
714 RemPositon = currentPosition;
715 RemMomentum = currentMomentum;
719 if(oldVolumeName.contains(
"Ab"))
724 if(msgFlag)cout<<
"---------Filter is OK---------- "<<endl;
730 RemPositon = currentPosition;
731 RemMomentum = currentMomentum;
740 if(myExtTrack)myExtTrack->
SetMucKalData(myMucchisq_,myMucnfit_,myMucdepth_,myMucbrLastLay_,myMucecLastLay_,myMucnhits_);
810 if(msgFlag) cout<<
"x:"<<currentPosition.x()<<
"//y:"<<currentPosition.y()<<
"//z:"<<currentPosition.z()<<
"||px:"<<currentMomentum.x()<<
"//py:"<<currentMomentum.y()<<
"//pz:"<<currentMomentum.z()<<endl;
811 double x = currentPosition.x();
812 double y = currentPosition.y();
813 double z = currentPosition.z();
814 if( (fabs(
x)>=2*myMucR) || (fabs(y)>=2*myMucR) || (fabs(z)>=2*myMucZ) )
816 {currentStep->GetTrack()->SetTrackStatus(fStopAndKill);m_trackstop=
true;}
820 else if(currentTrackStatus == fStopAndKill)
823 if(myEmcFlag) myExtTrack->
SetEmcPath(myPathInCrystal/10.);
827 cout <<
"myPathInTof1 = " ;
828 for(
int i=0; i!=myPathInTof1.size(); i++)
829 cout << myPathInTof1[i] <<
" ";
831 cout <<
"myPathInTof2 = " ;
832 for(
int i=0; i!=myPathInTof2.size(); i++)
833 cout << myPathInTof2[i] <<
" ";
841 std::cout<<
"x:"<<currentPosition.x()<<
"//y:"<<currentPosition.y()<<
"//z:"<<currentPosition.z()<<
"||px:"<<currentMomentum.x()<<
"//py:"<<currentMomentum.y()<<
"//pz:"<<currentMomentum.z()<<
"//stoped"<<endl;
842 cout<<
"Error matrix is:"<<extXpErr->
get_err()<<endl;
845 cout<<
"x:"<<currentPosition.x()<<
"//y:"<<currentPosition.y()<<
"//z:"<<currentPosition.z()<<
"||px:"<<currentMomentum.x()<<
"//py:"<<currentMomentum.y()<<
"//pz:"<<currentMomentum.z()<<
"//escaped"<<std::endl;
846 std::cout<<
"Error matrix is:"<<extXpErr->
get_err()<<std::endl;