AliPhysics  2c6b7ad (2c6b7ad)
readOCDB_Temperature.C
Go to the documentation of this file.
1 #if !defined( __CINT__) || defined(__MAKECINT__)
2 #include <AliCDBEntry.h>
3 #include <AliCDBManager.h>
4 #include <AliCDBMetaData.h>
5 #include <AliDCSValue.h>
6 #include <AliEMCALPreprocessor.h>
7 #include <AliEMCALSensorTempArray.h>
8 #include <AliEMCALTriggerDCSConfig.h>
9 #include <AliEMCALTriggerSTUDCSConfig.h>
10 #include <AliEMCALTriggerTRUDCSConfig.h>
11 #include <AliLog.h>
12 #include <TDatime.h>
13 #include <TFile.h>
14 #include <TGrid.h>
15 #include <TMap.h>
16 #include <TNtuple.h>
17 #include <stdio.h>
18 #include "TInfo.h"
19 TInfo *readOCDB_Temperature(Int_t runNb = 286350, Bool_t debug=1);
20 void testOCDB_Temperature(Int_t runNb = 286350);
21 #endif
22 
23 #ifndef _tempfuncs_
24 #define _tempfuncs_
26 {
27  if (!gGrid)
28  TGrid::Connect("alien://");
29 
30  AliCDBManager* cdb = AliCDBManager::Instance();
31  if (cdb->GetDefaultStorage()==0)
32  cdb->SetDefaultStorage("raw://");
33  cdb->SetRun(runNb);
34 
35  AliCDBEntry *en=0;
36  try {
37  en=cdb->Get("EMCAL/Calib/Temperature/");
38  } catch (...) { ; }
39  if (!en) {
40  printf("no entry found for run %d!\n", runNb);
41  return 0;
42  }
43 
44  TInfo *info = new TInfo(runNb);
45 
46  AliEMCALSensorTempArray *arr = dynamic_cast< AliEMCALSensorTempArray *> (en->GetObject());
47  //arr->Print();
48  cout << " NumSensors " << arr->NumSensors()
49  << " GetFirstIdDCS() " << arr->GetFirstIdDCS()
50  << " GetLastIdDCS() " << arr->GetLastIdDCS()
51  << endl;
52 
53  // info for each sensor
54  const Int_t kNumSens = 160;
55  Int_t np[kNumSens] = {0};
56  Double_t min[kNumSens] = {0};
57  Double_t max[kNumSens] = {0};
58  Double_t avg[kNumSens] = {0};
59  Double_t rms[kNumSens] = {0};
60 
61  Double_t avTime = 0;
62  UInt_t fTime = -1;
63  UInt_t lTime = 0;
64  for (Int_t isensor=0; isensor<kNumSens; isensor++) {
65  AliEMCALSensorTemp *o = arr->GetSensor(isensor);
66  if (!o)
67  continue;
68 
69  UInt_t startt = o->GetStartTime();
70  UInt_t stopt = o->GetEndTime();
71 
72  if (debug)
73  cout << "Sensor " << isensor
74  << " " << o->GetStringID() << ":"
75  << " side " << o->GetSide()
76  << " sector " << o->GetSector()
77  << " num " << o->GetNum()
78  << " startTime " << startt
79  << " endTime " << stopt
80  << endl;
81 
82  np[isensor] = 0;
83  min[isensor] = +100;
84  max[isensor] = -100;
85  avg[isensor] = 0;
86  rms[isensor] = 0;
87 
88  AliSplineFit *f = o->GetFit();
89  if (f) {
90  np[isensor] = f->GetKnots();
91  if (debug)
92  cout << " np " << np[isensor] << endl;
93  Double_t *x = f->GetX();
94  Double_t *y0 = f->GetY0();
95  Double_t *y1 = f->GetY1();
96  for (Int_t i=0; i<np[isensor]; ++i) {
97  if (debug)
98  cout << " i " << i
99  << " x " << x[i]
100  << " y0 " << y0[i]
101  << " y1 " << y1[i]
102  << endl;
103  avg[isensor] += y0[i];
104  rms[isensor] += y0[i]*y0[i];
105  if (min[isensor]>y0[i]) min[isensor]=y0[i];
106  if (max[isensor]<y0[i]) max[isensor]=y0[i];
107  }
108  } else {
109  TGraph *g = o->GetGraph();
110  if (g) {
111  np[isensor] = g->GetN();
112  if (debug)
113  cout << " np " << np[isensor] << endl;
114  Double_t *x = g->GetX();
115  Double_t *y0 = g->GetY();
116  for (Int_t i=0; i<np[isensor]; i++) {
117  if (debug)
118  cout << " i " << i
119  << " x " << x[i]
120  << " y0 " << y0[i]
121  << endl;
122  avg[isensor] += y0[i];
123  rms[isensor] += y0[i]*y0[i];
124  if (min[isensor]>y0[i]) min[isensor]=y0[i];
125  if (max[isensor]<y0[i]) max[isensor]=y0[i];
126  }
127  }
128  }
129 
130  if (np[isensor]>0) {
131  avg[isensor] /= np[isensor];
132  if (np[isensor]>1) {
133  rms[isensor] /= np[isensor];
134  rms[isensor] = TMath::Sqrt(rms[isensor]-avg[isensor]*avg[isensor])/(np[isensor]-1);
135  } else {
136  rms[isensor] = 0;
137  }
138  if (debug)
139  cout << "Avg Temp: " << avg[isensor] << " RMS Temp: " << rms[isensor] << " Min Temp: " << min[isensor] << " Max Temp: " << max[isensor] << endl;
140  info->Set(isensor, avg[isensor], rms[isensor], min[isensor], max[isensor]);
141  avTime += startt + stopt;
142  if (startt<fTime)
143  fTime=startt;
144  if (stopt>lTime)
145  lTime=stopt;
146  }
147 
148  if (0)
149  cout << "Tree: " << runNb
150  << " " << isensor
151  << " " << o->GetSide()
152  << " " << o->GetSector()
153  << " " << o->GetNum()
154  << " " << o->GetStartTime()
155  << " " << o->GetEndTime()
156  << " " << avg[isensor]
157  << " " << rms[isensor]
158  << " " << max[isensor]
159  << " " << max[isensor] << endl;
160  }
161  Int_t nv = info->Nvalid();
162  if (nv>0) {
163  avTime /= 2*nv;
164  info->SetTime(avTime,fTime,lTime);
165  }
166  return info;
167 }
168 
170 {
171  TInfo *i = readOCDB_Temperature(runNb,1);
172  i->Print();
173  return;
174 }
175 #endif
double Double_t
Definition: External.C:58
Definition: TInfo.h:10
Int_t Nvalid() const
Definition: TInfo.h:38
int Int_t
Definition: External.C:63
unsigned int UInt_t
Definition: External.C:33
void SetTime(UInt_t av, UInt_t f, UInt_t l)
Definition: TInfo.h:44
TInfo * readOCDB_Temperature(Int_t runNb=286350, Bool_t debug=1)
void Print(Option_t *option="") const
Definition: TInfo.cxx:71
void testOCDB_Temperature(Int_t runNb=286350)
void Set(Int_t ns, Float_t avg, Float_t rms, Float_t min, Float_t max)
Definition: TInfo.h:42
bool Bool_t
Definition: External.C:53