]> git.uio.no Git - u/mrichter/AliRoot.git/blob - T0/AliT0Reconstructor.cxx
coding conventions
[u/mrichter/AliRoot.git] / T0 / AliT0Reconstructor.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 #include <Riostream.h>
19
20 #include <TDirectory.h>
21
22 #include "AliRunLoader.h"
23 #include <AliESDEvent.h>
24 #include "AliLog.h"
25 #include "AliT0Loader.h"
26 #include "AliT0RecPoint.h"
27 #include "AliRawReader.h"
28 #include "AliT0RawReader.h"
29 #include "AliT0digit.h"
30 #include "AliT0Reconstructor.h"
31 #include "AliT0Parameters.h"
32 #include "AliT0Calibrator.h"
33 #include "AliCDBLocal.h"
34 #include "AliCDBStorage.h"
35 #include "AliCDBManager.h"
36 #include "AliCDBEntry.h"
37
38 #include <TArrayI.h>
39 #include <TGraph.h>
40 #include <TMath.h>
41
42 ClassImp(AliT0Reconstructor)
43
44   AliT0Reconstructor:: AliT0Reconstructor(): AliReconstructor(),
45                                              fdZonA(0),
46                                              fdZonC(0),
47                                              fZposition(0),
48                                              fParam(NULL),
49                                              fAmpLEDrec()
50 {
51  AliDebug(1,"Start reconstructor ");
52   
53   fParam = AliT0Parameters::Instance();
54   fParam->Init();
55   for (Int_t i=0; i<24; i++){
56     TGraph* gr = fParam ->GetAmpLEDRec(i);
57     fAmpLEDrec.AddAtAndExpand(gr,i) ;  
58     fTime0vertex[i]= fParam->GetTimeDelayDA(i);
59   }
60   fdZonC = TMath::Abs(fParam->GetZPositionShift("T0/C/PMT1"));
61   fdZonA = TMath::Abs(fParam->GetZPositionShift("T0/A/PMT15"));
62
63 }
64 //____________________________________________________________________
65
66 AliT0Reconstructor::AliT0Reconstructor(const AliT0Reconstructor &r):
67   AliReconstructor(r),
68                                              fdZonA(0),
69                                              fdZonC(0),
70                                              fZposition(0),
71                                              fParam(NULL),
72                                              fAmpLEDrec()
73  {
74   //
75   // AliT0Reconstructor copy constructor
76   //
77
78   ((AliT0Reconstructor &) r).Copy(*this);
79
80 }
81
82 //_____________________________________________________________________________
83 AliT0Reconstructor &AliT0Reconstructor::operator=(const AliT0Reconstructor &r)
84 {
85   //
86   // Assignment operator
87   //
88
89   if (this != &r) ((AliT0Reconstructor &) r).Copy(*this);
90   return *this;
91
92 }
93
94 //_____________________________________________________________________________
95
96 void AliT0Reconstructor::Reconstruct(TTree*digitsTree, TTree*clustersTree) const
97   
98 {
99   // T0 digits reconstruction
100   // T0RecPoint writing 
101   
102    
103   TArrayI * timeCFD = new TArrayI(24); 
104   TArrayI * timeLED = new TArrayI(24); 
105   TArrayI * chargeQT0 = new TArrayI(24); 
106   TArrayI * chargeQT1 = new TArrayI(24); 
107
108   AliT0Calibrator *calib=new AliT0Calibrator(); 
109
110   //  Int_t mV2Mip = param->GetmV2Mip();     
111   //mV2Mip = param->GetmV2Mip();     
112   Float_t channelWidth = fParam->GetChannelWidth() ;  
113   Int_t meanT0 = fParam->GetMeanT0();
114   
115   AliDebug(1,Form("Start DIGITS reconstruction "));
116   
117   TBranch *brDigits=digitsTree->GetBranch("T0");
118   AliT0digit *fDigits = new AliT0digit() ;
119   if (brDigits) {
120     brDigits->SetAddress(&fDigits);
121   }else{
122     AliError(Form("EXEC Branch T0 digits not found"));
123      return;
124   }
125   
126   digitsTree->GetEvent(0);
127   digitsTree->GetEntry(0);
128   brDigits->GetEntry(0);
129   fDigits->GetTimeCFD(*timeCFD);
130   fDigits->GetTimeLED(*timeLED);
131   fDigits->GetQT0(*chargeQT0);
132   fDigits->GetQT1(*chargeQT1);
133   
134   Float_t besttimeA=999999;
135   Float_t besttimeC=999999;
136   Int_t pmtBestA=99999;
137   Int_t pmtBestC=99999;
138   Float_t timeDiff=999999, meanTime=0;
139   
140
141
142   AliT0RecPoint* frecpoints= new AliT0RecPoint ();
143   clustersTree->Branch( "T0", "AliT0RecPoint" ,&frecpoints, 405,1);
144   
145   Float_t time[24], adc[24];
146   for (Int_t ipmt=0; ipmt<24; ipmt++) {
147     if(timeCFD->At(ipmt)>0 ){
148       Double_t qt0 = Double_t(chargeQT0->At(ipmt));
149       Double_t qt1 = Double_t(chargeQT1->At(ipmt));
150       if((qt1-qt0)>0)  adc[ipmt] = TMath::Exp( Double_t (channelWidth*(qt1-qt0)/1000));
151       time[ipmt] = calib-> WalkCorrection( ipmt,Int_t(qt1) , timeCFD->At(ipmt) ) ;
152       
153       //LED
154       Double_t sl = (timeLED->At(ipmt) - time[ipmt])*channelWidth;
155       Double_t qt=((TGraph*)fAmpLEDrec.At(ipmt))->Eval(sl/1000.);
156       frecpoints->SetTime(ipmt,time[ipmt]);
157       frecpoints->SetAmp(ipmt,adc[ipmt]);
158       frecpoints->SetAmpLED(ipmt,qt);
159     }
160     else {
161       time[ipmt] = 0;
162       adc[ipmt] = 0;
163     }
164   }
165   
166   for (Int_t ipmt=0; ipmt<12; ipmt++){
167     if(time[ipmt] > 1 ) {
168       if(time[ipmt]<besttimeC){
169         besttimeC=time[ipmt]; //timeC
170         pmtBestC=ipmt;
171       }
172     }
173   }
174   for ( Int_t ipmt=12; ipmt<24; ipmt++){
175     if(time[ipmt] > 1) {
176       if(time[ipmt]<besttimeA) {
177         besttimeA=time[ipmt]; //timeA
178         pmtBestA=ipmt;}
179     }
180   }
181   if(besttimeA !=999999)  frecpoints->SetTimeBestA(Int_t(besttimeA));
182   if( besttimeC != 999999 ) frecpoints->SetTimeBestC(Int_t(besttimeC));
183   AliDebug(1,Form(" besttimeA %f ps,  besttimeC %f ps",besttimeA, besttimeC));
184   Float_t c = 0.0299792; // cm/ps
185   Float_t vertex = 0;
186   if(besttimeA !=999999 && besttimeC != 999999 ){
187     timeDiff =(besttimeC - besttimeA)*channelWidth;
188     meanTime = (meanT0 - (besttimeA + besttimeC)/2) * channelWidth;
189     vertex = c*(timeDiff)/2. + (fdZonA - fdZonC)/2; //-(lenr-lenl))/2;
190     AliDebug(1,Form("  timeDiff %f ps,  meanTime %f ps, vertex %f cm",timeDiff, meanTime,vertex ));
191     frecpoints->SetVertex(vertex);
192     frecpoints->SetMeanTime(Int_t(meanTime));
193     
194   }
195   //time in each channel as time[ipmt]-MeanTimeinThisChannel(with vertex=0)
196   for (Int_t ipmt=0; ipmt<24; ipmt++) {
197     if(time[ipmt]>1) {
198       time[ipmt] = (time[ipmt] - fTime0vertex[ipmt])*channelWidth;
199       frecpoints->SetTime(ipmt,time[ipmt]);
200     }
201   }
202   clustersTree->Fill();
203
204   delete timeCFD;
205   delete timeLED;
206   delete chargeQT0; 
207   delete chargeQT1; 
208 }
209
210
211 //_______________________________________________________________________
212
213 void AliT0Reconstructor::Reconstruct(AliRawReader* rawReader, TTree*recTree) const
214 {
215   // T0 raw ->
216   // T0RecPoint writing 
217   
218   //Q->T-> coefficients !!!! should be measured!!!
219   Int_t allData[110][5];
220   
221   TArrayI * timeCFD = new TArrayI(24); 
222   TArrayI * timeLED = new TArrayI(24); 
223   TArrayI * chargeQT0 = new TArrayI(24); 
224   TArrayI * chargeQT1 = new TArrayI(24); 
225
226    for (Int_t i=0; i<110; i++) {
227      allData[i][0]=0;
228    }
229
230    AliT0RawReader myrawreader(rawReader);
231    if (!myrawreader.Next())
232      AliDebug(1,Form(" no raw data found!! %i", myrawreader.Next()));
233    for (Int_t i=0; i<110; i++) {
234      allData[i][0]=myrawreader.GetData(i,0);
235    }
236   AliT0Calibrator *calib = new AliT0Calibrator(); 
237
238   //  Int_t mV2Mip = param->GetmV2Mip();     
239   //mV2Mip = param->GetmV2Mip();     
240   Float_t channelWidth = fParam->GetChannelWidth() ;  
241
242   Int_t meanT0 = fParam->GetMeanT0();
243  
244   for (Int_t in=0; in<24; in++)
245      {
246        timeLED->AddAt(allData[in+1][0],in);
247        timeCFD->AddAt(allData[in+25][0],in);
248        chargeQT1->AddAt(allData[in+57][0],in);
249        chargeQT0->AddAt(allData[in+80][0],in);
250        AliDebug(10, Form(" readed Raw %i %i %i %i %i", in, timeLED->At(in),timeCFD->At(in),chargeQT0->At(in),chargeQT1->At(in)));
251      }
252
253   Float_t besttimeA=999999;
254   Float_t besttimeC=999999;
255   Int_t pmtBestA=99999;
256   Int_t pmtBestC=99999;
257   Float_t timeDiff=999999, meanTime=0;
258
259   
260   AliT0RecPoint* frecpoints= new AliT0RecPoint ();
261  
262   recTree->Branch( "T0", "AliT0RecPoint" ,&frecpoints, 405,1);
263   
264
265   Float_t time[24], adc[24];
266   for (Int_t ipmt=0; ipmt<24; ipmt++) {
267     if(timeCFD->At(ipmt)>0 ){
268       Double_t qt0 = Double_t(chargeQT0->At(ipmt));
269       Double_t qt1 = Double_t(chargeQT1->At(ipmt));
270       if((qt1-qt0)>0)  adc[ipmt] = TMath::Exp( Double_t (channelWidth*(qt1-qt0)/1000));
271       //      time[ipmt] = channelWidth * (calib-> WalkCorrection( ipmt,qt1 , timeCFD->At(ipmt) ) ) ;
272       time[ipmt] = calib-> WalkCorrection( ipmt,Int_t(qt1) , timeCFD->At(ipmt) ) ;
273       Double_t sl = (timeLED->At(ipmt) - time[ipmt])*channelWidth;
274       Double_t qt=((TGraph*)fAmpLEDrec.At(ipmt))->Eval(sl/1000.);
275       frecpoints->SetTime(ipmt,time[ipmt]);
276       frecpoints->SetAmp(ipmt,adc[ipmt]);
277       frecpoints->SetAmpLED(ipmt,qt);
278     AliDebug(1,Form(" QTC %f mv,  QTC  %f MIPS time in chann %f time %f ",adc[ipmt], adc[ipmt]/50.,time[ipmt], time[ipmt]*channelWidth));
279      
280     }
281     else {
282       time[ipmt] = 0;
283       adc[ipmt] = 0;
284     }
285   }
286
287   for (Int_t ipmt=0; ipmt<12; ipmt++){
288     if(time[ipmt] > 1 ) {
289       if(time[ipmt]<besttimeC){
290         besttimeC=time[ipmt]; //timeC
291         pmtBestC=ipmt;
292       }
293     }
294   }
295   for ( Int_t ipmt=12; ipmt<24; ipmt++){
296     if(time[ipmt] > 1) {
297       if(time[ipmt]<besttimeA) {
298         besttimeA=time[ipmt]; //timeA
299         pmtBestA=ipmt;}
300     }
301   }
302   if(besttimeA !=999999)  frecpoints->SetTimeBestA(Int_t(besttimeA));
303   if( besttimeC != 999999 ) frecpoints->SetTimeBestC(Int_t(besttimeC));
304   AliDebug(1,Form(" besttimeA %f ps,  besttimeC %f ps",besttimeA, besttimeC));
305   Float_t c = 0.0299792; // cm/ps
306   Float_t vertex = 0;
307   if(besttimeA !=999999 && besttimeC != 999999 ){
308     timeDiff = (besttimeC - besttimeA)*channelWidth;
309     meanTime = (meanT0 - (besttimeA + besttimeC)/2) * channelWidth;   
310     vertex = c*(timeDiff)/2. + (fdZonA - fdZonC)/2; //-(lenr-lenl))/2;
311     AliDebug(1,Form("  timeDiff %f ps,  meanTime %f ps, vertex %f cm",timeDiff, meanTime,vertex ));
312     frecpoints->SetVertex(vertex);
313     frecpoints->SetMeanTime(Int_t(meanTime));
314     
315   }
316   //time in each channel as time[ipmt]-MeanTimeinThisChannel(with vertex=0)
317   /*
318   for (Int_t ipmt=0; ipmt<24; ipmt++) {
319     if(time[ipmt]>1) {
320       time[ipmt] = (time[ipmt] - fTime0vertex[ipmt])*channelWidth;
321       frecpoints->SetTime(ipmt,time[ipmt]);
322     }
323     }
324   */
325   recTree->Fill();
326  
327
328   delete timeCFD;
329   delete timeLED;
330   delete chargeQT0; 
331   delete chargeQT1; 
332   
333 }
334 //____________________________________________________________
335
336 void AliT0Reconstructor::FillESD(TTree */*digitsTree*/, TTree *clustersTree, AliESDEvent *pESD) const
337 {
338
339   /***************************************************
340   Resonstruct digits to vertex position
341   ****************************************************/
342   
343   AliDebug(1,Form("Start FillESD T0"));
344
345   TTree *treeR = clustersTree;
346   
347    AliT0RecPoint* frecpoints= new AliT0RecPoint ();
348     if (!frecpoints) {
349     AliError("Reconstruct Fill ESD >> no recpoints found");
350     return;
351   }
352   
353   AliDebug(1,Form("Start FillESD T0"));
354   TBranch *brRec = treeR->GetBranch("T0");
355   if (brRec) {
356     brRec->SetAddress(&frecpoints);
357   }else{
358     AliError(Form("EXEC Branch T0 rec not found"));
359     return;
360   } 
361     
362     brRec->GetEntry(0);
363     Float_t amp[24], time[24];
364     Float_t  zPosition = frecpoints -> GetVertex();
365     Float_t timeStart = frecpoints -> GetMeanTime() ;
366     for ( Int_t i=0; i<24; i++) {
367       time[i] = Float_t (frecpoints -> GetTime(i)); // ps to ns
368       amp[i] = frecpoints -> GetAmp(i);
369     }
370     pESD->SetT0zVertex(zPosition); //vertex Z position 
371     pESD->SetT0(timeStart);        // interaction time 
372     pESD->SetT0time(time);         // best TOF on each PMT 
373     pESD->SetT0amplitude(amp);     // number of particles(MIPs) on each PMT
374  
375     AliDebug(1,Form(" Z position %f cm,  T0  %f ps",zPosition , timeStart));
376
377 } // vertex in 3 sigma
378
379
380
381
382
383