00070 {
00071
00072
00073 G4Track* currentTrack = currentStep->GetTrack();
00074 if(!currentTrack)
00075 {
00076 cout<<"Can't get currentTrack"<<endl;
00077 return;
00078 }
00079 G4TrackStatus currentTrackStatus = currentTrack->GetTrackStatus();
00080
00081 if(msgFlag)
00082 {
00083 int stepNumber = currentTrack->GetCurrentStepNumber();
00084 cout<<"STEP "<<stepNumber<<":"<<endl;
00085 }
00086
00087
00088 Hep3Vector currentPosition = currentTrack->GetPosition();
00089 Hep3Vector currentMomentum = currentTrack->GetMomentum();
00090
00091
00092
00093 G4VPhysicalVolume* oldVolume;
00094 G4VPhysicalVolume* newVolume;
00095 if(!currentTrack->GetTouchableHandle()) cout<<"Can't get currentTrack->GetTouchableHandle()"<<endl;
00096 else oldVolume= currentTrack->GetTouchableHandle()->GetVolume();
00097 if(!currentTrack->GetNextTouchableHandle()) cout<<"Can't get currentTrack->GetNextTouchableHandle()"<<endl;
00098 else newVolume= currentTrack->GetNextTouchableHandle()->GetVolume();
00099 if(!oldVolume) cout<<"Can't get oldVolume!"<<endl;
00100
00101
00102
00103 if(currentTrackStatus == fAlive)
00104 {
00105 if(oldVolume!=newVolume)
00106 {
00107
00108 double currentPoint[3]={currentPosition.x(),currentPosition.y(),currentPosition.z()};
00109 double currentBfield[3]={0.0,0.0,0.0};
00110 Hep3Vector currentB(0.0,0.0,1.0);
00111 if(G4TransportationManager::GetTransportationManager())
00112 {
00113 G4FieldManager* fieldManager=G4TransportationManager::GetTransportationManager()->GetFieldManager();
00114 if(fieldManager)
00115 {
00116 if(fieldManager->GetDetectorField())
00117 {
00118 fieldManager->GetDetectorField()->GetFieldValue(currentPoint,currentBfield);
00119 currentB.set(currentBfield[0]/tesla,currentBfield[1]/tesla,currentBfield[2]/tesla);
00120 if(msgFlag) cout<<"B:"<<currentB.x()<<","<<currentB.y()<<","<<currentB.z()<<endl;
00121 }
00122 }
00123 }
00124
00125
00126 G4Material* oldMaterial = oldVolume->GetLogicalVolume()->GetMaterial();
00127 if(!oldMaterial) std::cout<<"Can't get oldMaterial"<<std::endl;
00128 else CalculateChicc(oldMaterial);
00129
00130
00131 if(!(extXpErr->move(currentPosition,currentMomentum,currentB,1,chicc)))
00132 if(msgFlag) cout<<"can not update Error Matrix!!"<<endl;
00133
00134
00135 if(msgFlag)
00136 {
00137 cout<<"Volume name:"<<newVolume->GetName()<<endl;
00138 cout<<"Volume number:"<<newVolume->GetCopyNo()<<endl;
00139 cout<<"x:"<<currentPoint[0]<<"//y:"<<currentPoint[1]<<"//z:"<<currentPoint[2]
00140 <<"||px:"<<currentMomentum.x()<<"//py:"<<currentMomentum.y()<<"//pz:"
00141 <<currentMomentum.z()<<endl;
00142 cout<<"Error matrix is:"<<extXpErr->get_err()<<endl;
00143 cout<<"phi:"<<atan(currentPoint[1]/currentPoint[0])<<endl;
00144 Hep3Vector nz(0.,0.,1.);
00145 cout<<"Projected z error:"<<extXpErr->get_plane_err(currentMomentum.unit(),nz)
00146 <<endl;
00147 double x,y,R;
00148 x = currentPoint[0];
00149 y = currentPoint[1];
00150 R = sqrt(x*x+y*y);
00151 Hep3Vector nt(-y/R,x/R,0.);
00152 cout<<"Projected phi error:"<<(extXpErr->get_plane_err(currentMomentum.unit(),nt))/R
00153 <<endl<<endl;
00154 }
00155
00156
00157 Hep3Vector xVector(1.0,0,0);
00158 Hep3Vector yVector(0,1.0,0);
00159 Hep3Vector zVector(0,0,1.0);
00160 Hep3Vector tzVector;
00161 tzVector.setRThetaPhi(1.0,M_PI/2.0,currentPosition.phi());
00162 double r = currentPosition.perp();
00163 double x = currentPosition.x();
00164 double y = currentPosition.y();
00165 double z = currentPosition.z();
00166 G4String newVolumeName = newVolume->GetName();
00167 G4String oldVolumeName = oldVolume->GetName();
00168 G4StepPoint* postStepPoint = currentStep->GetPostStepPoint();
00169 G4TouchableHistory* theTouchable = (G4TouchableHistory*)(postStepPoint->GetTouchable());
00170 int newVolumeNumber=newVolume->GetCopyNo();
00171
00172
00173
00174 if( (!myTofFlag) && (!myTof1Flag) && newVolumeName.contains("Tof") )
00175 {
00176 newVolumeNumber = -2;
00177 double currentTrackLength = currentTrack->GetTrackLength();
00178 double totalTrackLength = currentTrackLength + initialPath;
00179
00180
00181
00182 double localTime = currentTrack->GetLocalTime();
00183
00184 double totalTOF = localTime + initialTof;
00185
00186
00187 if(myExtTrack)
00188 {
00189 double xError = extXpErr->get_plane_err(currentMomentum.unit(),xVector);
00190 double yError = extXpErr->get_plane_err(currentMomentum.unit(),yVector);
00191 double zError = extXpErr->get_plane_err(currentMomentum.unit(),zVector);
00192 double tzError= extXpErr->get_plane_err(currentMomentum.unit(),tzVector);
00193 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);
00194 myTofFlag = true;
00195 }
00196 return;
00197 }
00198
00199
00200 if( (!myTof1Flag) && (newVolumeName=="logicalScinBr1" || newVolumeName.contains("ScinEc") ) )
00201 {
00202 double currentTrackLength = currentTrack->GetTrackLength();
00203 double totalTrackLength = currentTrackLength+initialPath;
00204
00205 double localTime = currentTrack->GetLocalTime();
00206 double totalTOF = localTime + initialTof;
00207 myInTof1 = true;
00208 myPathIntoTof1 = currentTrackLength;
00209 if(msgFlag) cout << "myPathIntoTof1 = " << myPathIntoTof1 << endl;
00210 newVolumeNumber=theTouchable->GetReplicaNumber(2);
00211 if(newVolumeName.contains("ScinEc")) {
00212 newVolumeNumber=(95-newVolumeNumber)/2;
00213 newVolumeNumber=newVolumeNumber+176;
00214 if(newVolumeName.contains("East")) newVolumeNumber=newVolumeNumber+48;
00215 }
00216 else newVolumeNumber=(527-newVolumeNumber)/3;
00217
00218 if(myExtTrack)
00219 {
00220 double xError = extXpErr->get_plane_err(currentMomentum.unit(),xVector);
00221 double yError = extXpErr->get_plane_err(currentMomentum.unit(),yVector);
00222 double zError = extXpErr->get_plane_err(currentMomentum.unit(),zVector);
00223 double tzError= extXpErr->get_plane_err(currentMomentum.unit(),tzVector);
00224 myExtTrack->SetTof1Data(currentPosition/10,currentMomentum/1000,newVolumeName,newVolumeNumber,totalTOF,totalTrackLength/10,myOutputSymMatrix(extXpErr->get_err()),zError/10,tzError/10,xError/10,yError/10);
00225 myTof1Flag = true;
00226 }
00227 return;
00228 }
00229
00230 if( myInTof1 && ( oldVolumeName=="logicalScinBr1" || oldVolumeName.contains("ScinEc") ) ) {
00231 myInTof1 = false;
00232 myOutTof1 = true;
00233 myPathOutTof1 = currentTrack->GetTrackLength();
00234 myPathInTof1.push_back(myPathOutTof1 - myPathIntoTof1);
00235 if(msgFlag) cout << "myPathOutTof1 = " << myPathOutTof1 << endl;
00236 }
00237
00238 if( myOutTof1 && ( newVolumeName=="logicalScinBr1" || newVolumeName.contains("ScinEc") ) ) {
00239 myInTof1 = true;
00240 myOutTof1 = false;
00241 myPathIntoTof1 = currentTrack->GetTrackLength();
00242 if(msgFlag) cout << "myPathIntoTof1 = " << myPathIntoTof1 << endl;
00243 }
00244
00245
00246 if( (!myTof2Flag) && newVolumeName=="logicalScinBr2" )
00247 {
00248 double currentTrackLength = currentTrack->GetTrackLength();
00249 double totalTrackLength = currentTrackLength+initialPath;
00250
00251 double localTime = currentTrack->GetLocalTime();
00252 double totalTOF = localTime + initialTof;
00253 newVolumeNumber=(527-theTouchable->GetReplicaNumber(2))/3;
00254
00255 myInTof2 = true;
00256 myPathIntoTof2 = currentTrackLength;
00257 if(msgFlag) cout << "myPathIntoTof2 = " << myPathIntoTof2 << endl;
00258
00259 if(myExtTrack)
00260 {
00261 double xError = extXpErr->get_plane_err(currentMomentum.unit(),xVector);
00262 double yError = extXpErr->get_plane_err(currentMomentum.unit(),yVector);
00263 double zError = extXpErr->get_plane_err(currentMomentum.unit(),zVector);
00264 double tzError= extXpErr->get_plane_err(currentMomentum.unit(),tzVector);
00265 myExtTrack->SetTof2Data(currentPosition/10,currentMomentum/1000,newVolumeName,newVolumeNumber,totalTOF,totalTrackLength/10,myOutputSymMatrix(extXpErr->get_err()),zError/10,tzError/10,xError/10,yError/10);
00266 myTof2Flag = true;
00267 }
00268 return;
00269 }
00270
00271 if( myInTof2 && oldVolumeName=="logicalScinBr2" ) {
00272 myInTof2 = false;
00273 myOutTof2 = true;
00274 myPathOutTof2 = currentTrack->GetTrackLength();
00275 myPathInTof2.push_back(myPathOutTof2 - myPathIntoTof2);
00276 if(msgFlag) cout << "myPathOutTof2 = " << myPathOutTof2 << endl;
00277 }
00278
00279 if( myOutTof2 && newVolumeName=="logicalScinBr2" ) {
00280 myInTof2 = true;
00281 myOutTof2 = false;
00282 myPathIntoTof2 = currentTrack->GetTrackLength();
00283 if(msgFlag) cout << "myPathIntoTof2 = " << myPathIntoTof2 << endl;
00284 }
00285
00286
00287 if( (!myPhyEmcFlag) && (!myEmcFlag) && (newVolumeName=="EMC" || newVolumeName.contains("BSC") || newVolumeName=="EndPhi"))
00288 {
00289 newVolumeNumber = -2;
00290 if(myExtTrack)
00291 {
00292
00293 Hep3Vector nPhi(-y/r,x/r,0.);
00294 double errorPhi = (extXpErr->get_plane_err(currentMomentum.unit(),nPhi))/r;
00295
00296 Hep3Vector aPosition = currentPosition;
00297 double R = aPosition.r();
00298 double aTheta = aPosition.theta();
00299 aPosition.setTheta(aTheta + M_PI_2);
00300 double errorTheta;
00301 errorTheta =(extXpErr->get_plane_err(currentMomentum.unit(),aPosition.unit()))/R;
00302 if(msgFlag) cout<<"Theta direction: "<<aPosition<<endl;
00303 myExtTrack->SetEmcData(currentPosition/10,currentMomentum/1000,newVolumeName,newVolumeNumber,errorTheta,errorPhi,myOutputSymMatrix(extXpErr->get_err()));
00304 }
00305 myPhyEmcFlag = true;
00306 return;
00307 }
00308
00309
00310 if(!myEmcPathFlag && newVolumeName.contains("Crystal") )
00311 {
00312 myPathIntoCrystal = currentTrack->GetTrackLength();
00313
00314 myEmcPathFlag = true;
00315 }
00316
00317
00318 if( (!myEmcFlag) && newVolumeName.contains("Crystal") )
00319 {
00320 if(myExtTrack)
00321 {
00322
00323 int npart,ntheta,nphi;
00324 if(currentTrack->GetNextTouchableHandle()->GetVolume(1)->GetName().contains("BSC")) {
00325 npart=1;
00326 std::istringstream thetaBuf((currentTrack->GetNextTouchableHandle()->GetVolume(1)->GetName()).substr(16,2));
00327 thetaBuf >> ntheta ;
00328 nphi = 308-currentTrack->GetNextTouchableHandle()->GetCopyNumber(2);
00329 } else {
00330 npart=2-2*currentTrack->GetNextTouchableHandle()->GetCopyNumber(3);
00331 int endSector=currentTrack->GetNextTouchableHandle()->GetCopyNumber(2);
00332 int endNb,endNbGDML;
00333 std::istringstream thetaBuf((currentTrack->GetNextTouchableHandle()->GetVolume(0)->GetName()).substr(20,2));
00334 thetaBuf >> endNb ;
00335 endNbGDML=CalculateEmcEndCopyNb(endNb);
00336 int endSectorGDML=CalculateEmcEndPhiNb(endSector);
00337 CalculateEmcEndThetaPhi(npart,endSectorGDML,endNbGDML,ntheta,nphi);
00338 }
00339 ostringstream strEmc;
00340 if(ntheta<10) {
00341 strEmc<<"EmcPart"<<npart<<"Theta0"<<ntheta<<"Phi"<<nphi;
00342 } else {
00343 strEmc<<"EmcPart"<<npart<<"Theta"<<ntheta<<"Phi"<<nphi;
00344 }
00345
00346
00347 Hep3Vector nPhi(-y/r,x/r,0.);
00348 double errorPhi = (extXpErr->get_plane_err(currentMomentum.unit(),nPhi))/r;
00349
00350 Hep3Vector aPosition = currentPosition;
00351 double R = aPosition.r();
00352 double aTheta = aPosition.theta();
00353 aPosition.setTheta(aTheta + M_PI_2);
00354 double errorTheta;
00355 errorTheta =(extXpErr->get_plane_err(currentMomentum.unit(),aPosition.unit()))/R;
00356 if(msgFlag) cout<<"Theta direction: "<<aPosition<<endl;
00357 myExtTrack->SetEmcData(currentPosition/10,currentMomentum/1000,strEmc.str(),
00358
00359 newVolumeNumber,errorTheta,errorPhi,myOutputSymMatrix(extXpErr->get_err()));
00360 }
00361 myEmcFlag = true;
00362 return;
00363 }
00364
00365
00366 if(myEmcPathFlag && oldVolumeName.contains("Crystal") )
00367 {
00368 myPathOutCrystal = currentTrack->GetTrackLength();
00369 myPathInCrystal = myPathInCrystal+myPathOutCrystal-myPathIntoCrystal;
00370
00371 myEmcPathFlag=false;
00372 }
00373
00374
00375
00376 if( (!myMucFlag) && ( (fabs(x)>=myMucR) || (fabs(y)>=myMucR) || ((fabs(x-y)/sqrt(2.))>=myMucR) || ((fabs(x+y)/sqrt(2.))>=myMucR) || (fabs(z)>=myMucZ) ) )
00377 {
00378 int newVolumeNumber = newVolume->GetCopyNo();
00379 if(myExtTrack)
00380 {
00381 Hep3Vector xVector(1.0,0,0);
00382 Hep3Vector yVector(0,1.0,0);
00383 Hep3Vector zVector(0,0,1.0);
00384 double xError = extXpErr->get_plane_err(currentMomentum.unit(),xVector);
00385 double yError = extXpErr->get_plane_err(currentMomentum.unit(),yVector);
00386 double zError = extXpErr->get_plane_err(currentMomentum.unit(),zVector);
00387 double tzError;
00388 double phi = currentPosition.phi();
00389 if(phi<0.) phi+=M_PI;
00390 int i = int(8.0*phi/M_PI);
00391 if( i==0 || i==7 || i==8 )
00392 {
00393 tzError = yError;
00394 }
00395 if( i==1 || i==2 )
00396 {
00397 Hep3Vector tzVector(-1.0,1.0,0.);
00398 tzError =extXpErr->get_plane_err(currentMomentum.unit(),tzVector.unit());
00399 }
00400 if( i==3 || i==4 )
00401 {
00402 tzError = xError;
00403 }
00404 if( i==5 || i==6 )
00405 {
00406 Hep3Vector tzVector(1.0,1.0,0.);
00407 tzError =extXpErr->get_plane_err(currentMomentum.unit(),tzVector.unit());
00408 }
00409 myExtTrack->SetMucData(currentPosition/10,currentMomentum/1000,newVolumeName,newVolumeNumber,myOutputSymMatrix(extXpErr->get_err()),zError/10,tzError/10,xError/10,yError/10);
00410 }
00411 myMucFlag = true;
00412
00413 return;
00414 }
00415
00416
00417
00418 if(newVolumeName.contains("Muc"))
00419 {
00420 int newVolumeNumber = newVolume->GetCopyNo();
00421 if(myExtTrack)
00422 {
00423 ExtMucHit aExtMucHit;
00424 Hep3Vector xVector(1.0,0,0);
00425 Hep3Vector yVector(0,1.0,0);
00426 Hep3Vector zVector(0,0,1.0);
00427 double xError = extXpErr->get_plane_err(currentMomentum.unit(),xVector);
00428 double yError = extXpErr->get_plane_err(currentMomentum.unit(),yVector);
00429 double zError = extXpErr->get_plane_err(currentMomentum.unit(),zVector);
00430 double tzError;
00431 double phi = currentPosition.phi();
00432 if(phi<0.) phi+=M_PI;
00433 int i = int(8.0*phi/M_PI);
00434 if( i==0 || i==7 || i==8 )
00435 {
00436 tzError = yError;
00437 }
00438 if( i==1 || i==2 )
00439 {
00440 Hep3Vector tzVector(-1.0,1.0,0.);
00441 tzError =extXpErr->get_plane_err(currentMomentum.unit(),tzVector.unit());
00442 }
00443 if( i==3 || i==4 )
00444 {
00445 tzError = xError;
00446 }
00447 if( i==5 || i==6 )
00448 {
00449 Hep3Vector tzVector(1.0,1.0,0.);
00450 tzError =extXpErr->get_plane_err(currentMomentum.unit(),tzVector.unit());
00451 }
00452 aExtMucHit.SetExtMucHit(currentPosition,currentMomentum,newVolumeName,newVolumeNumber,extXpErr->get_err(),zError,tzError,xError,yError);
00453 myExtTrack->AddExtMucHit(aExtMucHit);
00454 }
00455 }
00456
00457 }
00458 else if(msgFlag) cout<<"x:"<<currentPosition.x()<<"//y:"<<currentPosition.y()<<"//z:"<<currentPosition.z()<<"||px:"<<currentMomentum.x()<<"//py:"<<currentMomentum.y()<<"//pz:"<<currentMomentum.z()<<endl;
00459
00460 }
00461 else if(currentTrackStatus == fStopAndKill)
00462 {
00463 if(myEmcFlag) myExtTrack->SetEmcPath(myPathInCrystal/10.);
00464 if(myTof1Flag) myExtTrack->setPathInTof1(myPathInTof1);
00465 if(myTof2Flag) myExtTrack->setPathInTof2(myPathInTof2);
00466 if(msgFlag) {
00467 cout << "myPathInTof1 = " ;
00468 for(int i=0; i!=myPathInTof1.size(); i++)
00469 cout << myPathInTof1[i] << " ";
00470 cout << endl;
00471 cout << "myPathInTof2 = " ;
00472 for(int i=0; i!=myPathInTof2.size(); i++)
00473 cout << myPathInTof2[i] << " ";
00474 cout << endl;
00475 }
00476
00477 if(msgFlag)
00478 {
00479 if(newVolume!=0)
00480 {
00481 std::cout<<"x:"<<currentPosition.x()<<"//y:"<<currentPosition.y()<<"//z:"<<currentPosition.z()<<"||px:"<<currentMomentum.x()<<"//py:"<<currentMomentum.y()<<"//pz:"<<currentMomentum.z()<<"//stoped"<<endl;
00482 cout<<"Error matrix is:"<<extXpErr->get_err()<<endl;
00483 }
00484 else {
00485 cout<<"x:"<<currentPosition.x()<<"//y:"<<currentPosition.y()<<"//z:"<<currentPosition.z()<<"||px:"<<currentMomentum.x()<<"//py:"<<currentMomentum.y()<<"//pz:"<<currentMomentum.z()<<"//escaped"<<std::endl;
00486 std::cout<<"Error matrix is:"<<extXpErr->get_err()<<std::endl;
00487 }
00488 }
00489 }
00490 }