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(),
56 //________________________________________________________________
57 AliT0CalibData::AliT0CalibData(const char* name):TNamed(),
65 TString namst = "Calib_";
67 SetName(namst.Data());
68 SetTitle(namst.Data());
72 //________________________________________________________________
73 AliT0CalibData::AliT0CalibData(const AliT0CalibData& calibda) :
85 SetName(calibda.GetName());
86 SetTitle(calibda.GetName());
91 //________________________________________________________________
92 AliT0CalibData &AliT0CalibData::operator =(const AliT0CalibData& calibda)
94 // assignment operator
95 SetName(calibda.GetName());
96 SetTitle(calibda.GetName());
101 //________________________________________________________________
102 AliT0CalibData::~AliT0CalibData()
106 //________________________________________________________________
107 void AliT0CalibData::Reset()
109 memset(fTimeDelayCFD,1,24*sizeof(Float_t));
110 memset(fTimeDelayDA,1,24*sizeof(Float_t));
114 //________________________________________________________________
115 void AliT0CalibData::Print(Option_t*) const
118 printf("\n ---- PM Arrays ----\n\n");
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]);
123 //________________________________________________________________
124 void AliT0CalibData::PrintLookup(Option_t*, Int_t iTRM, Int_t iTDC, Int_t iChannel) const
127 AliT0LookUpKey* lookkey= new AliT0LookUpKey();
128 AliT0LookUpValue* lookvalue= new AliT0LookUpValue();
130 cout<<" Number Of TRMs in setup "<<GetNumberOfTRMs()<<endl;
131 iTRM=0; iTDC=0; Int_t chain=0; iChannel=0;
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);
139 if (iChannel<6) iChannel +=2;
140 else {iChannel = 0; iTDC++;}
141 if(ik==57) { iTDC=0; iChannel=0; iTRM=1;}
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;
150 TString name= lookkey->GetChannelName();
151 cout<<" lookup KEY!!! "<<name.Data()<<" "<<lookkey->GetKey()<<" VALUE "<<lookvalue->GetTRM()<<" "
152 <<lookvalue->GetTDC()<<" "
153 << lookvalue->GetChain()<<" "
154 <<lookvalue->GetChannel()<<endl;
160 //________________________________________________________________
161 void AliT0CalibData::SetTimeDelayCFD(Float_t* TimeDelay)
163 if(TimeDelay) for(int t=0; t<24; t++) fTimeDelayCFD[t] = TimeDelay[t];
165 //________________________________________________________________
166 void AliT0CalibData::SetTimeDelayDA(Float_t* TimeDelay)
168 if(TimeDelay) for(int t=0; t<24; t++) fTimeDelayDA[t] = TimeDelay[t];
172 //________________________________________________________________
173 void AliT0CalibData::SetWalk(Int_t ipmt)
177 Int_t x[70000], y[70000], index[70000];
178 Float_t time[10000],amplitude[10000];
182 const char * filename = gSystem->ExpandPathName("$ALICE_ROOT/T0/data/CFD-Amp.txt");
183 ifstream inFile(filename);
184 if(!inFile) AliError(Form("Cannot open file %s !",filename));
187 while(getline(inFile,buffer)){
194 cout<<" number of data "<<i<<endl;
196 TMath::Sort(i, y, index,down);
197 Int_t amp=0, iin=0, isum=0, sum=0;
199 for (Int_t ii=0; ii<i; ii++)
210 time[isum] = Float_t (sum/(iin));
212 time[isum] =Float_t (x[ind]);
213 amplitude[isum] = Float_t (amp);
223 TGraph* gr = new TGraph(isum, amplitude, time);
224 fWalk.AddAtAndExpand(gr,ipmt);
228 //________________________________________________________________
230 void AliT0CalibData::SetAmpLED(Int_t ipmt)
233 Float_t x[100], y[100];
236 const char * filename = gSystem->ExpandPathName("$ALICE_ROOT/T0/data/CFD-LED.txt");
237 ifstream inFile(filename);
238 if(!inFile) {AliError(Form("Cannot open file %s !",filename));}
243 while(getline(inFile,buffer)){
249 TGraph* gr = new TGraph(i,x,y);
250 fAmpLED.AddAtAndExpand(gr,ipmt);
254 //________________________________________________________________
256 void AliT0CalibData::SetAmpLEDRec(Int_t ipmt)
259 Float_t x[100], y[100];
262 const char * filename = gSystem->ExpandPathName("$ALICE_ROOT/T0/data/CFD-LED.txt");
263 ifstream inFile(filename);
264 if(!inFile) {AliError(Form("Cannot open file %s !",filename));}
269 while(getline(inFile,buffer)){
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);
279 fAmpLEDRec.AddAtAndExpand(gr,ipmt);
283 //________________________________________________________________
285 void AliT0CalibData::ReadAsciiLookup(const Char_t *filename)
287 Int_t key, trm, tdc, chain, channel;
290 AliError(Form("Please, specify file with database")) ;
296 lookup.open(filename);
299 AliError(Form("!!!!!!!!!!!!!!No look up table in CDB!" ));
307 cout<<" !!!!!!! ntrms "<<ntrms<<endl;
308 // fNumberOfTRMs=ntrms;
309 SetNumberOfTRMs(ntrms);
312 AliT0LookUpKey * lookkey= new AliT0LookUpKey();
313 AliT0LookUpValue * lookvalue= new AliT0LookUpValue();
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);
321 lookkey->SetChannelName(varname);
322 cout<<"lookup "<<varname<<" "<<key<<" "<<trm<<" "<<chain<<" "<<tdc<<" "<<channel<<endl;
324 fLookup.Add((TObject*)lookvalue,(TObject*)lookkey);
332 //________________________________________________________________
334 Int_t AliT0CalibData::GetChannel(Int_t trm, Int_t tdc, Int_t chain, Int_t channel)
337 AliT0LookUpKey * lookkey;//= new AliT0LookUpKey();
338 AliT0LookUpValue * lookvalue= new AliT0LookUpValue(trm,tdc,chain,channel);
340 lookkey = (AliT0LookUpKey*) fLookup.GetValue((TObject*)lookvalue);
342 return lookkey->GetKey();