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(),
60 TString namst = "Calib_";
62 SetName(namst.Data());
63 SetTitle(namst.Data());
67 //________________________________________________________________
68 AliT0CalibData::AliT0CalibData(const AliT0CalibData& calibda) :
80 SetName(calibda.GetName());
81 SetTitle(calibda.GetName());
86 //________________________________________________________________
87 AliT0CalibData &AliT0CalibData::operator =(const AliT0CalibData& calibda)
89 // assignment operator
90 SetName(calibda.GetName());
91 SetTitle(calibda.GetName());
96 //________________________________________________________________
97 AliT0CalibData::~AliT0CalibData()
101 //________________________________________________________________
102 void AliT0CalibData::Reset()
104 memset(fTimeDelayCFD,1,24*sizeof(Float_t));
105 memset(fTimeDelayDA,1,24*sizeof(Float_t));
109 //________________________________________________________________
110 void AliT0CalibData::Print(Option_t*) const
113 printf("\n ---- PM Arrays ----\n\n");
114 printf(" Time delay CFD & DA\n");
115 for (Int_t i=0; i<24; i++) printf(" CFD %f DA %f ",fTimeDelayCFD[i], fTimeDelayDA[i]);
118 //________________________________________________________________
119 void AliT0CalibData::PrintLookup(Option_t*, Int_t iTRM, Int_t iTDC, Int_t iChannel) const
122 AliT0LookUpKey* lookkey= new AliT0LookUpKey();
123 AliT0LookUpValue* lookvalue= new AliT0LookUpValue();
125 cout<<" Number Of TRMs in setup "<<GetNumberOfTRMs()<<endl;
126 lookvalue->SetTRM(iTRM);
127 lookvalue->SetTDC(iTDC);
128 lookvalue->SetChain(0);
129 lookvalue->SetChannel(iChannel);
132 printf(" AliT0CalibData::PrintLookup ::start GetValue %i %i %i \n",iTRM, iTDC, iChannel);
133 lookkey = (AliT0LookUpKey*) fLookup.GetValue((TObject*)lookvalue);
138 cout<<" lookup KEY!!! "<<lookkey->GetKey()<<" VALUE "<<lookvalue->GetTRM()<<" "
139 <<lookvalue->GetTDC()<<" "
140 << lookvalue->GetChain()<<" "
141 <<lookvalue->GetChannel()<<endl;
147 //________________________________________________________________
148 void AliT0CalibData::SetTimeDelayCFD(Float_t* TimeDelay)
150 if(TimeDelay) for(int t=0; t<24; t++) fTimeDelayCFD[t] = TimeDelay[t];
152 //________________________________________________________________
153 void AliT0CalibData::SetTimeDelayDA(Float_t* TimeDelay)
155 if(TimeDelay) for(int t=0; t<24; t++) fTimeDelayDA[t] = TimeDelay[t];
159 //________________________________________________________________
160 void AliT0CalibData::SetWalk(Int_t ipmt)
164 Int_t x[70000], y[70000], index[70000];
165 Float_t time[10000],amplitude[10000];
169 const char * filename = gSystem->ExpandPathName("$ALICE_ROOT/T0/data/CFD-Amp.txt");
170 ifstream inFile(filename);
171 if(!inFile) AliError(Form("Cannot open file %s !",filename));
174 while(getline(inFile,buffer)){
181 cout<<" number of data "<<i<<endl;
183 TMath::Sort(i, y, index,down);
184 Int_t amp=0, iin=0, isum=0, sum=0;
186 for (Int_t ii=0; ii<i; ii++)
197 time[isum] = Float_t (sum/(iin));
199 time[isum] =Float_t (x[ind]);
200 amplitude[isum] = Float_t (amp);
210 TGraph* gr = new TGraph(isum, amplitude, time);
211 fWalk.AddAtAndExpand(gr,ipmt);
215 //________________________________________________________________
217 void AliT0CalibData::SetSlewingLED(Int_t ipmt)
220 Float_t x[100], y[100];
223 const char * filename = gSystem->ExpandPathName("$ALICE_ROOT/T0/data/CFD-LED.txt");
224 ifstream inFile(filename);
225 if(!inFile) {AliError(Form("Cannot open file %s !",filename));}
230 while(getline(inFile,buffer)){
236 TGraph* gr = new TGraph(i,x,y);
237 fSlewingLED.AddAtAndExpand(gr,ipmt);
241 //________________________________________________________________
243 void AliT0CalibData::SetSlewingRec(Int_t ipmt)
246 Float_t x[100], y[100];
249 const char * filename = gSystem->ExpandPathName("$ALICE_ROOT/T0/data/CFD-LED.root");
250 ifstream inFile(filename);
251 if(!inFile) {AliError(Form("Cannot open file %s !",filename));}
256 while(getline(inFile,buffer)){
262 Float_t y1[100], x1[100];
263 for (Int_t ir=0; ir<i; ir++){
264 y1[ir]=y[i-ir]; x1[ir]=x[i-ir];}
265 TGraph* gr = new TGraph(i,y1,x1);
266 fSlewingRec.AddAtAndExpand(gr,ipmt);
270 //________________________________________________________________
272 void AliT0CalibData::ReadAsciiLookup(const Char_t *filename)
274 Int_t key, trm, tdc, chain, channel;
277 AliError(Form("Please, specify file with database")) ;
283 lookup.open(filename);
286 // AliLog(Form("Cannot open file %s ! Getting hardcoded value",filename));
288 // fNumberOfTRMs = 2;
290 trm=0; tdc=0; chain=0; channel=0; key=0;
291 for (Int_t ik=0; ik<108; ik++)
293 AliT0LookUpKey * lookkey= new AliT0LookUpKey();
294 AliT0LookUpValue * lookvalue= new AliT0LookUpValue();
296 lookvalue->SetTRM(trm);
297 lookvalue->SetTDC(tdc);
298 lookvalue->SetChain(chain);
299 lookvalue->SetChannel(channel);
301 if(ik>53) { trm=1; tdc=0; channel=0;}
302 if (channel<7) channel +=2;
303 else {channel = 0; tdc++;}
311 cout<<" !!!!!!! ntrms "<<ntrms<<endl;
312 // fNumberOfTRMs=ntrms;
313 SetNumberOfTRMs(ntrms);
316 AliT0LookUpKey * lookkey= new AliT0LookUpKey();
317 AliT0LookUpValue * lookvalue= new AliT0LookUpValue();
319 lookup>>varname>>key>>trm>>chain>>tdc>>channel;
320 lookvalue->SetTRM(trm);
321 lookvalue->SetTDC(tdc);
322 lookvalue->SetChain(chain);
323 lookvalue->SetChannel(channel);
324 lookkey->SetKey(key);
325 cout<<"lookup "<<varname<<" "<<key<<" "<<trm<<" "<<chain<<" "<<tdc<<" "<<channel<<endl;
327 fLookup.Add((TObject*)lookvalue,(TObject*)lookkey);
335 //________________________________________________________________
337 Int_t AliT0CalibData::GetChannel(Int_t trm, Int_t tdc, Int_t chain, Int_t channel)
340 AliT0LookUpKey * lookkey;//= new AliT0LookUpKey();
341 AliT0LookUpValue * lookvalue= new AliT0LookUpValue(trm,tdc,chain,channel);
343 lookkey = (AliT0LookUpKey*) fLookup.GetValue((TObject*)lookvalue);
345 return lookkey->GetKey();