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