]> git.uio.no Git - u/mrichter/AliRoot.git/blob - T0/AliT0CalibData.cxx
all time measurements perfomed as difference with case vertex=0
[u/mrichter/AliRoot.git] / T0 / AliT0CalibData.cxx
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
24 #include "AliT0CalibData.h"
25 #include "AliT0LookUpValue.h"
26 #include "AliLog.h"
27
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>
36 #include <TSystem.h>
37 #include <Riostream.h>
38
39 #include <string>
40
41 ClassImp(AliT0CalibData)
42
43 //________________________________________________________________
44   AliT0CalibData::AliT0CalibData():   TNamed()
45
46 {
47   //
48 }
49
50 //________________________________________________________________
51 AliT0CalibData::AliT0CalibData(const char* name):TNamed(),
52                                       fTimeDelayTVD(0),
53                                       fMeanT0(0),
54                                       fWalk(0),
55                                       fSlewingLED(0),
56                                       fSlewingRec(0),
57                                       fLookup(0),
58                                       fNumberOfTRMs(0)
59 {
60   TString namst = "Calib_";
61   namst += name;
62   SetName(namst.Data());
63   SetTitle(namst.Data());
64
65 }
66
67 //________________________________________________________________
68 AliT0CalibData::AliT0CalibData(const AliT0CalibData& calibda) :
69   TNamed(calibda),              
70   fTimeDelayTVD(0),
71   fMeanT0(0),
72   fWalk(0),
73   fSlewingLED(0),
74   fSlewingRec(0),
75   fLookup(0),
76   fNumberOfTRMs(0)
77
78 {
79 // copy constructor
80   SetName(calibda.GetName());
81   SetTitle(calibda.GetName());
82
83
84 }
85
86 //________________________________________________________________
87 AliT0CalibData &AliT0CalibData::operator =(const AliT0CalibData& calibda)
88 {
89 // assignment operator
90   SetName(calibda.GetName());
91   SetTitle(calibda.GetName());
92  
93   return *this;
94 }
95
96 //________________________________________________________________
97 AliT0CalibData::~AliT0CalibData()
98 {
99   //
100 }
101 //________________________________________________________________
102 void AliT0CalibData::Reset()
103 {
104     memset(fTimeDelayCFD,1,24*sizeof(Float_t));
105     memset(fTimeDelayDA,1,24*sizeof(Float_t));
106 }
107
108
109 //________________________________________________________________
110 void  AliT0CalibData::Print(Option_t*) const
111 {
112
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]);
116
117
118 //________________________________________________________________
119 void  AliT0CalibData::PrintLookup(Option_t*, Int_t iTRM, Int_t iTDC, Int_t iChannel) const
120 {
121   
122   AliT0LookUpKey* lookkey= new AliT0LookUpKey();
123   AliT0LookUpValue*  lookvalue= new AliT0LookUpValue();
124
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);
130
131   
132   printf(" AliT0CalibData::PrintLookup ::start GetValue %i %i %i \n",iTRM, iTDC, iChannel);
133   lookkey = (AliT0LookUpKey*) fLookup.GetValue((TObject*)lookvalue);
134   
135
136   if (lookkey)
137     {
138       cout<<" lookup KEY!!! "<<lookkey->GetKey()<<" VALUE "<<lookvalue->GetTRM()<<" "
139           <<lookvalue->GetTDC()<<" "
140           << lookvalue->GetChain()<<" "
141           <<lookvalue->GetChannel()<<endl;
142     }
143   
144   
145 }
146
147 //________________________________________________________________
148 void AliT0CalibData::SetTimeDelayCFD(Float_t* TimeDelay)
149 {
150   if(TimeDelay) for(int t=0; t<24; t++) fTimeDelayCFD[t] = TimeDelay[t];
151 }  
152   //________________________________________________________________
153   void AliT0CalibData::SetTimeDelayDA(Float_t* TimeDelay)
154 {
155   if(TimeDelay) for(int t=0; t<24; t++) fTimeDelayDA[t] = TimeDelay[t];
156 }
157
158
159 //________________________________________________________________
160 void AliT0CalibData::SetWalk(Int_t ipmt)
161 {
162
163   Int_t mv, ps; 
164   Int_t x[70000], y[70000], index[70000];
165   Float_t time[10000],amplitude[10000];
166   string buffer;
167   Bool_t down=false;
168   
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));
172   
173   Int_t i=0;
174   while(getline(inFile,buffer)){
175     inFile >> ps >> mv;
176
177     x[i]=ps; y[i]=mv;
178     i++;
179   }
180   inFile.close();
181   cout<<" number of data "<<i<<endl;
182  
183   TMath::Sort(i, y, index,down);
184   Int_t amp=0, iin=0, isum=0, sum=0;
185   Int_t ind=0;
186   for (Int_t ii=0; ii<i; ii++)
187     {
188       ind=index[ii];
189       if(y[ind] == amp)
190         {
191           sum +=x[ind];
192           iin++;
193         }
194       else
195         {
196           if(iin>0)
197             time[isum] = Float_t (sum/(iin));
198           else
199             time[isum] =Float_t (x[ind]);
200           amplitude[isum] = Float_t (amp);
201           amp=y[ind];
202           iin=0;
203           isum++;
204           sum=0;
205         }
206     }
207
208   inFile.close();
209
210   TGraph* gr = new TGraph(isum, amplitude, time);
211   fWalk.AddAtAndExpand(gr,ipmt);
212 }
213
214
215 //________________________________________________________________
216
217 void AliT0CalibData::SetSlewingLED(Int_t ipmt)
218 {
219   Float_t mv, ps; 
220   Float_t x[100], y[100];
221   string buffer;
222   
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));}
226   
227   inFile >> mv>>ps;
228   Int_t i=0;
229   
230   while(getline(inFile,buffer)){
231     x[i]=mv; y[i]=ps;   
232     inFile >> mv >> ps;
233     i++;
234   }
235   inFile.close();
236   TGraph* gr = new TGraph(i,x,y);
237   fSlewingLED.AddAtAndExpand(gr,ipmt);
238    
239 }
240
241 //________________________________________________________________
242
243 void AliT0CalibData::SetSlewingRec(Int_t ipmt)
244 {
245   Float_t mv, ps; 
246   Float_t x[100], y[100];
247   string buffer;
248   
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));}
252   
253   inFile >> mv>>ps;
254   Int_t i=0;
255   
256   while(getline(inFile,buffer)){
257     x[i]=mv; y[i]=ps;   
258     inFile >> mv >> ps;
259     i++;
260   }
261   inFile.close();
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);
267   
268 }
269
270 //________________________________________________________________
271
272 void AliT0CalibData::ReadAsciiLookup(const Char_t *filename)
273 {
274   Int_t key, trm, tdc, chain, channel;
275
276   if(filename == 0){
277     AliError(Form("Please, specify file with database")) ;
278     return ;
279   }
280
281
282   ifstream lookup;
283   lookup.open(filename);
284   if(!lookup)
285     {
286       //  AliLog(Form("Cannot open file %s ! Getting hardcoded value",filename));
287
288       //      fNumberOfTRMs = 2;
289       SetNumberOfTRMs(2);
290       trm=0; tdc=0; chain=0; channel=0; key=0;
291       for (Int_t ik=0; ik<108; ik++)
292         {
293           AliT0LookUpKey * lookkey= new AliT0LookUpKey();
294           AliT0LookUpValue * lookvalue= new AliT0LookUpValue();
295           
296           lookvalue->SetTRM(trm);
297           lookvalue->SetTDC(tdc);
298           lookvalue->SetChain(chain);
299           lookvalue->SetChannel(channel);
300           lookkey->SetKey(ik);
301           if(ik>53) { trm=1; tdc=0; channel=0;}
302           if (channel<7) channel +=2;
303           else {channel = 0; tdc++;}
304         }
305     }
306   Char_t varname[11];
307   Int_t ntrms;
308   if(lookup)
309     {
310       lookup>>ntrms;
311       cout<<" !!!!!!! ntrms "<<ntrms<<endl;
312       //      fNumberOfTRMs=ntrms;
313       SetNumberOfTRMs(ntrms);
314        while(!lookup.eof())
315         {
316           AliT0LookUpKey * lookkey= new AliT0LookUpKey();
317           AliT0LookUpValue * lookvalue= new AliT0LookUpValue();
318           
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;         
326           
327           fLookup.Add((TObject*)lookvalue,(TObject*)lookkey);
328           
329         }
330       
331       lookup.close();
332       
333     }
334 }
335 //________________________________________________________________
336
337 Int_t AliT0CalibData::GetChannel(Int_t trm,  Int_t tdc, Int_t chain, Int_t channel)
338 {
339
340   AliT0LookUpKey * lookkey;//= new AliT0LookUpKey();
341   AliT0LookUpValue * lookvalue= new AliT0LookUpValue(trm,tdc,chain,channel);
342
343   lookkey = (AliT0LookUpKey*) fLookup.GetValue((TObject*)lookvalue);
344
345   return lookkey->GetKey();
346
347 }
348