StRoot
1

Public Member Functions  
StMagUtilities (StTpcDb *dbin=0, Int_t mode=0)  
StMagUtilities constructor using the DataBase.  
StMagUtilities (const StarMagField::EBField map, const Float_t factor, Int_t mode)  
StMagUtilities constructor not using the DataBase.  
virtual void  BField (const Float_t x[], Float_t B[]) 
virtual void  BrBzField (const Float_t r, const Float_t z, Float_t &Br_value, Float_t &Bz_value) 
virtual void  B3DField (const Float_t x[], Float_t B[]) 
virtual void  B3DFieldTpc (const Float_t xTpc[], Float_t BTpc[], Int_t Sector=1) 
virtual void  BFieldTpc (const Float_t xTpc[], Float_t BTpc[], Int_t Sector=1) 
virtual void  BrBz3DField (const Float_t r, const Float_t z, const Float_t phi, Float_t &Br_value, Float_t &Bz_value, Float_t &Bphi_value) 
virtual bool  UsingDistortion (const DistortSelect distortion) 
virtual void  DoDistortion (const Float_t x[], Float_t Xprime[], Int_t Sector=1) 
Main Entry Point for requests to DO the E and B field distortions (for simulations)  
virtual void  UndoDistortion (const Float_t x[], Float_t Xprime[], Int_t Sector=1) 
virtual void  UndoBDistortion (const Float_t x[], Float_t Xprime[], Int_t Sector=1) 
B field distortions in 3D ( no Table )  calculate the distortions due to the shape of the B field. More...  
virtual void  Undo2DBDistortion (const Float_t x[], Float_t Xprime[], Int_t Sector=1) 
2D  faster  B field distortions ( no Table )  calculate the distortions due to the shape of the B field More...  
virtual void  FastUndoBDistortion (const Float_t x[], Float_t Xprime[], Int_t Sector=1) 
3D  B field distortions (Table)  calculate the distortions due to the shape of the B field More...  
virtual void  FastUndo2DBDistortion (const Float_t x[], Float_t Xprime[], Int_t Sector=1) 
2D  faster  B field distortions (Table)  calculate the distortions due to the shape of the B field More...  
virtual void  UndoPad13Distortion (const Float_t x[], Float_t Xprime[], Int_t Sector=1) 
Pad row 13 distortion. More...  
virtual void  UndoPad40Distortion (const Float_t x[], Float_t Xprime[], Int_t Sector=1) 
PadRow 40 and/or PadRow 13 distortion correction. More...  
virtual void  UndoTwistDistortion (const Float_t x[], Float_t Xprime[], Int_t Sector=1) 
Twist distortion. More...  
virtual void  UndoClockDistortion (const Float_t x[], Float_t Xprime[], Int_t Sector=1) 
Clock distortion. More...  
virtual void  UndoMembraneDistortion (const Float_t x[], Float_t Xprime[], Int_t Sector=1) 
Membrane distortion.  
virtual void  UndoEndcapDistortion (const Float_t x[], Float_t Xprime[], Int_t Sector=1) 
Endcap distortion.  
virtual void  UndoSpaceChargeDistortion (const Float_t x[], Float_t Xprime[], Int_t Sector=1) 
Space Charge entry function. More...  
virtual void  UndoSpaceChargeR0Distortion (const Float_t x[], Float_t Xprime[], Int_t Sector=1) 
Space Charge Correction. More...  
virtual void  UndoSpaceChargeR2Distortion (const Float_t x[], Float_t Xprime[], Int_t Sector=1) 
1/R**2 SpaceCharge Distortion More...  
virtual void  UndoSpaceChargeFXTDistortion (const Float_t x[], Float_t Xprime[], Int_t Sector=1) 
FixedTarget 1/r SpaceCharge Distortion. More...  
virtual void  UndoGridLeakDistortion (const Float_t x[], Float_t Xprime[], Int_t Sector=1) 
Grid Leakage entry function. More...  
virtual void  Undo2DGridLeakDistortion (const Float_t x[], Float_t Xprime[], Int_t Sector=1) 
Grid Leakage Calculation. More...  
virtual void  Undo3DGridLeakDistortion (const Float_t x[], Float_t Xprime[], Int_t Sector=1) 
3D GridLeak Distortion Calculation More...  
virtual void  UndoFullGridLeakDistortion (const Float_t x[], Float_t Xprime[], Int_t Sector=1) 
Full GridLeak Distortion Calculation. More...  
virtual void  UndoIFCShiftDistortion (const Float_t x[], Float_t Xprime[], Int_t Sector=1) 
IFC Shift Distortion. More...  
virtual void  UndoShortedRingDistortion (const Float_t x[], Float_t Xprime[], Int_t Sector=1) 
Shorted Ring Distortion. More...  
virtual void  UndoGGVoltErrorDistortion (const Float_t x[], Float_t Xprime[], Int_t Sector=1) 
Gated Grid Voltage Error. More...  
virtual void  UndoSectorAlignDistortion (const Float_t x[], Float_t Xprime[], Int_t Sector=1) 
3D Sector Alignment Distortion Calculation More...  
virtual void  UndoAbortGapDistortion (const Float_t x[], Float_t Xprime[], Int_t Sector=1, Float_t TimeSinceDeposition=1.0) 
Abort Gap Cleaning Cycle space charge correction. More...  
virtual void  FixSpaceChargeDistortion (const Int_t Charge, const Float_t x[3], const Float_t p[3], const Prime PrimaryOrGlobal, Float_t x_new[3], Float_t p_new[3], const unsigned int RowMask1=0xFFFFFF00, const unsigned int RowMask2=0x1FFFFF, const Float_t VertexError=0.0200) 
Convert from the old (Uniform) space charge correction to the new (1/R**2) space charge correction. More...  
virtual void  ApplySpaceChargeDistortion (const Double_t sc, const Int_t Charge, const Float_t x[3], const Float_t p[3], const Prime PrimaryOrGlobal, Int_t &new_Charge, Float_t x_new[3], Float_t p_new[3], const unsigned int RowMask1=0xFFFFFF00, const unsigned int RowMask2=0x1FFFFF, const Float_t VertexError=0.0200) 
Apply the (1/R**2) space charge correction to selected data from the microDSTs. More...  
virtual Int_t  PredictSpaceChargeDistortion (Int_t sec, Int_t Charge, Float_t Pt, Float_t VertexZ, Float_t PseudoRapidity, Float_t DCA, const unsigned int RowMask1, const unsigned int RowMask2, Float_t &pSpace) 
PredictSpaceCharge  Input PhysicalSigned DCA and get back spacecharge parameter plus a success or failure flag. More...  
virtual Int_t  PredictSpaceChargeDistortion (Int_t sec, Int_t Charge, Float_t Pt, Float_t VertexZ, Float_t PseudoRapidity, Float_t Phi, Float_t DCA, const unsigned long long RowMask1, const unsigned long long RowMask2, Float_t RowMaskErrorR[64], Float_t RowMaskErrorRPhi[64], Float_t &pSpace) 
PredictSpaceCharge  Input PhysicalSigned DCA and get back spacecharge estimate. Includes the SVT and SSD. More...  
virtual Int_t  PredictSpaceChargeDistortion (Int_t NHits, Int_t Charge, Float_t Pt, Float_t VertexZ, Float_t PseudoRapidity, Float_t Phi, Float_t DCA, Double_t R[128], Double_t ErrorR[128], Double_t ErrorRPhi[128], Float_t &pSpace) 
PredictSpaceCharge  Input PhysicalSigned DCA and get back spacecharge estimate. More...  
virtual void  ManualShortedRing (Int_t EastWest, Int_t InnerOuter, Float_t RingNumber, Float_t MissingRValue, Float_t ExtraRValue) 
Manually setup a shorted ring in the TPC. More...  
virtual Int_t  GetSpaceChargeMode () 
Space Charge Correction Mode. More...  
virtual void  ManualSpaceCharge (Double_t SpcChg) 
virtual void  ManualSpaceChargeR2 (Double_t SpcChg, Float_t EWRatio=1.0) 
virtual void  ManualGridLeakStrength (Double_t inner, Double_t middle, Double_t outer) 
virtual void  ManualGridLeakRadius (Double_t inner, Double_t middle, Double_t outer) 
virtual void  ManualGridLeakWidth (Double_t inner, Double_t middle, Double_t outer) 
virtual void  AutoSpaceCharge () 
virtual void  AutoSpaceChargeR2 () 
virtual Double_t  CurrentSpaceCharge () 
virtual Double_t  CurrentSpaceChargeR2 () 
virtual Float_t  CurrentSpaceChargeEWRatio () 
virtual Bool_t  UpdateTPCHighVoltages () 
virtual Bool_t  UpdateShortedRing () 
virtual void  UseManualSCForPredict (Bool_t flag=kTRUE) 
virtual void  ManualGGVoltError (Double_t east, Double_t west) 
virtual void  UseIterativeUndoDistortion (Bool_t flag=kTRUE) 
virtual Int_t  IterationFailCount () 
Float_t  GetConst_0 () 
Float_t  GetConst_1 () 
Float_t  GetConst_2 () 
virtual void  Cart2Polar (const Float_t *x, Float_t &r, Float_t &phi) 
virtual void  Cart2Polar (const Float_t *x, Double_t &r, Double_t &phi) 
virtual void  Polar2Cart (const Double_t r, const Double_t phi, Float_t *Xprime) 
Static Public Member Functions  
static StMagUtilities *  Instance () 
static void  SetDoDistortionT (TFile *f=0) 
static void  SetUnDoDistortionT (TFile *f=0) 
A package of Bfield routines and distortion corrections for the STAR TPC. Methods included to read the correct Bfield map and scale it according to a scale factor provided during instantiation. All corrections automatically adjust themselves for different B field settings and E field settings. Even reversed fields.
An enumerated argument provided at the time of instantiation selects a constant magnetic field (value=1) or the measured magnetic field (value=2) at a field setting that you select manually. Alternatively, you can use the database to determine the magnetic field setting but you must then provide a a time stamp and use a different instantiation (this is usually done in the chain).
The enumerations for the manual settings are: enum EBField { kUndefined = 0, kConstant = 1, kMapped = 2, kChain = 3 } ; "kConstant = 1" means you wish to work with a constant, uniform, field. "kMapped = 2" means you want to read values from the measured magnet maps. The other enumerations are undefined and reserved for future expansion.
This code works in kGauss, cm  but note that the Bfield maps on disk are in gauss, cm.
A mode switch can be used to select the distortions that will be applied to the data. A choice of mode = 0 will give the default set of distortions. Other modes can be selected by turning on the appropriate bit field, shown below.
Bit counting starts at 1 for the mode switch (...,3,2,1)
enum DistortSelect
{
kBMap = 0x08, // Bit 4
kPadrow13 = 0x10, // Bit 5
kTwist = 0x20, // Bit 6
kClock = 0x40, // Bit 7
kMembrane = 0x80, // Bit 8
kEndcap = 0x100, // Bit 9
kIFCShift = 0x200, // Bit 10
kSpaceCharge = 0x400, // Bit 11
kSpaceChargeR2 = 0x800, // Bit 12
kShortedRing = 0x1000, // Bit 13
kFast2DBMap = 0x2000, // Bit 14
kGridLeak = 0x4000, // Bit 15
k3DGridLeak = 0x8000, // Bit 16
kGGVoltError = 0x10000, // Bit 17
kSectorAlign = 0x20000, // Bit 18
kDisableTwistClock = 0x40000, // Bit 19
kFullGridLeak = 0x80000, // Bit 20
kDistoSmearing = 0x100000, // Bit 21
kPadrow40 = 0x200000, // Bit 22
kAbortGap = 0x400000, // Bit 23
kSpaceChargeFXT = 0x800000, // Bit 24
} ;
Note that the option flag used in the chain is 2x larger than shown here in order to allow the first bit to be used as an on/off flag and then it is shifted away before entering StMagUtilities. This can be summarized by saying:
Bit counting starts at 0 for the chain option flag (...,3,2,1,0)
To do:
Definition at line 272 of file StMagUtilities.h.

