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"
41 //#include <TGeoManager.h>
42 //#include <TClonesArray.h>
43 //#include <TString.h>
44 //#include <TGeoPNEntry.h>
45 //#include <TGeoPhysicalNode.h>
46 //#include <TGeoHMatrix.h>
48 ClassImp(AliT0Reconstructor)
50 AliT0Reconstructor:: AliT0Reconstructor(): AliReconstructor(),
54 AliDebug(1,"Start reconstructor ");
56 fParam = AliT0Parameters::Instance();
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);
63 fdZ_C = TMath::Abs(fParam->GetZPositionShift("T0/C/PMT1"));
64 fdZ_A = TMath::Abs(fParam->GetZPositionShift("T0/A/PMT15"));
67 //____________________________________________________________________
69 AliT0Reconstructor::AliT0Reconstructor(const AliT0Reconstructor &r):
74 // AliT0Reconstructor copy constructor
77 ((AliT0Reconstructor &) r).Copy(*this);
81 //_____________________________________________________________________________
82 AliT0Reconstructor &AliT0Reconstructor::operator=(const AliT0Reconstructor &r)
85 // Assignment operator
88 if (this != &r) ((AliT0Reconstructor &) r).Copy(*this);
93 //_____________________________________________________________________________
95 void AliT0Reconstructor::Reconstruct(TTree*digitsTree, TTree*clustersTree) const
98 // T0 digits reconstruction
102 TArrayI * timeCFD = new TArrayI(24);
103 TArrayI * timeLED = new TArrayI(24);
104 TArrayI * chargeQT0 = new TArrayI(24);
105 TArrayI * chargeQT1 = new TArrayI(24);
107 AliT0Calibrator *calib=new AliT0Calibrator();
109 // Int_t mV2Mip = param->GetmV2Mip();
110 //mV2Mip = param->GetmV2Mip();
111 Int_t channelWidth = fParam->GetChannelWidth() ;
112 Int_t meanT0 = fParam->GetMeanT0();
114 AliDebug(1,Form("Start DIGITS reconstruction "));
116 TBranch *brDigits=digitsTree->GetBranch("T0");
117 AliT0digit *fDigits = new AliT0digit() ;
119 brDigits->SetAddress(&fDigits);
121 cerr<<"EXEC Branch T0 digits not found"<<endl;
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);
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;
141 AliT0RecPoint* frecpoints= new AliT0RecPoint ();
142 clustersTree->Branch( "T0", "AliT0RecPoint" ,&frecpoints, 405,1);
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) ) ;
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);
165 for (Int_t ipmt=0; ipmt<12; ipmt++){
166 if(time[ipmt] > 1 ) {
167 if(time[ipmt]<besttimeC){
168 besttimeC=time[ipmt]; //timeC
173 for ( Int_t ipmt=12; ipmt<24; ipmt++){
175 if(time[ipmt]<besttimeA) {
176 besttimeA=time[ipmt]; //timeA
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
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));
194 //time in each channel as time[ipmt]-MeanTimeinThisChannel(with vertex=0)
195 for (Int_t ipmt=0; ipmt<24; ipmt++) {
197 time[ipmt] = (time[ipmt] - fTime0vertex[ipmt])*channelWidth;
198 frecpoints->SetTime(ipmt,time[ipmt]);
201 clustersTree->Fill();
210 //_______________________________________________________________________
212 void AliT0Reconstructor::Reconstruct(AliRawReader* rawReader, TTree*recTree) const
215 // T0RecPoint writing
217 //Q->T-> coefficients !!!! should be measured!!!
218 Int_t allData[110][5];
220 TArrayI * timeCFD = new TArrayI(24);
221 TArrayI * timeLED = new TArrayI(24);
222 TArrayI * chargeQT0 = new TArrayI(24);
223 TArrayI * chargeQT1 = new TArrayI(24);
225 for (Int_t i=0; i<110; i++) {
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);
235 AliT0Calibrator *calib = new AliT0Calibrator();
237 // Int_t mV2Mip = param->GetmV2Mip();
238 //mV2Mip = param->GetmV2Mip();
239 Int_t channelWidth = fParam->GetChannelWidth() ;
240 Int_t meanT0 = fParam->GetMeanT0();
242 for (Int_t in=0; in<24; in++)
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)));
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;
258 AliT0RecPoint* frecpoints= new AliT0RecPoint ();
260 recTree->Branch( "T0", "AliT0RecPoint" ,&frecpoints, 405,1);
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);
283 for (Int_t ipmt=0; ipmt<12; ipmt++){
284 if(time[ipmt] > 1 ) {
285 if(time[ipmt]<besttimeC){
286 besttimeC=time[ipmt]; //timeC
291 for ( Int_t ipmt=12; ipmt<24; ipmt++){
293 if(time[ipmt]<besttimeA) {
294 besttimeA=time[ipmt]; //timeA
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
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));
313 //time in each channel as time[ipmt]-MeanTimeinThisChannel(with vertex=0)
314 for (Int_t ipmt=0; ipmt<24; ipmt++) {
316 time[ipmt] = (time[ipmt] - fTime0vertex[ipmt])*channelWidth;
317 frecpoints->SetTime(ipmt,time[ipmt]);
329 //____________________________________________________________
331 void AliT0Reconstructor::FillESD(AliRunLoader* runLoader, AliESDEvent *pESD) const
334 /***************************************************
335 Resonstruct digits to vertex position
336 ****************************************************/
340 AliError("Reconstruct >> No run loader");
344 AliDebug(1,Form("Start FillESD T0"));
346 AliT0Loader* pStartLoader = (AliT0Loader*) runLoader->GetLoader("T0Loader");
348 pStartLoader->LoadRecPoints("READ");
350 TTree *treeR = pStartLoader->TreeR();
352 AliT0RecPoint* frecpoints= new AliT0RecPoint ();
354 AliError("Reconstruct Fill ESD >> no recpoints found");
358 AliDebug(1,Form("Start FillESD T0"));
359 TBranch *brRec = treeR->GetBranch("T0");
361 brRec->SetAddress(&frecpoints);
363 cerr<<"EXEC Branch T0 rec not found"<<endl;
369 Float_t timeStart, Zposition, amp[24], time[24];
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);
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
382 AliDebug(1,Form(" Z position %f cm, T0 %f ps",Zposition , timeStart));
384 pStartLoader->UnloadRecPoints();
386 } // vertex in 3 sigma