StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
St_spaceChargeCorC.cxx
1 #include "St_spaceChargeCorC.h"
2 #include "St_trigDetSumsC.h"
3 #include "StMemStat.h"
4 
5 Double_t St_spaceChargeCorC::getSpaceChargeCoulombs(Double_t scaleFactor)
6  {
7  St_trigDetSumsC* scalers = St_trigDetSumsC::instance();
8  if (! scalers ) return 0;
9  Double_t zf = zeroField(0); // potential validity margin for scalers
10  if (zf>0 && zf<1) scalers->setValidityMargin(zf);
11  Double_t coulombs = 0;
12 // StMemStat::PrintMem("Space charge before GetDate");
13  int idate = StMaker::GetChain()->GetDate();
14 // StMemStat::PrintMem("Space charge AFTER int GetDate() conversion");
15 
16  bool use_powers = idate > 20090101;
17 // bool use_powers = (StMaker::GetChain()->GetDate() > 20090101);
18 // StMemStat::PrintMem("Space charge AFTER comparision");
19  for (int row=0;row< (int) getNumRows();row++) {
20  Double_t mult = 0;
21  switch ((int) getSpaceChargeDetector(row)) {
22  case (0) : mult = scalers->getMult(); break; // vpdx as of 2007-12-19
23  case (1) : mult = scalers->getBBCX(); break;
24  case (2) : mult = scalers->getZDCX(); break;
25  case (3) : mult = scalers->getZDCEast()+scalers->getZDCWest(); break;
26  case (4) : mult = scalers->getBBCEast()+scalers->getBBCWest(); break;
27  case (5) : mult = scalers->getZDCEast(); break;
28  case (6) : mult = scalers->getZDCWest(); break;
29  case (7) : mult = scalers->getBBCEast(); break;
30  case (8) : mult = scalers->getBBCWest(); break;
31  case (9) : mult = scalers->getBBCYellowBkg(); break;
32  case (10): mult = scalers->getBBCBlueBkg(); break;
33  case (11): mult = scalers->getPVPDEast(); break;
34  case (12): mult = scalers->getPVPDWest(); break;
35  case (13) : mult = scalers->getCTBOrTOFp(); break; // zdcx-no-killer as of 2011
36  case (14) : mult = scalers->getCTBEast(); break; // zdce-no-killer as of 2011
37  case (15) : mult = scalers->getCTBWest(); break; // zdcw-no-killer as of 2011
38  case (16) : mult = scalers->getEPDX(); break; // EPD after March 2018
39 
40  default : mult = 0.;
41  }
42  if (mult < 0) {
43  Mark();
44  return 0; // Unphysical scaler rates will be uncorrected
45  } else UnMark();
46  Double_t saturation = getSpaceChargeSatRate(row);
47  Double_t correction = getSpaceChargeCorrection(scaleFactor,row);
48  Double_t factor = getSpaceChargeFactor(row);
49  Double_t offset = getSpaceChargeOffset(row);
50  Double_t intens = (mult < saturation) ? mult : saturation;
51  if (use_powers) coulombs += ::pow(intens-offset,factor) * correction ;
52  else coulombs += factor * (intens-offset) * correction ;
53  }
54  return coulombs;
55  }
56 TString St_spaceChargeCorC::getSpaceChargeString(Double_t scaleFactor)
57  {
58  TString str,mult;
59  int idate = StMaker::GetChain()->GetDate();
60  bool use_powers = idate > 20090101;
61  for (int row=0;row< (int) getNumRows();row++) {
62  switch ((int) getSpaceChargeDetector(row)) {
63  case (0) : mult = "vpdx"; break; // vpdx as of 2007-12-19
64  case (1) : mult = "bbcx"; break;
65  case (2) : mult = "zdcx"; break;
66  case (3) : mult = "(zdce+zdcw)"; break;
67  case (4) : mult = "(bbce+bbcw)"; break;
68  case (5) : mult = "zdce"; break;
69  case (6) : mult = "zdcw"; break;
70  case (7) : mult = "bbce"; break;
71  case (8) : mult = "bbcw"; break;
72  case (9) : mult = "bbcyb"; break;
73  case (10): mult = "bbcbb"; break;
74  case (11): mult = "vpde"; break;
75  case (12): mult = "vpdw"; break;
76  case (13): mult = "zdcxnk"; break; // zdcx-no-killer as of 2011
77  case (14): mult = "zdcenk"; break; // zdce-no-killer as of 2011
78  case (15): mult = "zdcwnk"; break; // zdcw-no-killer as of 2011
79  default : mult = "";
80  }
81  Double_t correction = getSpaceChargeCorrection(scaleFactor,row);
82  Double_t factor = getSpaceChargeFactor(row);
83  Double_t offset = getSpaceChargeOffset(row);
84  if (factor==0 || correction==0 || mult.Length()==0) continue;
85  if (str.Length()) str += "+";
86  str += Form("(%g)*(",correction);
87  Bool_t factorIsInt = (TMath::Abs(factor - ((double) TMath::Nint(factor))) < 1e-6);
88  if (factorIsInt && factor>0.5 && factor<1.5) str += mult;
89  else {
90  if (use_powers) {
91  if (factorIsInt && factor>1.5) {
92  // use scaler*scaler*... form
93  while (factor>1.5) { (str += mult) += "*"; factor--; }
94  str += mult;
95  } else str += Form("pow(%s,%f)",mult.Data(),factor);
96  } else (str += Form("%g)*(",factor)) += mult;
97  }
98  if (offset!=0) str += Form("-(%g)",offset);
99  str += ")";
100  }
101  return str;
102  }