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 ///////////////////////////////////////////////////////////////////////////////
24 #include "AliT0CalibData.h"
25 #include "AliT0LookUpValue.h"
29 #include <TObjString.h>
30 #include <TObjArray.h>
37 #include <Riostream.h>
41 ClassImp(AliT0CalibData)
43 //________________________________________________________________
44 AliT0CalibData::AliT0CalibData(): TNamed()
50 //________________________________________________________________
51 AliT0CalibData::AliT0CalibData(const char* name):TNamed(),fTimeDelayTVD(0),fWalk(),fSlewingLED(),fSlewingRec()
53 TString namst = "Calib_";
55 SetName(namst.Data());
56 SetTitle(namst.Data());
60 //________________________________________________________________
61 AliT0CalibData::AliT0CalibData(const AliT0CalibData& calibda) :
62 TNamed(calibda),fTimeDelayTVD(0),fWalk(),fSlewingLED(),fSlewingRec()
65 SetName(calibda.GetName());
66 SetTitle(calibda.GetName());
71 //________________________________________________________________
72 AliT0CalibData &AliT0CalibData::operator =(const AliT0CalibData& calibda)
74 // assignment operator
75 SetName(calibda.GetName());
76 SetTitle(calibda.GetName());
81 //________________________________________________________________
82 AliT0CalibData::~AliT0CalibData()
86 //________________________________________________________________
87 void AliT0CalibData::Reset()
89 memset(fTimeDelayCFD,1,24*sizeof(Float_t));
90 memset(fTimeDelayLED,1,24*sizeof(Float_t));
94 //________________________________________________________________
95 void AliT0CalibData::Print(Option_t*) const
98 printf("\n ---- PM Arrays ----\n\n");
99 printf(" Time delay CFD \n");
100 for (Int_t i=0; i<24; i++) printf(" %f",fTimeDelayCFD[i]);
103 //________________________________________________________________
104 void AliT0CalibData::PrintLookup(Option_t*, Int_t iTRM, Int_t iTDC, Int_t iChannel) const
107 AliT0LookUpKey* lookkey= new AliT0LookUpKey();
108 AliT0LookUpValue* lookvalue= new AliT0LookUpValue();
110 lookvalue->SetTRM(iTRM);
111 lookvalue->SetTDC(iTDC);
112 lookvalue->SetChain(0);
113 lookvalue->SetChannel(iChannel);
115 printf(" AliT0CalibData::PrintLookup ::start GetValue %i %i %i \n",iTRM, iTDC, iChannel);
116 lookkey = (AliT0LookUpKey*) fLookup.GetValue((TObject*)lookvalue);
118 cout<<" AliT0CalibData::PrintLookup :: lookkey "<< lookkey<<endl;
121 cout<<" lookup KEY!!! "<<lookkey->GetKey()<<" VALUE "<<lookvalue->GetTRM()<<" "
122 <<lookvalue->GetTDC()<<" "
123 << lookvalue->GetChain()<<" "
124 <<lookvalue->GetChannel()<<endl;
130 //________________________________________________________________
131 void AliT0CalibData::SetTimeDelayCFD(Float_t* TimeDelay)
133 if(TimeDelay) for(int t=0; t<24; t++) fTimeDelayCFD[t] = TimeDelay[t];
135 //________________________________________________________________
136 void AliT0CalibData::SetTimeDelayLED(Float_t* TimeDelay)
138 if(TimeDelay) for(int t=0; t<24; t++) fTimeDelayLED[t] = TimeDelay[t];
142 //________________________________________________________________
143 void AliT0CalibData::SetWalk(Int_t ipmt)
147 Int_t x[70000], y[70000], index[70000];
148 Float_t time[10000],amplitude[10000];
152 const char * filename = gSystem->ExpandPathName("$ALICE_ROOT/T0/data/CFD-Amp.txt");
153 ifstream inFile(filename);
154 if(!inFile) AliError(Form("Cannot open file %s !",filename));
156 Int_t i=0, i1=0, i2=0;
157 while(getline(inFile,buffer)){
165 TMath::Sort(i, y, index,down);
166 Int_t amp=0, iin=0, isum=0, sum=0;
168 for (Int_t ii=0; ii<70000; ii++)
175 // cout<<ii<<" "<<ind<<" "<<y[ind]<<" "<<x[ind]<<" "<<sum<<endl;
180 time[isum] = Float_t (sum/(iin));
182 time[isum] =Float_t (x[ind]);
183 amplitude[isum] = Float_t (amp);
185 cout<<ii<<" "<<ind<<" "<<y[ind]<<" "<<x[ind]<<" iin "<<iin<<" mean "<<time[isum]<<" amp "<< amplitude[isum]<<" "<<isum<<endl;
194 TGraph* gr = new TGraph(isum, amplitude, time);
195 fWalk.AddAtAndExpand(gr,ipmt);
199 //________________________________________________________________
201 void AliT0CalibData::SetSlewingLED(Int_t ipmt)
204 Float_t x[100], y[100];
207 const char * filename = gSystem->ExpandPathName("$ALICE_ROOT/T0/data/CFD-LED.txt");
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)
230 Float_t x[100], y[100];
233 const char * filename = gSystem->ExpandPathName("$ALICE_ROOT/T0/data/re.root");
234 ifstream inFile(filename);
235 if(!inFile) {AliError(Form("Cannot open file %s !",filename));}
240 while(getline(inFile,buffer)){
246 Float_t y1[100], x1[100];
247 for (Int_t ir=0; ir<i; ir++){
248 y1[ir]=y[i-ir]; x1[ir]=x[i-ir];}
249 TGraph* gr = new TGraph(i,y1,x1);
250 fSlewingRec.AddAtAndExpand(gr,ipmt);
255 void AliT0CalibData::ReadAsciiLookup(const Char_t *filename)
257 Int_t key, trm, tdc, chain, channel;
260 AliError(Form("Please, specify file with database")) ;
266 lookup.open(filename);
269 // AliLog(Form("Cannot open file %s ! Getting hardcoded value",filename));
271 trm=0; tdc=0; chain=0; channel=0; key=0;
272 for (Int_t ik=0; ik<108; ik++)
274 AliT0LookUpKey * lookkey= new AliT0LookUpKey();
275 AliT0LookUpValue * lookvalue= new AliT0LookUpValue();
277 lookvalue->SetTRM(trm);
278 lookvalue->SetTDC(tdc);
279 lookvalue->SetChain(chain);
280 lookvalue->SetChannel(channel);
282 if(ik>53) { trm=1; tdc=0; channel=0;}
283 if (channel<7) channel +=2;
284 else {channel = 0; tdc++;}
288 // while(lookup.eof())
290 for (Int_t i=0; i<108; i++)
292 AliT0LookUpKey * lookkey= new AliT0LookUpKey();
293 AliT0LookUpValue * lookvalue= new AliT0LookUpValue();
295 lookup>>varname>>key>>trm>>chain>>tdc>>channel;
296 lookvalue->SetTRM(trm);
297 lookvalue->SetTDC(tdc);
298 lookvalue->SetChain(chain);
299 lookvalue->SetChannel(channel);
300 lookkey->SetKey(key);
303 fLookup.Add((TObject*)lookvalue,(TObject*)lookkey);
311 //________________________________________________________________
313 Int_t AliT0CalibData::GetChannel(Int_t trm, Int_t tdc, Int_t chain, Int_t channel)
316 AliT0LookUpKey * lookkey;//= new AliT0LookUpKey();
317 AliT0LookUpValue * lookvalue= new AliT0LookUpValue(trm,tdc,chain,channel);
319 lookkey = (AliT0LookUpKey*) fLookup.GetValue((TObject*)lookvalue);
321 return lookkey->GetKey();