]> git.uio.no Git - u/mrichter/AliRoot.git/blame - T0/AliT0CalibData.cxx
Take the modified track reference tree into account
[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//________________________________________________________________
29d3e0eb 44 AliT0CalibData::AliT0CalibData(): TNamed(),
45 fTimeDelayTVD(0),
46 fMeanT0(0),
47 fWalk(0),
48 fAmpLEDRec(0),
49 fLookup(0),
50 fNumberOfTRMs(0)
dc7ca31d 51
52{
53 //
54}
55
56//________________________________________________________________
94c27e4f 57AliT0CalibData::AliT0CalibData(const char* name):TNamed(),
58 fTimeDelayTVD(0),
59 fMeanT0(0),
60 fWalk(0),
74adb36a 61 fAmpLEDRec(0),
94c27e4f 62 fLookup(0),
63 fNumberOfTRMs(0)
dc7ca31d 64{
65 TString namst = "Calib_";
66 namst += name;
67 SetName(namst.Data());
68 SetTitle(namst.Data());
69
70}
71
72//________________________________________________________________
73AliT0CalibData::AliT0CalibData(const AliT0CalibData& calibda) :
94c27e4f 74 TNamed(calibda),
75 fTimeDelayTVD(0),
76 fMeanT0(0),
77 fWalk(0),
29d3e0eb 78 // fAmpLED(0),
74adb36a 79 fAmpLEDRec(0),
94c27e4f 80 fLookup(0),
81 fNumberOfTRMs(0)
82
dc7ca31d 83{
84// copy constructor
85 SetName(calibda.GetName());
86 SetTitle(calibda.GetName());
87
88
89}
90
91//________________________________________________________________
92AliT0CalibData &AliT0CalibData::operator =(const AliT0CalibData& calibda)
93{
94// assignment operator
95 SetName(calibda.GetName());
96 SetTitle(calibda.GetName());
97
98 return *this;
99}
100
101//________________________________________________________________
102AliT0CalibData::~AliT0CalibData()
103{
e0bba6cc 104 //
dc7ca31d 105}
106//________________________________________________________________
107void AliT0CalibData::Reset()
108{
109 memset(fTimeDelayCFD,1,24*sizeof(Float_t));
94c27e4f 110 memset(fTimeDelayDA,1,24*sizeof(Float_t));
dc7ca31d 111}
112
113
114//________________________________________________________________
115void AliT0CalibData::Print(Option_t*) const
116{
117
118 printf("\n ---- PM Arrays ----\n\n");
94c27e4f 119 printf(" Time delay CFD & DA\n");
120 for (Int_t i=0; i<24; i++) printf(" CFD %f DA %f ",fTimeDelayCFD[i], fTimeDelayDA[i]);
dc7ca31d 121}
122
e0bba6cc 123//________________________________________________________________
124void AliT0CalibData::PrintLookup(Option_t*, Int_t iTRM, Int_t iTDC, Int_t iChannel) const
125{
c41ceaac 126
127 AliT0LookUpKey* lookkey= new AliT0LookUpKey();
128 AliT0LookUpValue* lookvalue= new AliT0LookUpValue();
5325480c 129
130 cout<<" Number Of TRMs in setup "<<GetNumberOfTRMs()<<endl;
256d4943 131 iTRM=0; iTDC=0; Int_t chain=0; iChannel=0;
132
133 for (Int_t ik=0; ik<105; ik++){
134 lookvalue->SetTRM(iTRM);
135 lookvalue->SetTDC(iTDC);
136 lookvalue->SetChain(chain);
137 lookvalue->SetChannel(iChannel);
138
139 if (iChannel<6) iChannel +=2;
140 else {iChannel = 0; iTDC++;}
141 if(ik==57) { iTDC=0; iChannel=0; iTRM=1;}
142
143 printf(" AliT0CalibData::PrintLookup ::start GetValue %i %i %i %i\n",iTRM, iTDC,chain, iChannel);
144 lookkey = (AliT0LookUpKey*) fLookup.GetValue((TObject*)lookvalue);
145 cout<<" lookkey "<< lookkey<<endl;
146 // TString name= lookkey->GetChannelName();
147 // cout<<name.Data()<<endl;
148 if (lookkey)
149 {
150 TString name= lookkey->GetChannelName();
151 cout<<" lookup KEY!!! "<<name.Data()<<" "<<lookkey->GetKey()<<" VALUE "<<lookvalue->GetTRM()<<" "
152 <<lookvalue->GetTDC()<<" "
153 << lookvalue->GetChain()<<" "
c41ceaac 154 <<lookvalue->GetChannel()<<endl;
256d4943 155 }
156 }
c41ceaac 157
e0bba6cc 158}
dc7ca31d 159
160//________________________________________________________________
161void AliT0CalibData::SetTimeDelayCFD(Float_t* TimeDelay)
162{
163 if(TimeDelay) for(int t=0; t<24; t++) fTimeDelayCFD[t] = TimeDelay[t];
c41ceaac 164}
165 //________________________________________________________________
94c27e4f 166 void AliT0CalibData::SetTimeDelayDA(Float_t* TimeDelay)
dc7ca31d 167{
94c27e4f 168 if(TimeDelay) for(int t=0; t<24; t++) fTimeDelayDA[t] = TimeDelay[t];
dc7ca31d 169}
170
171
172//________________________________________________________________
ca7c0417 173void AliT0CalibData::SetWalk(Int_t ipmt)
dc7ca31d 174{
175
c41ceaac 176 Int_t mv, ps;
177 Int_t x[70000], y[70000], index[70000];
178 Float_t time[10000],amplitude[10000];
179 string buffer;
180 Bool_t down=false;
181
ca7c0417 182 const char * filename = gSystem->ExpandPathName("$ALICE_ROOT/T0/data/CFD-Amp.txt");
183 ifstream inFile(filename);
c41ceaac 184 if(!inFile) AliError(Form("Cannot open file %s !",filename));
185
5325480c 186 Int_t i=0;
c41ceaac 187 while(getline(inFile,buffer)){
188 inFile >> ps >> mv;
189
190 x[i]=ps; y[i]=mv;
191 i++;
192 }
193 inFile.close();
5325480c 194 cout<<" number of data "<<i<<endl;
c41ceaac 195
196 TMath::Sort(i, y, index,down);
197 Int_t amp=0, iin=0, isum=0, sum=0;
198 Int_t ind=0;
5325480c 199 for (Int_t ii=0; ii<i; ii++)
c41ceaac 200 {
201 ind=index[ii];
202 if(y[ind] == amp)
203 {
204 sum +=x[ind];
205 iin++;
c41ceaac 206 }
207 else
208 {
209 if(iin>0)
210 time[isum] = Float_t (sum/(iin));
211 else
212 time[isum] =Float_t (x[ind]);
213 amplitude[isum] = Float_t (amp);
214 amp=y[ind];
c41ceaac 215 iin=0;
216 isum++;
217 sum=0;
218 }
219 }
220
221 inFile.close();
222
223 TGraph* gr = new TGraph(isum, amplitude, time);
dc7ca31d 224 fWalk.AddAtAndExpand(gr,ipmt);
dc7ca31d 225}
226
227
228//________________________________________________________________
29d3e0eb 229/*
74adb36a 230void AliT0CalibData::SetAmpLED(Int_t ipmt)
dc7ca31d 231{
232 Float_t mv, ps;
233 Float_t x[100], y[100];
234 string buffer;
235
ca7c0417 236 const char * filename = gSystem->ExpandPathName("$ALICE_ROOT/T0/data/CFD-LED.txt");
dc7ca31d 237 ifstream inFile(filename);
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 TGraph* gr = new TGraph(i,x,y);
74adb36a 250 fAmpLED.AddAtAndExpand(gr,ipmt);
dc7ca31d 251
252}
29d3e0eb 253*/
dc7ca31d 254//________________________________________________________________
255
74adb36a 256void AliT0CalibData::SetAmpLEDRec(Int_t ipmt)
dc7ca31d 257{
258 Float_t mv, ps;
259 Float_t x[100], y[100];
260 string buffer;
261
74adb36a 262 const char * filename = gSystem->ExpandPathName("$ALICE_ROOT/T0/data/CFD-LED.txt");
ca7c0417 263 ifstream inFile(filename);
dc7ca31d 264 if(!inFile) {AliError(Form("Cannot open file %s !",filename));}
265
266 inFile >> mv>>ps;
267 Int_t i=0;
268
269 while(getline(inFile,buffer)){
270 x[i]=mv; y[i]=ps;
271 inFile >> mv >> ps;
272 i++;
273 }
274 inFile.close();
275 Float_t y1[100], x1[100];
276 for (Int_t ir=0; ir<i; ir++){
277 y1[ir]=y[i-ir]; x1[ir]=x[i-ir];}
278 TGraph* gr = new TGraph(i,y1,x1);
74adb36a 279 fAmpLEDRec.AddAtAndExpand(gr,ipmt);
dc7ca31d 280
281}
282
5325480c 283//________________________________________________________________
dc7ca31d 284
e0bba6cc 285void AliT0CalibData::ReadAsciiLookup(const Char_t *filename)
286{
c41ceaac 287 Int_t key, trm, tdc, chain, channel;
e0bba6cc 288
289 if(filename == 0){
290 AliError(Form("Please, specify file with database")) ;
291 return ;
292 }
293
e0bba6cc 294
295 ifstream lookup;
296 lookup.open(filename);
c41ceaac 297 if(!lookup)
298 {
29d3e0eb 299 AliError(Form("!!!!!!!!!!!!!!No look up table in CDB!" ));
300
c41ceaac 301 }
e0bba6cc 302 Char_t varname[11];
5325480c 303 Int_t ntrms;
304 if(lookup)
e0bba6cc 305 {
5325480c 306 lookup>>ntrms;
307 cout<<" !!!!!!! ntrms "<<ntrms<<endl;
308 // fNumberOfTRMs=ntrms;
309 SetNumberOfTRMs(ntrms);
310 while(!lookup.eof())
311 {
312 AliT0LookUpKey * lookkey= new AliT0LookUpKey();
313 AliT0LookUpValue * lookvalue= new AliT0LookUpValue();
314
315 lookup>>varname>>key>>trm>>chain>>tdc>>channel;
316 lookvalue->SetTRM(trm);
317 lookvalue->SetTDC(tdc);
318 lookvalue->SetChain(chain);
319 lookvalue->SetChannel(channel);
320 lookkey->SetKey(key);
256d4943 321 lookkey->SetChannelName(varname);
5325480c 322 cout<<"lookup "<<varname<<" "<<key<<" "<<trm<<" "<<chain<<" "<<tdc<<" "<<channel<<endl;
323
324 fLookup.Add((TObject*)lookvalue,(TObject*)lookkey);
325
326 }
327
328 lookup.close();
ca7c0417 329
e0bba6cc 330 }
e0bba6cc 331}
e0bba6cc 332//________________________________________________________________
333
334Int_t AliT0CalibData::GetChannel(Int_t trm, Int_t tdc, Int_t chain, Int_t channel)
335{
336
337 AliT0LookUpKey * lookkey;//= new AliT0LookUpKey();
338 AliT0LookUpValue * lookvalue= new AliT0LookUpValue(trm,tdc,chain,channel);
339
ca7c0417 340 lookkey = (AliT0LookUpKey*) fLookup.GetValue((TObject*)lookvalue);
341
e0bba6cc 342 return lookkey->GetKey();
343
344}
345