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