]> git.uio.no Git - u/mrichter/AliRoot.git/blob - T0/AliT0CalibData.cxx
correct path to data
[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(),fTimeDelayTVD(0),fWalk(),fSlewingLED(),fSlewingRec()
52 {
53   TString namst = "Calib_";
54   namst += name;
55   SetName(namst.Data());
56   SetTitle(namst.Data());
57
58 }
59
60 //________________________________________________________________
61 AliT0CalibData::AliT0CalibData(const AliT0CalibData& calibda) :
62   TNamed(calibda),fTimeDelayTVD(0),fWalk(),fSlewingLED(),fSlewingRec()
63 {
64 // copy constructor
65   SetName(calibda.GetName());
66   SetTitle(calibda.GetName());
67
68
69 }
70
71 //________________________________________________________________
72 AliT0CalibData &AliT0CalibData::operator =(const AliT0CalibData& calibda)
73 {
74 // assignment operator
75   SetName(calibda.GetName());
76   SetTitle(calibda.GetName());
77  
78   return *this;
79 }
80
81 //________________________________________________________________
82 AliT0CalibData::~AliT0CalibData()
83 {
84   //
85 }
86 //________________________________________________________________
87 void AliT0CalibData::Reset()
88 {
89     memset(fTimeDelayCFD,1,24*sizeof(Float_t));
90     memset(fTimeDelayLED,1,24*sizeof(Float_t));
91 }
92
93
94 //________________________________________________________________
95 void  AliT0CalibData::Print(Option_t*) const
96 {
97
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]);
101
102
103 //________________________________________________________________
104 void  AliT0CalibData::PrintLookup(Option_t*, Int_t iTRM, Int_t iTDC, Int_t iChannel) const
105 {
106   
107   AliT0LookUpKey* lookkey= new AliT0LookUpKey();
108   AliT0LookUpValue*  lookvalue= new AliT0LookUpValue();
109   
110   lookvalue->SetTRM(iTRM);
111   lookvalue->SetTDC(iTDC);
112   lookvalue->SetChain(0);
113   lookvalue->SetChannel(iChannel);
114   
115   printf(" AliT0CalibData::PrintLookup ::start GetValue %i %i %i \n",iTRM, iTDC, iChannel);
116   lookkey = (AliT0LookUpKey*) fLookup.GetValue((TObject*)lookvalue);
117   
118   cout<<"  AliT0CalibData::PrintLookup :: lookkey "<< lookkey<<endl;
119   if (lookkey)
120     {
121       cout<<" lookup KEY!!! "<<lookkey->GetKey()<<" VALUE "<<lookvalue->GetTRM()<<" "
122           <<lookvalue->GetTDC()<<" "
123           << lookvalue->GetChain()<<" "
124           <<lookvalue->GetChannel()<<endl;
125     }
126   
127   
128 }
129
130 //________________________________________________________________
131 void AliT0CalibData::SetTimeDelayCFD(Float_t* TimeDelay)
132 {
133   if(TimeDelay) for(int t=0; t<24; t++) fTimeDelayCFD[t] = TimeDelay[t];
134 }  
135   //________________________________________________________________
136   void AliT0CalibData::SetTimeDelayLED(Float_t* TimeDelay)
137 {
138   if(TimeDelay) for(int t=0; t<24; t++) fTimeDelayLED[t] = TimeDelay[t];
139 }
140
141
142 //________________________________________________________________
143 void AliT0CalibData::SetWalk(Int_t ipmt)
144 {
145
146   Int_t mv, ps; 
147   Int_t x[70000], y[70000], index[70000];
148   Float_t time[10000],amplitude[10000];
149   string buffer;
150   Bool_t down=false;
151   
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));
155   
156   Int_t i=0, i1=0, i2=0;
157   while(getline(inFile,buffer)){
158     inFile >> ps >> mv;
159
160     x[i]=ps; y[i]=mv;
161     i++;
162   }
163   inFile.close();
164  
165   TMath::Sort(i, y, index,down);
166   Int_t amp=0, iin=0, isum=0, sum=0;
167   Int_t ind=0;
168   for (Int_t ii=0; ii<70000; ii++)
169     {
170       ind=index[ii];
171       if(y[ind] == amp)
172         {
173           sum +=x[ind];
174           iin++;
175           //      cout<<ii<<" "<<ind<<" "<<y[ind]<<" "<<x[ind]<<" "<<sum<<endl;
176         }
177       else
178         {
179           if(iin>0)
180             time[isum] = Float_t (sum/(iin));
181           else
182             time[isum] =Float_t (x[ind]);
183           amplitude[isum] = Float_t (amp);
184           amp=y[ind];
185           cout<<ii<<" "<<ind<<" "<<y[ind]<<" "<<x[ind]<<" iin "<<iin<<" mean "<<time[isum]<<" amp "<< amplitude[isum]<<" "<<isum<<endl;
186           iin=0;
187           isum++;
188           sum=0;
189         }
190     }
191
192   inFile.close();
193
194   TGraph* gr = new TGraph(isum, amplitude, time);
195   fWalk.AddAtAndExpand(gr,ipmt);
196 }
197
198
199 //________________________________________________________________
200
201 void AliT0CalibData::SetSlewingLED(Int_t ipmt)
202 {
203   Float_t mv, ps; 
204   Float_t x[100], y[100];
205   string buffer;
206   
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));}
210   
211   inFile >> mv>>ps;
212   Int_t i=0;
213   
214   while(getline(inFile,buffer)){
215     x[i]=mv; y[i]=ps;   
216     inFile >> mv >> ps;
217     i++;
218   }
219   inFile.close();
220   TGraph* gr = new TGraph(i,x,y);
221   fSlewingLED.AddAtAndExpand(gr,ipmt);
222    
223 }
224
225 //________________________________________________________________
226
227 void AliT0CalibData::SetSlewingRec(Int_t ipmt)
228 {
229   Float_t mv, ps; 
230   Float_t x[100], y[100];
231   string buffer;
232   
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));}
236   
237   inFile >> mv>>ps;
238   Int_t i=0;
239   
240   while(getline(inFile,buffer)){
241     x[i]=mv; y[i]=ps;   
242     inFile >> mv >> ps;
243     i++;
244   }
245   inFile.close();
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);
251   
252 }
253
254
255 void AliT0CalibData::ReadAsciiLookup(const Char_t *filename)
256 {
257   Int_t key, trm, tdc, chain, channel;
258
259   if(filename == 0){
260     AliError(Form("Please, specify file with database")) ;
261     return ;
262   }
263
264
265   ifstream lookup;
266   lookup.open(filename);
267   if(!lookup)
268     {
269       //  AliLog(Form("Cannot open file %s ! Getting hardcoded value",filename));
270
271     trm=0; tdc=0; chain=0; channel=0; key=0;
272     for (Int_t ik=0; ik<108; ik++)
273       {
274         AliT0LookUpKey * lookkey= new AliT0LookUpKey();
275         AliT0LookUpValue * lookvalue= new AliT0LookUpValue();
276         
277       lookvalue->SetTRM(trm);
278       lookvalue->SetTDC(tdc);
279       lookvalue->SetChain(chain);
280       lookvalue->SetChannel(channel);
281       lookkey->SetKey(ik);
282       if(ik>53) { trm=1; tdc=0; channel=0;}
283       if (channel<7) channel +=2;
284       else {channel = 0; tdc++;}
285       }
286     }
287   Char_t varname[11];
288   // while(lookup.eof())
289
290  for (Int_t i=0; i<108; i++)
291     {
292        AliT0LookUpKey * lookkey= new AliT0LookUpKey();
293        AliT0LookUpValue * lookvalue= new AliT0LookUpValue();
294
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);
301
302       
303       fLookup.Add((TObject*)lookvalue,(TObject*)lookkey);
304
305     }
306
307    lookup.close();
308
309 }
310
311 //________________________________________________________________
312
313 Int_t AliT0CalibData::GetChannel(Int_t trm,  Int_t tdc, Int_t chain, Int_t channel)
314 {
315
316   AliT0LookUpKey * lookkey;//= new AliT0LookUpKey();
317   AliT0LookUpValue * lookvalue= new AliT0LookUpValue(trm,tdc,chain,channel);
318
319   lookkey = (AliT0LookUpKey*) fLookup.GetValue((TObject*)lookvalue);
320
321   return lookkey->GetKey();
322
323 }
324