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"
34 #include "AliESDTZERO.h"
35 #include "AliESDTZEROfriend.h"
37 #include "AliCDBEntry.h"
38 #include "AliCDBManager.h"
39 #include "AliCTPTimeParams.h"
40 #include "AliLHCClockPhase.h"
41 #include "AliT0CalibSeasonTimeShift.h"
42 #include "AliESDRun.h"
47 #include <Riostream.h>
49 ClassImp(AliT0Reconstructor)
51 AliT0Reconstructor:: AliT0Reconstructor(): AliReconstructor(),
67 fESDTZEROfriend(NULL),
71 for (Int_t i=0; i<24; i++) fTime0vertex[i] =0;
74 AliCDBEntry *entry = AliCDBManager::Instance()->Get("GRP/CTP/CTPtiming");
75 if (!entry) AliFatal("CTP timing parameters are not found in OCDB !");
76 AliCTPTimeParams *ctpParams = (AliCTPTimeParams*)entry->GetObject();
77 Float_t l1Delay = (Float_t)ctpParams->GetDelayL1L0()*25.0;
79 AliCDBEntry *entry1 = AliCDBManager::Instance()->Get("GRP/CTP/TimeAlign");
80 if (!entry1) AliFatal("CTP time-alignment is not found in OCDB !");
81 AliCTPTimeParams *ctpTimeAlign = (AliCTPTimeParams*)entry1->GetObject();
82 l1Delay += ((Float_t)ctpTimeAlign->GetDelayL1L0()*25.0);
84 AliCDBEntry *entry4 = AliCDBManager::Instance()->Get("GRP/Calib/LHCClockPhase");
85 if (!entry4) AliFatal("LHC clock-phase shift is not found in OCDB !");
86 AliLHCClockPhase *phase = (AliLHCClockPhase*)entry4->GetObject();
88 fGRPdelays = l1Delay - phase->GetMeanPhase();
90 AliCDBEntry *entry5 = AliCDBManager::Instance()->Get("T0/Calib/TimeAdjust");
92 AliT0CalibSeasonTimeShift *timeshift = (AliT0CalibSeasonTimeShift*)entry5->GetObject();
93 fTimeMeanShift = timeshift->GetT0Means();
94 fTimeSigmaShift = timeshift->GetT0Sigmas();
97 AliWarning("Time Adjust is not found in OCDB !");
99 fParam = AliT0Parameters::Instance();
102 for (Int_t i=0; i<24; i++){
103 TGraph* gr = fParam ->GetAmpLEDRec(i);
104 if (gr) fAmpLEDrec.AddAtAndExpand(gr,i) ;
105 TGraph* gr1 = fParam ->GetAmpLED(i);
106 if (gr1) fAmpLED.AddAtAndExpand(gr1,i) ;
107 TGraph* gr2 = fParam ->GetQTC(i);
108 if (gr2) fQTC.AddAtAndExpand(gr2,i) ;
109 fTime0vertex[i] = fParam->GetCFD(i);
110 AliDebug(2,Form("OCDB mean CFD time %i %f \n",i, fTime0vertex[i]));
112 fLatencyL1 = fParam->GetLatencyL1();
113 fLatencyL1A = fParam->GetLatencyL1A();
114 fLatencyL1C = fParam->GetLatencyL1C();
115 fLatencyHPTDC = fParam->GetLatencyHPTDC();
116 AliDebug(2,Form(" LatencyL1 %f latencyL1A %f latencyL1C %f latencyHPTDC %f \n",fLatencyL1, fLatencyL1A, fLatencyL1C, fLatencyHPTDC));
118 for (Int_t i=0; i<24; i++) {
119 if( fTime0vertex[i] < 500 || fTime0vertex[i] > 50000) fTime0vertex[i] =( 1000.*fLatencyHPTDC - 1000.*fLatencyL1 + 1000.*fGRPdelays)/24.4;
120 // printf(" calulated mean %i %f \n",i, fTime0vertex[i]);
122 //here real Z position
123 fdZonC = TMath::Abs(fParam->GetZPosition("T0/C/PMT1"));
124 fdZonA = TMath::Abs(fParam->GetZPosition("T0/A/PMT15"));
126 fCalib = new AliT0Calibrator();
127 fESDTZEROfriend = new AliESDTZEROfriend();
128 fESDTZERO = new AliESDTZERO();
133 //_____________________________________________________________________________
134 void AliT0Reconstructor::Reconstruct(TTree*digitsTree, TTree*clustersTree) const
136 // T0 digits reconstruction
137 Int_t refAmp = 0 ; /*Int_t (GetRecoParam()->GetRefAmp());*/
139 TArrayI * timeCFD = new TArrayI(24);
140 TArrayI * timeLED = new TArrayI(24);
141 TArrayI * chargeQT0 = new TArrayI(24);
142 TArrayI * chargeQT1 = new TArrayI(24);
145 Float_t c = 29.9792458; // cm/ns
146 Float_t channelWidth = fParam->GetChannelWidth() ;
147 Double32_t vertex = 9999999, meanVertex = 9999999 ;
148 Double32_t timeDiff=999999, meanTime=999999, timeclock=999999;
151 AliDebug(1,Form("Start DIGITS reconstruction "));
153 Float_t lowAmpThreshold = GetRecoParam()->GetAmpLowThreshold();
154 Float_t highAmpThreshold = GetRecoParam()->GetAmpHighThreshold();
155 printf( "AliT0Reconstructor::Reconstruct::: RecoParam amplitude %f %f \n",lowAmpThreshold, highAmpThreshold);
157 Double32_t besttimeA=9999999; Double32_t besttimeA_best=9999999;
158 Double32_t besttimeC=9999999; Double32_t besttimeC_best=9999999;
159 Int_t timeDelayCFD[24];
162 for (Int_t i=0; i<24; i++) {
163 badpmt[i] = GetRecoParam() -> GetBadChannels(i);
164 timeDelayCFD[i] = Int_t (fParam->GetTimeDelayCFD(i));
167 TBranch *brDigits=digitsTree->GetBranch("T0");
168 AliT0digit *fDigits = new AliT0digit() ;
170 brDigits->SetAddress(&fDigits);
172 AliError(Form("EXEC Branch T0 digits not found"));
176 digitsTree->GetEvent(0);
177 digitsTree->GetEntry(0);
178 brDigits->GetEntry(0);
179 fDigits->GetTimeCFD(*timeCFD);
180 fDigits->GetTimeLED(*timeLED);
181 fDigits->GetQT0(*chargeQT0);
182 fDigits->GetQT1(*chargeQT1);
183 Int_t onlineMean = fDigits->MeanTime();
186 for (Int_t i=0; i<5; i++) tr[i]=false;
189 AliT0RecPoint frecpoints;
190 AliT0RecPoint * pfrecpoints = &frecpoints;
191 clustersTree->Branch( "T0", "AliT0RecPoint" ,&pfrecpoints);
193 Float_t time[24], adc[24], adcmip[24];
194 for (Int_t ipmt=0; ipmt<24; ipmt++) {
195 if(timeCFD->At(ipmt)>0 ) {
196 if(( chargeQT1->At(ipmt) - chargeQT0->At(ipmt))>0)
197 adc[ipmt] = chargeQT1->At(ipmt) - chargeQT0->At(ipmt);
201 time[ipmt] = fCalib-> WalkCorrection(refAmp, ipmt, Int_t(adc[ipmt]), timeCFD->At(ipmt)) ;
203 Double_t sl = Double_t(timeLED->At(ipmt) - timeCFD->At(ipmt));
204 // time[ipmt] = fCalib-> WalkCorrection( refAmp,ipmt, Int_t(sl), timeCFD->At(ipmt) ) ;
205 AliDebug(5,Form(" ipmt %i QTC %i , time in chann %i (led-cfd) %i ",
206 ipmt, Int_t(adc[ipmt]) ,Int_t(time[ipmt]),Int_t( sl)));
209 TGraph* ampGraph = (TGraph*)fAmpLED.At(ipmt);
210 if (ampGraph) ampMip = ampGraph->Eval(sl);
212 TGraph* qtGraph = (TGraph*)fQTC.At(ipmt);
213 if (qtGraph) qtMip = qtGraph->Eval(adc[ipmt]);
214 AliDebug(5,Form(" Amlitude in MIPS LED %f , QTC %f in channels %f\n ",ampMip,qtMip, adc[ipmt]));
215 frecpoints.SetTime(ipmt, Float_t(time[ipmt]) );
216 frecpoints.SetAmpLED(ipmt, Float_t( ampMip));
217 frecpoints.SetAmp(ipmt, Float_t(qtMip));
229 for (Int_t ipmt=0; ipmt<12; ipmt++){
230 if(time[ipmt] !=0 && time[ipmt] > -9000
231 && adcmip[ipmt]>lowAmpThreshold && adcmip[ipmt]<highAmpThreshold )
233 if(time[ipmt]<besttimeC) besttimeC=time[ipmt]; //timeC
234 if(TMath::Abs(time[ipmt])<TMath::Abs(besttimeC_best))
235 besttimeC_best=time[ipmt]; //timeC
238 for ( Int_t ipmt=12; ipmt<24; ipmt++)
240 if(time[ipmt] != 0 && time[ipmt] > -9000
241 && adcmip[ipmt]>lowAmpThreshold && adcmip[ipmt]<highAmpThreshold)
243 if(time[ipmt]<besttimeA) besttimeA=time[ipmt];
244 if(TMath::Abs(time[ipmt] ) < TMath::Abs(besttimeA_best))
245 besttimeA_best=time[ipmt]; //timeA
249 if( besttimeA < 999999 && besttimeA!=0) {
250 frecpoints.SetTimeBestA((besttimeA_best * channelWidth - fdZonA/c) - 12500.);
251 frecpoints.SetTime1stA((besttimeA * channelWidth - fdZonA/c) - 12500.);
255 if( besttimeC < 999999 && besttimeC!=0) {
256 frecpoints.SetTimeBestC((besttimeC_best * channelWidth - fdZonC/c) - 12500.);
257 frecpoints.SetTime1stC((besttimeC * channelWidth - fdZonC/c) - 12500.);
261 AliDebug(5,Form("1stimeA %f , besttimeA %f 1sttimeC %f besttimeC %f ",
262 besttimeA, besttimeA_best,
263 besttimeC, besttimeC_best) );
265 if(besttimeA <999999 && besttimeC < 999999 ){
266 // timeDiff = (besttimeC - besttimeA)*channelWidth;
267 timeDiff = (besttimeA - besttimeC)*channelWidth;
268 meanTime = channelWidth * (besttimeA_best + besttimeC_best)/2. ;
269 timeclock = channelWidth * (besttimeA + besttimeC)/2. ;
270 vertex = meanVertex - c*(timeDiff)/2.;// + (fdZonA - fdZonC)/2;
273 frecpoints.SetVertex(vertex);
274 frecpoints.SetMeanTime(meanTime - 12500.);
275 frecpoints.SetT0clock(timeclock - 12500.);
276 frecpoints.SetT0Trig(tr);
278 AliDebug(5,Form("fRecPoints::: 1stimeA %f , besttimeA %f 1sttimeC %f besttimeC %f shiftA %f shiftC %f ",
279 frecpoints.Get1stTimeA(), frecpoints.GetBestTimeA(),
280 frecpoints.Get1stTimeC(), frecpoints.GetBestTimeC(),
281 fTimeMeanShift[1],fTimeMeanShift[2] ) );
283 AliDebug(5,Form("T0 triggers %d %d %d %d %d",tr[0],tr[1],tr[2],tr[3],tr[4]));
286 frecpoints.SetOnlineMean(Int_t(onlineMean));
287 AliDebug(10,Form(" timeDiff %f #channel, meanTime %f #channel, vertex %f cm online mean %i timeclock %f ps",timeDiff, meanTime,vertex, Int_t(onlineMean), timeclock));
289 clustersTree->Fill();
298 //_______________________________________________________________________
300 void AliT0Reconstructor::Reconstruct(AliRawReader* rawReader, TTree*recTree) const
305 Float_t meanOrA = fTime0vertex[0] + 587;
306 Float_t meanOrC = fTime0vertex[0] + 678;
307 Float_t meanTVDC = fTime0vertex[0] + 2564;
308 Int_t timeDelayCFD[24];
313 for (Int_t i=0; i<24; i++) {
314 badpmt[i] = GetRecoParam() -> GetBadChannels(i);
315 timeDelayCFD[i] = Int_t (fParam->GetTimeDelayCFD(i));
317 Int_t equalize = GetRecoParam() -> GetEq();
318 // printf( "AliT0Reconstructor::Reconstruct::: RecoParam %i \n",equalize);
319 fCalib->SetEq(equalize);
320 Int_t low[500], high[500];
321 Float_t timefull=-9999;;
322 Float_t tvdc = -9999; Float_t ora = -9999; Float_t orc = -9999;
324 Int_t allData[110][5];
326 Int_t timeCFD[24], timeLED[24], chargeQT0[24], chargeQT1[24];
327 Float_t time2zero[24];
328 Double32_t timeDiff, meanTime, timeclock;
329 timeDiff = meanTime = timeclock = 9999999;
330 Float_t c = 29.9792458; // cm/ns
331 Double32_t vertex = 9999999;
333 Float_t meanVertex = 0;
334 for (Int_t i0=0; i0<24; i0++) {
335 low[i0] = Int_t(fTime0vertex[i0]) - 200;
336 high[i0] = Int_t(fTime0vertex[i0]) + 200;
337 time2zero[i0] = 99999;
340 for (Int_t i0=0; i0<110; i0++)
341 for (Int_t j0=0; j0<5; j0++) allData[i0][j0]=0;
343 Float_t lowAmpThreshold = GetRecoParam()->GetAmpLowThreshold();
344 Float_t highAmpThreshold = GetRecoParam()->GetAmpHighThreshold();
345 printf( "AliT0Reconstructor::Reconstruct::: RecoParam amplitude %f %f \n",lowAmpThreshold, highAmpThreshold);
347 Double32_t besttimeA=9999999; Double32_t besttimeA_best=9999999;
348 Double32_t besttimeC=9999999; Double32_t besttimeC_best=9999999;
350 Float_t channelWidth = fParam->GetChannelWidth() ;
352 AliT0RecPoint frecpoints;
353 AliT0RecPoint * pfrecpoints = &frecpoints;
355 recTree->Branch( "T0", "AliT0RecPoint" ,&pfrecpoints);
357 AliDebug(10," before read data ");
358 AliT0RawReader myrawreader(rawReader);
360 UInt_t type =rawReader->GetType();
362 if (!myrawreader.Next())
363 AliDebug(1,Form(" no raw data found!!"));
366 for (Int_t i=0; i<24; i++)
368 timeCFD[i]=0; timeLED[i]=0; chargeQT0[i]=0; chargeQT1[i]=0;
370 Int_t fBCID=Int_t (rawReader->GetBCID());
371 Int_t trmbunch= myrawreader.GetTRMBunchID();
372 AliDebug(10,Form(" CDH BC ID %i, TRM BC ID %i \n", fBCID, trmbunch ));
374 if(type == 7 ) { //only physics
375 for (Int_t i=0; i<107; i++) {
376 for (Int_t iHit=0; iHit<5; iHit++)
378 allData[i][iHit] = myrawreader.GetData(i,iHit);
382 for (Int_t in=0; in<12; in++)
384 for (Int_t iHit=0; iHit<5; iHit++)
386 if(allData[in+1][iHit] > low[in] &&
387 allData[in+1][iHit] < high[in])
389 timeCFD[in] = allData[in+1][iHit] ;
393 for (Int_t iHit=0; iHit<5; iHit++)
395 if(allData[in+1+56][iHit] > low[in] &&
396 allData[in+1+56][iHit] < high[in])
398 timeCFD[in+12] = allData[in+56+1][iHit] ;
402 timeLED[in+12] = allData[in+68+1][0] ;
403 timeLED[in] = allData[in+12+1][0] ;
404 AliDebug(50, Form(" readed i %i cfdC %i cfdA %i ledC %i ledA%i ",
405 in, timeCFD[in],timeCFD[in+12],timeLED[in],
411 for (Int_t in=0; in<12; in++)
413 chargeQT0[in]=allData[2*in+25][0];
414 chargeQT1[in]=allData[2*in+26][0];
415 AliDebug(25, Form(" readed Raw %i %i %i",
416 in, chargeQT0[in],chargeQT1[in]));
418 for (Int_t in=12; in<24; in++)
420 chargeQT0[in]=allData[2*in+57][0];
421 chargeQT1[in]=allData[2*in+58][0];
422 AliDebug(25, Form(" readed Raw %i %i %i",
423 in, chargeQT0[in],chargeQT1[in]));
426 onlineMean = allData[49][0];
428 Double32_t time[24], adc[24], adcmip[24], noncalibtime[24];
429 for (Int_t ipmt=0; ipmt<24; ipmt++) {
430 if(timeCFD[ipmt] > 0 /* && badpmt[ipmt]==0*/ ){
433 if(( chargeQT0[ipmt] - chargeQT1[ipmt])>0) {
434 adc[ipmt] = chargeQT0[ipmt] - chargeQT1[ipmt];
438 // time[ipmt] = fCalib-> WalkCorrection(refAmp, ipmt, Int_t(adc[ipmt]), timeCFD[ipmt] ) ;
439 Int_t refAmp = Int_t (fTime0vertex[ipmt]);
440 time[ipmt] = fCalib-> WalkCorrection( refAmp, ipmt, Int_t(adc[ipmt]), timeCFD[ipmt] ) ;
441 Double_t sl = timeLED[ipmt] - timeCFD[ipmt];
442 // time[ipmt] = fCalib-> WalkCorrection( refAmp,ipmt, Int_t(sl), timeCFD[ipmt] ) ;
443 AliDebug(5,Form(" ipmt %i QTC %i , time in chann %i (led-cfd) %i ",
444 ipmt, Int_t(adc[ipmt]) ,Int_t(time[ipmt]),Int_t( sl)));
446 TGraph * ampGraph = (TGraph*)fAmpLED.At(ipmt);
447 if (ampGraph) ampMip = ampGraph->Eval(sl);
449 TGraph * qtGraph = (TGraph*)fQTC.At(ipmt);
450 if (qtGraph) qtMip = qtGraph->Eval(adc[ipmt]);
451 AliDebug(10,Form(" Amlitude in MIPS LED %f ; QTC %f; in channels %f\n ",ampMip,qtMip, adc[ipmt]));
452 if( qtMip>lowAmpThreshold && qtMip<highAmpThreshold )
455 frecpoints.SetTime(ipmt, Float_t(time[ipmt]) );
457 frecpoints.SetTime(ipmt, Float_t(time[ipmt] + fTime0vertex[ipmt]) );
458 // frecpoints.SetTime(ipmt, Float_t(time[ipmt] ) );
460 frecpoints.SetAmp(ipmt, Double32_t( qtMip));
462 frecpoints.SetAmpLED(ipmt, Double32_t(ampMip));
463 noncalibtime[ipmt]= Double32_t (timeCFD[ipmt]);
469 noncalibtime[ipmt] = -9999;
472 fESDTZEROfriend->SetT0timeCorr(noncalibtime) ;
474 for (Int_t ipmt=0; ipmt<12; ipmt++){
475 if(time[ipmt] !=0 && time[ipmt] > -9000
476 /*&& badpmt[ipmt]==0 */
477 && adcmip[ipmt]>lowAmpThreshold && adcmip[ipmt]<highAmpThreshold )
479 if(time[ipmt]<besttimeC) besttimeC=time[ipmt]; //timeC
480 if(TMath::Abs(time[ipmt])<TMath::Abs(besttimeC_best))
481 besttimeC_best=time[ipmt]; //timeC
484 for ( Int_t ipmt=12; ipmt<24; ipmt++)
486 if(time[ipmt] != 0 && time[ipmt] > -9000
487 /* && badpmt[ipmt]==0*/
488 && adcmip[ipmt]>lowAmpThreshold && adcmip[ipmt]<highAmpThreshold)
490 if(time[ipmt]<besttimeA) besttimeA=time[ipmt];
491 if(TMath::Abs(time[ipmt] ) < TMath::Abs(besttimeA_best))
492 besttimeA_best=time[ipmt]; //timeA
496 if(besttimeA < 999999 && besttimeA!=0 ) {
498 frecpoints.SetTime1stA((besttimeA * channelWidth)- 1000.*fLatencyHPTDC + 1000.*fLatencyL1A - 1000.*fGRPdelays - fTimeMeanShift[1] );
501 frecpoints.SetTimeBestA((besttimeA_best * channelWidth ));
502 frecpoints.SetTime1stA((besttimeA * channelWidth - fTimeMeanShift[1]));
505 if( besttimeC < 999999 && besttimeC!=0) {
507 frecpoints.SetTime1stC((besttimeC * channelWidth)- 1000.*fLatencyHPTDC +1000.*fLatencyL1C - 1000.*fGRPdelays - fTimeMeanShift[2]);
510 frecpoints.SetTimeBestC((besttimeC_best * channelWidth ));
511 frecpoints.SetTime1stC((besttimeC * channelWidth - fTimeMeanShift[2]));
514 AliDebug(5,Form("1stimeA %f , besttimeA %f 1sttimeC %f besttimeC %f ",
515 besttimeA, besttimeA_best,
516 besttimeC, besttimeC_best) );
517 AliDebug(5,Form("fRecPoints::: 1stimeA %f , besttimeA %f 1sttimeC %f besttimeC %f shiftA %f shiftC %f ",
518 frecpoints.Get1stTimeA(), frecpoints.GetBestTimeA(),
519 frecpoints.Get1stTimeC(), frecpoints.GetBestTimeC(),
520 fTimeMeanShift[1],fTimeMeanShift[2] ) );
521 if( besttimeC < 999999 && besttimeA < 999999) {
523 timeclock = ((besttimeC * channelWidth)- 1000.*fLatencyHPTDC +1000.*fLatencyL1 - 1000.*fGRPdelays - fTimeMeanShift[0]);
526 timeclock = channelWidth * Float_t( besttimeA+besttimeC)/2. - fTimeMeanShift[0];
527 meanTime = channelWidth * Float_t(besttimeA_best + besttimeC_best )/2.;
529 timeDiff = ( besttimeA - besttimeC)* 0.001* channelWidth ;
530 vertex = meanVertex - c*(timeDiff)/2. ; //+ (fdZonA - fdZonC)/2;
534 AliDebug(1,Form(" timeDiff %f #channel, meanTime %f #ps, TOFmean%f vertex %f cm meanVertex %f \n",timeDiff, meanTime,timeclock, vertex,meanVertex));
535 frecpoints.SetT0clock(timeclock);
536 frecpoints.SetVertex(vertex);
537 frecpoints.SetMeanTime(meanTime);
538 frecpoints.SetOnlineMean(Int_t(onlineMean));
542 Int_t trchan[5] = {50,51,52,55,56};
543 Float_t lowtr[5] = {meanTVDC-700, meanOrA-700, meanOrC-700, meanOrC-1000, meanOrC-1000 };
544 Float_t hightr[5] = {meanTVDC+700, meanOrA+700, meanOrC+700, meanOrC+1000, meanOrC+1000};
546 for (Int_t i=0; i<5; i++) tr[i] = false;
547 for (Int_t itr=0; itr<5; itr++) {
548 for (Int_t iHit=0; iHit<1; iHit++)
550 Int_t trr=trchan[itr];
551 if( allData[trr][iHit] > lowtr[itr] && allData[trr][iHit] < hightr[itr]) tr[itr]=true;
553 AliDebug(15,Form("Reconstruct ::: T0 triggers iHit %i tvdc %d orA %d orC %d centr %d semicentral %d",iHit, tr[0],tr[1],tr[2],tr[3],tr[4]));
556 frecpoints.SetT0Trig(tr);
558 // all times with amplitude correction
560 for (Int_t iHit=0; iHit<5; iHit++)
562 timefull = timecent = -9999;
563 tvdc = ora = orc = -9999;
564 if(allData[50][iHit]>0)
565 tvdc = (Float_t(allData[50][iHit]) - meanTVDC) * channelWidth* 0.001;
566 if(allData[51][iHit]>0)
567 ora = (Float_t(allData[51][iHit]) - meanOrA) * channelWidth* 0.001;
569 if(allData[52][iHit]>0)
570 orc = (Float_t(allData[52][iHit]) - meanOrC) * channelWidth* 0.001;
572 frecpoints.SetOrC( iHit, orc);
573 frecpoints.SetOrA( iHit, ora);
574 frecpoints.SetTVDC( iHit, tvdc);
575 for (Int_t i0=0; i0<12; i0++) {
577 timecent = fTime0vertex[i0] + timeDelayCFD[i0];
579 timecent = fTime0vertex[i0];
581 if(allData[i0+1][iHit]>1)
582 timefull = (Float_t(allData[i0+1][iHit]) - timecent)* channelWidth* 0.001;
583 frecpoints.SetTimeFull(i0, iHit,timefull) ;
584 // if(allData[i0+1][iHit]>1) printf("i0 %d iHit %d data %d fTime0vertex %f timefull %f \n",i0, iHit, allData[i0+1][iHit], fTime0vertex[i0], timefull);
588 for (Int_t i0=12; i0<24; i0++) {
591 timecent = fTime0vertex[i0] + timeDelayCFD[i0];
593 timecent = fTime0vertex[i0];
594 if(allData[i0+45][iHit]>1) {
595 timefull = (Float_t(allData[i0+45][iHit]) - timecent)* channelWidth* 0.001;
597 // if(allData[i0+45][iHit]>1) printf("i0 %d iHit %d data %d fTime0vertex %f timefull %f \n",i0, iHit, allData[i0+45][iHit], fTime0vertex[i0], timefull);
598 frecpoints.SetTimeFull(i0, iHit, timefull) ;
604 if(allData[53][0]>0 && allData[54][0])
605 frecpoints.SetMultA(allData[53][0]-allData[54][0]);
606 if(allData[105][0]>0 && allData[106][0])
607 frecpoints.SetMultC(allData[105][0]-allData[106][0]);
610 } // if (else )raw data
615 //____________________________________________________________
617 void AliT0Reconstructor::FillESD(TTree */*digitsTree*/, TTree *clustersTree, AliESDEvent *pESD) const
620 /***************************************************
621 Resonstruct digits to vertex position
622 ****************************************************/
624 AliDebug(1,Form("Start FillESD T0"));
626 AliError("No ESD Event");
629 pESD ->SetT0spread(fTimeSigmaShift);
632 Float_t channelWidth = fParam->GetChannelWidth() ;
633 Float_t c = 0.0299792458; // cm/ps
634 Float_t currentVertex=0, shift=0;
636 const AliESDVertex* vertex = pESD->GetPrimaryVertex();
637 if (!vertex) vertex = pESD->GetPrimaryVertexSPD();
638 if (!vertex) vertex = pESD->GetPrimaryVertexTPC();
639 if (!vertex) vertex = pESD->GetVertex();
642 AliDebug(2, Form("Got %s (%s) from ESD: %f",
643 vertex->GetName(), vertex->GetTitle(), vertex->GetZ()));
644 currentVertex = vertex->GetZ();
646 ncont = vertex->GetNContributors();
648 shift = currentVertex/c;
651 TTree *treeR = clustersTree;
653 AliT0RecPoint frecpoints;
654 AliT0RecPoint * pfrecpoints = &frecpoints;
656 AliDebug(1,Form("Start FillESD T0"));
657 TBranch *brRec = treeR->GetBranch("T0");
659 brRec->SetAddress(&pfrecpoints);
661 AliError(Form("EXEC Branch T0 rec not found"));
666 Double32_t amp[24], time[24], ampQTC[24], timecorr[24];
668 for(Int_t i=0; i<24; i++)
669 amp[i]=time[i]=ampQTC[i]=timecorr[i]=0;
672 Double32_t timeClock[3];
673 Double32_t zPosition = frecpoints.GetVertex();
675 timeClock[0] = frecpoints.GetT0clock() ;
676 timeClock[1] = frecpoints.Get1stTimeA() + shift;
677 timeClock[2] = frecpoints.Get1stTimeC() - shift;
679 Double32_t timemean[3];
680 timemean[0] = frecpoints.GetMeanTime();
681 timemean[1] = frecpoints.GetBestTimeA() + shift;
682 timemean[2] = frecpoints.GetBestTimeC() - shift;
684 for(Int_t i=0; i<3; i++) {
685 fESDTZERO->SetT0TOF(i,timeClock[i]); // interaction time (ns)
686 fESDTZERO->SetT0TOFbest(i,timemean[i]); // interaction time (ns)
688 for ( Int_t i=0; i<24; i++) {
689 time[i] = frecpoints.GetTime(i); // ps to ns
690 if ( time[i] != 0 && time[i]>-9999) {
691 ampQTC[i] = frecpoints.GetAmp(i);
692 amp[i] = frecpoints.AmpLED(i);
693 AliDebug(1,Form("T0: %i time %f ampQTC %f ampLED %f \n", i, time[i], ampQTC[i], amp[i]));
696 fESDTZERO->SetT0time(time); // best TOF on each PMT
697 fESDTZERO->SetT0amplitude(ampQTC); // number of particles(MIPs) on each PMT
698 Int_t trig= frecpoints.GetT0Trig();
699 frecpoints.PrintTriggerSignals( trig);
700 // printf(" !!!!! FillESD trigger %i \n",trig);
701 fESDTZERO->SetT0Trig(trig);
702 fESDTZERO->SetT0zVertex(zPosition); //vertex Z position
704 Double32_t multA=frecpoints.GetMultA();
705 Double32_t multC=frecpoints.GetMultC();
706 fESDTZERO->SetMultA(multA); // for backward compatubility
707 fESDTZERO->SetMultC(multC); // for backward compatubility
710 for (Int_t iHit =0; iHit<5; iHit++ ) {
711 AliDebug(10,Form("FillESD ::: iHit %i tvdc %f orA %f orC %f\n", iHit,
712 frecpoints.GetTVDC(iHit),
713 frecpoints.GetOrA(iHit),
714 frecpoints.GetOrC(iHit) ));
715 fESDTZERO->SetTVDC(iHit,frecpoints.GetTVDC(iHit));
716 fESDTZERO->SetOrA(iHit,frecpoints.GetOrA(iHit));
717 fESDTZERO->SetOrC(iHit,frecpoints.GetOrC(iHit));
719 for (Int_t i0=0; i0<24; i0++) {
720 // if(frecpoints.GetTimeFull(i0,iHit)>0){
721 // printf("FillESD ::: iHit %i cfd %i time %f \n", iHit, i0, frecpoints.GetTimeFull(i0,iHit));
722 fESDTZERO->SetTimeFull(i0, iHit,frecpoints.GetTimeFull(i0,iHit));
728 AliDebug(1,Form("T0: SPDshift %f Vertex %f (T0A+T0C)/2 best %f #ps T0signal %f ps OrA %f ps OrC %f ps T0trig %i\n",shift, zPosition, timemean[0], timeClock[0], timeClock[1], timeClock[2], trig));
730 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
732 Bool_t background = BackgroundFlag();
733 fESDTZERO->SetBackgroundFlag(background);
734 Bool_t pileup = PileupFlag();
735 fESDTZERO->SetPileupFlag(pileup);
736 for (Int_t i=0; i<5; i++) {
737 fESDTZERO->SetPileupTime(i, frecpoints.GetTVDC(i) ) ;
738 // printf("!!!!!! FillESD :: pileup %i %f %f \n", i,fESDTZERO->GetPileupTime(i), frecpoints.GetTVDC(i));
740 Bool_t sat = SatelliteFlag();
741 fESDTZERO->SetSatelliteFlag(sat);
743 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
746 AliESDfriend *fr = (AliESDfriend*)pESD->FindListObject("AliESDfriend");
748 AliDebug(10, Form("Writing TZERO friend data to ESD tree"));
751 tcorr = fESDTZEROfriend->GetT0timeCorr();
752 for ( Int_t i=0; i<24; i++) {
753 if(i<12 && time[i]>1) timecorr[i] = tcorr[i] - shift/channelWidth;
754 if(i>11 && time[i]>1) timecorr[i] = tcorr[i] + shift/channelWidth;
755 if(time[i]>1) AliDebug(10,Form("T0 friend : %i time %f ampQTC %f ampLED %f \n", i, timecorr[i], ampQTC[i], amp[i]));
757 fESDTZEROfriend->SetT0timeCorr( timecorr) ;
758 fESDTZEROfriend->SetT0ampLEDminCFD(amp);
759 fESDTZEROfriend->SetT0ampQTC(ampQTC);
760 fr->SetTZEROfriend(fESDTZEROfriend);
764 pESD->SetTZEROData(fESDTZERO);
767 } // vertex in 3 sigma
769 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
770 //____________________________________________________________
772 Bool_t AliT0Reconstructor::PileupFlag() const
775 Bool_t pileup = false;
777 for (Int_t ih=0; ih<5; ih++)
779 tvdc[ih] = fESDTZERO->GetTVDC(ih);
781 if( tvdc[0] !=0 && tvdc[0]> -10 && tvdc[0]< 10 )
782 if(ih>0 && tvdc[ih]>20 ) pileup = true;
783 if( tvdc[0] >20 || (tvdc[0] < -20 && tvdc[0] > -9000) ) pileup =true;
784 // if (pileup) printf(" !!!!! pile up %i tvdc %f \n",ih, tvdc[ih]);
792 //____________________________________________________________
794 Bool_t AliT0Reconstructor::BackgroundFlag() const
796 Bool_t background = false;
798 Float_t orA = fESDTZERO->GetOrA(0);
799 Float_t orC = fESDTZERO->GetOrC(0);
800 Float_t tvdc = fESDTZERO->GetTVDC(0);
802 if ( (orA > -5 && orA <5) && (orC > -5 && orC <5) && (tvdc < -5 || tvdc > 5)) {
804 // printf(" orA %f orC %f tvdc %f\n", orA, orC, tvdc);
812 //____________________________________________________________
814 Bool_t AliT0Reconstructor::SatelliteFlag() const
817 Float_t satelliteLow = GetRecoParam() -> GetLowSatelliteThreshold();
818 Float_t satelliteHigh = GetRecoParam() -> GetHighSatelliteThreshold();
819 Bool_t satellite = false;
820 for (Int_t i0=0; i0<24; i0++) {
821 Float_t timefull = fESDTZERO -> GetTimeFull(i0,0);
822 if( timefull > satelliteLow && timefull < satelliteHigh) satellite=true;