195 #ifndef StMagUtilities_H
196 #define StMagUtilities_H
197 #define __NEW_MagUtilities__
204 #include "StarMagField/StarMagField.h"
209 enum EBField { kUndefined = 0, kConstant = 1, kMapped = 2, kChain = 3 } ;
210 enum Prime { IsPrimary = 0 , IsGlobal = 1 } ;
223 kSpaceCharge = 0x400,
224 kSpaceChargeR2 = 0x800,
225 kShortedRing = 0x1000,
226 kFast2DBMap = 0x2000,
228 k3DGridLeak = 0x8000,
229 kGGVoltError = 0x10000,
230 kSectorAlign = 0x20000,
231 kDisableTwistClock = 0x40000,
232 kFullGridLeak = 0x80000,
233 kDistoSmearing = 0x100000,
234 kPadrow40 = 0x200000,
235 kAbortGap = 0x400000,
236 kSpaceChargeFXT = 0x800000
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() ;
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[] ) ;
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 )
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 ) ;
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) ;
337 Int_t mDistortionMode;
338 UInt_t mCorrectionsMode;
348 Float_t Inner_GLW_Voltage[24] ;
349 Float_t Outer_GLW_Voltage[24] ;
353 Float_t GGeffectiveness ;
354 Float_t deltaGGeffectiveness ;
355 Float_t EASTCLOCKERROR ;
356 Float_t WESTCLOCKERROR ;
359 Float_t INNERGGFirst ;
360 Float_t INNERGGLast ;
361 Float_t OUTERGGFirst ;
362 Float_t OUTERGGLast ;
365 Double_t TPCROWR[24][128] ;
372 Float_t Const_0, Const_1, Const_2 ;
373 Float_t SpaceChargeEWRatio ;
374 Double_t SpaceCharge, SpaceChargeR2 ;
375 Double_t InnerGridLeakStrength ;
376 Double_t InnerGridLeakRadius ;
377 Double_t InnerGridLeakWidth ;
378 Double_t MiddlGridLeakStrength ;
379 Double_t MiddlGridLeakRadius ;
380 Double_t MiddlGridLeakWidth ;
381 Double_t OuterGridLeakStrength ;
382 Double_t OuterGridLeakRadius ;
383 Double_t OuterGridLeakWidth ;
384 Float_t GLWeights[96] ;
385 Int_t ShortTableRows ;
389 Float_t MissingResistance[10] ;
390 Float_t Resistor[10] ;
391 Float_t deltaVGGEast ;
392 Float_t deltaVGGWest ;
393 Bool_t useManualSCForPredict ;
394 Bool_t iterateDistortion ;
395 Int_t iterationFailCounter ;
396 Bool_t doingDistortion ;
397 Bool_t usingCartesian ;
399 Float_t SmearCoefSC ;
400 Float_t SmearCoefGL ;
401 TArrayF* AbortGapCharges ;
402 TArrayD* AbortGapTimes ;
403 Float_t AbortGapChargeCoef ;
404 Float_t IonDriftVel ;
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] ;
414 static Float_t ePhiList[EMap_nPhi] ;
415 static Float_t eRList[EMap_nR] ;
416 static Float_t eZList[EMap_nZ] ;
417 static TNtuple *fgDoDistortion;
418 static TNtuple *fgUnDoDistortion;
422 StMagUtilities (
const StarMagField::EBField map,
const Float_t factor, Int_t mode );
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);}
438 virtual bool UsingDistortion(
const DistortSelect distortion ) {
return ((mDistortionMode & distortion) ?
true :
false); }
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 );
444 virtual void FastUndoBDistortion (
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 ) ;
464 virtual void UndoAbortGapDistortion (
const Float_t x[], Float_t Xprime[] , Int_t Sector = -1, Float_t TimeSinceDeposition = -1.0 ) ;
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 ) ;
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 ) ;
485 Float_t PseudoRapidity,
487 const unsigned int RowMask1,
488 const unsigned int RowMask2,
495 Float_t PseudoRapidity,
498 const unsigned long long RowMask1,
499 const unsigned long long RowMask2,
500 Float_t RowMaskErrorR[64],
501 Float_t RowMaskErrorRPhi[64],
508 Float_t PseudoRapidity,
512 Double_t ErrorR[128],
513 Double_t ErrorRPhi[128],
517 Float_t RingNumber, Float_t MissingRValue, Float_t ExtraRValue) ;
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() ; }
527 virtual void AutoSpaceChargeR2() {GetSpaceChargeR2(); }
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();
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);
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]) ;
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]) ;
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) ;
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.