virtual 
Apply the (1/R**2) space charge correction to selected data from the microDSTs.
Given the charge and momentum of a particle and a point on the circular path described by the particle , this function returns the new position of the point (cm) and the new momentum of the particle (GeV). The momentum p[] must be the momentum at the point x[].
Input x[], p[] and return x_new[], p_new[]. x[] in cm and p[] in GeV.
The program works by calculating the hits on the TPC rows for the input track, removes the distortion from the hits according to the 1/R**2 spacecharge presciption, and then refits the new hits to find the new track parameters. If the track is a primary track (PrimaryOrGlobal == 0) then x[] is assumed to be the vertex and it is included in the refit. If the track is a global track (PrimaryOrGlobal == 1) then x[] is assumed to lie somewhere (anywhere) on the track but it is not included in the fit. For a global track, x[] must lie on the track because it is used to determine where the track flies (ie. angle phi).
PrimaryOrGlobal = 0 for a primary track. PrimaryOrGlobal = 1 for a global track. You can also use the "Prime" enumeration in the .h file.
The code attempts to be as realistic as possible when it does the refit. Therefore, it asks you for the hit masks from the microDSTs. These masks tell you which TPC rows were used in the original track fit. For future reference, the masks come in two words. The first word covers TPC rows 124 and the second word covers rows 2545. The first 8 bits of the first word are reserved for the FTPC and therefore 0xFFFFFF00, 0x1FFFFF represent all 45 rows of the TPC and no SVT or SSD hits. (NB: this is dependent on the implementation of the topology map, and may be subject to change!)
VertexError is quoted in cm (RMS). It is for experts. If you are working with primary tracks, the vertex is included in the fit. The true error bar is multiplcity dependent. (sigma**2 increase linearly with mult). So you can calculate this, external to the function, and then work with a realistic vertex error bar if you wish to do it. 200 microns error is a good average value for central AuAu events.
Definition at line 4390 of file StMagUtilities.cxx.
References UndoSpaceChargeR2Distortion().

