Fixes
[u/mrichter/AliRoot.git] / T0 / AliT0Reconstructor.cxx
CommitLineData
73df58ab 1
1b9fc3b4 2
dc7ca31d 3/**************************************************************************
4 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5 * *
6 * Author: The ALICE Off-line Project. *
7 * Contributors are mentioned in the code where appropriate. *
8 * *
9 * Permission to use, copy, modify and distribute this software and its *
10 * documentation strictly for non-commercial purposes is hereby granted *
11 * without fee, provided that the above copyright notice appears in all *
12 * copies and that both the copyright notice and this permission notice *
13 * appear in the supporting documentation. The authors make no claims *
14 * about the suitability of this software for any purpose. It is *
15 * provided "as is" without express or implied warranty. *
16 **************************************************************************/
17
18/* $Id$ */
72e48d95 19/*********************************************************************
20 * T0 reconstruction and filling ESD
21 * - reconstruct mean time (interation time)
22 * - vertex position
23 * - multiplicity
24 ********************************************************************/
dc7ca31d 25
af885e0f 26#include <AliESDEvent.h>
dc7ca31d 27#include "AliLog.h"
dc7ca31d 28#include "AliT0RecPoint.h"
29#include "AliRawReader.h"
30#include "AliT0RawReader.h"
dc7ca31d 31#include "AliT0digit.h"
32#include "AliT0Reconstructor.h"
33#include "AliT0Parameters.h"
c41ceaac 34#include "AliT0Calibrator.h"
58bd3a16 35#include "AliESDfriend.h"
73df58ab 36#include "AliESDTZEROfriend.h"
8f8d0732 37#include "AliLog.h"
85f61e3b 38#include "AliCDBEntry.h"
39#include "AliCDBManager.h"
40#include "AliCTPTimeParams.h"
41#include "AliLHCClockPhase.h"
669dc07f 42#include "AliT0CalibSeasonTimeShift.h"
dc7ca31d 43
44#include <TArrayI.h>
45#include <TGraph.h>
aad72f45 46#include <TMath.h>
b09247a2 47#include <Riostream.h>
dc7ca31d 48
49ClassImp(AliT0Reconstructor)
50
c41ceaac 51 AliT0Reconstructor:: AliT0Reconstructor(): AliReconstructor(),
f16935f7 52 fdZonA(0),
53 fdZonC(0),
54 fZposition(0),
55 fParam(NULL),
2e6a5ee0 56 fAmpLEDrec(),
c883fdf2 57 fQTC(0),
58 fAmpLED(0),
58bd3a16 59 fCalib(),
60 fLatencyHPTDC(9000),
61 fLatencyL1(0),
62 fLatencyL1A(0),
73df58ab 63 fLatencyL1C(0),
85f61e3b 64 fGRPdelays(0),
669dc07f 65 fTimeMeanShift(0x0),
66 fTimeSigmaShift(0x0),
73df58ab 67 fESDTZEROfriend(NULL)
58bd3a16 68
e0bba6cc 69{
72e48d95 70 //constructor
85f61e3b 71 AliCDBEntry *entry = AliCDBManager::Instance()->Get("GRP/CTP/CTPtiming");
72 if (!entry) AliFatal("CTP timing parameters are not found in OCDB !");
73 AliCTPTimeParams *ctpParams = (AliCTPTimeParams*)entry->GetObject();
74 Float_t l1Delay = (Float_t)ctpParams->GetDelayL1L0()*25.0;
75
76 AliCDBEntry *entry1 = AliCDBManager::Instance()->Get("GRP/CTP/TimeAlign");
77 if (!entry1) AliFatal("CTP time-alignment is not found in OCDB !");
78 AliCTPTimeParams *ctpTimeAlign = (AliCTPTimeParams*)entry1->GetObject();
79 l1Delay += ((Float_t)ctpTimeAlign->GetDelayL1L0()*25.0);
80
81 AliCDBEntry *entry4 = AliCDBManager::Instance()->Get("GRP/Calib/LHCClockPhase");
82 if (!entry4) AliFatal("LHC clock-phase shift is not found in OCDB !");
83 AliLHCClockPhase *phase = (AliLHCClockPhase*)entry4->GetObject();
84
85f61e3b 85 fGRPdelays = l1Delay - phase->GetMeanPhase();
72e48d95 86
669dc07f 87 AliCDBEntry *entry5 = AliCDBManager::Instance()->Get("T0/Calib/TimeAdjust");
88 if (entry5) {
89 AliT0CalibSeasonTimeShift *timeshift = (AliT0CalibSeasonTimeShift*)entry5->GetObject();
90 fTimeMeanShift = timeshift->GetT0Means();
91 fTimeSigmaShift = timeshift->GetT0Sigmas();
92 timeshift->Print();
93 }
94 else
95 AliWarning("Time Adjust is not found in OCDB !");
96
74adb36a 97 fParam = AliT0Parameters::Instance();
98 fParam->Init();
c883fdf2 99
74adb36a 100 for (Int_t i=0; i<24; i++){
2e6a5ee0 101 TGraph* gr = fParam ->GetAmpLEDRec(i);
29ed1d0e 102 if (gr) fAmpLEDrec.AddAtAndExpand(gr,i) ;
c883fdf2 103 TGraph* gr1 = fParam ->GetAmpLED(i);
104 if (gr1) fAmpLED.AddAtAndExpand(gr1,i) ;
105 TGraph* gr2 = fParam ->GetQTC(i);
539b9cb9 106 if (gr2) fQTC.AddAtAndExpand(gr2,i) ;
c883fdf2 107 }
539b9cb9 108
58bd3a16 109 fLatencyL1 = fParam->GetLatencyL1();
110 fLatencyL1A = fParam->GetLatencyL1A();
111 fLatencyL1C = fParam->GetLatencyL1C();
112 fLatencyHPTDC = fParam->GetLatencyHPTDC();
9d026202 113 AliDebug(2,Form(" LatencyL1 %f latencyL1A %f latencyL1C %f latencyHPTDC %f \n",fLatencyL1, fLatencyL1A, fLatencyL1C, fLatencyHPTDC));
29ed1d0e 114
adf36b9d 115 // fdZonC = TMath::Abs(fParam->GetZPositionShift("T0/C/PMT1"));
116 //fdZonA = TMath::Abs(fParam->GetZPositionShift("T0/A/PMT15"));
8f620945 117 //here real Z position
118 fdZonC = TMath::Abs(fParam->GetZPosition("T0/C/PMT1"));
119 fdZonA = TMath::Abs(fParam->GetZPosition("T0/A/PMT15"));
539b9cb9 120
12e9daf9 121 fCalib = new AliT0Calibrator();
73df58ab 122 fESDTZEROfriend = new AliESDTZEROfriend();
12e9daf9 123
dc7ca31d 124}
c41ceaac 125
126//_____________________________________________________________________________
dc7ca31d 127void AliT0Reconstructor::Reconstruct(TTree*digitsTree, TTree*clustersTree) const
94c27e4f 128
dc7ca31d 129{
94c27e4f 130 // T0 digits reconstruction
38cbfa7c 131 Int_t refAmp = Int_t (GetRecoParam()->GetRefAmp());
776de217 132
c41ceaac 133 TArrayI * timeCFD = new TArrayI(24);
134 TArrayI * timeLED = new TArrayI(24);
135 TArrayI * chargeQT0 = new TArrayI(24);
136 TArrayI * chargeQT1 = new TArrayI(24);
74adb36a 137
d0bcd1fb 138
8955c6b4 139 Float_t channelWidth = fParam->GetChannelWidth() ;
b95e8d87 140 Float_t meanVertex = fParam->GetMeanVertex();
776de217 141 Float_t c = 0.0299792; // cm/ps
adf36b9d 142 Double32_t vertex = 9999999;
143 Double32_t timeDiff=999999, meanTime=999999, timeclock=999999;
776de217 144
94c27e4f 145
dc7ca31d 146 AliDebug(1,Form("Start DIGITS reconstruction "));
94c27e4f 147
2e6a5ee0 148
d0bcd1fb 149 TBranch *brDigits=digitsTree->GetBranch("T0");
e0bba6cc 150 AliT0digit *fDigits = new AliT0digit() ;
dc7ca31d 151 if (brDigits) {
152 brDigits->SetAddress(&fDigits);
153 }else{
f16935f7 154 AliError(Form("EXEC Branch T0 digits not found"));
155 return;
dc7ca31d 156 }
e0bba6cc 157
c41ceaac 158 digitsTree->GetEvent(0);
159 digitsTree->GetEntry(0);
160 brDigits->GetEntry(0);
161 fDigits->GetTimeCFD(*timeCFD);
162 fDigits->GetTimeLED(*timeLED);
163 fDigits->GetQT0(*chargeQT0);
164 fDigits->GetQT1(*chargeQT1);
446d6ec4 165 Int_t onlineMean = fDigits->MeanTime();
c883fdf2 166
adf36b9d 167 Bool_t tr[5];
168 for (Int_t i=0; i<5; i++) tr[i]=false;
c41ceaac 169
adf36b9d 170 Double32_t besttimeA=999999;
171 Double32_t besttimeC=999999;
c41ceaac 172 Int_t pmtBestA=99999;
173 Int_t pmtBestC=99999;
dc7ca31d 174
94c27e4f 175 AliT0RecPoint* frecpoints= new AliT0RecPoint ();
1b544d5a 176 clustersTree->Branch( "T0", "AliT0RecPoint" ,&frecpoints);
94c27e4f 177
b95e8d87 178 Float_t time[24], adc[24];
dc7ca31d 179 for (Int_t ipmt=0; ipmt<24; ipmt++) {
c41ceaac 180 if(timeCFD->At(ipmt)>0 ){
d0bcd1fb 181 if(( chargeQT1->At(ipmt) - chargeQT0->At(ipmt))>0)
182 adc[ipmt] = chargeQT1->At(ipmt) - chargeQT0->At(ipmt);
a7027400 183 else
d0bcd1fb 184 adc[ipmt] = 0;
185
38cbfa7c 186 time[ipmt] = fCalib-> WalkCorrection(refAmp, ipmt, Int_t(adc[ipmt]), timeCFD->At(ipmt)) ;
d0bcd1fb 187
188 Double_t sl = Double_t(timeLED->At(ipmt) - timeCFD->At(ipmt));
8f620945 189 // time[ipmt] = fCalib-> WalkCorrection( refAmp,ipmt, Int_t(sl), timeCFD->At(ipmt) ) ;
669dc07f 190 AliDebug(5,Form(" ipmt %i QTC %i , time in chann %i (led-cfd) %i ",
d0bcd1fb 191 ipmt, Int_t(adc[ipmt]) ,Int_t(time[ipmt]),Int_t( sl)));
776de217 192
d0bcd1fb 193 Double_t ampMip =((TGraph*)fAmpLED.At(ipmt))->Eval(sl);
194 Double_t qtMip = ((TGraph*)fQTC.At(ipmt))->Eval(adc[ipmt]);
669dc07f 195 AliDebug(5,Form(" Amlitude in MIPS LED %f , QTC %f in channels %f\n ",ampMip,qtMip, adc[ipmt]));
d0bcd1fb 196
197 frecpoints->SetTime(ipmt, Float_t(time[ipmt]) );
345f03db 198 frecpoints->SetAmpLED(ipmt, Float_t( ampMip)); //for cosmic &pp beam
199 frecpoints->SetAmp(ipmt, Float_t(qtMip));
d0bcd1fb 200
dc7ca31d 201 }
202 else {
203 time[ipmt] = 0;
204 adc[ipmt] = 0;
205 }
206 }
94c27e4f 207
dc7ca31d 208 for (Int_t ipmt=0; ipmt<12; ipmt++){
209 if(time[ipmt] > 1 ) {
c41ceaac 210 if(time[ipmt]<besttimeC){
211 besttimeC=time[ipmt]; //timeC
212 pmtBestC=ipmt;
dc7ca31d 213 }
214 }
215 }
216 for ( Int_t ipmt=12; ipmt<24; ipmt++){
217 if(time[ipmt] > 1) {
c41ceaac 218 if(time[ipmt]<besttimeA) {
219 besttimeA=time[ipmt]; //timeA
220 pmtBestA=ipmt;}
dc7ca31d 221 }
222 }
adf36b9d 223 if(besttimeA < 999999) {
8f620945 224 frecpoints->SetTimeBestA(Int_t(besttimeA *channelWidth - fdZonA/c));
adf36b9d 225 tr[1]=true;
226 }
227 if( besttimeC < 999999 ) {
8f620945 228 frecpoints->SetTimeBestC(Int_t(besttimeC *channelWidth - fdZonA/c));
adf36b9d 229 tr[2]=true;
230 }
669dc07f 231 AliDebug(5,Form(" besttimeA %f ch, besttimeC %f ch",besttimeA, besttimeC));
adf36b9d 232 if(besttimeA <999999 && besttimeC < 999999 ){
9b83615d 233 // timeDiff = (besttimeC - besttimeA)*channelWidth;
234 timeDiff = (besttimeA - besttimeC)*channelWidth;
adf36b9d 235 meanTime = (besttimeA + besttimeC)/2;// * channelWidth);
8f620945 236 timeclock = meanTime *channelWidth -fdZonA/c ;
adf36b9d 237 vertex = meanVertex - c*(timeDiff)/2.;// + (fdZonA - fdZonC)/2;
238 tr[0]=true;
239 }
240 frecpoints->SetVertex(vertex);
241 frecpoints->SetMeanTime(meanTime);
242 frecpoints->SetT0clock(timeclock);
243 frecpoints->SetT0Trig(tr);
244
669dc07f 245 AliDebug(5,Form("T0 triggers %d %d %d %d %d",tr[0],tr[1],tr[2],tr[3],tr[4]));
adf36b9d 246
247 //online mean
248 frecpoints->SetOnlineMean(Int_t(onlineMean));
b5a9f753 249 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));
adf36b9d 250
251
252
253
b95e8d87 254
dc7ca31d 255 clustersTree->Fill();
bd375212 256
257 delete timeCFD;
258 delete timeLED;
259 delete chargeQT0;
260 delete chargeQT1;
dc7ca31d 261}
262
263
c41ceaac 264//_______________________________________________________________________
265
266void AliT0Reconstructor::Reconstruct(AliRawReader* rawReader, TTree*recTree) const
267{
94c27e4f 268 // T0 raw ->
539b9cb9 269 //
270 // reference amplitude and time ref. point from reco param
271
38cbfa7c 272 Float_t refAmp = GetRecoParam()->GetRefAmp();
273 Int_t refPoint = 0;
274 //Bad channel
275 Int_t badpmt = GetRecoParam()->GetRefPoint();
38cbfa7c 276 Int_t low[110], high[110];
58bd3a16 277
e8ed1cd0 278 Int_t allData[110][5];
2e6a5ee0 279
e8ed1cd0 280 Int_t timeCFD[24], timeLED[24], chargeQT0[24], chargeQT1[24];
291f31a1 281 Double32_t timeDiff=999999, meanTime=999999, timeclock=9999999;
adf36b9d 282 Float_t c = 29.9792458; // cm/ns
283 Double32_t vertex = 9999999;
776de217 284 Int_t onlineMean=0;
9480f05f 285 // Float_t meanVertex = fParam->GetMeanVertex();
286 Float_t meanVertex = 0;
669dc07f 287 for (Int_t i0=0; i0<110; i0++)
bce12dc5 288 {
38cbfa7c 289 for (Int_t j0=0; j0<5; j0++) allData[i0][j0]=0;
290 low[i0] = Int_t (GetRecoParam()->GetLow(i0));
291 high[i0] = Int_t (GetRecoParam()->GetHigh(i0));
1b9fc3b4 292 }
b9c0936d 293 Float_t lowAmpThreshold = GetRecoParam()->GetLow(200);
294 Float_t highAmpThreshold = GetRecoParam()->GetHigh(200);
adf36b9d 295 Double32_t besttimeA=9999999;
296 Double32_t besttimeC=9999999;
bce12dc5 297 Int_t pmtBestA=99999;
298 Int_t pmtBestC=99999;
29a60970 299
bce12dc5 300 AliT0RecPoint* frecpoints= new AliT0RecPoint ();
301
1b544d5a 302 recTree->Branch( "T0", "AliT0RecPoint" ,&frecpoints);
2e6a5ee0 303
bce12dc5 304 AliDebug(10," before read data ");
305 AliT0RawReader myrawreader(rawReader);
776de217 306
307 UInt_t type =rawReader->GetType();
308
bce12dc5 309 if (!myrawreader.Next())
310 AliDebug(1,Form(" no raw data found!!"));
311 else
312 {
38cbfa7c 313 for (Int_t i=0; i<24; i++)
314 {
315 timeCFD[i]=0; timeLED[i]=0; chargeQT0[i]=0; chargeQT1[i]=0;
316 }
317 Int_t fBCID=Int_t (rawReader->GetBCID());
8f620945 318 Int_t trmbunch= myrawreader.GetTRMBunchID();
86fd0587 319 AliDebug(10,Form(" CDH BC ID %i, TRM BC ID %i \n", fBCID, trmbunch ));
320
38cbfa7c 321 if(type == 7 ) { //only physics
669dc07f 322 for (Int_t i=0; i<107; i++) {
bce12dc5 323 for (Int_t iHit=0; iHit<5; iHit++)
324 {
325 allData[i][iHit] = myrawreader.GetData(i,iHit);
326 }
8f620945 327 }
328 Int_t ref=0;
329 if (refPoint>0)
330 ref = allData[refPoint][0]-5000;
331
332 Float_t channelWidth = fParam->GetChannelWidth() ;
333
334 // Int_t meanT0 = fParam->GetMeanT0();
335
85f61e3b 336 for (Int_t in=0; in<12; in++)
337 {
338 for (Int_t iHit=0; iHit<5; iHit++)
38cbfa7c 339 {
85f61e3b 340 if(allData[in+1][iHit] > low[in+1] &&
341 allData[in+1][iHit] < high[in+1])
38cbfa7c 342 {
85f61e3b 343 timeCFD[in] = allData[in+1][iHit] ;
344 break;
38cbfa7c 345 }
85f61e3b 346 }
347 for (Int_t iHit=0; iHit<5; iHit++)
348 {
349 if(allData[in+12+1][iHit] > low[in+12+1] &&
350 allData[in+1+12][iHit] < high[in+12+1])
38cbfa7c 351 {
38cbfa7c 352 timeLED[in] = allData[in+12+1][iHit] ;
353 break;
38cbfa7c 354 }
85f61e3b 355 }
356 for (Int_t iHit=0; iHit<5; iHit++)
357 {
358 if(allData[in+1+56][iHit] > low[in+1+56] &&
359 allData[in+1+56][iHit] < high[in+1+56])
38cbfa7c 360 {
85f61e3b 361 timeCFD[in+12] = allData[in+56+1][iHit] ;
362 break;
38cbfa7c 363 }
38cbfa7c 364 }
365
85f61e3b 366 for (Int_t iHit=0; iHit<5; iHit++)
38cbfa7c 367 {
85f61e3b 368 if(allData[in+1+68][iHit] > low[in+1+68] &&
369 allData[in+1+68][iHit] < high[in+1+68])
370 {
669dc07f 371
85f61e3b 372 timeLED[in+12] = allData[in+68+1][iHit] ;
373 break;
374 }
38cbfa7c 375 }
669dc07f 376 AliDebug(5, Form(" readed i %i cfdC %i cfdA %i ledC %i ledA%i ",
85f61e3b 377 in, timeCFD[in],timeCFD[in+12],timeLED[in],
378 timeLED[in+12]));
38cbfa7c 379
8f620945 380 }
381
8f620945 382
85f61e3b 383 for (Int_t in=0; in<12; in++)
384 {
385 chargeQT0[in]=allData[2*in+25][0];
386 chargeQT1[in]=allData[2*in+26][0];
387 AliDebug(10, Form(" readed Raw %i %i %i",
388 in, chargeQT0[in],chargeQT1[in]));
389 }
390 for (Int_t in=12; in<24; in++)
391 {
392 chargeQT0[in]=allData[2*in+57][0];
393 chargeQT1[in]=allData[2*in+58][0];
394 AliDebug(10, Form(" readed Raw %i %i %i",
395 in, chargeQT0[in],chargeQT1[in]));
396
397 }
398
399 for (Int_t iHit=0; iHit<5; iHit++)
38cbfa7c 400 {
85f61e3b 401 if(allData[49][iHit] > low[49] &&
402 allData[49][iHit] < high[49]){
403 onlineMean = allData[49][iHit];
404 break;
405 }
38cbfa7c 406 }
73df58ab 407 Double32_t time[24], adc[24], noncalibtime[24];
8f620945 408 for (Int_t ipmt=0; ipmt<24; ipmt++) {
38cbfa7c 409 if(timeCFD[ipmt]>0 ){
bce12dc5 410 //for simulated data
d0bcd1fb 411 //for physics data
73df58ab 412 if(( chargeQT0[ipmt] - chargeQT1[ipmt])>0) {
541b42c4 413 adc[ipmt] = chargeQT0[ipmt] - chargeQT1[ipmt];
73df58ab 414 }
d0bcd1fb 415 else
416 adc[ipmt] = 0;
38cbfa7c 417 time[ipmt] = fCalib-> WalkCorrection(Int_t (refAmp), ipmt, Int_t(adc[ipmt]), timeCFD[ipmt] ) ;
bce12dc5 418
d0bcd1fb 419 Double_t sl = timeLED[ipmt] - timeCFD[ipmt];
8f620945 420 // time[ipmt] = fCalib-> WalkCorrection( refAmp,ipmt, Int_t(sl), timeCFD[ipmt] ) ;
73df58ab 421 AliDebug(5,Form(" ipmt %i QTC %i , time in chann %i (led-cfd) %i ",
d0bcd1fb 422 ipmt, Int_t(adc[ipmt]) ,Int_t(time[ipmt]),Int_t( sl)));
423 Double_t ampMip =( (TGraph*)fAmpLED.At(ipmt))->Eval(sl);
424 Double_t qtMip = ((TGraph*)fQTC.At(ipmt))->Eval(adc[ipmt]);
345f03db 425 AliDebug(10,Form(" Amlitude in MIPS LED %f ; QTC %f; in channels %f\n ",ampMip,qtMip, adc[ipmt]));
73df58ab 426 //bad peak removing
73df58ab 427 frecpoints->SetTime(ipmt, Float_t(time[ipmt]) );
428 // frecpoints->SetTime(ipmt,Double32_t(timeCFD[ipmt]));
345f03db 429 frecpoints->SetAmp(ipmt, Double32_t( qtMip)); //for cosmic &pp beam
430 frecpoints->SetAmpLED(ipmt, Double32_t(ampMip));
73df58ab 431 noncalibtime[ipmt]= Double32_t (timeCFD[ipmt]);
2e6a5ee0 432 }
433 else {
434 time[ipmt] = 0;
435 adc[ipmt] = 0;
73df58ab 436 noncalibtime[ipmt] = 0;
2e6a5ee0 437 }
438 }
73df58ab 439 fESDTZEROfriend->SetT0timeCorr(noncalibtime) ;
2e6a5ee0 440 for (Int_t ipmt=0; ipmt<12; ipmt++){
b9c0936d 441 if(time[ipmt] > 1 && ipmt != badpmt && adc[ipmt]>lowAmpThreshold && adc[ipmt]<highAmpThreshold)
73df58ab 442 {
443 if(time[ipmt]<besttimeC){
669dc07f 444 besttimeC=time[ipmt]; //timeC
445 pmtBestC=ipmt;
73df58ab 446 }
2e6a5ee0 447 }
2e6a5ee0 448 }
73df58ab 449 for ( Int_t ipmt=12; ipmt<24; ipmt++)
450 {
b9c0936d 451 if(time[ipmt] > 1 && ipmt != badpmt && adc[ipmt]>lowAmpThreshold && adc[ipmt]<highAmpThreshold)
73df58ab 452 {
453 if(time[ipmt]<besttimeA) {
454 besttimeA=time[ipmt]; //timeA
455 pmtBestA=ipmt;
456 }
457 }
2e6a5ee0 458 }
adf36b9d 459 if(besttimeA < 999999)
669dc07f 460 frecpoints->SetTimeBestA(besttimeA * channelWidth - 1000.*fLatencyHPTDC + 1000.*fLatencyL1A - 1000.*fGRPdelays - fTimeMeanShift[1]);
461
adf36b9d 462 if( besttimeC < 999999 )
669dc07f 463 frecpoints->SetTimeBestC(besttimeC * channelWidth - 1000.*fLatencyHPTDC +1000.*fLatencyL1C - 1000.*fGRPdelays - fTimeMeanShift[2]);
464 AliDebug(5,Form(" pmtA %i besttimeA %f shift A %f ps, pmtC %i besttimeC %f shiftC %f ps",
465 pmtBestA,besttimeA, fTimeMeanShift[1],
1b9fc3b4 466
669dc07f 467 pmtBestC, besttimeC,fTimeMeanShift[2]));
adf36b9d 468 if(besttimeA <999999 && besttimeC < 999999 ){
73df58ab 469 timeDiff = ( besttimeA - besttimeC)* 0.001* channelWidth + fLatencyL1A - fLatencyL1C;
669dc07f 470 timeclock = channelWidth * Float_t( besttimeA+besttimeC)/2. - 1000.*fLatencyHPTDC + 1000.*fLatencyL1 - 1000.*fGRPdelays - fTimeMeanShift[0];
adf36b9d 471 meanTime = (besttimeA+besttimeC-2.*Float_t(ref))/2.;
9480f05f 472 vertex = meanVertex - c*(timeDiff)/2. ; //+ (fdZonA - fdZonC)/2;
adf36b9d 473 }
776de217 474 } //if phys event
291f31a1 475 AliDebug(10,Form(" timeDiff %f #channel, meanTime %f #channel, TOFmean%f vertex %f cm meanVertex %f online mean %i \n",timeDiff, meanTime,timeclock, vertex,meanVertex, onlineMean));
776de217 476 frecpoints->SetT0clock(timeclock);
477 frecpoints->SetVertex(vertex);
adf36b9d 478 frecpoints->SetMeanTime(meanTime);
776de217 479 frecpoints->SetOnlineMean(Int_t(onlineMean));
adf36b9d 480 // Set triggers
481
482 Bool_t tr[5];
483 Int_t trchan[5]= {50,51,52,55,56};
484 for (Int_t i=0; i<5; i++) tr[i]=false;
485 for (Int_t itr=0; itr<5; itr++) {
38cbfa7c 486 for (Int_t iHit=0; iHit<5; iHit++)
487 {
488 Int_t trr=trchan[itr];
669dc07f 489 if( allData[trr][iHit] > 0) tr[itr]=true;
38cbfa7c 490 }
adf36b9d 491 }
38cbfa7c 492 frecpoints->SetT0Trig(tr);
669dc07f 493
494 //Set MPD
495 if(allData[53][0]>0 && allData[54][0])
496 frecpoints->SetMultA(allData[53][0]-allData[54][0]);
497 if(allData[105][0]>0 && allData[106][0])
498 frecpoints->SetMultC(allData[105][0]-allData[106][0]);
499
500
501 } // if (else )raw data
58bd3a16 502 recTree->Fill();
503 if(frecpoints) delete frecpoints;
504}
adf36b9d 505
506
507 //____________________________________________________________
508
509 void AliT0Reconstructor::FillESD(TTree */*digitsTree*/, TTree *clustersTree, AliESDEvent *pESD) const
510 {
dc7ca31d 511
512 /***************************************************
513 Resonstruct digits to vertex position
514 ****************************************************/
515
dc7ca31d 516 AliDebug(1,Form("Start FillESD T0"));
58bd3a16 517 Float_t channelWidth = fParam->GetChannelWidth() ;
f7c2c2fc 518 Float_t c = 0.0299792458; // cm/ps
adf36b9d 519 Float_t currentVertex=0, shift=0;
291f31a1 520 Int_t ncont=-1;
adf36b9d 521 const AliESDVertex* vertex = pESD->GetPrimaryVertex();
522 if (!vertex) vertex = pESD->GetPrimaryVertexSPD();
523 if (!vertex) vertex = pESD->GetPrimaryVertexTPC();
524 if (!vertex) vertex = pESD->GetVertex();
525
526 if (vertex) {
527 AliDebug(2, Form("Got %s (%s) from ESD: %f",
528 vertex->GetName(), vertex->GetTitle(), vertex->GetZ()));
529 currentVertex = vertex->GetZ();
530
531 ncont = vertex->GetNContributors();
85f61e3b 532 // cout<<"@@ spdver "<<spdver<<" ncont "<<ncont<<endl;
291f31a1 533 if(ncont>0 ) {
adf36b9d 534 shift = currentVertex/c;
adf36b9d 535 }
536 }
d76c31f4 537 TTree *treeR = clustersTree;
dc7ca31d 538
73df58ab 539 AliT0RecPoint* frecpoints= new AliT0RecPoint ();
540 if (!frecpoints) {
dc7ca31d 541 AliError("Reconstruct Fill ESD >> no recpoints found");
542 return;
543 }
544
545 AliDebug(1,Form("Start FillESD T0"));
546 TBranch *brRec = treeR->GetBranch("T0");
547 if (brRec) {
548 brRec->SetAddress(&frecpoints);
549 }else{
f16935f7 550 AliError(Form("EXEC Branch T0 rec not found"));
dc7ca31d 551 return;
552 }
73df58ab 553
554 brRec->GetEntry(0);
555 Double32_t amp[24], time[24], ampQTC[24], timecorr[24];
556 Double32_t* tcorr;
557 for(Int_t i=0; i<24; i++)
558 amp[i]=time[i]=ampQTC[i]=timecorr[i]=0;
559
669dc07f 560
73df58ab 561 Double32_t timeClock[3];
562 Double32_t zPosition = frecpoints -> GetVertex();
563 Double32_t timeStart = frecpoints -> GetMeanTime();
564 timeClock[0] = frecpoints -> GetT0clock() ;
565 timeClock[1] = frecpoints -> GetBestTimeA() + shift;
566 timeClock[2] = frecpoints -> GetBestTimeC() - shift;
567 for ( Int_t i=0; i<24; i++) {
568 time[i] = frecpoints -> GetTime(i); // ps to ns
569 if ( time[i] >1) {
345f03db 570 ampQTC[i] = frecpoints -> GetAmp(i);
571 amp[i] = frecpoints -> AmpLED(i);
85f61e3b 572 AliDebug(1,Form("T0: time %f ampQTC %f ampLED %f \n", time[i], ampQTC[i], amp[i]));
573 }
73df58ab 574 }
575 Int_t trig= frecpoints ->GetT0Trig();
576 pESD->SetT0Trig(trig);
577
578 pESD->SetT0zVertex(zPosition); //vertex Z position
669dc07f 579
580 Double32_t multA=frecpoints ->GetMultA();
581 Double32_t multC=frecpoints ->GetMultC();
3050a127 582 // pESD->SetT0MultC(multC); // multiplicity Cside
583 // pESD->SetT0MultA(multA); // multiplicity Aside
1b9fc3b4 584 pESD->SetT0(multA); // for backward compatubility
585 pESD->SetT0clock(multC); // for backward compatubility
669dc07f 586
73df58ab 587 for(Int_t i=0; i<3; i++)
588 pESD->SetT0TOF(i,timeClock[i]); // interaction time (ns)
589 pESD->SetT0time(time); // best TOF on each PMT
345f03db 590 pESD->SetT0amplitude(ampQTC); // number of particles(MIPs) on each PMT
73df58ab 591
592 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));
593
594 if (pESD) {
adf36b9d 595
73df58ab 596 AliESDfriend *fr = (AliESDfriend*)pESD->FindListObject("AliESDfriend");
597 if (fr) {
598 AliDebug(1, Form("Writing TZERO friend data to ESD tree"));
599
85f61e3b 600 // if (ncont>2) {
73df58ab 601 tcorr = fESDTZEROfriend->GetT0timeCorr();
602 for ( Int_t i=0; i<24; i++) {
85f61e3b 603 if(i<12 && time[i]>1) timecorr[i] = tcorr[i] - shift/channelWidth;
604 if(i>11 && time[i]>1) timecorr[i] = tcorr[i] + shift/channelWidth;
669dc07f 605 if(time[i]>1) AliDebug(10,Form("T0 friend : time %f ampQTC %f ampLED %f \n", timecorr[i], ampQTC[i], amp[i]));
58bd3a16 606 }
73df58ab 607 fESDTZEROfriend->SetT0timeCorr( timecorr) ;
608 fESDTZEROfriend->SetT0ampLEDminCFD(amp);
609 fESDTZEROfriend->SetT0ampQTC(ampQTC);
85f61e3b 610 fr->SetTZEROfriend(fESDTZEROfriend);
611 // }//
58bd3a16 612 }
613 }
73df58ab 614
615
616
dc7ca31d 617} // vertex in 3 sigma
618
619
620
621
622
623