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"
25 #include "AliT0Loader.h"
26 #include <TClonesArray.h>
27 #include "AliT0RecPoint.h"
28 #include "AliRawReader.h"
29 #include "AliT0RawReader.h"
30 #include "AliT0digit.h"
31 #include "AliT0Reconstructor.h"
32 #include "AliT0Parameters.h"
33 #include "AliT0Calibrator.h"
34 #include "AliCDBLocal.h"
35 #include "AliCDBStorage.h"
36 #include "AliCDBManager.h"
37 #include "AliCDBEntry.h"
42 ClassImp(AliT0Reconstructor)
44 AliT0Reconstructor:: AliT0Reconstructor(): AliReconstructor(),
50 AliDebug(1,"Start reconstructor ");
52 //____________________________________________________________________
54 AliT0Reconstructor::AliT0Reconstructor(const AliT0Reconstructor &r):
61 // AliT0Reconstructor copy constructor
64 ((AliT0Reconstructor &) r).Copy(*this);
68 //_____________________________________________________________________________
69 AliT0Reconstructor &AliT0Reconstructor::operator=(const AliT0Reconstructor &r)
72 // Assignment operator
75 if (this != &r) ((AliT0Reconstructor &) r).Copy(*this);
80 //_____________________________________________________________________________
82 void AliT0Reconstructor::Reconstruct(TTree*digitsTree, TTree*clustersTree) const
85 // T0 digits reconstruction
89 Float_t timeDelayLED[24];
91 TObjArray slewingLEDrec;
94 TArrayI * timeCFD = new TArrayI(24);
95 TArrayI * timeLED = new TArrayI(24);
96 TArrayI * chargeQT0 = new TArrayI(24);
97 TArrayI * chargeQT1 = new TArrayI(24);
99 AliT0Parameters* param = AliT0Parameters::Instance();
101 AliT0Calibrator *calib=new AliT0Calibrator();
103 Int_t mV2Mip = param->GetmV2Mip();
104 //mV2Mip = param->GetmV2Mip();
105 Int_t channelWidth = param->GetChannelWidth() ;
107 for (Int_t i=0; i<24; i++){
108 TGraph* gr = param ->GetSlewRec(i);
109 slewingLEDrec.AddAtAndExpand(gr,i) ;
111 zdetC = param->GetZposition(0);
112 zdetA = param->GetZposition(1);
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 Int_t qt0= chargeQT0->At(ipmt);
148 Int_t qt1= chargeQT1->At(ipmt);
149 if((qt1-qt0)>0) adc[ipmt] = TMath::Exp( Double_t (channelWidth*(qt1-qt0)/1000));
150 time[ipmt] = channelWidth * (calib-> WalkCorrection( ipmt,qt1 , timeCFD->At(ipmt) ) ) ;
153 Double_t sl = (timeLED->At(ipmt) - timeCFD->At(ipmt)- (1000.*timeDelayLED[ipmt]/channelWidth))*channelWidth;
154 Double_t qt=((TGraph*)slewingLEDrec.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;
187 meanTime = (besttimeA + besttimeC)/2.;
188 vertex = c*(timeDiff)/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 clustersTree->Fill();
198 //_______________________________________________________________________
200 void AliT0Reconstructor::Reconstruct(AliRawReader* rawReader, TTree*recTree) const
203 // T0RecPoint writing
205 //Q->T-> coefficients !!!! should be asked!!!
206 Float_t timeDelayLED[24];
208 TObjArray slewingLEDrec;
211 TArrayI * timeCFD = new TArrayI(24);
212 TArrayI * timeLED = new TArrayI(24);
213 TArrayI * chargeQT0 = new TArrayI(24);
214 TArrayI * chargeQT1 = new TArrayI(24);
216 AliT0RawReader myrawreader(rawReader);
217 if (!myrawreader.Next())
218 AliDebug(1,Form(" no raw data found!! %i", myrawreader.Next()));
219 Int_t allData[110][5];
220 for (Int_t i=0; i<110; i++) {
221 allData[i][0]=myrawreader.GetData(i,0);
224 AliT0Parameters* param = AliT0Parameters::Instance();
226 AliT0Calibrator *calib=new AliT0Calibrator();
228 Int_t mV2Mip = param->GetmV2Mip();
229 //mV2Mip = param->GetmV2Mip();
230 Int_t channelWidth = param->GetChannelWidth() ;
232 for (Int_t i=0; i<24; i++){
233 TGraph* gr = param ->GetSlewRec(i);
234 slewingLEDrec.AddAtAndExpand(gr,i) ;
237 zdetC = param->GetZposition(0);
238 zdetA = param->GetZposition(1);
240 for (Int_t in=0; in<24; in++)
242 timeLED->AddAt(allData[in+1][0],in);
243 timeCFD->AddAt(allData[in+25][0],in);
244 chargeQT1->AddAt(allData[in+55][0],in);
245 chargeQT0->AddAt(allData[in+79][0],in);
246 AliDebug(10, Form(" readed Raw %i %i %i %i %i", in, timeLED->At(in),timeCFD->At(in),chargeQT0->At(in),chargeQT1->At(in)));
249 Float_t besttimeA=999999;
250 Float_t besttimeC=999999;
251 Int_t pmtBestA=99999;
252 Int_t pmtBestC=99999;
253 Float_t timeDiff=999999, meanTime=0;
256 AliT0RecPoint* frecpoints= new AliT0RecPoint ();
258 recTree->Branch( "T0", "AliT0RecPoint" ,&frecpoints, 405,1);
261 Float_t time[24], adc[24];
262 for (Int_t ipmt=0; ipmt<24; ipmt++) {
263 if(timeCFD->At(ipmt)>0 ){
264 Int_t qt0= chargeQT0->At(ipmt);
265 Int_t qt1= chargeQT1->At(ipmt);
266 if((qt1-qt0)>0) adc[ipmt] = TMath::Exp( Double_t (channelWidth*(qt1-qt0)/1000));
267 time[ipmt] = channelWidth * (calib-> WalkCorrection( ipmt,qt1 , timeCFD->At(ipmt) ) ) ;
268 Double_t sl = (timeLED->At(ipmt) - timeCFD->At(ipmt)- (1000.*timeDelayLED[ipmt]/channelWidth))*channelWidth;
269 Double_t qt=((TGraph*)slewingLEDrec.At(ipmt))->Eval(sl/1000.);
270 frecpoints->SetTime(ipmt,time[ipmt]);
271 frecpoints->SetAmp(ipmt,adc[ipmt]);
272 frecpoints->SetAmpLED(ipmt,qt);
280 for (Int_t ipmt=0; ipmt<12; ipmt++){
281 if(time[ipmt] > 1 ) {
282 if(time[ipmt]<besttimeC){
283 besttimeC=time[ipmt]; //timeC
288 for ( Int_t ipmt=12; ipmt<24; ipmt++){
290 if(time[ipmt]<besttimeA) {
291 besttimeA=time[ipmt]; //timeA
295 if(besttimeA !=999999) frecpoints->SetTimeBestA(Int_t(besttimeA));
296 if( besttimeC != 999999 ) frecpoints->SetTimeBestC(Int_t(besttimeC));
297 AliDebug(1,Form(" besttimeA %f ps, besttimeC %f ps",besttimeA, besttimeC));
298 Float_t c = 0.0299792; // cm/ps
300 if(besttimeA !=999999 && besttimeC != 999999 ){
301 timeDiff = besttimeC - besttimeA;
302 meanTime = (besttimeA + besttimeC)/2.;
303 vertex = c*(timeDiff)/2.; //-(lenr-lenl))/2;
304 AliDebug(1,Form(" timeDiff %f ps, meanTime %f ps, vertex %f cm",timeDiff, meanTime,vertex ));
305 frecpoints->SetVertex(vertex);
306 frecpoints->SetMeanTime(Int_t(meanTime));
311 //____________________________________________________________
313 void AliT0Reconstructor::FillESD(AliRunLoader* runLoader, AliESD *pESD) const
316 /***************************************************
317 Resonstruct digits to vertex position
318 ****************************************************/
322 AliError("Reconstruct >> No run loader");
326 AliDebug(1,Form("Start FillESD T0"));
328 AliT0Loader* pStartLoader = (AliT0Loader*) runLoader->GetLoader("T0Loader");
330 pStartLoader->LoadRecPoints("READ");
332 TTree *treeR = pStartLoader->TreeR();
334 AliT0RecPoint* frecpoints= new AliT0RecPoint ();
336 AliError("Reconstruct Fill ESD >> no recpoints found");
340 AliDebug(1,Form("Start FillESD T0"));
341 TBranch *brRec = treeR->GetBranch("T0");
343 brRec->SetAddress(&frecpoints);
345 cerr<<"EXEC Branch T0 rec not found"<<endl;
351 Float_t timeStart, Zposition, amp[24], time[24];
354 Zposition = frecpoints -> GetVertex();
355 timeStart = frecpoints -> GetMeanTime() - mean0;
356 for ( i=0; i<24; i++) {
357 time[i] = Float_t (frecpoints -> GetTime(i)) / 1000.; // ps to ns
358 amp[i] = frecpoints -> GetAmp(i);
360 pESD->SetT0zVertex(Zposition); //vertex Z position
361 pESD->SetT0(timeStart); // interaction time
362 pESD->SetT0time(time); // best TOF on each PMT
363 pESD->SetT0amplitude(amp); // number of particles(MIPs) on each PMT
364 cout<<" ESD >> "<<Zposition<<" "<<timeStart<<endl;
366 pStartLoader->UnloadRecPoints();
368 } // vertex in 3 sigma