1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 #include <Riostream.h>
20 #include <TDirectory.h>
22 #include "AliRunLoader.h"
23 #include <AliESDEvent.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"
42 ClassImp(AliT0Reconstructor)
44 AliT0Reconstructor:: AliT0Reconstructor(): AliReconstructor(),
51 AliDebug(1,"Start reconstructor ");
53 fParam = AliT0Parameters::Instance();
55 for (Int_t i=0; i<24; i++){
56 TGraph* gr = fParam ->GetAmpLEDRec(i);
57 fAmpLEDrec.AddAtAndExpand(gr,i) ;
58 // fTime0vertex[i]= fParam->GetTimeV0(i);
60 fdZonC = TMath::Abs(fParam->GetZPositionShift("T0/C/PMT1"));
61 fdZonA = TMath::Abs(fParam->GetZPositionShift("T0/A/PMT15"));
64 //____________________________________________________________________
66 AliT0Reconstructor::AliT0Reconstructor(const AliT0Reconstructor &r):
75 // AliT0Reconstructor copy constructor
78 ((AliT0Reconstructor &) r).Copy(*this);
82 //_____________________________________________________________________________
83 AliT0Reconstructor &AliT0Reconstructor::operator=(const AliT0Reconstructor &r)
86 // Assignment operator
89 if (this != &r) ((AliT0Reconstructor &) r).Copy(*this);
94 //_____________________________________________________________________________
96 void AliT0Reconstructor::Reconstruct(TTree*digitsTree, TTree*clustersTree) const
99 // T0 digits reconstruction
100 // T0RecPoint writing
103 TArrayI * timeCFD = new TArrayI(24);
104 TArrayI * timeLED = new TArrayI(24);
105 TArrayI * chargeQT0 = new TArrayI(24);
106 TArrayI * chargeQT1 = new TArrayI(24);
108 AliT0Calibrator *calib=new AliT0Calibrator();
110 // Int_t mV2Mip = param->GetmV2Mip();
111 //mV2Mip = param->GetmV2Mip();
112 Float_t channelWidth = fParam->GetChannelWidth() ;
113 Int_t meanT0 = fParam->GetMeanT0();
115 AliDebug(1,Form("Start DIGITS reconstruction "));
117 TBranch *brDigits=digitsTree->GetBranch("T0");
118 AliT0digit *fDigits = new AliT0digit() ;
120 brDigits->SetAddress(&fDigits);
122 AliError(Form("EXEC Branch T0 digits not found"));
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);
134 cout<<"!!!! AliT0Reconstructor::Reconstruct RefPoint "<<fDigits->RefPoint()<<endl;
136 Float_t besttimeA=999999;
137 Float_t besttimeC=999999;
138 Int_t pmtBestA=99999;
139 Int_t pmtBestC=99999;
140 Float_t timeDiff=999999, meanTime=0;
144 AliT0RecPoint* frecpoints= new AliT0RecPoint ();
145 clustersTree->Branch( "T0", "AliT0RecPoint" ,&frecpoints, 405,1);
147 Float_t time[24], adc[24];
148 for (Int_t ipmt=0; ipmt<24; ipmt++) {
149 if(timeCFD->At(ipmt)>0 ){
150 Double_t qt0 = Double_t(chargeQT0->At(ipmt));
151 Double_t qt1 = Double_t(chargeQT1->At(ipmt));
152 if((qt1-qt0)>0) adc[ipmt] = TMath::Exp( Double_t (channelWidth*(qt1-qt0)/1000));
153 time[ipmt] = calib-> WalkCorrection( ipmt,Int_t(qt1) , timeCFD->At(ipmt) ) ;
156 Double_t sl = (timeLED->At(ipmt) - time[ipmt])*channelWidth;
157 Double_t qt=((TGraph*)fAmpLEDrec.At(ipmt))->Eval(sl/1000.);
158 frecpoints->SetTime(ipmt,time[ipmt]);
159 frecpoints->SetAmp(ipmt,adc[ipmt]);
160 frecpoints->SetAmpLED(ipmt,qt);
168 for (Int_t ipmt=0; ipmt<12; ipmt++){
169 if(time[ipmt] > 1 ) {
170 if(time[ipmt]<besttimeC){
171 besttimeC=time[ipmt]; //timeC
176 for ( Int_t ipmt=12; ipmt<24; ipmt++){
178 if(time[ipmt]<besttimeA) {
179 besttimeA=time[ipmt]; //timeA
183 if(besttimeA !=999999) frecpoints->SetTimeBestA(Int_t(besttimeA));
184 if( besttimeC != 999999 ) frecpoints->SetTimeBestC(Int_t(besttimeC));
185 AliDebug(1,Form(" besttimeA %f ps, besttimeC %f ps",besttimeA, besttimeC));
186 Float_t c = 0.0299792; // cm/ps
188 if(besttimeA !=999999 && besttimeC != 999999 ){
189 timeDiff =(besttimeC - besttimeA)*channelWidth;
190 meanTime = (meanT0 - (besttimeA + besttimeC)/2) * channelWidth;
191 vertex = c*(timeDiff)/2. + (fdZonA - fdZonC)/2; //-(lenr-lenl))/2;
192 AliDebug(1,Form(" timeDiff %f ps, meanTime %f ps, vertex %f cm",timeDiff, meanTime,vertex ));
193 frecpoints->SetVertex(vertex);
194 frecpoints->SetMeanTime(Int_t(meanTime));
197 //time in each channel as time[ipmt]-MeanTimeinThisChannel(with vertex=0)
198 for (Int_t ipmt=0; ipmt<24; ipmt++) {
200 // time[ipmt] = (time[ipmt] - fTime0vertex[ipmt])*channelWidth;
201 time[ipmt] = time[ipmt] * channelWidth;
202 frecpoints->SetTime(ipmt,time[ipmt]);
205 clustersTree->Fill();
214 //_______________________________________________________________________
216 void AliT0Reconstructor::Reconstruct(AliRawReader* rawReader, TTree*recTree) const
219 // T0RecPoint writing
221 //Q->T-> coefficients !!!! should be measured!!!
222 Int_t allData[110][5];
224 TArrayI * timeCFD = new TArrayI(24);
225 TArrayI * timeLED = new TArrayI(24);
226 TArrayI * chargeQT0 = new TArrayI(24);
227 TArrayI * chargeQT1 = new TArrayI(24);
229 for (Int_t i=0; i<110; i++) {
233 AliT0RawReader myrawreader(rawReader);
234 if (!myrawreader.Next())
235 AliDebug(1,Form(" no raw data found!! %i", myrawreader.Next()));
236 for (Int_t i=0; i<110; i++) {
237 allData[i][0]=myrawreader.GetData(i,0);
239 AliT0Calibrator *calib = new AliT0Calibrator();
241 // Int_t mV2Mip = param->GetmV2Mip();
242 //mV2Mip = param->GetmV2Mip();
243 Float_t channelWidth = fParam->GetChannelWidth() ;
245 Int_t meanT0 = fParam->GetMeanT0();
247 for (Int_t in=0; in<24; in++)
249 timeLED->AddAt(allData[in+1][0],in);
250 timeCFD->AddAt(allData[in+25][0],in);
251 chargeQT1->AddAt(allData[in+57][0],in);
252 chargeQT0->AddAt(allData[in+80][0],in);
253 AliDebug(10, Form(" readed Raw %i %i %i %i %i", in, timeLED->At(in),timeCFD->At(in),chargeQT0->At(in),chargeQT1->At(in)));
256 Float_t besttimeA=999999;
257 Float_t besttimeC=999999;
258 Int_t pmtBestA=99999;
259 Int_t pmtBestC=99999;
260 Float_t timeDiff=999999, meanTime=0;
263 AliT0RecPoint* frecpoints= new AliT0RecPoint ();
265 recTree->Branch( "T0", "AliT0RecPoint" ,&frecpoints, 405,1);
268 Float_t time[24], adc[24];
269 for (Int_t ipmt=0; ipmt<24; ipmt++) {
270 if(timeCFD->At(ipmt)>0 ){
271 Double_t qt0 = Double_t(chargeQT0->At(ipmt));
272 Double_t qt1 = Double_t(chargeQT1->At(ipmt));
273 if((qt1-qt0)>0) adc[ipmt] = TMath::Exp( Double_t (channelWidth*(qt1-qt0)/1000));
274 // time[ipmt] = channelWidth * (calib-> WalkCorrection( ipmt,qt1 , timeCFD->At(ipmt) ) ) ;
275 time[ipmt] = calib-> WalkCorrection( ipmt,Int_t(qt1) , timeCFD->At(ipmt) ) ;
276 Double_t sl = (timeLED->At(ipmt) - time[ipmt])*channelWidth;
277 Double_t qt=((TGraph*)fAmpLEDrec.At(ipmt))->Eval(sl/1000.);
278 frecpoints->SetTime(ipmt,time[ipmt]);
279 frecpoints->SetAmp(ipmt,adc[ipmt]);
280 frecpoints->SetAmpLED(ipmt,qt);
281 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));
290 for (Int_t ipmt=0; ipmt<12; ipmt++){
291 if(time[ipmt] > 1 ) {
292 if(time[ipmt]<besttimeC){
293 besttimeC=time[ipmt]; //timeC
298 for ( Int_t ipmt=12; ipmt<24; ipmt++){
300 if(time[ipmt]<besttimeA) {
301 besttimeA=time[ipmt]; //timeA
305 if(besttimeA !=999999) frecpoints->SetTimeBestA(Int_t(besttimeA));
306 if( besttimeC != 999999 ) frecpoints->SetTimeBestC(Int_t(besttimeC));
307 AliDebug(1,Form(" besttimeA %f ps, besttimeC %f ps",besttimeA, besttimeC));
308 Float_t c = 0.0299792; // cm/ps
310 if(besttimeA !=999999 && besttimeC != 999999 ){
311 timeDiff = (besttimeC - besttimeA)*channelWidth;
312 meanTime = (meanT0 - (besttimeA + besttimeC)/2) * channelWidth;
313 vertex = c*(timeDiff)/2. + (fdZonA - fdZonC)/2; //-(lenr-lenl))/2;
314 AliDebug(1,Form(" timeDiff %f ps, meanTime %f ps, vertex %f cm",timeDiff, meanTime,vertex ));
315 frecpoints->SetVertex(vertex);
316 frecpoints->SetMeanTime(Int_t(meanTime));
319 //time in each channel as time[ipmt]-MeanTimeinThisChannel(with vertex=0)
321 for (Int_t ipmt=0; ipmt<24; ipmt++) {
323 time[ipmt] = (time[ipmt] - fTime0vertex[ipmt])*channelWidth;
324 frecpoints->SetTime(ipmt,time[ipmt]);
337 //____________________________________________________________
339 void AliT0Reconstructor::FillESD(TTree */*digitsTree*/, TTree *clustersTree, AliESDEvent *pESD) const
342 /***************************************************
343 Resonstruct digits to vertex position
344 ****************************************************/
346 AliDebug(1,Form("Start FillESD T0"));
348 TTree *treeR = clustersTree;
350 AliT0RecPoint* frecpoints= new AliT0RecPoint ();
352 AliError("Reconstruct Fill ESD >> no recpoints found");
356 AliDebug(1,Form("Start FillESD T0"));
357 TBranch *brRec = treeR->GetBranch("T0");
359 brRec->SetAddress(&frecpoints);
361 AliError(Form("EXEC Branch T0 rec not found"));
366 Float_t amp[24], time[24];
367 Float_t zPosition = frecpoints -> GetVertex();
368 Float_t timeStart = frecpoints -> GetMeanTime() ;
369 for ( Int_t i=0; i<24; i++) {
370 time[i] = Float_t (frecpoints -> GetTime(i)); // ps to ns
371 amp[i] = frecpoints -> GetAmp(i);
373 pESD->SetT0zVertex(zPosition); //vertex Z position
374 pESD->SetT0(timeStart); // interaction time
375 pESD->SetT0time(time); // best TOF on each PMT
376 pESD->SetT0amplitude(amp); // number of particles(MIPs) on each PMT
378 AliDebug(1,Form(" Z position %f cm, T0 %f ps",zPosition , timeStart));
380 } // vertex in 3 sigma