]> git.uio.no Git - u/mrichter/AliRoot.git/blob - T0/AliT0CalibData.cxx
macros for simulation and reconstruction
[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 & LED\n");
100   for (Int_t i=0; i<24; i++) printf(" CFD  %f LED %f ",fTimeDelayCFD[i], fTimeDelayLED[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   cout<<" Number Of TRMs in setup "<<GetNumberOfTRMs()<<endl;
111   lookvalue->SetTRM(iTRM);
112   lookvalue->SetTDC(iTDC);
113   lookvalue->SetChain(0);
114   lookvalue->SetChannel(iChannel);
115
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)
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   const char * filename = gSystem->ExpandPathName("$ALICE_ROOT/T0/data/CFD-Amp.txt");
155   ifstream inFile(filename);
156   if(!inFile) AliError(Form("Cannot open file %s !",filename));
157   
158   Int_t i=0;
159   while(getline(inFile,buffer)){
160     inFile >> ps >> mv;
161
162     x[i]=ps; y[i]=mv;
163     i++;
164   }
165   inFile.close();
166   cout<<" number of data "<<i<<endl;
167  
168   TMath::Sort(i, y, index,down);
169   Int_t amp=0, iin=0, isum=0, sum=0;
170   Int_t ind=0;
171   for (Int_t ii=0; ii<i; ii++)
172     {
173       ind=index[ii];
174       if(y[ind] == amp)
175         {
176           sum +=x[ind];
177           iin++;
178           //      cout<<ii<<" "<<ind<<" "<<y[ind]<<" "<<x[ind]<<" "<<sum<<endl;
179         }
180       else
181         {
182           if(iin>0)
183             time[isum] = Float_t (sum/(iin));
184           else
185             time[isum] =Float_t (x[ind]);
186           amplitude[isum] = Float_t (amp);
187           amp=y[ind];
188           //      cout<<ii<<" "<<ind<<" "<<y[ind]<<" "<<x[ind]<<" iin "<<iin<<" mean "<<time[isum]<<" amp "<< amplitude[isum]<<" "<<isum<<endl;
189           iin=0;
190           isum++;
191           sum=0;
192         }
193     }
194
195   inFile.close();
196
197   TGraph* gr = new TGraph(isum, amplitude, time);
198   fWalk.AddAtAndExpand(gr,ipmt);
199 }
200
201
202 //________________________________________________________________
203
204 void AliT0CalibData::SetSlewingLED(Int_t ipmt)
205 {
206   Float_t mv, ps; 
207   Float_t x[100], y[100];
208   string buffer;
209   
210   const char * filename = gSystem->ExpandPathName("$ALICE_ROOT/T0/data/CFD-LED.txt");
211   ifstream inFile(filename);
212   if(!inFile) {AliError(Form("Cannot open file %s !",filename));}
213   
214   inFile >> mv>>ps;
215   Int_t i=0;
216   
217   while(getline(inFile,buffer)){
218     x[i]=mv; y[i]=ps;   
219     inFile >> mv >> ps;
220     i++;
221   }
222   inFile.close();
223   TGraph* gr = new TGraph(i,x,y);
224   fSlewingLED.AddAtAndExpand(gr,ipmt);
225    
226 }
227
228 //________________________________________________________________
229
230 void AliT0CalibData::SetSlewingRec(Int_t ipmt)
231 {
232   Float_t mv, ps; 
233   Float_t x[100], y[100];
234   string buffer;
235   
236  const char * filename = gSystem->ExpandPathName("$ALICE_ROOT/T0/data/CFD-LED.root");
237    ifstream inFile(filename);
238   if(!inFile) {AliError(Form("Cannot open file %s !",filename));}
239   
240   inFile >> mv>>ps;
241   Int_t i=0;
242   
243   while(getline(inFile,buffer)){
244     x[i]=mv; y[i]=ps;   
245     inFile >> mv >> ps;
246     i++;
247   }
248   inFile.close();
249   Float_t y1[100], x1[100];
250   for (Int_t ir=0; ir<i; ir++){
251     y1[ir]=y[i-ir]; x1[ir]=x[i-ir];}
252   TGraph* gr = new TGraph(i,y1,x1);
253   fSlewingRec.AddAtAndExpand(gr,ipmt);
254   
255 }
256
257 //________________________________________________________________
258
259 void AliT0CalibData::ReadAsciiLookup(const Char_t *filename)
260 {
261   Int_t key, trm, tdc, chain, channel;
262
263   if(filename == 0){
264     AliError(Form("Please, specify file with database")) ;
265     return ;
266   }
267
268
269   ifstream lookup;
270   lookup.open(filename);
271   if(!lookup)
272     {
273       //  AliLog(Form("Cannot open file %s ! Getting hardcoded value",filename));
274
275       //      fNumberOfTRMs = 2;
276       SetNumberOfTRMs(2);
277       trm=0; tdc=0; chain=0; channel=0; key=0;
278       for (Int_t ik=0; ik<108; ik++)
279         {
280           AliT0LookUpKey * lookkey= new AliT0LookUpKey();
281           AliT0LookUpValue * lookvalue= new AliT0LookUpValue();
282           
283           lookvalue->SetTRM(trm);
284           lookvalue->SetTDC(tdc);
285           lookvalue->SetChain(chain);
286           lookvalue->SetChannel(channel);
287           lookkey->SetKey(ik);
288           if(ik>53) { trm=1; tdc=0; channel=0;}
289           if (channel<7) channel +=2;
290           else {channel = 0; tdc++;}
291         }
292     }
293   Char_t varname[11];
294   Int_t ntrms;
295   if(lookup)
296     {
297       lookup>>ntrms;
298       cout<<" !!!!!!! ntrms "<<ntrms<<endl;
299       //      fNumberOfTRMs=ntrms;
300       SetNumberOfTRMs(ntrms);
301        while(!lookup.eof())
302         {
303           AliT0LookUpKey * lookkey= new AliT0LookUpKey();
304           AliT0LookUpValue * lookvalue= new AliT0LookUpValue();
305           
306           lookup>>varname>>key>>trm>>chain>>tdc>>channel;
307           lookvalue->SetTRM(trm);
308           lookvalue->SetTDC(tdc);
309           lookvalue->SetChain(chain);
310           lookvalue->SetChannel(channel);
311           lookkey->SetKey(key);
312           cout<<"lookup "<<varname<<" "<<key<<" "<<trm<<" "<<chain<<" "<<tdc<<" "<<channel<<endl;         
313           
314           fLookup.Add((TObject*)lookvalue,(TObject*)lookkey);
315           
316         }
317       
318       lookup.close();
319       
320     }
321 }
322 //________________________________________________________________
323
324 Int_t AliT0CalibData::GetChannel(Int_t trm,  Int_t tdc, Int_t chain, Int_t channel)
325 {
326
327   AliT0LookUpKey * lookkey;//= new AliT0LookUpKey();
328   AliT0LookUpValue * lookvalue= new AliT0LookUpValue(trm,tdc,chain,channel);
329
330   lookkey = (AliT0LookUpKey*) fLookup.GetValue((TObject*)lookvalue);
331
332   return lookkey->GetKey();
333
334 }
335