]> git.uio.no Git - u/mrichter/AliRoot.git/blob - T0/AliT0CalibData.cxx
more realistic calibration
[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 <iostream>
25 #include <fstream>
26 #include <iomanip>
27 #include <string>
28 #include <TCanvas.h>
29
30 #include "AliT0CalibData.h"
31 #include "AliT0LookUpValue.h"
32 #include "TObjArray.h"
33 #include "TGraph.h"
34 #include "TFile.h"
35 #include "AliLog.h"
36 #include "TObjString.h"
37
38 #include "TAxis.h"
39 #include "TH2F.h"
40
41
42
43 ClassImp(AliT0CalibData)
44
45 //________________________________________________________________
46   AliT0CalibData::AliT0CalibData():   TNamed()
47
48 {
49   //
50 }
51
52 //________________________________________________________________
53 AliT0CalibData::AliT0CalibData(const char* name):TNamed(),fTimeDelayTVD(0),fWalk(),fSlewingLED(),fSlewingRec()
54 {
55   TString namst = "Calib_";
56   namst += name;
57   SetName(namst.Data());
58   SetTitle(namst.Data());
59
60 }
61
62 //________________________________________________________________
63 AliT0CalibData::AliT0CalibData(const AliT0CalibData& calibda) :
64   TNamed(calibda),fTimeDelayTVD(0),fWalk(),fSlewingLED(),fSlewingRec()
65 {
66 // copy constructor
67   SetName(calibda.GetName());
68   SetTitle(calibda.GetName());
69
70
71 }
72
73 //________________________________________________________________
74 AliT0CalibData &AliT0CalibData::operator =(const AliT0CalibData& calibda)
75 {
76 // assignment operator
77   SetName(calibda.GetName());
78   SetTitle(calibda.GetName());
79  
80   return *this;
81 }
82
83 //________________________________________________________________
84 AliT0CalibData::~AliT0CalibData()
85 {
86   //
87 }
88 //________________________________________________________________
89 void AliT0CalibData::Reset()
90 {
91     memset(fTimeDelayCFD,1,24*sizeof(Float_t));
92     memset(fTimeDelayLED,1,24*sizeof(Float_t));
93 }
94
95
96 //________________________________________________________________
97 void  AliT0CalibData::Print(Option_t*) const
98 {
99
100   printf("\n    ----    PM Arrays       ----\n\n");
101   printf(" Time delay CFD \n");
102   for (Int_t i=0; i<24; i++) printf("  %f",fTimeDelayCFD[i]);
103
104
105 //________________________________________________________________
106 void  AliT0CalibData::PrintLookup(Option_t*, Int_t iTRM, Int_t iTDC, Int_t iChannel) const
107 {
108   
109   AliT0LookUpKey* lookkey= new AliT0LookUpKey();
110   AliT0LookUpValue*  lookvalue= new AliT0LookUpValue();
111   
112   lookvalue->SetTRM(iTRM);
113   lookvalue->SetTDC(iTDC);
114   lookvalue->SetChain(0);
115   lookvalue->SetChannel(iChannel);
116   
117   printf(" AliT0CalibData::PrintLookup ::start GetValue %i %i %i \n",iTRM, iTDC, iChannel);
118   lookkey = (AliT0LookUpKey*) fLookup.GetValue((TObject*)lookvalue);
119   
120   cout<<"  AliT0CalibData::PrintLookup :: lookkey "<< lookkey<<endl;
121   if (lookkey)
122     {
123       cout<<" lookup KEY!!! "<<lookkey->GetKey()<<" VALUE "<<lookvalue->GetTRM()<<" "
124           <<lookvalue->GetTDC()<<" "
125           << lookvalue->GetChain()<<" "
126           <<lookvalue->GetChannel()<<endl;
127     }
128   
129   
130 }
131
132 //________________________________________________________________
133 void AliT0CalibData::SetTimeDelayCFD(Float_t* TimeDelay)
134 {
135   if(TimeDelay) for(int t=0; t<24; t++) fTimeDelayCFD[t] = TimeDelay[t];
136 }  
137   //________________________________________________________________
138   void AliT0CalibData::SetTimeDelayLED(Float_t* TimeDelay)
139 {
140   if(TimeDelay) for(int t=0; t<24; t++) fTimeDelayLED[t] = TimeDelay[t];
141 }
142
143
144 //________________________________________________________________
145 void AliT0CalibData::SetWalk(Int_t ipmt, const Char_t *filename)
146 {
147
148   Int_t mv, ps; 
149   Int_t x[70000], y[70000], index[70000];
150   Float_t time[10000],amplitude[10000];
151   string buffer;
152   Bool_t down=false;
153   
154   ifstream inFile("data/CFD-Amp.txt");
155   if(!inFile) AliError(Form("Cannot open file %s !",filename));
156   
157   Int_t i=0, i1=0, i2=0;
158   while(getline(inFile,buffer)){
159     inFile >> ps >> mv;
160
161     x[i]=ps; y[i]=mv;
162     i++;
163   }
164   inFile.close();
165  
166   TMath::Sort(i, y, index,down);
167   Int_t amp=0, iin=0, isum=0, sum=0;
168   Int_t ind=0;
169   for (Int_t ii=0; ii<70000; ii++)
170     {
171       ind=index[ii];
172       if(y[ind] == amp)
173         {
174           sum +=x[ind];
175           iin++;
176           //      cout<<ii<<" "<<ind<<" "<<y[ind]<<" "<<x[ind]<<" "<<sum<<endl;
177         }
178       else
179         {
180           if(iin>0)
181             time[isum] = Float_t (sum/(iin));
182           else
183             time[isum] =Float_t (x[ind]);
184           amplitude[isum] = Float_t (amp);
185           amp=y[ind];
186           cout<<ii<<" "<<ind<<" "<<y[ind]<<" "<<x[ind]<<" iin "<<iin<<" mean "<<time[isum]<<" amp "<< amplitude[isum]<<" "<<isum<<endl;
187           iin=0;
188           isum++;
189           sum=0;
190         }
191     }
192
193   inFile.close();
194
195   TGraph* gr = new TGraph(isum, amplitude, time);
196   fWalk.AddAtAndExpand(gr,ipmt);
197 }
198
199
200 //________________________________________________________________
201
202 void AliT0CalibData::SetSlewingLED(Int_t ipmt,const Char_t *filename)
203 {
204   Float_t mv, ps; 
205   Float_t x[100], y[100];
206   string buffer;
207   
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,const Char_t *filename)
228 {
229   Float_t mv, ps; 
230   Float_t x[100], y[100];
231   string buffer;
232   
233   ifstream inFile(filename);
234   if(!inFile) {AliError(Form("Cannot open file %s !",filename));}
235   
236   inFile >> mv>>ps;
237   Int_t i=0;
238   
239   while(getline(inFile,buffer)){
240     x[i]=mv; y[i]=ps;   
241     inFile >> mv >> ps;
242     i++;
243   }
244   inFile.close();
245   Float_t y1[100], x1[100];
246   for (Int_t ir=0; ir<i; ir++){
247     y1[ir]=y[i-ir]; x1[ir]=x[i-ir];}
248   TGraph* gr = new TGraph(i,y1,x1);
249   fSlewingRec.AddAtAndExpand(gr,ipmt);
250   
251 }
252
253
254 void AliT0CalibData::ReadAsciiLookup(const Char_t *filename)
255 {
256   Int_t key, trm, tdc, chain, channel;
257
258   if(filename == 0){
259     AliError(Form("Please, specify file with database")) ;
260     return ;
261   }
262
263   //  AliT0LookUpKey * lookkey= new AliT0LookUpKey();
264   //  AliT0LookUpValue * lookvalue= new AliT0LookUpValue();
265
266   ifstream lookup;
267   lookup.open(filename);
268   if(!lookup)
269     {
270       //  AliLog(Form("Cannot open file %s ! Getting hardcoded value",filename));
271
272     trm=0; tdc=0; chain=0; channel=0; key=0;
273     for (Int_t ik=0; ik<108; ik++)
274       {
275         AliT0LookUpKey * lookkey= new AliT0LookUpKey();
276         AliT0LookUpValue * lookvalue= new AliT0LookUpValue();
277         
278       lookvalue->SetTRM(trm);
279       lookvalue->SetTDC(tdc);
280       lookvalue->SetChain(chain);
281       lookvalue->SetChannel(channel);
282       lookkey->SetKey(ik);
283       if(ik>53) { trm=1; tdc=0; channel=0;}
284       if (channel<7) channel +=2;
285       else {channel = 0; tdc++;}
286       }
287     }
288   Char_t varname[11];
289   // while(lookup.eof())
290
291  for (Int_t i=0; i<108; i++)
292     {
293        AliT0LookUpKey * lookkey= new AliT0LookUpKey();
294        AliT0LookUpValue * lookvalue= new AliT0LookUpValue();
295
296  lookup>>varname>>key>>trm>>chain>>tdc>>channel;
297       lookvalue->SetTRM(trm);
298       lookvalue->SetTDC(tdc);
299       lookvalue->SetChain(chain);
300       lookvalue->SetChannel(channel);
301       lookkey->SetKey(key);
302
303       //      cout<<"TRM="<<trm<<" TDC="<<tdc<<" chain="<<chain<<" channel="<<channel<<" key="<<key<<endl;
304
305       cout<<"AliT0CalibData:: "<<varname<<" "<<key<<" "<<trm<<" "<<chain<<" "<<tdc<<" "<<channel<<endl;
306
307       //    fLookup.Add((TObject*)lookkey,(TObject*)lookvalue);
308       // ar_key.AddAt(lookkey,i);
309       // ar_val.AddAt(lookvalue,i);
310
311         fLookup.Add((TObject*)lookvalue,(TObject*)lookkey);
312
313     }
314
315    lookup.close();
316
317 }
318
319 //________________________________________________________________
320
321 Int_t AliT0CalibData::GetChannel(Int_t trm,  Int_t tdc, Int_t chain, Int_t channel)
322 {
323
324   AliT0LookUpKey * lookkey;//= new AliT0LookUpKey();
325   AliT0LookUpValue * lookvalue= new AliT0LookUpValue(trm,tdc,chain,channel);
326
327      lookkey = (AliT0LookUpKey*) fLookup.GetValue((TObject*)lookvalue);
328     cout<<"AliT0CalibData:: key "<<lookkey->GetKey()<<endl;
329   return lookkey->GetKey();
330
331 }
332