1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 // class for T0 calibration TM-AC-AM_6-02-2006 //
22 ///////////////////////////////////////////////////////////////////////////////
30 #include "AliT0CalibData.h"
31 #include "AliT0LookUpValue.h"
32 #include "TObjArray.h"
36 #include "TObjString.h"
43 ClassImp(AliT0CalibData)
45 //________________________________________________________________
46 AliT0CalibData::AliT0CalibData(): TNamed()
52 //________________________________________________________________
53 AliT0CalibData::AliT0CalibData(const char* name):TNamed(),fTimeDelayTVD(0),fWalk(),fSlewingLED(),fSlewingRec()
55 TString namst = "Calib_";
57 SetName(namst.Data());
58 SetTitle(namst.Data());
62 //________________________________________________________________
63 AliT0CalibData::AliT0CalibData(const AliT0CalibData& calibda) :
64 TNamed(calibda),fTimeDelayTVD(0),fWalk(),fSlewingLED(),fSlewingRec()
67 SetName(calibda.GetName());
68 SetTitle(calibda.GetName());
73 //________________________________________________________________
74 AliT0CalibData &AliT0CalibData::operator =(const AliT0CalibData& calibda)
76 // assignment operator
77 SetName(calibda.GetName());
78 SetTitle(calibda.GetName());
83 //________________________________________________________________
84 AliT0CalibData::~AliT0CalibData()
88 //________________________________________________________________
89 void AliT0CalibData::Reset()
91 memset(fTimeDelayCFD,1,24*sizeof(Float_t));
92 memset(fTimeDelayLED,1,24*sizeof(Float_t));
96 //________________________________________________________________
97 void AliT0CalibData::Print(Option_t*) const
100 printf("\n ---- PM Arrays ----\n\n");
101 printf(" Time delay CFD \n");
102 for (Int_t i=0; i<24; i++) printf(" %f",fTimeDelayCFD[i]);
105 //________________________________________________________________
106 void AliT0CalibData::PrintLookup(Option_t*, Int_t iTRM, Int_t iTDC, Int_t iChannel) const
109 AliT0LookUpKey* lookkey= new AliT0LookUpKey();
110 AliT0LookUpValue* lookvalue= new AliT0LookUpValue();
112 lookvalue->SetTRM(iTRM);
113 lookvalue->SetTDC(iTDC);
114 lookvalue->SetChain(0);
115 lookvalue->SetChannel(iChannel);
117 printf(" AliT0CalibData::PrintLookup ::start GetValue %i %i %i \n",iTRM, iTDC, iChannel);
118 lookkey = (AliT0LookUpKey*) fLookup.GetValue((TObject*)lookvalue);
120 cout<<" AliT0CalibData::PrintLookup :: lookkey "<< lookkey<<endl;
123 cout<<" lookup KEY!!! "<<lookkey->GetKey()<<" VALUE "<<lookvalue->GetTRM()<<" "
124 <<lookvalue->GetTDC()<<" "
125 << lookvalue->GetChain()<<" "
126 <<lookvalue->GetChannel()<<endl;
132 //________________________________________________________________
133 void AliT0CalibData::SetTimeDelayCFD(Float_t* TimeDelay)
135 if(TimeDelay) for(int t=0; t<24; t++) fTimeDelayCFD[t] = TimeDelay[t];
137 //________________________________________________________________
138 void AliT0CalibData::SetTimeDelayLED(Float_t* TimeDelay)
140 if(TimeDelay) for(int t=0; t<24; t++) fTimeDelayLED[t] = TimeDelay[t];
144 //________________________________________________________________
145 void AliT0CalibData::SetWalk(Int_t ipmt, const Char_t *filename)
149 Int_t x[70000], y[70000], index[70000];
150 Float_t time[10000],amplitude[10000];
154 ifstream inFile("data/CFD-Amp.txt");
155 if(!inFile) AliError(Form("Cannot open file %s !",filename));
157 Int_t i=0, i1=0, i2=0;
158 while(getline(inFile,buffer)){
166 TMath::Sort(i, y, index,down);
167 Int_t amp=0, iin=0, isum=0, sum=0;
169 for (Int_t ii=0; ii<70000; ii++)
176 // cout<<ii<<" "<<ind<<" "<<y[ind]<<" "<<x[ind]<<" "<<sum<<endl;
181 time[isum] = Float_t (sum/(iin));
183 time[isum] =Float_t (x[ind]);
184 amplitude[isum] = Float_t (amp);
186 cout<<ii<<" "<<ind<<" "<<y[ind]<<" "<<x[ind]<<" iin "<<iin<<" mean "<<time[isum]<<" amp "<< amplitude[isum]<<" "<<isum<<endl;
195 TGraph* gr = new TGraph(isum, amplitude, time);
196 fWalk.AddAtAndExpand(gr,ipmt);
200 //________________________________________________________________
202 void AliT0CalibData::SetSlewingLED(Int_t ipmt,const Char_t *filename)
205 Float_t x[100], y[100];
208 ifstream inFile(filename);
209 if(!inFile) {AliError(Form("Cannot open file %s !",filename));}
214 while(getline(inFile,buffer)){
220 TGraph* gr = new TGraph(i,x,y);
221 fSlewingLED.AddAtAndExpand(gr,ipmt);
225 //________________________________________________________________
227 void AliT0CalibData::SetSlewingRec(Int_t ipmt,const Char_t *filename)
230 Float_t x[100], y[100];
233 ifstream inFile(filename);
234 if(!inFile) {AliError(Form("Cannot open file %s !",filename));}
239 while(getline(inFile,buffer)){
245 Float_t y1[100], x1[100];
246 for (Int_t ir=0; ir<i; ir++){
247 y1[ir]=y[i-ir]; x1[ir]=x[i-ir];}
248 TGraph* gr = new TGraph(i,y1,x1);
249 fSlewingRec.AddAtAndExpand(gr,ipmt);
254 void AliT0CalibData::ReadAsciiLookup(const Char_t *filename)
256 Int_t key, trm, tdc, chain, channel;
259 AliError(Form("Please, specify file with database")) ;
263 // AliT0LookUpKey * lookkey= new AliT0LookUpKey();
264 // AliT0LookUpValue * lookvalue= new AliT0LookUpValue();
267 lookup.open(filename);
270 // AliLog(Form("Cannot open file %s ! Getting hardcoded value",filename));
272 trm=0; tdc=0; chain=0; channel=0; key=0;
273 for (Int_t ik=0; ik<108; ik++)
275 AliT0LookUpKey * lookkey= new AliT0LookUpKey();
276 AliT0LookUpValue * lookvalue= new AliT0LookUpValue();
278 lookvalue->SetTRM(trm);
279 lookvalue->SetTDC(tdc);
280 lookvalue->SetChain(chain);
281 lookvalue->SetChannel(channel);
283 if(ik>53) { trm=1; tdc=0; channel=0;}
284 if (channel<7) channel +=2;
285 else {channel = 0; tdc++;}
289 // while(lookup.eof())
291 for (Int_t i=0; i<108; i++)
293 AliT0LookUpKey * lookkey= new AliT0LookUpKey();
294 AliT0LookUpValue * lookvalue= new AliT0LookUpValue();
296 lookup>>varname>>key>>trm>>chain>>tdc>>channel;
297 lookvalue->SetTRM(trm);
298 lookvalue->SetTDC(tdc);
299 lookvalue->SetChain(chain);
300 lookvalue->SetChannel(channel);
301 lookkey->SetKey(key);
303 // cout<<"TRM="<<trm<<" TDC="<<tdc<<" chain="<<chain<<" channel="<<channel<<" key="<<key<<endl;
305 cout<<"AliT0CalibData:: "<<varname<<" "<<key<<" "<<trm<<" "<<chain<<" "<<tdc<<" "<<channel<<endl;
307 // fLookup.Add((TObject*)lookkey,(TObject*)lookvalue);
308 // ar_key.AddAt(lookkey,i);
309 // ar_val.AddAt(lookvalue,i);
311 fLookup.Add((TObject*)lookvalue,(TObject*)lookkey);
319 //________________________________________________________________
321 Int_t AliT0CalibData::GetChannel(Int_t trm, Int_t tdc, Int_t chain, Int_t channel)
324 AliT0LookUpKey * lookkey;//= new AliT0LookUpKey();
325 AliT0LookUpValue * lookvalue= new AliT0LookUpValue(trm,tdc,chain,channel);
327 lookkey = (AliT0LookUpKey*) fLookup.GetValue((TObject*)lookvalue);
328 cout<<"AliT0CalibData:: key "<<lookkey->GetKey()<<endl;
329 return lookkey->GetKey();