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