StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
St_trigDetSumsC.h
1 #ifndef St_trigDetSumsC_h
2 #define St_trigDetSumsC_h
3 
4 #include "TChair.h"
5 #include <math.h>
6 #include "tables/St_trigDetSums_Table.h"
7 #include "StDetectorDbClock.h"
8 #include "St_richvoltagesC.h"
9 #include "TMath.h"
10 class St_trigDetSumsC : public TChair {
11  public:
12  St_trigDetSumsC(St_trigDetSums *table=0) : TChair(table) {SafeDelete(fgInstance); fgInstance = this; fMargin = 0;}
13  virtual ~St_trigDetSumsC();
14  static St_trigDetSumsC* instance();
15  static St_trigDetSumsC* GetInstance() {return fgInstance;}
16  trigDetSums_st *Struct(Int_t i = 0) {return ((St_trigDetSums*) Table())->GetTable()+i;}
17  UInt_t getNumRows() {return GetNRows();}
18  UInt_t runNumber(Int_t i = 0) {return Struct(i)->runNumber;}
19  UInt_t timeOffset(Int_t i = 0) {return Struct(i)->timeOffset;}
20  Double_t ctbWest(Int_t i = 0) {return validity(Struct(i)->ctbWest);}
21  Double_t ctbEast(Int_t i = 0) {return validity(Struct(i)->ctbEast);}
22  Double_t ctbTOFp(Int_t i = 0) {return validity(Struct(i)->ctbTOFp);}
23  Double_t tofp(Int_t i = 0) {return validity(Struct(i)->tofp);}
24  Double_t zdcWest(Int_t i = 0) {return validity(Struct(i)->zdcWest);}
25  Double_t zdcEast(Int_t i = 0) {return validity(Struct(i)->zdcEast);}
26  Double_t zdcX(Int_t i = 0) {return validity(Struct(i)->zdcX);}
27  Double_t mult(Int_t i = 0) {return validity(Struct(i)->mult);}
28  Double_t L0(Int_t i = 0) {return validity(Struct(i)->L0);}
29  Double_t bbcX(Int_t i = 0) {return validity(Struct(i)->bbcX);}
30  Double_t bbcXctbTOFp(Int_t i = 0) {return validity(Struct(i)->bbcXctbTOFp);}
31  Double_t bbcWest(Int_t i = 0) {return validity(Struct(i)->bbcWest);}
32  Double_t bbcEast(Int_t i = 0) {return validity(Struct(i)->bbcEast);}
33  Double_t bbcYellowBkg(Int_t i = 0) {return validity(Struct(i)->bbcYellowBkg);}
34  Double_t bbcBlueBkg(Int_t i = 0) {return validity(Struct(i)->bbcBlueBkg);}
35  Double_t pvpdWest(Int_t i = 0) {return validity(Struct(i)->pvpdWest);}
36  Double_t pvpdEast(Int_t i = 0) {return validity(Struct(i)->pvpdEast);}
37  Double_t zdcCoin(Int_t i = 0) {return Nc(zdcX(i),zdcEast(i),zdcWest(i));}
38  Double_t bbcCoin(Int_t i = 0) {return Nc(bbcX(i),bbcEast(i),bbcWest(i));}
39  static St_trigDetSums* fgTableCopy;
40  void validityMargin(Double_t margin=0) {fMargin = margin;}
41  Double_t getCTBWest() {return ctbWest();}
42  Double_t getCTBEast() {return ctbEast();}
43  Double_t getCTBOrTOFp() {return ctbTOFp();}
44  Double_t getTOFp() {return tofp();}
45  Double_t getZDCWest() {return zdcWest();}
46  Double_t getZDCEast() {return zdcEast();}
47  Double_t getZDCX() {return zdcX();}
48  Double_t getZDCCoin() {return zdcCoin();}
49  Double_t getMult() {return mult();}
50  Double_t getL0() {return L0();}
51  Double_t getBBCX() {return bbcX();}
52  Double_t getBBCCoin() {return bbcCoin();}
53  Double_t getBBCXCTB() {return bbcXctbTOFp();}
54  Double_t getBBCWest() {return bbcWest();}
55  Double_t getBBCEast() {return bbcEast();}
56  Double_t getBBCYellowBkg() {return bbcYellowBkg();}
57  Double_t getBBCBlueBkg() {return bbcBlueBkg();}
58  Double_t getPVPDWest() {return pvpdWest();}
59  Double_t getPVPDEast() {return pvpdEast();}
60  UInt_t getRichHVStatus() {return St_richvoltagesC::instance()->status();}
61  void setValidityMargin(Double_t margin=0) {validityMargin(margin);}
62 
63  // The following code attempts to correct coincidence rates for accidentals and multiples
64  // See STAR Note 528
65  static Double_t Nc(Double_t New, Double_t Ne, Double_t Nw, Int_t n_bunches=111) {
66  // 111 is a guess using the maximum seen filled bunches in RHIC so far
67  // (not always the case, but we don't have access to this number)
68  Double_t Nbc = StDetectorDbClock::instance()->CurrentFrequency() * ((Double_t) n_bunches) / 120.;
69  return -Nbc * TMath::Log(1. - ((New - (Ne*Nw/Nbc)) / (Nbc+New-Ne-Nw)));
70  }
71 
72  protected:
73  private:
74  static St_trigDetSumsC* fgInstance;
75  Double_t fMargin;
76 
77  // The following code is meant to handle "stuck" RICH Scalers, where the scaler
78  // integrates rates for a factor of 2 or 3 times as long as it is expected to,
79  // leading to erroneous numbers.
80  // validity margin parameter is passed (probably from spaceChargeCor)
81  Double_t validity(double& newval) {
82 
83  if (!fgTableCopy)
84  fgTableCopy = new St_trigDetSums(*((St_trigDetSums*) Table()));
85 
86  // reference pointer to previous table's data
87  double& oldval = *((double*) (((char*) (fgTableCopy->GetTable())) +
88  (((char*) &newval) - ((char*) Struct(0)))));
89 
90  // Corrupt scalers >1e9 seen in Run 9 (not possible at RHIC)
91  // Will return previous value, unless it is also corrupt,
92  // otherwise an unphysical value (-1) which can be used to trap problems
93  double CORRUPT = 1e9;
94  if (newval > CORRUPT || newval < 0)
95  return (oldval > CORRUPT || oldval < 0 ? -1 : oldval);
96 
97  if (fMargin == 0) return newval;
98 
99  // Use newval for low rates, below (x2-margin), outside (multiple+/-margin)
100  if ((oldval < 100) ||
101  ((newval/oldval) < (2.0-fMargin)) ||
102  (fabs(fmod((newval/oldval)+0.5,1.0)-0.5) > fMargin))
103  oldval = newval;
104 
105  return oldval;
106  }
107 
108  ClassDefChair(St_trigDetSums, trigDetSums_st )
109  ClassDef(St_trigDetSumsC,3) //C++ TChair for trigDetSums table class
110 };
111 #endif
Definition: TChair.h:27