Message: The Strangest Problem I've ever met Not Logged In (login)

## The Strangest Problem I've ever met

Forum: Fields: Magnetic and Otherwise
Date: 19 Feb, 2009
From: Zukai Wang <Zukai Wang>

 ```Dear All: Actually, I really have no idea which category my problem belongs to. If my magnetic field definition is in a simple way like this: ------------------------------------------------------------------------- void ExN02MagneticField::GetFieldValue(const double Point,double *Bfield) const { Bfield=0.; Bfield=0.; Bfield=0.; if(fabs(Point)<75.*mm && fabs(Point)<405.*mm && fabs(Point)<705.*mm) Bfield=-6450.*gauss;} -------------------------------------------------------------------------- The whole project works well.``` ` But when I put on a real magnetic field like this:` ```------------------------------------------------------------------ void ExN02MagneticField::GetFieldValue(const double Point,double *Bfield) const { Bfield=0.; Bfield=0.; Bfield=0.;``` ` fstream in;` ` G4double x=0.,y=0.,z=0.,Bx=0.,By=0.,Bz=0.;` ``` if (fabs(fabs(Point)-70.*mm)<5.*mm) in.open("Bmap36.dat");``` ``` else if (fabs(fabs(Point)-60.*mm)<5.*mm) in.open("Bmap37.dat");``` ``` else if (fabs(fabs(Point)-50.*mm)<5.*mm) in.open("Bmap38.dat"); ``` ``` else if (fabs(fabs(Point)-40.*mm)<5.*mm) in.open("Bmap39.dat");``` ` else if (fabs(fabs(Point)-30.*mm)<5.*mm)` ``` { if (fabs(Point)<75.*mm) in.open("Bmap401.dat");``` ``` else if (fabs(Point)<145.*mm) in.open("Bmap4022.dat");``` ``` else in.open("Bmap4021.dat"); }``` ` else if (fabs(fabs(Point)-20.*mm)<5.*mm)` ``` {if (fabs(Point)<65.*mm) in.open("Bmap411.dat");``` ` else in.open("Bmap412.dat");}` ``` else if (fabs(fabs(Point)-10.*mm)<5.*mm) in.open("Bmap42.dat");``` ``` else if (fabs(Point)<5.*mm) in.open("Bmap43.dat");``` ` while ( fabs(Point)<405.*mm && fabs(Point)<705.*mm) ` ```{ in>>x>>y>>z>>Bx>>By>>Bz;``` ` if (!in.good()) break;` ` if(Point>0 && fabs(Point-y*mm)<5.*mm && fabs(Point-z*mm)<5.*mm)` ```{ Bfield=Bx*gauss; Bfield=By*gauss; Bfield=Bz*gauss;``` ``` break; }``` else if (Point<0 && fabs(Point-y*mm)<5.*mm && fabs(Point-z*mm)<5.*mm) ```{ Bfield=Bx*gauss; Bfield=-By*gauss; Bfield=-Bz*gauss;``` ``` break; }``` else if (Point>0 && fabs(-Point-y*mm)<5.*mm && fabs(Point-z*mm)<5.*mm) ```{ Bfield=Bx*gauss; Bfield=-By*gauss; Bfield=Bz*gauss;``` ``` break; }``` else if (Point<0 && fabs(-Point-y*mm)<5.*mm && fabs(Point-z*mm)<5.*mm) ```{ Bfield=Bx*gauss; Bfield=By*gauss; Bfield=-Bz*gauss;``` ``` break; }``` else if (Point>0 && fabs(Point-y*mm)<5.*mm && fabs(-Point-z*mm)<5.*mm) ```{ Bfield=Bx*gauss; Bfield=By*gauss; Bfield=-Bz*gauss;``` ``` break; }``` ` else if (Point<0 && fabs(Point-y*mm)<5.*mm && fabs(-Point-z*mm)<5.*mm)` ```{ Bfield=Bx*gauss; Bfield=-By*gauss; Bfield=Bz*gauss;``` ``` break; }``` ` else if (Point>0 && fabs(-Point-y*mm)<5.*mm && fabs(-Point-z*mm)<5.*mm)` ```{ Bfield=Bx*gauss; Bfield=-By*gauss; Bfield=-Bz*gauss;``` ``` break; }``` ` else if (Point<0*mm && fabs(-Point-y*mm)<5.*mm && fabs(-Point-z*mm)<5.*mm)` ```{ Bfield=Bx*gauss; Bfield=By*gauss; Bfield=Bz*gauss;``` ``` break; } }``` ```if (in.good()) in.close();``` } -------------------------------------------------------------------------- ``` The magnetic field values must be read from several files. The magnetic field values of more than 17000*8 points should be defined. I have edited the data files in a certain way to make the running of the program as fast as possible. The codes compiled and nothing wrong has been found. I shoot Krypton 78 in the particle gun and it will hit a detector which can record its kinetic energy and other information. The information has been showed on the screen. And at the end of an event, the event id should show up on the screen according to my codes. However, the event id has never appeared on the screen. Never one event has been finished! I wrote something in SteppingAction to track the Krypton 78 and found it pass through the magnetic field quickly (only 3 or 4 min) and hit the detector. And then, this ion kept on going. It reached the end of World and since then, the program ceased running. I mean, it was not aborted, it just stopped as if the poor ion did not know what to do next! I then increased the size of World. The ion (Kr78) lost all its energy in the last step, and the program stopped again! No errors and no segment faults have been reported. If I didn't track the ion from the particle gun, I would think that the whole program might last for hours! So, I doubt that the pointers (or something else) has exceed the maximum of Geant4.8.3(my version). If you have come across similar problems, I'd like to thank you in advance for your direction. Zukai Wang ```

1 Re: The Strangest Problem I've ever met   (Tom Roberts - 19 Feb, 2009)  Re: The Strangest Problem I've ever met   (Zukai Wang - 20 Feb, 2009)  Is This the Reason?   (Zukai Wang - 20 Feb, 2009)
 to: "The Strangest Problem I've ever met"
This site runs SLAC HyperNews version 1.11-slac-98, derived from the original HyperNews

[ Geant 4 Home | Geant 4 HyperNews | Search | Request New Forum | Feedback ]