virtual 
2D  faster  B field distortions (Table)  calculate the distortions due to the shape of the B field
Distortions are calculated and then stored in a table. This calculation uses a 2D magnetic field which is phi symmetric. The real 3D field has a slight twist that may be important for high precision work. I recommend using this faster version (JT) if you don't care about distortions smaller than 200 microns. This method requires about 10 seconds of CPU time to generate the table but it is very fast after the table has been created. Use it when you have a large number of points ( > 10,000 ).
Definition at line 1629 of file StMagUtilities.cxx.
References Undo2DBDistortion().

virtual 
3D  B field distortions (Table)  calculate the distortions due to the shape of the B field
Distortions are calculated in 3D and then stored in a table. This method requires about 1 minute of CPU time to generate the table but it is very fast after the table has been created. Use it when you have a large number of points ( > 10,000 ).
Definition at line 1545 of file StMagUtilities.cxx.
References UndoBDistortion().

virtual 
Convert from the old (Uniform) space charge correction to the new (1/R**2) space charge correction.
Applicable to 200 GeV Au+Au data that is on the P02ge (and other) microDSTs. Given the charge and momentum of a particle and a point on the circular path described by the particle , this function returns the new position of the point (cm) and the new momentum of the particle (GeV). This is done by undoing the old space charge corrections and then applying the new space charge corrections.
Input x[3], p[3] and return x_new[3], p_new[3]. x[3] in cm and p[3] in GeV.
The program works by calculating the hits on the TPC rows for the input track, distorts the hits according to the new presciption, and then refits the new hits to find the new track parameters. If the track is a primary track (PrimaryOrGlobal == 0) then x[3] is assumed to be the vertex and it is included in the refit. If the track is a global track (PrimaryOrGlobal == 1) then x[3] is assumed to lie somewhere (anywhere) on the track but it is not included in the fit. For a global track, x[3] must lie on the track because it is used to determine where the track flies (ie. angle phi).
PrimaryOrGlobal = 0 for a primary track. PrimaryOrGlobal = 1 for a global track. You can also use the "Prime" enumeration in the .h file.
The code attempts to be as realistic as possible when it does the refit. Therefore, it asks you for the hit masks from the microDSTs. These masks tell you which TPC rows were used in the original track fit. For future reference, the masks come in two words. The first word covers TPC rows 124 and the second word covers rows 2545. The first 8 bits of the first word are reserved for the FTPC and therefore 0xFFFFFF00, 0x1FFFFF represent all 45 rows of the TPC and no SVT or SSD hits. (NB: this is dependent on the implementation of the topology map, and may be subject to change!)
VertexError is quoted in cm (RMS). It is for experts. If you are working with primary tracks, the vertex is included in the fit. The true error bar is multiplcity dependent. (sigma**2 increase linearly with mult). So you can calculate this, external to the function, and then work with a realistic vertex error bar if you wish to do it. 200 microns error is a good average value for central AuAu events.
Definition at line 4214 of file StMagUtilities.cxx.
References UndoSpaceChargeR0Distortion(), and UndoSpaceChargeR2Distortion().
Referenced by StRedoTracks::Make().

