StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StMagUtilities.h
1 /***********************************************************************
2  *
3  * $Id: StMagUtilities.h,v 1.67 2019/04/22 20:47:12 genevb Exp $
4  *
5  * Author: Jim Thomas 11/1/2000
6  *
7  ***********************************************************************
8  *
9  * Description: Utilities for the Magnetic Field
10  *
11  ***********************************************************************
12  *
13  * $Log: StMagUtilities.h,v $
14  * Revision 1.67 2019/04/22 20:47:12 genevb
15  * Introducing codes for AbortGapCleaning distortion corrections
16  *
17  * Revision 1.66 2018/12/06 19:36:45 genevb
18  * Move Instance() definition to resolve undefined symbol
19  *
20  * Revision 1.65 2018/10/19 20:41:29 genevb
21  * Clean up after Y. Fisyak modifications (which were for iTPC, not dE/dx), and add new PredictSpaceCharge() using real hit radii
22  *
23  * Revision 1.64 2018/10/17 20:45:24 fisyak
24  * Restore update for Run XVIII dE/dx calibration removed by Gene on 08/07/2018
25  *
26  * Revision 1.63 2018/06/08 18:18:37 genevb
27  * Introduce padrow 40 correction for iTPC GridLeak Wall, reduce includes dependencies
28  *
29  * Revision 1.62 2018/04/11 02:35:57 genevb
30  * Distortion smearing by calibration resolutions
31  *
32  * Revision 1.61 2017/10/26 02:47:42 genevb
33  * Allow FullGridLeak to work on specific sheets via sheet widths
34  *
35  * Revision 1.60 2017/04/12 19:47:02 genevb
36  * Generic SpaceCharge and GridLeak functions independent of specific modes
37  *
38  * Revision 1.59 2017/01/06 22:30:45 genevb
39  * Introduce FullGridLeak distortion correction
40  *
41  * Revision 1.58 2014/07/08 09:50:43 fisyak
42  * Fix old correction with 2D and 3D mag.field
43  *
44  * Revision 1.57 2014/07/01 20:29:02 fisyak
45  * Clean up
46  *
47  * Revision 1.56 2014/06/26 21:29:27 fisyak
48  * New Tpc Alignment, v632
49  *
50  * Revision 1.55 2014/01/16 17:55:14 genevb
51  * Two speed improvements: less calls to DB for SpaceCharge, avoid unnecessary cartesian/cylindrical coordinate conversions
52  *
53  * Revision 1.54 2013/12/11 18:27:56 genevb
54  * Account for GG voltage errorsi + shifts in UndoGGVoltErrorDistortion(), other minor optimizations
55  *
56  * Revision 1.53 2013/03/07 23:02:48 genevb
57  * Accessor functions for Const_n parameters
58  *
59  * Revision 1.52 2012/12/10 22:46:33 genevb
60  * Handle multiple runs by reinitialization at reinstantiation, introduce corrections modes, enable iterative UndoDistortions
61  *
62  * Revision 1.51 2012/10/31 20:05:10 genevb
63  * Row radii stored in arrays of doubles
64  *
65  * Revision 1.50 2012/10/25 22:44:38 genevb
66  * Switch from hardcoded to DB for several values, and fix a bug with east-west-asymmetric 3DGridLeak since ver. 1.82
67  *
68  * Revision 1.49 2012/04/25 19:22:56 genevb
69  * More use of GLWeights, more realistic geometry model in PredictSpaceCharge
70  *
71  * Revision 1.48 2011/08/23 22:15:10 genevb
72  * Introduce sector alignment distortion corrections and big speed improvements to Poisson relaxations
73  *
74  * Revision 1.47 2010/10/28 19:10:59 genevb
75  * Provide for usage of tpcHVPlanes and GG Voltage Error
76  *
77  * Revision 1.46 2010/05/30 21:12:44 genevb
78  * For GridLeak studies: more knobs to adjust GL and SC in Predict() functions
79  *
80  * Revision 1.45 2010/02/25 21:49:05 genevb
81  * Using sector number to better handle post-membrane hits, prep for sector-by-sector GL, and GGVoltage errors
82  *
83  * Revision 1.44 2009/12/11 04:53:58 genevb
84  * Give the enum constants unique names
85  *
86  * Revision 1.43 2009/12/11 03:55:21 genevb
87  * Singleton implementation + no defines in header
88  *
89  * Revision 1.42 2009/11/06 13:38:05 fisyak
90  * Revert the change done 11/03/09
91  *
92  * Revision 1.40 2009/10/19 21:29:01 jhthomas
93  * Improved execution speed for many algorithms: especially GridLeak.
94  *
95  * Revision 1.39 2009/10/01 22:40:11 jhthomas
96  * Update grid spacing for UndoShort, and prepare for other future gridding upgrades to achieve higher resolution results.
97  *
98  * Revision 1.38 2008/03/27 00:09:54 jhthomas
99  * Modify previous magfield changes and set 'zero' field to ~1 Gauss in a more robust way.
100  * Add SpaceChargeEWRatio and appropriate functions that allow us to calibrate d-Au collisions.
101  *
102  * Revision 1.37 2007/07/12 19:20:42 fisyak
103  * Account that StDetectorDbSpaceChargeR2 is not inherit from StDetectorDbSpaceCharge anymore
104  *
105  * Revision 1.36 2006/12/16 23:46:25 jhthomas
106  * Add ManualShortedRing() for Gene, and protect against B=0 ... set to a minimum of 0.25 gauss instead
107  *
108  * Revision 1.35 2006/08/07 20:38:13 fisyak
109  * TMatrix is typedef to TMatrixT<Float_t> now, with ROOT 5,12
110  *
111  * Revision 1.34 2006/07/28 04:58:32 jhthomas
112  * Add code by GeneVB to update the ShortedRing tables every time the DB changes.
113  *
114  * Revision 1.33 2006/06/27 18:17:47 jhthomas
115  * ADD new PredictSpaceCharge() function so that it includes fit errors in the prediction
116  * It is now capable of including the SSD and SVT hits in the predictor/corrector loop
117  *
118  * Revision 1.32 2005/05/24 18:53:20 jhthomas
119  * Add 3DGridLeak Distortion Correction and Utilities to support it.
120  *
121  * Revision 1.31 2005/02/17 02:00:51 jhthomas
122  * Make GetSpaceChargeMode() a public member function.
123  *
124  * Revision 1.30 2005/02/09 23:50:36 jeromel
125  * Changes by JHT for SpaceCharge / Leak corrections
126  *
127  * Revision 1.28 2004/10/20 17:53:11 jhthomas
128  * Add StGetSpaceChargeMode() function
129  *
130  * Revision 1.27 2004/07/01 17:49:07 jhthomas
131  * Add Event by Event SpaceCharge form GVB. Start adding incomplete/unfinished work on Endcaps from JT.
132  *
133  * Revision 1.26 2004/04/01 22:19:48 jhthomas
134  * Add 3D SpaceCharge capabilities
135  *
136  * Revision 1.25 2004/03/16 20:45:32 jhthomas
137  * Add new (faster) BField shape distortion routine. See comments for chain flags.
138  *
139  * Revision 1.24 2004/03/01 17:23:36 jhthomas
140  * Add function to get shorted ring parameters.
141  *
142  * Revision 1.23 2004/01/06 20:09:26 jhthomas
143  * Add new routine to handle shorted stripe on East end of TPC
144  *
145  * Revision 1.22 2003/09/02 17:57:51 perev
146  * gcc 3.2 updates + WarnOff
147  *
148  * Revision 1.21 2003/06/27 18:47:12 jhthomas
149  * Add new function called FixSpaceChargeDistortion( ,,,,, )
150  *
151  * Revision 1.20 2002/09/18 22:21:35 jhthomas
152  * Add new option for 1/R**2 space charge density distribution. Flag = 0x800
153  *
154  * Revision 1.19 2002/02/22 17:44:19 jhthomas
155  * Get CathodeV and GG from DB. Change Defaults. Change Instantiation argument
156  * order. Update D'Oxygen documentation. Remove 2000/2001 E field switch.
157  *
158  * Revision 1.18 2002/02/02 01:01:09 jeromel
159  * Jim's modif for FC & SpaceCharge corrections.
160  *
161  * Revision 1.17 2001/10/25 23:00:24 hardtke
162  * Use database to get a few parameters in StMagUtilities (including twist)
163  *
164  * Revision 1.16 2001/10/05 21:27:35 jeromel
165  * Small comment addition for historical purposes.
166  *
167  * Revision 1.15 2001/10/05 20:18:02 dunlop
168  * Tweaked enumeration of distortion selection to respect first three bits for
169  * year flag
170  *
171  * Revision 1.14 2001/10/05 03:44:25 jeromel
172  * Modifications by Jamie so we can turn on/off every corrections.
173  *
174  * Revision 1.13 2001/08/01 18:34:40 jhthomas
175  * Add temporary mode flag for year 2 running (different cathode potentials)
176  *
177  * Revision 1.12 2001/06/14 22:12:11 jhthomas
178  * Speedup UndoBDistorion by adding table lookups
179  *
180  * Revision 1.11 2001/06/13 16:24:43 jhthomas
181  * Speed up PadRow13 Corrections
182  *
183  * Revision 1.3 2000/12/15 16:10:45 jhthomas
184  * Add PadRow13, Clock, and Twist corrections to UndoDistortion
185  *
186  * Revision 1.2 2000/11/03 02:41:58 jhthomas
187  * Added CVS comment structure to .h and .cxx files
188  *
189  ***********************************************************************/
191 // //
192 // StMagUtilities Class //
193 // //
195 #ifndef StMagUtilities_H
196 #define StMagUtilities_H
197 #define __NEW_MagUtilities__
198 #include <math.h>
199 #include <stdio.h>
200 #include <stdlib.h>
201 #include <Stiostream.h>
202 
203 #include "TMatrix.h" // TMatrix keeps changing ... keep it here until proven otherwise.
204 #include "StarMagField/StarMagField.h"
205 class TFile;
206 class TNtuple;
207 #include "TMath.h"
208 
209 enum EBField { kUndefined = 0, kConstant = 1, kMapped = 2, kChain = 3 } ;
210 enum Prime { IsPrimary = 0 , IsGlobal = 1 } ;
211 
212 // Bit counting starts at 1 for the mode switch (...,3,2,1)
213 
214 enum DistortSelect
215 {
216  kBMap = 0x08, // Bit 4
217  kPadrow13 = 0x10, // Bit 5
218  kTwist = 0x20, // Bit 6
219  kClock = 0x40, // Bit 7
220  kMembrane = 0x80, // Bit 8
221  kEndcap = 0x100, // Bit 9
222  kIFCShift = 0x200, // Bit 10
223  kSpaceCharge = 0x400, // Bit 11
224  kSpaceChargeR2 = 0x800, // Bit 12
225  kShortedRing = 0x1000, // Bit 13
226  kFast2DBMap = 0x2000, // Bit 14
227  kGridLeak = 0x4000, // Bit 15
228  k3DGridLeak = 0x8000, // Bit 16
229  kGGVoltError = 0x10000, // Bit 17
230  kSectorAlign = 0x20000, // Bit 18
231  kDisableTwistClock = 0x40000, // Bit 19
232  kFullGridLeak = 0x80000, // Bit 20
233  kDistoSmearing = 0x100000, // Bit 21
234  kPadrow40 = 0x200000, // Bit 22
235  kAbortGap = 0x400000, // Bit 23
236  kSpaceChargeFXT = 0x800000 // Bit 24
237 } ;
238 enum CorrectSelect
239 {
240  kIterateUndo = 0x1 // Bit 1
241 } ;
242 enum EBMapSizes
243 {
244  BMap_nZ = 57, // Number of Z points in table. Measured STAR B field Maps from Steve T.
245  BMap_nR = 28, // Number of R points in table.
246  BMap_nPhi = 37, // Number of Phi points in table.
247  EMap_nZ = 224, // Number of Z points in table. Standard STAR distortion tables for interpolating.
248  EMap_nR = 82, // Number of R points in table
249  EMap_nPhi = 13 // Number of Phi points in table ( add one for 360 == 0 )
250 } ;
251 
252 // DO NOT change the numbering of these constants. StBFChain depends
253 // on these values to build an option flag. The option flag used in
254 // the chain is 2x larger than shown here in order to allow the first
255 // bit to be used as an on/off flag. It is shifted away before entering
256 // StMagUtilities. So, this can be summarized by saying:
257 // Bit counting starts at 0 for the chain option flag (...,3,2,1,0)
258 
259 class StTpcDb ;
260 class TDataSet ;
261 class St_tpcHVPlanesC;
263 class St_tpcHighVoltagesC;
264 class St_tpcOmegaTauC;
265 class St_tpcGridLeakC;
266 class St_spaceChargeCorC;
267 class St_tpcChargeEventC;
268 class TRandom;
269 
270 //class TMatrix ;
271 
273 
274 
275  private:
276  static StMagUtilities *fgInstance;
277  St_spaceChargeCorC* fSpaceCharge ;
278  St_spaceChargeCorC* fSpaceChargeR2 ;
279  St_tpcHighVoltagesC* fTpcVolts ;
280  St_tpcOmegaTauC* fOmegaTau ;
281  St_tpcGridLeakC* fGridLeak ;
282  St_tpcHVPlanesC* fHVPlanes ;
283  St_tpcCalibResolutionsC* fCalibResolutions ;
284  St_tpcChargeEventC* fAbortGapCharge;
285 
286  virtual void GetDistoSmearing ( Int_t mode) ;
287  virtual void GetMagFactor () ;
288  virtual void GetTPCParams () ;
289  virtual void GetTPCVoltages ( Int_t mode ) ;
290  virtual void GetSpaceCharge () ;
291  virtual void GetSpaceChargeR2 () ;
292  virtual void GetShortedRing () ;
293  virtual void GetOmegaTau () ;
294  virtual void GetGridLeak ( Int_t mode ) ;
295  virtual void GetHVPlanes() ;
296  virtual void GetE() ;
297  virtual void GetAbortGapCharge() ;
298 
299  virtual void CommonStart ( Int_t mode ) ;
300  virtual void Search ( const Int_t N, const Float_t Xarray[], const Float_t x, Int_t &low )
301  {StarMagField::Instance()->Search(N,Xarray,x,low);}
302  virtual Int_t IsPowerOfTwo (Int_t i) ;
303  virtual void SectorNumber ( Int_t& Sector , const Float_t x[] ) ;
304  virtual void SectorNumber ( Int_t& Sector , Float_t phi, const Float_t z ) ;
305  virtual void GetGLWallData( const Int_t select, Float_t DataInTheGap[] ) ;
306  virtual Int_t SectorSide ( Int_t& Sector , const Float_t x[] ) ; // -1 for east, +1 for west
307  virtual Int_t SectorSide ( Int_t& Sector , const Float_t z ) ;
308  virtual Float_t LimitZ (Int_t& Sector, const Float_t x[] ) ;
309  virtual Float_t Interpolate ( const Float_t Xarray[], const Float_t Yarray[],
310  const Int_t ORDER, const Float_t x )
311  {return StarMagField::Instance()->Interpolate(Xarray,Yarray,ORDER,x);}
312  virtual Float_t Interpolate2DTable ( const Int_t ORDER, const Float_t x, const Float_t y, const Int_t nx, const Int_t ny,
313  const Float_t XV[], const Float_t YV[], const TMatrix &Array ) ;
314  virtual Float_t Interpolate3DTable ( const Int_t ORDER, const Float_t x, const Float_t y, const Float_t z,
315  const Int_t nx, const Int_t ny, const Int_t nz,
316  const Float_t XV[], const Float_t YV[], const Float_t ZV[],
317  TMatrix **ArrayofArrays ) ;
318  virtual void Interpolate2DBfield ( const Float_t r, const Float_t z,
319  Float_t &Br_value, Float_t &Bz_value )
320  {StarMagField::Instance()->Interpolate2DBfield ( r, z, Br_value, Bz_value );}
321  virtual void Interpolate3DBfield ( const Float_t r, const Float_t z, const Float_t phi,
322  Float_t &Br_value, Float_t &Bz_value, Float_t &Bphi_value )
323  {StarMagField::Instance()->Interpolate3DBfield ( r, z, phi, Br_value, Bz_value, Bphi_value );}
324  virtual void Interpolate2DEdistortion ( const Int_t ORDER, const Float_t r, const Float_t z,
325  const Float_t Er[EMap_nZ][EMap_nR], Float_t &Er_value ) ;
326  virtual void Interpolate3DEdistortion ( const Int_t ORDER, const Float_t r, const Float_t phi, const Float_t z,
327  const Float_t Er[EMap_nZ][EMap_nPhi][EMap_nR], const Float_t Ephi[EMap_nZ][EMap_nPhi][EMap_nR],
328  Float_t &Er_value, Float_t &Ephi_value ) ;
329  virtual void PoissonRelaxation ( TMatrix &ArrayV, TMatrix &Charge, TMatrix &EroverEz,
330  const Int_t ITERATIONS ) ;
331 
332  virtual void Poisson3DRelaxation( TMatrix **ArrayofArrayV, TMatrix **ArrayofCharge, TMatrix **ArrayofEroverEz,
333  TMatrix **ArrayofEPhioverEz,
334  const Int_t PHISLICES, const Float_t DeltaPhi,
335  const Int_t ITERATIONS, const Int_t SYMMETRY) ;
336 
337  Int_t mDistortionMode; // Distortion mode - determines which corrections are run
338  UInt_t mCorrectionsMode; // Corrections mode - determines how corrections are run
339  Bool_t DoOnce ; // First pass: initializations
340 
341  Float_t StarDriftV ; // Drift Velocity (cm/microSec) Magnitude
342  Float_t TPC_Z0 ; // Z location of STAR TPC Ground Wire Plane (cm) Magnitude
343  Float_t XTWIST ; // X Displacement of West end of TPC wrt magnet (mRad)
344  Float_t YTWIST ; // Y Displacement of West end of TPC wrt magnet (mRad)
345  Double_t CathodeV ; // Cathode Potential (volts)
346  Double_t GG ; // Gating Grid voltage (volts)
347  Float_t GGideal ; // Ideal set GG voltage, not effective voltage
348  Float_t Inner_GLW_Voltage[24] ; // Voltage on the inside of the Grid Leak Wall facing the GG (~GG effective voltage)
349  Float_t Outer_GLW_Voltage[24] ; // Voltage on the outside surface of the Grid Leak Wall facing the outer sector
350  Float_t Rtot ; // Total resistance of the (normal) resistor chain
351  Float_t Rfrac ; // Fraction of full resistor chain inside TPC drift volume (~1.0)
352  Float_t RPitch ; // Field Cage Ring to Ring pitch (cm)
353  Float_t GGeffectiveness ; // Effectiveness of GG voltage to be the average at its plane
354  Float_t deltaGGeffectiveness ; // Effectiveness of GG voltage changes to be expressed in average
355  Float_t EASTCLOCKERROR ; // Phi rotation of East end of TPC in milli-radians
356  Float_t WESTCLOCKERROR ; // Phi rotation of West end of TPC in milli-radians
357  Float_t IFCRadius ; // Radius of the Inner Field Cage
358  Float_t OFCRadius ; // Radius of the Outer Field Cage
359  Float_t INNERGGFirst ; // Radius of the first Inner Gating Grid Wire
360  Float_t INNERGGLast ; // Radius of the last Inner Gating Grid Wire
361  Float_t OUTERGGFirst ; // Radius of the first Outer Gating Grid Wire
362  Float_t OUTERGGLast ; // Radius of the last Outer Gating Grid Wire
363  Float_t GAPRADIUS ; // Radius of the gap between the inner and outer grids (cm)
364  Float_t WIREGAP ; // Width of the gap between the inner and outer grids (cm)
365  Double_t TPCROWR[24][128] ; // Radii of TPC rows along the sector centerlines
366  Int_t INNER[24]; // Number of TPC rows in the inner sectors
367  Int_t TPCROWS[24]; // Total number of TPC rows per sector (Inner + Outer)
368  Float_t StarMagE ; // STAR Electric Field (V/cm) Magnitude
369  Float_t IFCShift ; // Shift of the IFC towards the West Endcap (cm)
370  Float_t TensorV1 ; // Omega Tau tensor parameter - in the ExB direction
371  Float_t TensorV2 ; // Omega Tau tensor parameter - in the direction perpendicular to ExB and Z axis
372  Float_t Const_0, Const_1, Const_2 ; // OmegaTau parameters
373  Float_t SpaceChargeEWRatio ; // Ratio of East/West Space charge ... for example, d-Au should be ratio 6/5, Au-Au ratio 1/1
374  Double_t SpaceCharge, SpaceChargeR2 ; // Space Charge parameters (uniform or 1/R**2 in the TPC - arbitrary units)
375  Double_t InnerGridLeakStrength ; // Relative strength of the Inner grid leak
376  Double_t InnerGridLeakRadius ; // Location (in local Y coordinates) of the Inner grid leak
377  Double_t InnerGridLeakWidth ; // Half-width of the Inner grid leak. Must be larger than life for numerical reasons.
378  Double_t MiddlGridLeakStrength ; // Relative strength of the Middle grid leak
379  Double_t MiddlGridLeakRadius ; // Location (in local Y coordinates) of the Middle grid leak
380  Double_t MiddlGridLeakWidth ; // Half-width of the Middle grid leak. Must be larger than life for numerical reasons.
381  Double_t OuterGridLeakStrength ; // Relative strength of the Outer grid leak
382  Double_t OuterGridLeakRadius ; // Location (in local Y coordinates) of the Outer grid leak
383  Double_t OuterGridLeakWidth ; // Half-width of the Outer grid leak. Must be larger than life for numerical reasons.
384  Float_t GLWeights[96] ; // GridLeak weights per sector. 24 sectors x 3 locations
385  Int_t ShortTableRows ; // Number of rows in the Shorted Ring Table
386  Int_t Side[10] ; // Location of Short E=0 / W=1
387  Int_t Cage[10] ; // Location of Short IFC=0 / OFC=1
388  Float_t Ring[10] ; // Location of Short counting out from the CM. CM==0
389  Float_t MissingResistance[10] ; // Amount of Missing Resistance due to this short (MOhm)
390  Float_t Resistor[10] ; // Amount of compensating resistance added for this short
391  Float_t deltaVGGEast ; // Voltage error on the East Gated Grid
392  Float_t deltaVGGWest ; // Voltage error on the West Gated Grid
393  Bool_t useManualSCForPredict ; // Flag on using fixed SC value or manually set one for Predict()
394  Bool_t iterateDistortion ; // Flag on whether to iterate in determining distortions
395  Int_t iterationFailCounter ; // Count of number of iteration fails
396  Bool_t doingDistortion ; // Flag on whether doing or undoing distortions
397  Bool_t usingCartesian ; // Using Cartesian or cylindrical coordinates
398  TRandom* mRandom ; // Random number generator (used in distortion smearing)
399  Float_t SmearCoefSC ; // Distortion smearing coefficient for SpaceCharge
400  Float_t SmearCoefGL ; // Distortion smearing coefficient for GridLeak
401  TArrayF* AbortGapCharges ; // Charges deposited into the TPC due to Abort Gap Cleaning events
402  TArrayD* AbortGapTimes ; // Times since charges deposited into the TPC due to Abort Gap Cleaning events
403  Float_t AbortGapChargeCoef ; // Scale factor for charge deposited due to Abort Gap Cleaning events
404  Float_t IonDriftVel ; // Drift velocity of ions in the TPC gas
405 
406 
407 
408  Float_t shiftEr[EMap_nZ][EMap_nR] ;
409  Float_t spaceEr[EMap_nZ][EMap_nR] ;
410  Float_t spaceR2Er[EMap_nZ][EMap_nR] ;
411  Float_t shortEr[EMap_nZ][EMap_nR] ;
412  Float_t GGVoltErrorEr[EMap_nZ][EMap_nR] ;
413 
414  static Float_t ePhiList[EMap_nPhi] ; // Note: These are initialized near CommonStart() in the .cxx file
415  static Float_t eRList[EMap_nR] ;
416  static Float_t eZList[EMap_nZ] ;
417  static TNtuple *fgDoDistortion;
418  static TNtuple *fgUnDoDistortion;
419  public:
420 
421  StMagUtilities ( StTpcDb* dbin = 0,Int_t mode = 0 ) ;
422  StMagUtilities ( const StarMagField::EBField map, const Float_t factor, Int_t mode );
423  virtual ~StMagUtilities () {fgInstance = 0;}
424  static StMagUtilities *Instance();
425 
426  virtual void BField ( const Float_t x[], Float_t B[] )
427  {StarMagField::Instance()->BField(x,B);}
428  virtual void BrBzField( const Float_t r, const Float_t z, Float_t &Br_value, Float_t &Bz_value )
429  {StarMagField::Instance()->BrBzField(r,z,Br_value,Bz_value );}
430  virtual void B3DField ( const Float_t x[], Float_t B[] )
431  {StarMagField::Instance()->B3DField(x,B);}
432  virtual void B3DFieldTpc ( const Float_t xTpc[], Float_t BTpc[], Int_t Sector = -1 );
433  virtual void BFieldTpc ( const Float_t xTpc[], Float_t BTpc[], Int_t Sector = -1 );
434  virtual void BrBz3DField ( const Float_t r, const Float_t z, const Float_t phi,
435  Float_t &Br_value, Float_t &Bz_value, Float_t &Bphi_value )
436  {StarMagField::Instance()->BrBz3DField(r, z, phi, Br_value, Bz_value, Bphi_value);}
437 
438  virtual bool UsingDistortion( const DistortSelect distortion ) { return ((mDistortionMode & distortion) ? true : false); }
439 
440  virtual void DoDistortion ( const Float_t x[], Float_t Xprime[] , Int_t Sector = -1 ) ;
441  virtual void UndoDistortion ( const Float_t x[], Float_t Xprime[] , Int_t Sector = -1 ) ;
442  virtual void UndoBDistortion ( const Float_t x[], Float_t Xprime[] , Int_t Sector = -1 ) ;
443  virtual void Undo2DBDistortion ( const Float_t x[], Float_t Xprime[] , Int_t Sector = -1 );// {UndoBDistortion(x,Xprime,Sector);}
444  virtual void FastUndoBDistortion ( const Float_t x[], Float_t Xprime[] , Int_t Sector = -1 ) ;
445  virtual void FastUndo2DBDistortion ( const Float_t x[], Float_t Xprime[] , Int_t Sector = -1 ) ;
446  virtual void UndoPad13Distortion ( const Float_t x[], Float_t Xprime[] , Int_t Sector = -1 ) ;
447  virtual void UndoPad40Distortion ( const Float_t x[], Float_t Xprime[], Int_t Sector = -1 ) ;
448  virtual void UndoTwistDistortion ( const Float_t x[], Float_t Xprime[] , Int_t Sector = -1 ) ;
449  virtual void UndoClockDistortion ( const Float_t x[], Float_t Xprime[] , Int_t Sector = -1 ) ;
450  virtual void UndoMembraneDistortion ( const Float_t x[], Float_t Xprime[] , Int_t Sector = -1 ) ;
451  virtual void UndoEndcapDistortion ( const Float_t x[], Float_t Xprime[] , Int_t Sector = -1 ) ;
452  virtual void UndoSpaceChargeDistortion ( const Float_t x[], Float_t Xprime[] , Int_t Sector = -1 ) ;
453  virtual void UndoSpaceChargeR0Distortion ( const Float_t x[], Float_t Xprime[] , Int_t Sector = -1 ) ;
454  virtual void UndoSpaceChargeR2Distortion ( const Float_t x[], Float_t Xprime[] , Int_t Sector = -1 ) ;
455  virtual void UndoSpaceChargeFXTDistortion ( const Float_t x[], Float_t Xprime[] , Int_t Sector = -1 ) ;
456  virtual void UndoGridLeakDistortion ( const Float_t x[], Float_t Xprime[] , Int_t Sector = -1 ) ;
457  virtual void Undo2DGridLeakDistortion ( const Float_t x[], Float_t Xprime[] , Int_t Sector = -1 ) ;
458  virtual void Undo3DGridLeakDistortion ( const Float_t x[], Float_t Xprime[] , Int_t Sector = -1 ) ;
459  virtual void UndoFullGridLeakDistortion ( const Float_t x[], Float_t Xprime[] , Int_t Sector = -1 ) ;
460  virtual void UndoIFCShiftDistortion ( const Float_t x[], Float_t Xprime[] , Int_t Sector = -1 ) ;
461  virtual void UndoShortedRingDistortion ( const Float_t x[], Float_t Xprime[] , Int_t Sector = -1 ) ;
462  virtual void UndoGGVoltErrorDistortion ( const Float_t x[], Float_t Xprime[], Int_t Sector = -1 ) ;
463  virtual void UndoSectorAlignDistortion ( const Float_t x[], Float_t Xprime[], Int_t Sector = -1 ) ;
464  virtual void UndoAbortGapDistortion ( const Float_t x[], Float_t Xprime[] , Int_t Sector = -1, Float_t TimeSinceDeposition = -1.0 ) ;
465 
466  virtual void FixSpaceChargeDistortion ( const Int_t Charge, const Float_t x[3], const Float_t p[3],
467  const Prime PrimaryOrGlobal,
468  Float_t x_new[3], Float_t p_new[3],
469  const unsigned int RowMask1 = 0xFFFFFF00 ,
470  const unsigned int RowMask2 = 0x1FFFFF,
471  const Float_t VertexError = 0.0200 ) ;
472 
473  virtual void ApplySpaceChargeDistortion ( const Double_t sc, const Int_t Charge,
474  const Float_t x[3], const Float_t p[3],
475  const Prime PrimaryOrGlobal, Int_t &new_Charge,
476  Float_t x_new[3], Float_t p_new[3],
477  const unsigned int RowMask1 = 0xFFFFFF00 ,
478  const unsigned int RowMask2 = 0x1FFFFF,
479  const Float_t VertexError = 0.0200 ) ;
480 
481  virtual Int_t PredictSpaceChargeDistortion ( Int_t sec,
482  Int_t Charge,
483  Float_t Pt,
484  Float_t VertexZ,
485  Float_t PseudoRapidity,
486  Float_t DCA,
487  const unsigned int RowMask1,
488  const unsigned int RowMask2,
489  Float_t &pSpace ) ;
490 
491  virtual Int_t PredictSpaceChargeDistortion ( Int_t sec,
492  Int_t Charge,
493  Float_t Pt,
494  Float_t VertexZ,
495  Float_t PseudoRapidity,
496  Float_t Phi,
497  Float_t DCA,
498  const unsigned long long RowMask1,
499  const unsigned long long RowMask2,
500  Float_t RowMaskErrorR[64],
501  Float_t RowMaskErrorRPhi[64],
502  Float_t &pSpace ) ;
503 
504  virtual Int_t PredictSpaceChargeDistortion ( Int_t NHits,
505  Int_t Charge,
506  Float_t Pt,
507  Float_t VertexZ,
508  Float_t PseudoRapidity,
509  Float_t Phi,
510  Float_t DCA,
511  Double_t R[128],
512  Double_t ErrorR[128],
513  Double_t ErrorRPhi[128],
514  Float_t &pSpace ) ;
515 
516  virtual void ManualShortedRing ( Int_t EastWest, Int_t InnerOuter,
517  Float_t RingNumber, Float_t MissingRValue, Float_t ExtraRValue) ;
518 
519  virtual Int_t GetSpaceChargeMode();
520  virtual void ManualSpaceCharge(Double_t SpcChg) { SpaceCharge = SpcChg ; fSpaceCharge = 0 ; }
521  virtual void ManualSpaceChargeR2(Double_t SpcChg, Float_t EWRatio = 1.0 ) { SpaceChargeR2 = SpcChg ; fSpaceChargeR2 = 0 ;
522  SpaceChargeEWRatio = EWRatio ; }
523  virtual void ManualGridLeakStrength(Double_t inner, Double_t middle, Double_t outer);
524  virtual void ManualGridLeakRadius (Double_t inner, Double_t middle, Double_t outer);
525  virtual void ManualGridLeakWidth (Double_t inner, Double_t middle, Double_t outer);
526  virtual void AutoSpaceCharge() {GetSpaceCharge() ; } // use DB
527  virtual void AutoSpaceChargeR2() {GetSpaceChargeR2(); } // use DB
528  virtual Double_t CurrentSpaceCharge() {return SpaceCharge ;}
529  virtual Double_t CurrentSpaceChargeR2() {return SpaceChargeR2;}
530  virtual Float_t CurrentSpaceChargeEWRatio() { return SpaceChargeEWRatio ; }
531  virtual Bool_t UpdateTPCHighVoltages();
532  virtual Bool_t UpdateShortedRing();
533  virtual void UseManualSCForPredict(Bool_t flag=kTRUE) { useManualSCForPredict=flag; }
534  virtual void ManualGGVoltError(Double_t east, Double_t west);
535  virtual void UseIterativeUndoDistortion(Bool_t flag=kTRUE) { iterateDistortion=flag; }
536  virtual Int_t IterationFailCount(); // must be called once before first actual use
537  Float_t GetConst_0() { return Const_0; }
538  Float_t GetConst_1() { return Const_1; }
539  Float_t GetConst_2() { return Const_2; }
540  static void SetDoDistortionT (TFile *f = 0);
541  static void SetUnDoDistortionT(TFile *f = 0);
542 
543  virtual void Cart2Polar(const Float_t* x, Float_t& r, Float_t& phi) {
544  r = TMath::Sqrt( x[0]*x[0] + x[1]*x[1] ) ;
545  phi = TMath::ATan2(x[1],x[0]) ;
546  }
547  virtual void Cart2Polar(const Float_t* x, Double_t& r, Double_t& phi) {
548  r = TMath::Sqrt( x[0]*x[0] + x[1]*x[1] ) ;
549  phi = TMath::ATan2(x[1],x[0]) ;
550  }
551  virtual void Polar2Cart(const Double_t r, const Double_t phi, Float_t* Xprime) {
552  Xprime[0] = r * TMath::Cos(phi) ;
553  Xprime[1] = r * TMath::Sin(phi) ;
554  }
555 
556 
557 
558  ClassDef(StMagUtilities,1) // Base class for all STAR MagField
559 
560 };
561 
562 #endif
563 
564 
565 
566 
567 
568 
569 
570 
571 
virtual void UndoTwistDistortion(const Float_t x[], Float_t Xprime[], Int_t Sector=-1)
Twist distortion.
virtual void UndoFullGridLeakDistortion(const Float_t x[], Float_t Xprime[], Int_t Sector=-1)
Full GridLeak Distortion Calculation.
virtual void UndoIFCShiftDistortion(const Float_t x[], Float_t Xprime[], Int_t Sector=-1)
IFC Shift Distortion.
virtual void UndoClockDistortion(const Float_t x[], Float_t Xprime[], Int_t Sector=-1)
Clock distortion.
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.
virtual void Interpolate2DBfield(const Float_t r, const Float_t z, Float_t &Br_value, Float_t &Bz_value)
Interpolate the B field map - 2D interpolation.
virtual void UndoGridLeakDistortion(const Float_t x[], Float_t Xprime[], Int_t Sector=-1)
Grid Leakage entry function.
virtual void B3DField(const Float_t x[], Float_t B[])
Bfield in Cartesian coordinates - 3D field.
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...
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...
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 ...
virtual void Undo3DGridLeakDistortion(const Float_t x[], Float_t Xprime[], Int_t Sector=-1)
3D GridLeak Distortion Calculation
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 ...
static void Search(Int_t N, const Float_t Xarray[], Float_t x, Int_t &low)
Search an ordered table by starting at the most recently used point.
virtual void UndoSectorAlignDistortion(const Float_t x[], Float_t Xprime[], Int_t Sector=-1)
3D Sector Alignment Distortion Calculation
virtual Float_t Interpolate(const Float_t Xarray[], const Float_t Yarray[], const Int_t ORDER, const Float_t x)
Interpolate a 3x2 table (quadratic) or a 2x2 table (linear)
virtual void UndoGGVoltErrorDistortion(const Float_t x[], Float_t Xprime[], Int_t Sector=-1)
Gated Grid Voltage Error.
virtual void Undo2DGridLeakDistortion(const Float_t x[], Float_t Xprime[], Int_t Sector=-1)
Grid Leakage Calculation.
StMagUtilities(StTpcDb *dbin=0, Int_t mode=0)
StMagUtilities constructor using the DataBase.
virtual void Interpolate3DBfield(const Float_t r, const Float_t z, const Float_t phi, Float_t &Br_value, Float_t &Bz_value, Float_t &Bphi_value)
Interpolate the B field map - 3D interpolation.
virtual void UndoSpaceChargeDistortion(const Float_t x[], Float_t Xprime[], Int_t Sector=-1)
Space Charge entry function.
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 Physical-Signed DCA and get back spacecharge parameter plus a success or f...
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 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 UndoAbortGapDistortion(const Float_t x[], Float_t Xprime[], Int_t Sector=-1, Float_t TimeSinceDeposition=-1.0)
Abort Gap Cleaning Cycle space charge correction.
virtual void BrBzField(const Float_t r, const Float_t z, Float_t &Br_value, Float_t &Bz_value)
B field in Radial coordinates - 2D field (ie Phi symmetric)
virtual void UndoPad13Distortion(const Float_t x[], Float_t Xprime[], Int_t Sector=-1)
Pad row 13 distortion.
virtual Int_t GetSpaceChargeMode()
Space Charge Correction Mode.
virtual void UndoPad40Distortion(const Float_t x[], Float_t Xprime[], Int_t Sector=-1)
PadRow 40 and/or PadRow 13 distortion correction.
virtual void UndoShortedRingDistortion(const Float_t x[], Float_t Xprime[], Int_t Sector=-1)
Shorted Ring Distortion.
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.
virtual void UndoSpaceChargeR0Distortion(const Float_t x[], Float_t Xprime[], Int_t Sector=-1)
Space Charge Correction.
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...
virtual void UndoSpaceChargeR2Distortion(const Float_t x[], Float_t Xprime[], Int_t Sector=-1)
1/R**2 SpaceCharge Distortion
virtual void UndoSpaceChargeFXTDistortion(const Float_t x[], Float_t Xprime[], Int_t Sector=-1)
FixedTarget 1/r SpaceCharge Distortion.