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