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 **************************************************************************/
17 /*********************************************************************
18 * T0 reconstruction and filling ESD
19 * - reconstruct mean time (interation time)
22 ********************************************************************/
24 #include <AliESDEvent.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 "AliESDfriend.h"
39 #include <Riostream.h>
41 ClassImp(AliT0Reconstructor)
43 AliT0Reconstructor:: AliT0Reconstructor(): AliReconstructor(),
60 fParam = AliT0Parameters::Instance();
63 for (Int_t i=0; i<24; i++){
64 TGraph* gr = fParam ->GetAmpLEDRec(i);
65 if (gr) fAmpLEDrec.AddAtAndExpand(gr,i) ;
66 TGraph* gr1 = fParam ->GetAmpLED(i);
67 if (gr1) fAmpLED.AddAtAndExpand(gr1,i) ;
68 TGraph* gr2 = fParam ->GetQTC(i);
69 if (gr2) fQTC.AddAtAndExpand(gr2,i) ;
72 fLatencyL1 = fParam->GetLatencyL1();
73 fLatencyL1A = fParam->GetLatencyL1A();
74 fLatencyL1C = fParam->GetLatencyL1C();
75 fLatencyHPTDC = fParam->GetLatencyHPTDC();
76 AliDebug(10,Form(" LatencyL1 %f latencyL1A %f latencyL1C %f latencyHPTDC %f \n",fLatencyL1, fLatencyL1A, fLatencyL1C, fLatencyHPTDC));
78 // fdZonC = TMath::Abs(fParam->GetZPositionShift("T0/C/PMT1"));
79 //fdZonA = TMath::Abs(fParam->GetZPositionShift("T0/A/PMT15"));
82 fCalib = new AliT0Calibrator();
86 //_____________________________________________________________________________
87 void AliT0Reconstructor::Reconstruct(TTree*digitsTree, TTree*clustersTree) const
90 // T0 digits reconstruction
91 Int_t refAmp = GetRecoParam()->GetRefAmp();
93 TArrayI * timeCFD = new TArrayI(24);
94 TArrayI * timeLED = new TArrayI(24);
95 TArrayI * chargeQT0 = new TArrayI(24);
96 TArrayI * chargeQT1 = new TArrayI(24);
99 Float_t channelWidth = fParam->GetChannelWidth() ;
100 Float_t meanVertex = fParam->GetMeanVertex();
101 Float_t c = 0.0299792; // cm/ps
102 Double32_t vertex = 9999999;
103 Double32_t timeDiff=999999, meanTime=999999, timeclock=999999;
106 AliDebug(1,Form("Start DIGITS reconstruction "));
109 TBranch *brDigits=digitsTree->GetBranch("T0");
110 AliT0digit *fDigits = new AliT0digit() ;
112 brDigits->SetAddress(&fDigits);
114 AliError(Form("EXEC Branch T0 digits not found"));
118 digitsTree->GetEvent(0);
119 digitsTree->GetEntry(0);
120 brDigits->GetEntry(0);
121 fDigits->GetTimeCFD(*timeCFD);
122 fDigits->GetTimeLED(*timeLED);
123 fDigits->GetQT0(*chargeQT0);
124 fDigits->GetQT1(*chargeQT1);
125 Int_t onlineMean = fDigits->MeanTime();
128 for (Int_t i=0; i<5; i++) tr[i]=false;
130 Double32_t besttimeA=999999;
131 Double32_t besttimeC=999999;
132 Int_t pmtBestA=99999;
133 Int_t pmtBestC=99999;
135 AliT0RecPoint* frecpoints= new AliT0RecPoint ();
136 clustersTree->Branch( "T0", "AliT0RecPoint" ,&frecpoints, 405,1);
138 Float_t time[24], adc[24];
139 for (Int_t ipmt=0; ipmt<24; ipmt++) {
140 if(timeCFD->At(ipmt)>0 ){
141 if(( chargeQT1->At(ipmt) - chargeQT0->At(ipmt))>0)
142 adc[ipmt] = chargeQT1->At(ipmt) - chargeQT0->At(ipmt);
146 // time[ipmt] = fCalib-> WalkCorrection(refAmp, ipmt, adc[ipmt], timeCFD->At(ipmt)) ;
148 Double_t sl = Double_t(timeLED->At(ipmt) - timeCFD->At(ipmt));
149 time[ipmt] = fCalib-> WalkCorrection( refAmp,ipmt, Int_t(sl), timeCFD->At(ipmt) ) ;
150 AliDebug(10,Form(" ipmt %i QTC %i , time in chann %i (led-cfd) %i ",
151 ipmt, Int_t(adc[ipmt]) ,Int_t(time[ipmt]),Int_t( sl)));
153 Double_t ampMip =((TGraph*)fAmpLED.At(ipmt))->Eval(sl);
154 Double_t qtMip = ((TGraph*)fQTC.At(ipmt))->Eval(adc[ipmt]);
155 AliDebug(10,Form(" Amlitude in MIPS LED %f , QTC %f in channels %i\n ",ampMip,qtMip, adc[ipmt]));
157 frecpoints->SetTime(ipmt, Float_t(time[ipmt]) );
158 frecpoints->SetAmp(ipmt, Float_t( ampMip)); //for cosmic &pp beam
159 frecpoints->SetAmpLED(ipmt, Float_t(qtMip));
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) {
184 frecpoints->SetTimeBestA(Int_t(besttimeA *channelWidth));
187 if( besttimeC < 999999 ) {
188 frecpoints->SetTimeBestC(Int_t(besttimeC *channelWidth));
191 AliDebug(10,Form(" besttimeA %f ch, besttimeC %f ch",besttimeA, besttimeC));
192 if(besttimeA <999999 && besttimeC < 999999 ){
193 // timeDiff = (besttimeC - besttimeA)*channelWidth;
194 timeDiff = (besttimeA - besttimeC)*channelWidth;
195 meanTime = (besttimeA + besttimeC)/2;// * channelWidth);
196 timeclock = meanTime *channelWidth ;
197 vertex = meanVertex - c*(timeDiff)/2.;// + (fdZonA - fdZonC)/2;
200 frecpoints->SetVertex(vertex);
201 frecpoints->SetMeanTime(meanTime);
202 frecpoints->SetT0clock(timeclock);
203 frecpoints->SetT0Trig(tr);
205 AliInfo(Form("T0 triggers %d %d %d %d %d",tr[0],tr[1],tr[2],tr[3],tr[4]));
208 frecpoints->SetOnlineMean(Int_t(onlineMean));
209 AliDebug(10,Form(" timeDiff %i #channel, meanTime %i #channel, vertex %f cm online mean %i timeclock %i ps",timeDiff, meanTime,vertex, Int_t(onlineMean), timeclock));
215 clustersTree->Fill();
224 //_______________________________________________________________________
226 void AliT0Reconstructor::Reconstruct(AliRawReader* rawReader, TTree*recTree) const
230 // reference amplitude and time ref. point from reco param
232 Int_t refAmp = GetRecoParam()->GetRefAmp();
233 Int_t refPoint = GetRecoParam()->GetRefPoint();
235 Int_t allData[110][5];
237 Int_t timeCFD[24], timeLED[24], chargeQT0[24], chargeQT1[24];
238 Double32_t timeDiff=999999, meanTime=999999, timeclock=999999;
239 Float_t c = 29.9792458; // cm/ns
240 Double32_t vertex = 9999999;
242 // Float_t meanVertex = fParam->GetMeanVertex();
243 Float_t meanVertex = 0;
245 AliDebug(1,Form(" @@@@ Latency ",fLatencyL1));
246 for (Int_t i0=0; i0<105; i0++)
248 for (Int_t j0=0; j0<5; j0++) allData[i0][j0]=0;
251 Double32_t besttimeA=9999999;
252 Double32_t besttimeC=9999999;
253 Int_t pmtBestA=99999;
254 Int_t pmtBestC=99999;
256 AliT0RecPoint* frecpoints= new AliT0RecPoint ();
258 recTree->Branch( "T0", "AliT0RecPoint" ,&frecpoints, 405,1);
260 AliDebug(10," before read data ");
261 AliT0RawReader myrawreader(rawReader);
263 UInt_t type =rawReader->GetType();
265 if (!myrawreader.Next())
266 AliDebug(1,Form(" no raw data found!!"));
269 if(type == 7) { //only physics
270 for (Int_t i=0; i<105; i++) {
271 for (Int_t iHit=0; iHit<5; iHit++)
273 allData[i][iHit] = myrawreader.GetData(i,iHit);
278 ref = allData[refPoint][0]-5000;
280 Float_t channelWidth = fParam->GetChannelWidth() ;
282 // Int_t meanT0 = fParam->GetMeanT0();
285 for (Int_t in=0; in<12; in++)
287 timeCFD[in] = allData[in+1][0] ;
288 timeCFD[in+12] = allData[in+56+1][0] ;
289 timeLED[in] = allData[in+12+1][0] ;
290 timeLED[in+12] = allData[in+68+1][0] ;
291 AliDebug(10, Form(" readed i %i cfdC %i cfdA %i ledC %i ledA%i ",
292 in, timeCFD[in],timeCFD[in+12],timeLED[in],
296 for (Int_t in=0; in<12; in++)
298 chargeQT0[in]=allData[2*in+25][0];
299 chargeQT1[in]=allData[2*in+26][0];
302 for (Int_t in=12; in<24; in++)
304 chargeQT0[in]=allData[2*in+57][0];
305 chargeQT1[in]=allData[2*in+58][0];
308 // } //cosmic with physics event
309 for (Int_t in=0; in<24; in++)
310 AliDebug(10, Form(" readed Raw %i %i %i %i %i",
311 in, timeLED[in],timeCFD[in],chargeQT0[in],chargeQT1[in]));
312 onlineMean = allData[49][0];
314 Double32_t time[24], adc[24];
315 for (Int_t ipmt=0; ipmt<24; ipmt++) {
316 if(timeCFD[ipmt]>0 && timeLED[ipmt]>0){
319 if(( chargeQT1[ipmt] - chargeQT0[ipmt])>0)
320 adc[ipmt] = chargeQT0[ipmt] - chargeQT1[ipmt];
325 // time[ipmt] = fCalib-> WalkCorrection(refAmp, ipmt, adc[ipmt], timeCFD[ipmt] ) ;
327 Double_t sl = timeLED[ipmt] - timeCFD[ipmt];
328 time[ipmt] = fCalib-> WalkCorrection( refAmp,ipmt, Int_t(sl), timeCFD[ipmt] ) ;
329 AliDebug(10,Form(" ipmt %i QTC %i , time in chann %i (led-cfd) %i ",
330 ipmt, Int_t(adc[ipmt]) ,Int_t(time[ipmt]),Int_t( sl)));
331 Double_t ampMip =( (TGraph*)fAmpLED.At(ipmt))->Eval(sl);
332 Double_t qtMip = ((TGraph*)fQTC.At(ipmt))->Eval(adc[ipmt]);
333 AliDebug(10,Form(" Amlitude in MIPS LED %f ; QTC %f; in channels %i\n ",ampMip,qtMip, adc[ipmt]));
335 frecpoints->SetTime(ipmt, Float_t(time[ipmt]) );
336 // frecpoints->SetTime(ipmt,Double32_t(timeCFD[ipmt]));
337 frecpoints->SetAmpLED(ipmt, Double32_t( qtMip)); //for cosmic &pp beam
338 frecpoints->SetAmp(ipmt, Double32_t(ampMip));
347 for (Int_t ipmt=0; ipmt<12; ipmt++){
348 if(time[ipmt] > 1 ) {
349 if(time[ipmt]<besttimeC){
350 besttimeC=time[ipmt]; //timeC
355 for ( Int_t ipmt=12; ipmt<24; ipmt++){
357 if(time[ipmt]<besttimeA) {
358 besttimeA=time[ipmt]; //timeA
362 if(besttimeA < 999999)
363 frecpoints->SetTimeBestA(0.001* besttimeA * channelWidth - fLatencyHPTDC + fLatencyL1A);
364 if( besttimeC < 999999 )
365 frecpoints->SetTimeBestC( 0.001 *besttimeC * channelWidth - fLatencyHPTDC + fLatencyL1C);
366 AliDebug(10,Form(" pmtA %i besttimeA %f ps, pmtC %i besttimeC %f ps",
367 pmtBestA,besttimeA, pmtBestC, besttimeC));
368 if(besttimeA <999999 && besttimeC < 999999 ){
369 timeDiff = ( besttimeA - besttimeC) *0.001 * channelWidth + fLatencyL1A - fLatencyL1C;
370 timeclock = 0.001*channelWidth * Float_t( besttimeA+besttimeC)/2. - fLatencyHPTDC + fLatencyL1;
371 meanTime = (besttimeA+besttimeC-2.*Float_t(ref))/2.;
372 vertex = meanVertex - c*(timeDiff)/2. ; //+ (fdZonA - fdZonC)/2;
375 AliDebug(5,Form(" timeDiff %f #channel, meanTime %f #channel, TOFmean%f vertex %f cm meanVertex %f online mean %i \n",timeDiff, meanTime,timeclock, vertex,meanVertex, onlineMean));
376 frecpoints->SetT0clock(timeclock);
377 frecpoints->SetVertex(vertex);
378 frecpoints->SetMeanTime(meanTime);
379 frecpoints->SetOnlineMean(Int_t(onlineMean));
383 Int_t trchan[5]= {50,51,52,55,56};
384 for (Int_t i=0; i<5; i++) tr[i]=false;
385 for (Int_t itr=0; itr<5; itr++) {
386 if(allData[trchan[itr]][0]>0) tr[itr]=true;
387 frecpoints->SetT0Trig(tr);
390 } // if (else )raw data
392 if(frecpoints) delete frecpoints;
396 //____________________________________________________________
398 void AliT0Reconstructor::FillESD(TTree */*digitsTree*/, TTree *clustersTree, AliESDEvent *pESD) const
401 /***************************************************
402 Resonstruct digits to vertex position
403 ****************************************************/
405 AliDebug(1,Form("Start FillESD T0"));
406 Float_t channelWidth = fParam->GetChannelWidth() ;
407 Float_t c = 29.9792458; // cm/ns
408 Float_t currentVertex=0, shift=0;
410 const AliESDVertex* vertex = pESD->GetPrimaryVertex();
411 if (!vertex) vertex = pESD->GetPrimaryVertexSPD();
412 if (!vertex) vertex = pESD->GetPrimaryVertexTPC();
413 if (!vertex) vertex = pESD->GetVertex();
416 AliDebug(2, Form("Got %s (%s) from ESD: %f",
417 vertex->GetName(), vertex->GetTitle(), vertex->GetZ()));
418 currentVertex = vertex->GetZ();
420 ncont = vertex->GetNContributors();
421 // cout<<" spdver "<<spdver<<" ncont "<<ncont<<endl;
423 shift = currentVertex/c;
424 // cout<<" vertex shif "<<shift<<" vertex "<<spdver<<" IsFromVertexer3D "<<fverSPD->IsFromVertexer3D()<<endl;
427 TTree *treeR = clustersTree;
429 AliT0RecPoint* frecpoints= new AliT0RecPoint ();
431 AliError("Reconstruct Fill ESD >> no recpoints found");
435 AliDebug(1,Form("Start FillESD T0"));
436 TBranch *brRec = treeR->GetBranch("T0");
438 brRec->SetAddress(&frecpoints);
440 AliError(Form("EXEC Branch T0 rec not found"));
445 Double32_t amp[24], time[24], ampQTC[24], timecorr[24];
446 Double32_t timeClock[3];
447 Double32_t zPosition = frecpoints -> GetVertex();
448 Double32_t timeStart = frecpoints -> GetMeanTime();
449 timeClock[0] = frecpoints -> GetT0clock() ;
450 timeClock[1] = frecpoints -> GetBestTimeA() + shift;
451 timeClock[2] = frecpoints -> GetBestTimeC() - shift;
452 for ( Int_t i=0; i<24; i++) {
453 time[i] = frecpoints -> GetTime(i); // ps to ns
454 amp[i] = frecpoints -> GetAmp(i);
455 ampQTC[i] = frecpoints -> AmpLED(i);
457 Int_t trig= frecpoints ->GetT0Trig();
458 pESD->SetT0Trig(trig);
460 pESD->SetT0zVertex(zPosition); //vertex Z position
461 pESD->SetT0(timeStart); // interaction time
462 for(Int_t i=0; i<3; i++)
463 pESD->SetT0TOF(i,timeClock[i]); // interaction time (ns)
464 pESD->SetT0time(time); // best TOF on each PMT
465 pESD->SetT0amplitude(amp); // number of particles(MIPs) on each PMT
467 AliDebug(1,Form("T0: Vertex %f (T0A+T0C)/2 %f #channels T0signal %f ns OrA %f ns OrC %f T0trig %i\n",zPosition, timeStart, timeClock[0], timeClock[1], timeClock[2], trig));
470 AliESDfriend *fr = (AliESDfriend*)pESD->FindListObject("AliESDfriend");
472 AliDebug(1, Form("Writing TZERO friend data to ESD tree"));
475 for ( Int_t i=0; i<24; i++) {
476 if(i<12) timecorr[i]=time[i]-shift*channelWidth;
477 if(i>11) timecorr[i]=time[i]-shift*channelWidth;
478 fr->SetT0timeCorr(timecorr) ;
480 fr->SetT0ampLEDminCFD(amp);
481 fr->SetT0ampQTC(ampQTC);
488 } // vertex in 3 sigma