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