]> git.uio.no Git - u/mrichter/AliRoot.git/blame - T0/AliT0CalibData.cxx
Register new StraightLineSetXyzz classes.
[u/mrichter/AliRoot.git] / T0 / AliT0CalibData.cxx
CommitLineData
dc7ca31d 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16/* $Id$ */
17
18///////////////////////////////////////////////////////////////////////////////
19// //
20// class for T0 calibration TM-AC-AM_6-02-2006 //
21// //
22///////////////////////////////////////////////////////////////////////////////
23
dc7ca31d 24#include "AliT0CalibData.h"
e0bba6cc 25#include "AliT0LookUpValue.h"
dc7ca31d 26#include "AliLog.h"
dc7ca31d 27
7d95281b 28#include <TCanvas.h>
29#include <TObjString.h>
30#include <TObjArray.h>
31#include <TGraph.h>
32#include <TFile.h>
33#include <TAxis.h>
34#include <TH2F.h>
35#include <TMath.h>
ca7c0417 36#include <TSystem.h>
7d95281b 37#include <Riostream.h>
dc7ca31d 38
7d95281b 39#include <string>
dc7ca31d 40
41ClassImp(AliT0CalibData)
42
43//________________________________________________________________
44 AliT0CalibData::AliT0CalibData(): TNamed()
45
46{
47 //
48}
49
50//________________________________________________________________
51AliT0CalibData::AliT0CalibData(const char* name):TNamed(),fTimeDelayTVD(0),fWalk(),fSlewingLED(),fSlewingRec()
52{
53 TString namst = "Calib_";
54 namst += name;
55 SetName(namst.Data());
56 SetTitle(namst.Data());
57
58}
59
60//________________________________________________________________
61AliT0CalibData::AliT0CalibData(const AliT0CalibData& calibda) :
62 TNamed(calibda),fTimeDelayTVD(0),fWalk(),fSlewingLED(),fSlewingRec()
63{
64// copy constructor
65 SetName(calibda.GetName());
66 SetTitle(calibda.GetName());
67
68
69}
70
71//________________________________________________________________
72AliT0CalibData &AliT0CalibData::operator =(const AliT0CalibData& calibda)
73{
74// assignment operator
75 SetName(calibda.GetName());
76 SetTitle(calibda.GetName());
77
78 return *this;
79}
80
81//________________________________________________________________
82AliT0CalibData::~AliT0CalibData()
83{
e0bba6cc 84 //
dc7ca31d 85}
86//________________________________________________________________
87void AliT0CalibData::Reset()
88{
89 memset(fTimeDelayCFD,1,24*sizeof(Float_t));
90 memset(fTimeDelayLED,1,24*sizeof(Float_t));
dc7ca31d 91}
92
93
94//________________________________________________________________
95void AliT0CalibData::Print(Option_t*) const
96{
97
98 printf("\n ---- PM Arrays ----\n\n");
5325480c 99 printf(" Time delay CFD & LED\n");
100 for (Int_t i=0; i<24; i++) printf(" CFD %f LED %f ",fTimeDelayCFD[i], fTimeDelayLED[i]);
dc7ca31d 101}
102
e0bba6cc 103//________________________________________________________________
104void AliT0CalibData::PrintLookup(Option_t*, Int_t iTRM, Int_t iTDC, Int_t iChannel) const
105{
c41ceaac 106
107 AliT0LookUpKey* lookkey= new AliT0LookUpKey();
108 AliT0LookUpValue* lookvalue= new AliT0LookUpValue();
5325480c 109
110 cout<<" Number Of TRMs in setup "<<GetNumberOfTRMs()<<endl;
c41ceaac 111 lookvalue->SetTRM(iTRM);
112 lookvalue->SetTDC(iTDC);
113 lookvalue->SetChain(0);
114 lookvalue->SetChannel(iChannel);
5325480c 115
c41ceaac 116
117 printf(" AliT0CalibData::PrintLookup ::start GetValue %i %i %i \n",iTRM, iTDC, iChannel);
118 lookkey = (AliT0LookUpKey*) fLookup.GetValue((TObject*)lookvalue);
119
120 cout<<" AliT0CalibData::PrintLookup :: lookkey "<< lookkey<<endl;
121 if (lookkey)
122 {
123 cout<<" lookup KEY!!! "<<lookkey->GetKey()<<" VALUE "<<lookvalue->GetTRM()<<" "
124 <<lookvalue->GetTDC()<<" "
125 << lookvalue->GetChain()<<" "
126 <<lookvalue->GetChannel()<<endl;
127 }
128
129
e0bba6cc 130}
dc7ca31d 131
132//________________________________________________________________
133void AliT0CalibData::SetTimeDelayCFD(Float_t* TimeDelay)
134{
135 if(TimeDelay) for(int t=0; t<24; t++) fTimeDelayCFD[t] = TimeDelay[t];
c41ceaac 136}
137 //________________________________________________________________
138 void AliT0CalibData::SetTimeDelayLED(Float_t* TimeDelay)
dc7ca31d 139{
140 if(TimeDelay) for(int t=0; t<24; t++) fTimeDelayLED[t] = TimeDelay[t];
dc7ca31d 141}
142
143
144//________________________________________________________________
ca7c0417 145void AliT0CalibData::SetWalk(Int_t ipmt)
dc7ca31d 146{
147
c41ceaac 148 Int_t mv, ps;
149 Int_t x[70000], y[70000], index[70000];
150 Float_t time[10000],amplitude[10000];
151 string buffer;
152 Bool_t down=false;
153
ca7c0417 154 const char * filename = gSystem->ExpandPathName("$ALICE_ROOT/T0/data/CFD-Amp.txt");
155 ifstream inFile(filename);
c41ceaac 156 if(!inFile) AliError(Form("Cannot open file %s !",filename));
157
5325480c 158 Int_t i=0;
c41ceaac 159 while(getline(inFile,buffer)){
160 inFile >> ps >> mv;
161
162 x[i]=ps; y[i]=mv;
163 i++;
164 }
165 inFile.close();
5325480c 166 cout<<" number of data "<<i<<endl;
c41ceaac 167
168 TMath::Sort(i, y, index,down);
169 Int_t amp=0, iin=0, isum=0, sum=0;
170 Int_t ind=0;
5325480c 171 for (Int_t ii=0; ii<i; ii++)
c41ceaac 172 {
173 ind=index[ii];
174 if(y[ind] == amp)
175 {
176 sum +=x[ind];
177 iin++;
178 // cout<<ii<<" "<<ind<<" "<<y[ind]<<" "<<x[ind]<<" "<<sum<<endl;
179 }
180 else
181 {
182 if(iin>0)
183 time[isum] = Float_t (sum/(iin));
184 else
185 time[isum] =Float_t (x[ind]);
186 amplitude[isum] = Float_t (amp);
187 amp=y[ind];
5325480c 188 // cout<<ii<<" "<<ind<<" "<<y[ind]<<" "<<x[ind]<<" iin "<<iin<<" mean "<<time[isum]<<" amp "<< amplitude[isum]<<" "<<isum<<endl;
c41ceaac 189 iin=0;
190 isum++;
191 sum=0;
192 }
193 }
194
195 inFile.close();
196
197 TGraph* gr = new TGraph(isum, amplitude, time);
dc7ca31d 198 fWalk.AddAtAndExpand(gr,ipmt);
dc7ca31d 199}
200
201
202//________________________________________________________________
203
ca7c0417 204void AliT0CalibData::SetSlewingLED(Int_t ipmt)
dc7ca31d 205{
206 Float_t mv, ps;
207 Float_t x[100], y[100];
208 string buffer;
209
ca7c0417 210 const char * filename = gSystem->ExpandPathName("$ALICE_ROOT/T0/data/CFD-LED.txt");
dc7ca31d 211 ifstream inFile(filename);
212 if(!inFile) {AliError(Form("Cannot open file %s !",filename));}
213
214 inFile >> mv>>ps;
215 Int_t i=0;
216
217 while(getline(inFile,buffer)){
218 x[i]=mv; y[i]=ps;
219 inFile >> mv >> ps;
220 i++;
221 }
222 inFile.close();
223 TGraph* gr = new TGraph(i,x,y);
224 fSlewingLED.AddAtAndExpand(gr,ipmt);
225
226}
227
228//________________________________________________________________
229
ca7c0417 230void AliT0CalibData::SetSlewingRec(Int_t ipmt)
dc7ca31d 231{
232 Float_t mv, ps;
233 Float_t x[100], y[100];
234 string buffer;
235
5325480c 236 const char * filename = gSystem->ExpandPathName("$ALICE_ROOT/T0/data/CFD-LED.root");
ca7c0417 237 ifstream inFile(filename);
dc7ca31d 238 if(!inFile) {AliError(Form("Cannot open file %s !",filename));}
239
240 inFile >> mv>>ps;
241 Int_t i=0;
242
243 while(getline(inFile,buffer)){
244 x[i]=mv; y[i]=ps;
245 inFile >> mv >> ps;
246 i++;
247 }
248 inFile.close();
249 Float_t y1[100], x1[100];
250 for (Int_t ir=0; ir<i; ir++){
251 y1[ir]=y[i-ir]; x1[ir]=x[i-ir];}
252 TGraph* gr = new TGraph(i,y1,x1);
253 fSlewingRec.AddAtAndExpand(gr,ipmt);
254
255}
256
5325480c 257//________________________________________________________________
dc7ca31d 258
e0bba6cc 259void AliT0CalibData::ReadAsciiLookup(const Char_t *filename)
260{
c41ceaac 261 Int_t key, trm, tdc, chain, channel;
e0bba6cc 262
263 if(filename == 0){
264 AliError(Form("Please, specify file with database")) ;
265 return ;
266 }
267
e0bba6cc 268
269 ifstream lookup;
270 lookup.open(filename);
c41ceaac 271 if(!lookup)
272 {
273 // AliLog(Form("Cannot open file %s ! Getting hardcoded value",filename));
274
5325480c 275 // fNumberOfTRMs = 2;
276 SetNumberOfTRMs(2);
277 trm=0; tdc=0; chain=0; channel=0; key=0;
278 for (Int_t ik=0; ik<108; ik++)
279 {
280 AliT0LookUpKey * lookkey= new AliT0LookUpKey();
281 AliT0LookUpValue * lookvalue= new AliT0LookUpValue();
282
283 lookvalue->SetTRM(trm);
284 lookvalue->SetTDC(tdc);
285 lookvalue->SetChain(chain);
286 lookvalue->SetChannel(channel);
287 lookkey->SetKey(ik);
288 if(ik>53) { trm=1; tdc=0; channel=0;}
289 if (channel<7) channel +=2;
290 else {channel = 0; tdc++;}
291 }
c41ceaac 292 }
e0bba6cc 293 Char_t varname[11];
5325480c 294 Int_t ntrms;
295 if(lookup)
e0bba6cc 296 {
5325480c 297 lookup>>ntrms;
298 cout<<" !!!!!!! ntrms "<<ntrms<<endl;
299 // fNumberOfTRMs=ntrms;
300 SetNumberOfTRMs(ntrms);
301 while(!lookup.eof())
302 {
303 AliT0LookUpKey * lookkey= new AliT0LookUpKey();
304 AliT0LookUpValue * lookvalue= new AliT0LookUpValue();
305
306 lookup>>varname>>key>>trm>>chain>>tdc>>channel;
307 lookvalue->SetTRM(trm);
308 lookvalue->SetTDC(tdc);
309 lookvalue->SetChain(chain);
310 lookvalue->SetChannel(channel);
311 lookkey->SetKey(key);
312 cout<<"lookup "<<varname<<" "<<key<<" "<<trm<<" "<<chain<<" "<<tdc<<" "<<channel<<endl;
313
314 fLookup.Add((TObject*)lookvalue,(TObject*)lookkey);
315
316 }
317
318 lookup.close();
ca7c0417 319
e0bba6cc 320 }
e0bba6cc 321}
e0bba6cc 322//________________________________________________________________
323
324Int_t AliT0CalibData::GetChannel(Int_t trm, Int_t tdc, Int_t chain, Int_t channel)
325{
326
327 AliT0LookUpKey * lookkey;//= new AliT0LookUpKey();
328 AliT0LookUpValue * lookvalue= new AliT0LookUpValue(trm,tdc,chain,channel);
329
ca7c0417 330 lookkey = (AliT0LookUpKey*) fLookup.GetValue((TObject*)lookvalue);
331
e0bba6cc 332 return lookkey->GetKey();
333
334}
335