virtual 
Space Charge Correction Mode.
The spacecharge correction is performed using one of a variety of modes. See the UndoSpaceChargeDistortion*() functions for more information on the different shapes used to correct the distortion. Additionally, the magnitude of the correction may be set either manually, or from the database. This routine provides a method to determine which mode is in use at any given time. Return values are as follows:
0 : no correction 10 : uniform, from DB 11 : uniform, manually set 20 : R2, from DB 21 : R2, manually set
Definition at line 857 of file StMagUtilities.cxx.

virtual 
Manually setup a shorted ring in the TPC.
Insert one shorted ring of your choice Side(E=0/W=1) Cage(IFC=0/OFC=1) Ring(# from CM) MissingResistance(MOhm) ExtraResistance(MOhm) For addtional information, see the comments associated with UndoShortedRing().
Definition at line 814 of file StMagUtilities.cxx.
Referenced by StMagUtilities().

virtual 
PredictSpaceCharge  Input PhysicalSigned DCA and get back spacecharge parameter plus a success or failure flag.
Add comments here. TPC Hits only. Does not include SVT or SSD or any other inner tracking detectors.
Definition at line 4579 of file StMagUtilities.cxx.
References UndoGridLeakDistortion(), and UndoSpaceChargeDistortion().

virtual 
PredictSpaceCharge  Input PhysicalSigned DCA and get back spacecharge estimate. Includes the SVT and SSD.
Input the parameters for a global track fit and get back an estimate of the spacecharge that distorted the track.
Input for the track includes the Charge, Pt, VertexZ, PseudoRapidity, and measured DCA.
The code attempts to be as realistic as possible when it does the refit. Therefore, it asks you for the hit masks from the microDSTs. These masks tell you which TPC rows were used in the original track fit and whether or not there were hits in the SVT and/or SSD detectors. It the masks have bits set for the SVT then this will affect the track and will pull the fits. For future reference, the masks come in two words. The first 8 bits of the first word describe the vertex, then six layers of the SVT, and finally the SSD. The vertex bit is only set for primary tracks and is not used by this routine. You should only input global tracks. The remaining bits of the first word cover TPC rows 124. The second word covers rows 2545. So, for example 0xFFFFFF00, 0x1FFFFF represent all 45 rows of the TPC and no SVT or SSD hits. (NB: this is dependent on the implementation of the topology map, and may be subject to change!)
You must provide the hit errors by instantiating with two vectors that include the track errors in both X and Y. RowMaskErrorR[] is the array of hit errors in the radial direction (ie in the direction of a high pt track) RowMaskErrorRPhi[] is the array of hit errors in the rphi direction (ie tranvsverse to the direction of a high pt track)
pSpace contains the estimate of the space charge in the TPC that caused the distortion on the original track.
The function returns zero if it succeeds and pSpace will be finite. The function returns nonzero if it fails and pSpace will be zero. The function returns nonzero if there are too few hits in the TPC inner and outer sectors. There are also cuts on Pt and rapdity, etc, that can cause the funtion to return nonzero.
Definition at line 4781 of file StMagUtilities.cxx.
References DoDistortion().

virtual 
PredictSpaceCharge  Input PhysicalSigned DCA and get back spacecharge estimate.
Input the parameters for a global track fit and get back an estimate of the spacecharge that distorted the track.
Input for the track includes the Charge, Pt, VertexZ, PseudoRapidity, and measured DCA.
The code attempts to be as realistic as possible when it does the refit and takes as its primary input the radii of hits on the track. Hits that are not within the dimensions of the TPC are not moved. You must provide the hit errors by instantiating with two vectors that include the track errors in both r and phi R[] is the array of hit radii (ie in the direction of a high pt track) ErrorR[] is the array of hit errors in the radial direction (ie in the direction of a high pt track) ErrorRPhi[] is the array of hit errors in the rphi direction (ie tranvsverse to the direction of a high pt track)
pSpace contains the estimate of the space charge in the TPC that caused the distortion on the original track.
The function returns zero if it succeeds and pSpace will be finite. The function returns nonzero if it fails and pSpace will be zero. The function returns nonzero if there are too few hits in the TPC inner and outer sectors. There are also cuts on Pt and rapdity, etc, that can cause the funtion to return nonzero.
Definition at line 5027 of file StMagUtilities.cxx.
References DoDistortion().

virtual 
2D  faster  B field distortions ( no Table )  calculate the distortions due to the shape of the B field
Distortions are calculated point by point and integrated in real time. This avoids the time required to set up a table of distorted values but is slow for a very large number of points ( > 10,000 ).
Definition at line 1501 of file StMagUtilities.cxx.
Referenced by FastUndo2DBDistortion().

virtual 
Grid Leakage Calculation.
Calculate the distortions due to charge leaking out of the gap between the inner and outer sectors as well as the gap between the IFC and the innersector, as well as outersector and OFC. Original work by Gene VanBuren, and J. Thomas NOTE: This routine is obsolete: 10/31/2009 Recommend that you use Undo3DGridLeakDistortion, instead.
Definition at line 5296 of file StMagUtilities.cxx.
Referenced by UndoGridLeakDistortion().

virtual 
3D GridLeak Distortion Calculation
Calculate the 3D distortions due to charge leaking out of the gap between the inner and outer sectors. Original work by Gene VanBuren, and J. Thomas
Definition at line 5404 of file StMagUtilities.cxx.
Referenced by UndoGridLeakDistortion().

virtual 
Abort Gap Cleaning Cycle space charge correction.
Calculate the 3D distortions due to the charge introduced by an Abort Gap Cleaning Cycle. As we understand the process, the abort gap cleaning cycle causes a burst of charge to appear in the TPC every few seconds (cycle time predefined by MCR). The positive charge then dissapates by drifting from the Central Membrane to the TPC readout planes. However, the drift time of the ions is very slow and so it takes approximately 0.75 seconds (279 cm/sec) to drift from CM to readout.
Gene proposed that we solve this problem by calculating the spacecharge in the TPC every 0.05 seconds (or so) as the charge drifts to the readout plane. Thus, a discretized solution.
Charge distribution: we do not know the distribution of charge in the TPC due to an abort gap cleaning cycle. We are going to start by assuming that the charge distribution has the same shape as a normal event (approximately 1/R**2). This assumption will hold at t=0, but then we will move the charge distribution in Z as time evolves. Thus, at 0.05 seconds the charge distribution in Z will be shifted towards the endcaps by (about) 14 cm. Repeat and shift every 0.05 seconds.
"const Float_t Time" is the time since the last cleaning of the abort gap. Typically 0 to 0.75 seconds because 0.75 seconds is an estimate of the full length ion drift time. Time > 0.75 s is a noop.
This codes does not stack events. It assumes that the time between Abort Gap cleaning cycles is > 0.75 seconds.
This code is an extension of the "1/R**2 SpaceCharge Distortion" but allows for the possibility of storing and applying N maps (where N ~ 15). The following comments are excerpted from that code base:
Space Charge distortion using space charge from a real event (an assumption). The best charge distribution for one event is Howard's fit to HiJet events. The radial distribution is approximately 1/R**2, however we use a better parameterization in the code. The charge distribution has been integrated over Z to simulate the linear increase of space charge in Z due to the slow drift velocity of the ions. Electrostatic equations solved by relaxtion. Note that on 3/26/2008, we added a new element to the DB so that the space charge in the East and West halves of the TPC can be different by a constant factor. The constant is called "SpaceChargeEWRatio" and is greater than 1.0 when there is more charge in the East half to the TPC.
Original work by Gene VanBuren, Benjamin Kimelman and Jim Thomas
Definition at line 3077 of file StMagUtilities.cxx.

virtual 
B field distortions in 3D ( no Table )  calculate the distortions due to the shape of the B field.
Distortions are calculated point by point and integrated in real time. This avoids the time required to set up a table of distorted values but is slow for a very large number of points ( > 10,000 ).
Definition at line 1459 of file StMagUtilities.cxx.
Referenced by FastUndoBDistortion().

virtual 
Clock distortion.
The East endwheel of the TPC and the West endwheel of the TPC are not perfectly aligned. They were inserted separately into the TPC field cage tube. They are aligned at the outer diameter (4 meters) to within about 1 mm. This causes a slight misalingment of the relative coordinate systems. By convention, we assume that one end is perfect and attribute all of the error to a rotation of the other end ... however, the method (and the DB) allow you to input a rotation angle for each end, if you wish. Note: this is a coordinate transformation and not a distortion correction. It is here for historical reasons.
Definition at line 2484 of file StMagUtilities.cxx.

virtual 
Full GridLeak Distortion Calculation.
Calculate the 3D distortions due to charge leaking out around the edge of all wire grids 4 locations per sector, all sectors. Mostly a copy of Undo3DGridLeakDistortion(). Original work by Gene Van Buren and Irakli Chakaberia (GARFIELD simulations)
Definition at line 5618 of file StMagUtilities.cxx.
Referenced by UndoGridLeakDistortion().

virtual 
Gated Grid Voltage Error.
This code assumes that information about the GG voltage errors will come from the DB.
Calculate the effect of having an incorrect voltage on the East or West Gated Grids.
Electrostatic Equations from SN0253 by Howard Wieman. Note that we use Howard's funny coordinate system where Z==0 at the GG.
Definition at line 3436 of file StMagUtilities.cxx.

virtual 
Grid Leakage entry function.
Call the appropriate GridLeak function based on distortion mode
Definition at line 5266 of file StMagUtilities.cxx.
References Undo2DGridLeakDistortion(), Undo3DGridLeakDistortion(), and UndoFullGridLeakDistortion().
Referenced by PredictSpaceChargeDistortion().

virtual 
IFC Shift Distortion.
The Inner field cage of the TPC is not perfectly aligned with the outer field cage of the TPC. They are shifted along the Z axis by about 1 mm. This causes a tilting of the equipotential lines inside the TPC and therefore a DCA error at the vertex. The distortion is anti symmetric in Z. Electrostatic equations solved in Rectangular Coodinates by Jim Thomas Updated to work in cylindrical coordinates by Jamie Dunlop 11/01/2001
Definition at line 2605 of file StMagUtilities.cxx.

virtual 
Pad row 13 distortion.
Remove the effect of the mechanical imperfections between the inner sectors and the outer sectors. There is a gap between the sectors that allow E field lines to leak out of the anode and gated grid region. HHWieman has modelled this effect and his solution is used to remove the distortions.
Definition at line 1742 of file StMagUtilities.cxx.

virtual 
PadRow 40 and/or PadRow 13 distortion correction.
There is a gap between the inner and outer sectors that allow E field lines to leak out of the anode and gated grid region. This routine removes the effect of this (static) mechanical imperfection between the inner and the outer sectors.
The distortions are modelled within a "box" around the gap between the sectors. By definition, the distortions are zero outside the box ... but the distortion can still be significant if a secondary electron drifts through the box on its way to the padplane.
The (circa)1995 TPC had 13 pad rows on the inner sector. The iTPC has 40 rows on the inner sector. This routine will calculate the distortion for either the old or new iTPC sectors. The iTPC has a GridLeak wall between the inner and outer sectors. The wall can prevent some or all ions from dynamically leaking out into the TPC. This routine calculate the STATIC distortion caused by the wall voltages (or lack thereof). The DYNAMIC distortions are treated elsewhere (SpaceCharge).
The data were calculated on a grid with the following parameters. The center of the gap is at point 5000.
COLUMNS = 10001 // Radial direction in TPC ROWS = 5401 // Z direction in TPC GPPMM = 20 // Grid Points per millimeter
Select_Maps
0 No Wall Old TPC (circa 1995) Valid for all data taken prior to Run 19 (and part of 18) 1 100 Volt Difference Outer wall. Difference between 500_113 and 400_113 volt setting. 2 100 Volt Difference Inner wall. Difference between 113_600 and 113_500 volt setting. 3 113 Volt 113 Volt Minimum Static Distortion (but large dynamic Grid Leak)
Note that only 1001 points (centered around 5000) are saved in the maps. The remaining 9000 points are zero and so are suppressed. Sum these maps with the following weights: Total = output_113_113[]  ((Outer_GLW_Voltage+113.0)/100.0)*output_100_diff[] + ((Inner_GLW_Voltage+113.0)/100.0)*output_diff_100[]
The new iTPC sectors require two voltages to be applied to the GridLeak Walls. Typical values are Inner_GLW_Voltage = 113 volts and Outer_GLW_Voltage = 700 volts. Note negative magnitude. If the HV trips off, then both voltages = 0.0 The old TPC sectors (year < 2019) require a different map without the wall in place. Inner_GLW_Voltage >= (positive) 100 selects the old "no_wall" configuration. Inner_GLW_Voltage <= 0.0 selects the iTPC configuration.
Note that Voltage >= (positive) 100 is the flag for the old sectors.
Definition at line 1885 of file StMagUtilities.cxx.

virtual 
3D Sector Alignment Distortion Calculation
Calculate the 3D distortions due to z displacements caused by misalignment of the inner and outer sectors. Original work by Gene VanBuren, and J. Thomas Method: Determine the potential offsets at the innermost and outermost points of the Inner and Outer Sector grids along this phi angle, then interpolate to any poinr between the two. Also interpolate radially to zero out to the field cages.
Definition at line 5879 of file StMagUtilities.cxx.

virtual 
Shorted Ring Distortion.
This code assumes that information about shorted rings in the TPC field cage will come from the DB. The DB returns rows from a table and the columns have the following meaning:
Side(E=0/W=1) Cage(IFC=0/OFC=1) Ring(# from CM) MissingResistance(MOhm) ExtraResistance(MOhm)
0 0 169.5 2.0 2.0 0 0 115.5 2.0 0.0 1 1 150.5 1.0 1.0 0 0 0.0 0.0 0.0 etc.
The table indicates that there are two shorted rings on the IFC of the East end of the TPC. One of these shorts has a 2.0 MegOhm compensating resistor installed in the external resistor chain. There is also a short on the OFC of the West end of the TPC. It is a nonstandard short of 1 MOhm. It has an external compensating resistor of 1.0 MOhm. The row of zeros indicates that there are no more shorts in the TPC. Counting of the rings starts at the Central Membrane; the CM is ring zero, and 150.5 means the short is between rings 150 and 151.
Electrostatic Equations from SN0253 by Howard Wieman. Note that we use Howard's funny coordinate system where Z==0 at the GG.
Definition at line 3264 of file StMagUtilities.cxx.

virtual 
Space Charge entry function.
Call the appropriate Space Charge function based on distortion mode
Definition at line 2679 of file StMagUtilities.cxx.
References UndoSpaceChargeFXTDistortion(), UndoSpaceChargeR0Distortion(), and UndoSpaceChargeR2Distortion().
Referenced by PredictSpaceChargeDistortion().

virtual 
FixedTarget 1/r SpaceCharge Distortion.
Similar to R2 distortion correction for SpaceCharge, but using distinct radiual distributions on the east and west sides as determined by studies of URQMD simulations of fixed target collisions conducted by YueHang Leung in June 2022.
Definition at line 2935 of file StMagUtilities.cxx.
Referenced by UndoSpaceChargeDistortion().

virtual 
Space Charge Correction.
Space Charge distortion assuming a uniform distribution of charge per unit volume in the TPC. We now know that this is not a good assumption but the code is here for legacy reasons. Electrostatic equations solved by Jamie Dunlop 11/01/2001 Updated to include linear increase of charge from endcap to CM by Jim Thomas 12/18/2001
Definition at line 2710 of file StMagUtilities.cxx.
Referenced by FixSpaceChargeDistortion(), and UndoSpaceChargeDistortion().

virtual 
1/R**2 SpaceCharge Distortion
Space Charge distortion using space charge from a real event. Any charge distribution can be simulated by this method. However, the best charge distribution is Howard's fit to HiJet events. It is approximately independent of Z due to the Bjorken Plateau a midrapidity. The radial distribution is approximately 1/R**2, however we use a better parameterization in the code. Many different charge distributions are hidden in the comments of the code. All candidate distributions have been integrated over Z to simulate the linear increase of space charge in Z due to the slow drift velocity of the ions. Electrostatic equations solved by relaxtion. Note that on 3/26/2008, we added a new element to the DB so that the space charge in the East and West halves of the TPC can be different by a constant factor. The constant is called "SpaceChargeEWRatio" and is greater than 1.0 when there is more charge in the East half to the TPC. Original work by H. H. Wieman, N. Smirnov, and J. Thomas
Definition at line 2802 of file StMagUtilities.cxx.
Referenced by ApplySpaceChargeDistortion(), FixSpaceChargeDistortion(), and UndoSpaceChargeDistortion().

virtual 
Twist distortion.
Remove the effects of a simple "twist" of the TPC in the magnet. If there is an angle between the E and B fields, there will be a distortion in the recorded tracks. This routine takes out that distortion.
Definition at line 1704 of file StMagUtilities.cxx.