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