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] > 60000) fTime0vertex[i] =( 1000.*fLatencyHPTDC - 1000.*fLatencyL1 + 1000.*fGRPdelays)/24.4;
121 //here real Z position
122 fdZonC = TMath::Abs(fParam->GetZPosition("T0/C/PMT1"));
123 fdZonA = TMath::Abs(fParam->GetZPosition("T0/A/PMT15"));
125 fCalib = new AliT0Calibrator();
126 fESDTZEROfriend = new AliESDTZEROfriend();
127 fESDTZERO = new AliESDTZERO();
132 //_____________________________________________________________________________
133 void AliT0Reconstructor::Reconstruct(TTree*digitsTree, TTree*clustersTree) const
135 // T0 digits reconstruction
136 Int_t refAmp = 0 ; /*Int_t (GetRecoParam()->GetRefAmp());*/
138 TArrayI * timeCFD = new TArrayI(24);
139 TArrayI * timeLED = new TArrayI(24);
140 TArrayI * chargeQT0 = new TArrayI(24);
141 TArrayI * chargeQT1 = new TArrayI(24);
144 Float_t c = 29.9792458; // cm/ns
145 Float_t channelWidth = fParam->GetChannelWidth() ;
146 Double32_t vertex = 9999999, meanVertex = 0 ;
147 Double32_t timeDiff=999999, meanTime=999999, timeclock=999999;
150 AliDebug(1,Form("Start DIGITS reconstruction "));
152 Float_t lowAmpThreshold = GetRecoParam()->GetAmpLowThreshold();
153 Float_t highAmpThreshold = GetRecoParam()->GetAmpHighThreshold();
154 printf("Reconstruct(TTree*digitsTree highAmpThreshold %f lowAmpThreshold %f \n",lowAmpThreshold, highAmpThreshold);
156 //shift T0A, T0C , T0AC
157 Float_t shiftA = GetRecoParam() -> GetLow(310);
158 Float_t shiftC = GetRecoParam() -> GetLow(311);
159 Float_t shiftAC = GetRecoParam() -> GetLow(312);
160 printf("Reconstruct(TTree*digitsTree shiftA %f shiftC %f shiftAC %f \n",shiftA, shiftC, shiftAC);
162 Double32_t besttimeA=9999999; Double32_t besttimeA_best=9999999;
163 Double32_t besttimeC=9999999; Double32_t besttimeC_best=9999999;
164 Int_t timeDelayCFD[24];
167 for (Int_t i=0; i<24; i++) {
168 badpmt[i] = GetRecoParam() -> GetBadChannels(i);
169 timeDelayCFD[i] = Int_t (fParam->GetTimeDelayCFD(i));
172 TBranch *brDigits=digitsTree->GetBranch("T0");
173 AliT0digit *fDigits = new AliT0digit() ;
175 brDigits->SetAddress(&fDigits);
177 AliError(Form("EXEC Branch T0 digits not found"));
181 digitsTree->GetEvent(0);
182 digitsTree->GetEntry(0);
183 brDigits->GetEntry(0);
184 fDigits->GetTimeCFD(*timeCFD);
185 fDigits->GetTimeLED(*timeLED);
186 fDigits->GetQT0(*chargeQT0);
187 fDigits->GetQT1(*chargeQT1);
188 Int_t onlineMean = fDigits->MeanTime();
191 for (Int_t i=0; i<5; i++) tr[i]=false;
194 AliT0RecPoint frecpoints;
195 AliT0RecPoint * pfrecpoints = &frecpoints;
196 clustersTree->Branch( "T0", "AliT0RecPoint" ,&pfrecpoints);
198 Float_t time[24], adc[24], adcmip[24];
199 for (Int_t ipmt=0; ipmt<24; ipmt++) {
200 if(timeCFD->At(ipmt)>0 ) {
201 Float_t timefull = 0.001*( timeCFD->At(ipmt) - 511 - timeDelayCFD[ipmt]) * channelWidth;
202 frecpoints.SetTimeFull(ipmt, 0 ,timefull) ;
203 if(( chargeQT1->At(ipmt) - chargeQT0->At(ipmt))>0)
204 adc[ipmt] = chargeQT1->At(ipmt) - chargeQT0->At(ipmt);
208 time[ipmt] = fCalib-> WalkCorrection(refAmp, ipmt, Int_t(adc[ipmt]), timeCFD->At(ipmt)) ;
209 time[ipmt] = time[ipmt] - 511;
210 Double_t sl = Double_t(timeLED->At(ipmt) - timeCFD->At(ipmt));
211 // time[ipmt] = fCalib-> WalkCorrection( refAmp,ipmt, Int_t(sl), timeCFD->At(ipmt) ) ;
212 AliDebug(5,Form(" ipmt %i QTC %i , time in chann %i (led-cfd) %i ",
213 ipmt, Int_t(adc[ipmt]) ,Int_t(time[ipmt]),Int_t( sl)));
216 TGraph* ampGraph = (TGraph*)fAmpLED.At(ipmt);
217 if (ampGraph) ampMip = ampGraph->Eval(sl);
219 TGraph* qtGraph = (TGraph*)fQTC.At(ipmt);
220 if (qtGraph) qtMip = qtGraph->Eval(adc[ipmt]);
221 AliDebug(5,Form(" Amlitude in MIPS LED %f , QTC %f in channels %f\n ",ampMip,qtMip, adc[ipmt]));
222 frecpoints.SetTime(ipmt, Float_t(time[ipmt]) );
223 frecpoints.SetAmpLED(ipmt, Float_t( ampMip));
224 frecpoints.SetAmp(ipmt, Float_t(qtMip));
236 for (Int_t ipmt=0; ipmt<12; ipmt++){
237 if(time[ipmt] !=0 && time[ipmt] > -9000
238 && adcmip[ipmt]>lowAmpThreshold && adcmip[ipmt]<highAmpThreshold )
240 if(time[ipmt]<besttimeC) besttimeC=time[ipmt]; //timeC
241 if(TMath::Abs(time[ipmt])<TMath::Abs(besttimeC_best))
242 besttimeC_best=time[ipmt]; //timeC
245 for ( Int_t ipmt=12; ipmt<24; ipmt++)
247 if(time[ipmt] != 0 && time[ipmt] > -9000
248 && adcmip[ipmt]>lowAmpThreshold && adcmip[ipmt]<highAmpThreshold)
250 if(time[ipmt]<besttimeA) besttimeA=time[ipmt];
251 if(TMath::Abs(time[ipmt] ) < TMath::Abs(besttimeA_best))
252 besttimeA_best=time[ipmt]; //timeA
256 if( besttimeA < 999999 && besttimeA!=0) {
257 frecpoints.SetTimeBestA((besttimeA_best * channelWidth - fdZonA/c) );
258 frecpoints.SetTime1stA((besttimeA * channelWidth - fdZonA/c - shiftA) );
262 if( besttimeC < 999999 && besttimeC!=0) {
263 frecpoints.SetTimeBestC((besttimeC_best * channelWidth - fdZonC/c) );
264 frecpoints.SetTime1stC((besttimeC * channelWidth - fdZonC/c - shiftC) );
268 AliDebug(5,Form("1stimeA %f , besttimeA %f 1sttimeC %f besttimeC %f ",
269 besttimeA, besttimeA_best,
270 besttimeC, besttimeC_best) );
272 if(besttimeA <999999 && besttimeC < 999999 ){
273 // timeDiff = (besttimeC - besttimeA)*channelWidth;
274 timeDiff = (besttimeA - besttimeC)*channelWidth;
275 meanTime = channelWidth * (besttimeA_best + besttimeC_best)/2. ;
276 timeclock = channelWidth * (besttimeA + besttimeC)/2. - shiftAC ;
277 vertex = meanVertex - 0.001* c*(timeDiff)/2.;// + (fdZonA - fdZonC)/2;
280 frecpoints.SetVertex(vertex);
281 frecpoints.SetMeanTime(meanTime );
282 frecpoints.SetT0clock(timeclock );
283 frecpoints.SetT0Trig(tr);
285 AliDebug(5,Form("fRecPoints::: 1stimeA %f , besttimeA %f 1sttimeC %f besttimeC %f vertex %f",
286 frecpoints.Get1stTimeA(), frecpoints.GetBestTimeA(),
287 frecpoints.Get1stTimeC(), frecpoints.GetBestTimeC(),
290 AliDebug(5,Form("T0 triggers %d %d %d %d %d",tr[0],tr[1],tr[2],tr[3],tr[4]));
293 frecpoints.SetOnlineMean(Int_t(onlineMean));
294 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));
296 clustersTree->Fill();
305 //_______________________________________________________________________
307 void AliT0Reconstructor::Reconstruct(AliRawReader* rawReader, TTree*recTree) const
312 Float_t meanOrA = fTime0vertex[0] + 587;
313 Float_t meanOrC = fTime0vertex[0] + 678;
314 Float_t meanTVDC = fTime0vertex[0] + 2564;
315 Int_t timeDelayCFD[24];
316 Int_t corridor = GetRecoParam() -> GetCorridor();
317 // printf("!!!! corridor %i \n",corridor);
320 for (Int_t i=0; i<24; i++) {
321 badpmt[i] = GetRecoParam() -> GetBadChannels(i);
322 timeDelayCFD[i] = Int_t (fParam->GetTimeDelayCFD(i));
324 Int_t equalize = GetRecoParam() -> GetEq();
325 printf( "AliT0Reconstructor::Reconstruct::: RecoParam %i \n",equalize);
326 fCalib->SetEq(equalize);
327 Int_t low[500], high[500];
328 Float_t timefull=-99999;;
329 Float_t tvdc = -99999; Float_t ora = -99999; Float_t orc = -99999;
331 Int_t allData[110][5];
333 Int_t timeCFD[24], timeLED[24], chargeQT0[24], chargeQT1[24];
334 Float_t time2zero[24];
335 Double32_t timeDiff, meanTime, timeclock;
336 timeDiff = meanTime = timeclock = 9999999;
337 Float_t c = 29.9792458; // cm/ns
338 Double32_t vertex = 9999999;
340 Float_t meanVertex = 0;
342 for (Int_t i0=0; i0<24; i0++) {
343 low[i0] = Int_t(fTime0vertex[i0]) - corridor;
344 high[i0] = Int_t(fTime0vertex[i0]) + corridor;
345 time2zero[i0] = 99999;
346 pedestal[i0]=Int_t (GetRecoParam()->GetLow(100+i0) );
349 for (Int_t i0=0; i0<110; i0++)
350 for (Int_t j0=0; j0<5; j0++) allData[i0][j0]=0;
352 Float_t lowAmpThreshold = GetRecoParam()->GetAmpLowThreshold();
353 Float_t highAmpThreshold = GetRecoParam()->GetAmpHighThreshold();
354 printf( "AliT0Reconstructor::Reconstruct::: RecoParam amplitude %f %f \n",lowAmpThreshold, highAmpThreshold);
356 Double32_t besttimeA=9999999; Double32_t besttimeA_best=9999999;
357 Double32_t besttimeC=9999999; Double32_t besttimeC_best=9999999;
359 Float_t channelWidth = fParam->GetChannelWidth() ;
361 AliT0RecPoint frecpoints;
362 AliT0RecPoint * pfrecpoints = &frecpoints;
364 recTree->Branch( "T0", "AliT0RecPoint" ,&pfrecpoints);
366 AliDebug(10," before read data ");
367 AliT0RawReader myrawreader(rawReader);
369 UInt_t type =rawReader->GetType();
371 if (!myrawreader.Next())
372 AliDebug(1,Form(" no raw data found!!"));
375 for (Int_t i=0; i<24; i++)
377 timeCFD[i]=0; timeLED[i]=0; chargeQT0[i]=0; chargeQT1[i]=0;
380 if(type == 7 ) { //only physics
381 for (Int_t i=0; i<107; i++) {
382 for (Int_t iHit=0; iHit<5; iHit++)
384 allData[i][iHit] = myrawreader.GetData(i,iHit);
388 Int_t fBCID=Int_t (rawReader->GetBCID());
389 Int_t trmbunch= myrawreader.GetTRMBunchID();
390 AliDebug(10,Form(" CDH BC ID %i, TRM BC ID %i \n", fBCID, trmbunch ));
391 if( (trmbunch-fBCID)!=37 ) {
392 AliDebug(0,Form("wrong :::: CDH BC ID %i, TRM BC ID %i \n", fBCID, trmbunch ));
395 for (Int_t in=0; in<12; in++)
397 for (Int_t iHit=0; iHit<5; iHit++)
399 if(allData[in+1][iHit] > low[in] &&
400 allData[in+1][iHit] < high[in])
402 timeCFD[in] = allData[in+1][iHit] ;
406 for (Int_t iHit=0; iHit<5; iHit++)
408 if(allData[in+1+56][iHit] > low[in+12] &&
409 allData[in+1+56][iHit] < high[in+12])
411 timeCFD[in+12] = allData[in+56+1][iHit] ;
415 timeLED[in+12] = allData[in+68+1][0] ;
416 timeLED[in] = allData[in+12+1][0] ;
417 AliDebug(50, Form(" readed i %i cfdC %i cfdA %i ledC %i ledA%i ",
418 in, timeCFD[in],timeCFD[in+12],timeLED[in],
423 for (Int_t in=0; in<12; in++)
425 if(allData[2*in+26][0] > low[in] + 1000)
427 chargeQT0[in]=allData[2*in+25][0];
428 chargeQT1[in]=allData[2*in+26][0];
429 AliDebug(25, Form(" readed Raw %i %i %i",
430 in, chargeQT0[in],chargeQT1[in]));
433 for (Int_t in=12; in<24; in++)
435 if(allData[2*in+58][0] > low[in] + 1000)
437 chargeQT0[in]=allData[2*in+57][0];
438 chargeQT1[in]=allData[2*in+58][0];
439 AliDebug(25, Form(" readed Raw %i %i %i",
440 in, chargeQT0[in],chargeQT1[in]));
444 onlineMean = allData[49][0];
446 Double32_t time[24], adc[24], adcmip[24], noncalibtime[24];
447 for (Int_t ipmt=0; ipmt<24; ipmt++) {
448 // if(timeCFD[ipmt] > 0 && (chargeQT0[ipmt] - chargeQT1[ipmt])>pedestal[ipmt] ){
449 if(timeCFD[ipmt] > 0 && (chargeQT0[ipmt] - chargeQT1[ipmt])> 0 ){
452 if(( chargeQT0[ipmt] - chargeQT1[ipmt])>pedestal[ipmt]) {
453 adc[ipmt] = chargeQT0[ipmt] - chargeQT1[ipmt];
457 // time[ipmt] = fCalib-> WalkCorrection(refAmp, ipmt, Int_t(adc[ipmt]), timeCFD[ipmt] ) ;
458 Int_t refAmp = Int_t (fTime0vertex[ipmt]);
459 time[ipmt] = fCalib-> WalkCorrection( refAmp, ipmt, Int_t(adc[ipmt]), timeCFD[ipmt] ) ;
460 Double_t sl = timeLED[ipmt] - timeCFD[ipmt];
461 // time[ipmt] = fCalib-> WalkCorrection( refAmp,ipmt, Int_t(sl), timeCFD[ipmt] ) ;
462 AliDebug(5,Form(" ipmt %i QTC %i , time in chann %i (led-cfd) %i ",
463 ipmt, Int_t(adc[ipmt]) ,Int_t(time[ipmt]),Int_t( sl)));
465 TGraph * ampGraph = (TGraph*)fAmpLED.At(ipmt);
466 if (ampGraph) ampMip = ampGraph->Eval(sl);
468 TGraph * qtGraph = (TGraph*)fQTC.At(ipmt);
469 if (qtGraph) qtMip = qtGraph->Eval(adc[ipmt]);
470 AliDebug(10,Form(" Amlitude in MIPS LED %f ; QTC %f; in channels %f\n ",ampMip,qtMip, adc[ipmt]));
472 frecpoints.SetTime(ipmt, Float_t(time[ipmt]) );
474 frecpoints.SetTime(ipmt, Float_t(time[ipmt] + fTime0vertex[ipmt]) );
475 // frecpoints.SetTime(ipmt, Float_t(time[ipmt] ) );
476 frecpoints.SetAmp(ipmt, Double32_t( qtMip));
478 frecpoints.SetAmpLED(ipmt, Double32_t(ampMip));
479 noncalibtime[ipmt]= Double32_t (timeCFD[ipmt]);
485 noncalibtime[ipmt] = -9999;
488 fESDTZEROfriend->SetT0timeCorr(noncalibtime) ;
490 for (Int_t ipmt=0; ipmt<12; ipmt++){
491 if(time[ipmt] !=0 && time[ipmt] > -9000
492 /*&& badpmt[ipmt]==0 */
493 && adcmip[ipmt]>lowAmpThreshold )
495 if(time[ipmt]<besttimeC) besttimeC=time[ipmt]; //timeC
496 if(TMath::Abs(time[ipmt])<TMath::Abs(besttimeC_best))
497 besttimeC_best=time[ipmt]; //timeC
500 for ( Int_t ipmt=12; ipmt<24; ipmt++)
502 if(time[ipmt] != 0 && time[ipmt] > -9000
503 /* && badpmt[ipmt]==0*/
504 && adcmip[ipmt]>lowAmpThreshold )
506 if(time[ipmt]<besttimeA) besttimeA=time[ipmt];
507 if(TMath::Abs(time[ipmt] ) < TMath::Abs(besttimeA_best))
508 besttimeA_best=time[ipmt]; //timeA
512 if(besttimeA < 999999 && besttimeA!=0 ) {
514 frecpoints.SetTime1stA((besttimeA * channelWidth)- 1000.*fLatencyHPTDC + 1000.*fLatencyL1A - 1000.*fGRPdelays - fTimeMeanShift[1] );
517 frecpoints.SetTimeBestA((besttimeA_best * channelWidth ));
518 frecpoints.SetTime1stA((besttimeA * channelWidth - fTimeMeanShift[1]));
521 if( besttimeC < 999999 && besttimeC!=0) {
523 frecpoints.SetTime1stC((besttimeC * channelWidth)- 1000.*fLatencyHPTDC +1000.*fLatencyL1C - 1000.*fGRPdelays - fTimeMeanShift[2]);
526 frecpoints.SetTimeBestC((besttimeC_best * channelWidth ));
527 frecpoints.SetTime1stC((besttimeC * channelWidth - fTimeMeanShift[2]));
530 AliDebug(5,Form("1stimeA %f , besttimeA %f 1sttimeC %f besttimeC %f ",
531 besttimeA, besttimeA_best,
532 besttimeC, besttimeC_best) );
533 AliDebug(5,Form("fRecPoints::: 1stimeA %f , besttimeA %f 1sttimeC %f besttimeC %f shiftA %f shiftC %f ",
534 frecpoints.Get1stTimeA(), frecpoints.GetBestTimeA(),
535 frecpoints.Get1stTimeC(), frecpoints.GetBestTimeC(),
536 fTimeMeanShift[1],fTimeMeanShift[2] ) );
537 if( besttimeC < 999999 && besttimeA < 999999) {
539 timeclock = (channelWidth*(besttimeC + besttimeA)/2.- 1000.*fLatencyHPTDC +1000.*fLatencyL1 - 1000.*fGRPdelays - fTimeMeanShift[0]);
542 timeclock = channelWidth * Float_t( besttimeA+besttimeC)/2. - fTimeMeanShift[0];
543 meanTime = channelWidth * Float_t(besttimeA_best + besttimeC_best )/2.;
545 timeDiff = ( besttimeA - besttimeC)* 0.001* channelWidth ;
546 vertex = meanVertex - c*(timeDiff)/2. ; //+ (fdZonA - fdZonC)/2;
550 AliDebug(1,Form(" timeDiff %f #channel, meanTime %f #ps, TOFmean%f vertex %f cm meanVertex %f \n",timeDiff, meanTime,timeclock, vertex,meanVertex));
551 frecpoints.SetT0clock(timeclock);
552 frecpoints.SetVertex(vertex);
553 frecpoints.SetMeanTime(meanTime);
554 frecpoints.SetOnlineMean(Int_t(onlineMean));
558 Int_t trchan[5] = {50,51,52,55,56};
559 Float_t lowtr[5] = {meanTVDC-700, meanOrA-700, meanOrC-700, meanOrC-1000, meanOrC-1000 };
560 Float_t hightr[5] = {meanTVDC+700, meanOrA+700, meanOrC+700, meanOrC+1000, meanOrC+1000};
562 for (Int_t i=0; i<5; i++) tr[i] = false;
563 for (Int_t itr=0; itr<5; itr++) {
564 for (Int_t iHit=0; iHit<1; iHit++)
566 Int_t trr=trchan[itr];
567 if( allData[trr][iHit] > lowtr[itr] && allData[trr][iHit] < hightr[itr]) tr[itr]=true;
569 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]));
572 frecpoints.SetT0Trig(tr);
574 // all times with amplitude correction
576 for (Int_t iHit=0; iHit<5; iHit++)
578 timefull = timecent = -9999;
579 tvdc = ora = orc = -9999;
580 if(allData[50][iHit]>0)
581 tvdc = (Float_t(allData[50][iHit]) - meanTVDC) * channelWidth* 0.001;
582 if(allData[51][iHit]>0)
583 ora = (Float_t(allData[51][iHit]) - meanOrA) * channelWidth* 0.001;
585 if(allData[52][iHit]>0)
586 orc = (Float_t(allData[52][iHit]) - meanOrC) * channelWidth* 0.001;
588 frecpoints.SetOrC( iHit, orc);
589 frecpoints.SetOrA( iHit, ora);
590 frecpoints.SetTVDC( iHit, tvdc);
591 for (Int_t i0=0; i0<12; i0++) {
593 timecent = fTime0vertex[i0] + timeDelayCFD[i0];
595 timecent = fTime0vertex[i0];
597 if(allData[i0+1][iHit]>1)
598 timefull = (Float_t(allData[i0+1][iHit]) - timecent)* channelWidth* 0.001;
599 frecpoints.SetTimeFull(i0, iHit,timefull) ;
600 // 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);
604 for (Int_t i0=12; i0<24; i0++) {
607 timecent = fTime0vertex[i0] + timeDelayCFD[i0];
609 timecent = fTime0vertex[i0];
610 if(allData[i0+45][iHit]>1) {
611 timefull = (Float_t(allData[i0+45][iHit]) - timecent)* channelWidth* 0.001;
613 // 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);
614 frecpoints.SetTimeFull(i0, iHit, timefull) ;
620 if(allData[53][0]>0 && allData[54][0])
621 frecpoints.SetMultA(allData[53][0]-allData[54][0]);
622 if(allData[105][0]>0 && allData[106][0])
623 frecpoints.SetMultC(allData[105][0]-allData[106][0]);
626 } // if (else )raw data
631 //____________________________________________________________
633 void AliT0Reconstructor::FillESD(TTree */*digitsTree*/, TTree *clustersTree, AliESDEvent *pESD) const
636 /***************************************************
637 Resonstruct digits to vertex position
638 ****************************************************/
640 AliDebug(1,Form("Start FillESD T0"));
642 AliError("No ESD Event");
645 pESD ->SetT0spread(fTimeSigmaShift);
648 Float_t channelWidth = fParam->GetChannelWidth() ;
649 Float_t c = 0.0299792458; // cm/ps
650 Float_t currentVertex=0, shift=0;
652 const AliESDVertex* vertex = pESD->GetPrimaryVertex();
653 if (!vertex) vertex = pESD->GetPrimaryVertexSPD();
654 if (!vertex) vertex = pESD->GetPrimaryVertexTPC();
655 if (!vertex) vertex = pESD->GetVertex();
658 AliDebug(2, Form("Got %s (%s) from ESD: %f",
659 vertex->GetName(), vertex->GetTitle(), vertex->GetZ()));
660 currentVertex = vertex->GetZ();
662 ncont = vertex->GetNContributors();
664 shift = currentVertex/c;
667 TTree *treeR = clustersTree;
669 AliT0RecPoint frecpoints;
670 AliT0RecPoint * pfrecpoints = &frecpoints;
672 AliDebug(1,Form("Start FillESD T0"));
673 TBranch *brRec = treeR->GetBranch("T0");
675 brRec->SetAddress(&pfrecpoints);
677 AliError(Form("EXEC Branch T0 rec not found"));
682 Double32_t amp[24], time[24], ampQTC[24], timecorr[24];
684 for(Int_t i=0; i<24; i++)
685 amp[i]=time[i]=ampQTC[i]=timecorr[i]=0;
688 Double32_t timeClock[3];
689 Double32_t zPosition = frecpoints.GetVertex();
691 timeClock[0] = frecpoints.GetT0clock() ;
692 timeClock[1] = frecpoints.Get1stTimeA() + shift;
693 timeClock[2] = frecpoints.Get1stTimeC() - shift;
695 Double32_t timemean[3];
696 timemean[0] = frecpoints.GetMeanTime();
697 timemean[1] = frecpoints.GetBestTimeA() + shift;
698 timemean[2] = frecpoints.GetBestTimeC() - shift;
700 for(Int_t i=0; i<3; i++) {
701 fESDTZERO->SetT0TOF(i,timeClock[i]); // interaction time (ns)
702 fESDTZERO->SetT0TOFbest(i,timemean[i]); // interaction time (ns)
704 for ( Int_t i=0; i<24; i++) {
705 time[i] = frecpoints.GetTime(i); // ps to ns
706 if ( time[i] != 0 && time[i]>-9999) {
707 ampQTC[i] = frecpoints.GetAmp(i);
708 amp[i] = frecpoints.AmpLED(i);
709 AliDebug(1,Form("T0: %i time %f ampQTC %f ampLED %f \n", i, time[i], ampQTC[i], amp[i]));
712 fESDTZERO->SetT0time(time); // best TOF on each PMT
713 fESDTZERO->SetT0amplitude(ampQTC); // number of particles(MIPs) on each PMT
714 Int_t trig= frecpoints.GetT0Trig();
715 frecpoints.PrintTriggerSignals( trig);
716 // printf(" !!!!! FillESD trigger %i \n",trig);
717 fESDTZERO->SetT0Trig(trig);
718 fESDTZERO->SetT0zVertex(zPosition); //vertex Z position
720 Double32_t multA=frecpoints.GetMultA();
721 Double32_t multC=frecpoints.GetMultC();
722 fESDTZERO->SetMultA(multA); // for backward compatubility
723 fESDTZERO->SetMultC(multC); // for backward compatubility
726 for (Int_t iHit =0; iHit<5; iHit++ ) {
727 AliDebug(10,Form("FillESD ::: iHit %i tvdc %f orA %f orC %f\n", iHit,
728 frecpoints.GetTVDC(iHit),
729 frecpoints.GetOrA(iHit),
730 frecpoints.GetOrC(iHit) ));
731 fESDTZERO->SetTVDC(iHit,frecpoints.GetTVDC(iHit));
732 fESDTZERO->SetOrA(iHit,frecpoints.GetOrA(iHit));
733 fESDTZERO->SetOrC(iHit,frecpoints.GetOrC(iHit));
735 for (Int_t i0=0; i0<24; i0++) {
736 // if(frecpoints.GetTimeFull(i0,iHit)>0){
737 // printf("FillESD ::: iHit %i cfd %i time %f \n", iHit, i0, frecpoints.GetTimeFull(i0,iHit));
738 fESDTZERO->SetTimeFull(i0, iHit,frecpoints.GetTimeFull(i0,iHit));
744 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));
746 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
748 Bool_t background = BackgroundFlag();
749 fESDTZERO->SetBackgroundFlag(background);
750 Bool_t pileup = PileupFlag();
751 fESDTZERO->SetPileupFlag(pileup);
752 for (Int_t i=0; i<5; i++) {
753 fESDTZERO->SetPileupTime(i, frecpoints.GetTVDC(i) ) ;
754 // printf("!!!!!! FillESD :: pileup %i %f %f \n", i,fESDTZERO->GetPileupTime(i), frecpoints.GetTVDC(i));
756 Bool_t sat = SatelliteFlag();
757 fESDTZERO->SetSatelliteFlag(sat);
759 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
762 AliESDfriend *fr = (AliESDfriend*)pESD->FindListObject("AliESDfriend");
764 AliDebug(10, Form("Writing TZERO friend data to ESD tree"));
767 tcorr = fESDTZEROfriend->GetT0timeCorr();
768 for ( Int_t i=0; i<24; i++) {
769 if(i<12 && time[i]>1) timecorr[i] = tcorr[i] - shift/channelWidth;
770 if(i>11 && time[i]>1) timecorr[i] = tcorr[i] + shift/channelWidth;
771 if(time[i]>1) AliDebug(10,Form("T0 friend : %i time %f ampQTC %f ampLED %f \n", i, timecorr[i], ampQTC[i], amp[i]));
773 fESDTZEROfriend->SetT0timeCorr( timecorr) ;
774 fESDTZEROfriend->SetT0ampLEDminCFD(amp);
775 fESDTZEROfriend->SetT0ampQTC(ampQTC);
776 fr->SetTZEROfriend(fESDTZEROfriend);
780 pESD->SetTZEROData(fESDTZERO);
783 } // vertex in 3 sigma
785 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
786 //____________________________________________________________
788 Bool_t AliT0Reconstructor::PileupFlag() const
791 Bool_t pileup = false;
793 for (Int_t ih=0; ih<5; ih++)
795 tvdc[ih] = fESDTZERO->GetTVDC(ih);
797 if( tvdc[0] !=0 && tvdc[0]> -10 && tvdc[0]< 10 )
798 if(ih>0 && tvdc[ih]>20 ) pileup = true;
799 if( tvdc[0] >20 || (tvdc[0] < -20 && tvdc[0] > -9000) ) pileup =true;
800 // if (pileup) printf(" !!!!! pile up %i tvdc %f \n",ih, tvdc[ih]);
808 //____________________________________________________________
810 Bool_t AliT0Reconstructor::BackgroundFlag() const
813 Bool_t background = false;
815 Float_t orA = fESDTZERO->GetOrA(0);
816 Float_t orC = fESDTZERO->GetOrC(0);
817 Float_t tvdc = fESDTZERO->GetTVDC(ih);
819 if ( (orA > -5 && orA <5) && (orC > -5 && orC <5) && (tvdc < -5 || tvdc > 5)) {
821 // printf(" orA %f orC %f tvdc %f\n", orA, orC, tvdc);
830 //____________________________________________________________
832 Bool_t AliT0Reconstructor::SatelliteFlag() const
835 Float_t satelliteLow = GetRecoParam() -> GetLowSatelliteThreshold();
836 Float_t satelliteHigh = GetRecoParam() -> GetHighSatelliteThreshold();
837 Bool_t satellite = false;
838 for (Int_t i0=0; i0<24; i0++) {
839 Float_t timefull = fESDTZERO -> GetTimeFull(i0,0);
840 if( timefull > satelliteLow && timefull < satelliteHigh) satellite=true;