]> git.uio.no Git - u/mrichter/AliRoot.git/blame - T0/AliT0DataDCS.cxx
calibration data
[u/mrichter/AliRoot.git] / T0 / AliT0DataDCS.cxx
CommitLineData
dc7ca31d 1#include "AliT0DataDCS.h"
2
3#include "AliCDBMetaData.h"
4#include "AliDCSValue.h"
5#include "AliLog.h"
6
7#include <TTimeStamp.h>
8#include <TObjString.h>
9#include <TH2F.h>
10#include <TProfile.h>
11#include <TGraph.h>
12#include <TDatime.h>
13#include <TStyle.h>
14#include <TCanvas.h>
15
16ClassImp(AliT0DataDCS)
17
18//---------------------------------------------------------------
19AliT0DataDCS::AliT0DataDCS():
20 TObject(),
21 fRun(0),
22 fStartTime(0),
23 fEndTime(0),
24 fGraphs("TGraph",kNGraphs),
25 fIsProcessed(kFALSE)
26{
27 for(int i=0;i<kNHistos;i++) fHv[i]=0x0;
28 fFunc = 0;
29}
30
31//---------------------------------------------------------------
32AliT0DataDCS::AliT0DataDCS(Int_t nRun, UInt_t startTime, UInt_t endTime):
33 TObject(),
34 fRun(nRun),
35 fStartTime(startTime),
36 fEndTime(endTime),
37 fGraphs("TGraph",kNGraphs),
38 fIsProcessed(kFALSE)
39{
40 AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", nRun,
41 TTimeStamp(startTime).AsString(),
42 TTimeStamp(endTime).AsString()));
43
44 fFunc = 0;
45 Init();
46
47}
48
49//---------------------------------------------------------------
50AliT0DataDCS::~AliT0DataDCS() {
51
52 for(int i=0;i<kNHistos;i++) {delete fHv[i]; fHv[i]=0;}
53 fGraphs.Clear("C");
54 fFunc=0;
55}
56
57//---------------------------------------------------------------
58void AliT0DataDCS::ProcessData(TMap& aliasMap){
59
60 if(!(fHv[0])) Init();
61
62 TObjArray *aliasArr;
63 AliDCSValue* aValue;
64 for(int j=0; j<kNAliases; j++){
65 aliasArr = (TObjArray*) aliasMap.GetValue(fAliasNames[j].Data());
66 if(!aliasArr){
67 AliError(Form("Alias %s not found!", fAliasNames[j].Data()));
68 continue;
69 }
70 Introduce(j, aliasArr);
71
72 if(aliasArr->GetEntries()<2){
73 AliError(Form("Alias %s has just %d entries!",
74 fAliasNames[j].Data(),aliasArr->GetEntries()));
75 continue;
76 }
77
78 TIter iterarray(aliasArr);
79
80 Double_t *time = new Double_t[aliasArr->GetEntries()];
81 Double_t *val = new Double_t[aliasArr->GetEntries()];
82
83 UInt_t ne=0;
84 while ((aValue = (AliDCSValue*) iterarray.Next())) {
85
86 val[ne] = aValue->GetFloat();
87 time[ne] = (Double_t) (aValue->GetTimeStamp());
88 // fill histos (alias 0-2)
89 if(j < 3) fHv[j]->Fill(val[ne]);
90 ne++;
91 }
92 // fill graphs (alias 3-5)
93 if(j >= 3) CreateGraph(j, aliasArr->GetEntries(), time, val);
94 delete[] val;
95 delete[] time;
96 }
97
98 // calculate mean and rms of the first two histos
99 for(int i=0;i<kNHistos;i++){
100 fMean[i] = fHv[i]->GetMean();
101 fWidth[i] = fHv[i]->GetRMS();
102 }
103
104 // pol1 fit of the first graph
105 if(fGraphs.GetEntries() > 0){
106 ((TGraph*) fGraphs.UncheckedAt(0))->Fit("pol1");
107 fFunc = ((TGraph*) fGraphs.UncheckedAt(0))->GetFunction("pol1");
108 }
109
110 fIsProcessed=kTRUE;
111
112
113}
114
115//---------------------------------------------------------------
116void AliT0DataDCS::Init(){
117
118 TH1::AddDirectory(kFALSE);
119
120 fGraphs.SetOwner(1);
121
122 for(int i=0;i<kNAliases;i++){
123 fAliasNames[i] = "DCSAlias";
124 fAliasNames[i] += i;
125 }
126
127 for(int i=0;i<kNHistos;i++){
128 fHv[i] = new TH1F(fAliasNames[i].Data(),fAliasNames[i].Data(), 20, kHvMin, kHvMax);
129 fHv[i]->GetXaxis()->SetTitle("Hv");
130 }
131}
132
133//---------------------------------------------------------------
134void AliT0DataDCS::Introduce(UInt_t numAlias, const TObjArray* aliasArr){
135
136 int entries=aliasArr->GetEntries();
137 AliInfo(Form("************ Alias: %s **********",fAliasNames[numAlias].Data()));
138 AliInfo(Form(" %d DP values collected",entries));
139
140}
141
142//---------------------------------------------------------------
143void AliT0DataDCS::CreateGraph(int i, int dim, const Double_t *x, const Double_t *y)
144{
145
146 TGraph *gr = new(fGraphs[fGraphs.GetEntriesFast()]) TGraph(dim, x, y);
147
148 gr->GetXaxis()->SetTimeDisplay(1);
149 gr->SetTitle(fAliasNames[i].Data());
150
151 AliInfo(Form("Array entries: %d",fGraphs.GetEntriesFast()));
152
153
154}
155
156//---------------------------------------------------------------
157void AliT0DataDCS::Draw(const Option_t* /*option*/)
158{
159// Draw all histos and graphs
160
161 if(!fIsProcessed) return;
162
163 TCanvas *ch;
164 TString canvasHistoName="Histos";
165 ch=new TCanvas(canvasHistoName,canvasHistoName,20,20,600,600);
166 ch->Divide(2,2);
167 ch->cd(1);
168 fHv[0]->Draw();
169 ch->cd(2);
170 fHv[1]->Draw();
171 ch->cd(3);
172 fHv[2]->Draw();
173
174
175 if(fGraphs.GetEntries() == 0) return;
176
177 TCanvas *cg;
178 TString canvasGraphName="Graphs";
179 cg=new TCanvas(canvasGraphName,canvasGraphName,40,40,600,600);
180 cg->Divide(2,2);
181 cg->cd(1);
182 ((TGraph*) fGraphs.UncheckedAt(0))->Draw("alp");
183
184 cg->cd(2);
185 ((TGraph*) fGraphs.UncheckedAt(1))->Draw("alp");
186 cg->cd(3);
187 ((TGraph*) fGraphs.UncheckedAt(2))->Draw("alp");
188
189 if(fFunc){
190 cg->cd(4);
191 fFunc->Draw("l");
192 }
193
194}
195