StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
St_starMagOnlC.h
1 #ifndef St_starMagOnlC_h
2 #define St_starMagOnlC_h
3 
4 #include "TChair.h"
5 #include "TMath.h"
6 #include "tables/St_starMagOnl_Table.h"
7 
8 enum StMagnetPolarity {eUnknownMField, eFullMFieldPolB, eHalfMFieldPolB,
9  eZeroMField, eHalfMFieldPolA, eFullMFieldPolA};
10 
11 class St_starMagOnlC : public TChair {
12  public:
13  static St_starMagOnlC* instance();
14  starMagOnl_st*Struct(Int_t i = 0) {return ((St_starMagOnl*) Table())->GetTable()+i;}
15  UInt_t getNumRows() {return GetNRows();}
16  UInt_t runNumber(Int_t i = 0) {return Struct(i)->runNumber;}
17  UInt_t time(Int_t i = 0) {return Struct(i)->time;}
18  Double_t current(Int_t i = 0) {return Struct(i)->current;}
19  // Double_t ScaleFactor(Int_t i = 0){return current()/(4500*(0.49827/0.497611));} // scale 9.98677423886647819e-01 Run 2020 11p5GeV K0s mass to PDG value
20  Double_t ScaleFactor(Int_t i = 0){return current()/4500.;};//11/26/21 (4500/(9.98071899596718826e-01));} // 12/03/20 scale Run 2020 11p5GeV K0s (pcmax(0.49827)/pcmax(0.497611)) to PDG value
21  Double_t getScaleFactor(UInt_t time=0) {return currentToScaleFactor(getMagnetCurrent(time));}
22  Double_t getMagnetCurrent(UInt_t time=0) {
23  if (! instance()) return 0;
24  if (getNumRows() == 1 || time == 0) return current();
25  Double_t tempCurrent = -9999;
26  for (UInt_t i = 0; i < getNumRows()-1; i++)
27  if( time >= getTimeEntry(i) && time <= getTimeEntry(i+1) )
28  if( TMath::Abs(getMagnetCurrentEntry(i) - getMagnetCurrentEntry(i+1)) < 50 )
29  tempCurrent = getMagnetCurrentEntry(i);
30  return tempCurrent;
31  }
32  StMagnetPolarity getMagneticField(UInt_t time=0) {
33  StMagnetPolarity value = eUnknownMField;
34  if (! instance()) return value;
35  Double_t scaleFactor = getScaleFactor(time);
36  if(scaleFactor == 1.0) value = eFullMFieldPolA;
37  if(scaleFactor == 0.5) value = eHalfMFieldPolA;
38  if(scaleFactor == 0.0) value = eZeroMField;
39  if(scaleFactor == -0.5) value = eHalfMFieldPolB;
40  if(scaleFactor == -1.0) value = eFullMFieldPolB;
41  return value;
42  }
43  UInt_t getRunNumber() {return runNumber();}
44  UInt_t getTimeEntry(UInt_t i=0) {return time(i);}
45  Double_t getMagnetCurrentEntry(UInt_t i=0) {return current(i);}
46  static Double_t currentToScaleFactor(Double_t current) {
47  Double_t value = -9999;
48  if (! instance()) return value;
49  if (current < -4450 && current > -4550) value = -1.0;
50  else if(current < -2200 && current > -2300) value = -0.5;
51  else if(current > -50 && current < 50) value = 0.0;
52  else if(current > 2200 && current < 2300) value = 0.5;
53  else if(current > 4450 && current < 4550) value = 1.0;
54  return value;
55  }
56  protected:
57  St_starMagOnlC(St_starMagOnl *table=0) : TChair(table) {}
58  virtual ~St_starMagOnlC() {fgInstance = 0;}
59  private:
60  static St_starMagOnlC* fgInstance;
61  ClassDefChair(St_starMagOnl, starMagOnl_st )
62  ClassDef(St_starMagOnlC,1) //C++ TChair for starMagOnl table class
63 };
64 #endif
Definition: TChair.h:27