Adding monitoring on the chip level
[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
c41ceaac 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++){
36da3ca3 212 if(time[ipmt] > 1 && adc[ipmt]>0.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++){
36da3ca3 220 if(time[ipmt] > 1 && adc[ipmt]>0.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();
36da3ca3 279 Int_t low[500], high[500];
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
36da3ca3 297 Float_t lowAmpThreshold = GetRecoParam()->GetLow(200);
298 Float_t highAmpThreshold = GetRecoParam()->GetHigh(200);
adf36b9d 299 Double32_t besttimeA=9999999;
300 Double32_t besttimeC=9999999;
bce12dc5 301 Int_t pmtBestA=99999;
302 Int_t pmtBestC=99999;
29a60970 303
bce12dc5 304 AliT0RecPoint* frecpoints= new AliT0RecPoint ();
305
1b544d5a 306 recTree->Branch( "T0", "AliT0RecPoint" ,&frecpoints);
2e6a5ee0 307
bce12dc5 308 AliDebug(10," before read data ");
309 AliT0RawReader myrawreader(rawReader);
776de217 310
311 UInt_t type =rawReader->GetType();
312
bce12dc5 313 if (!myrawreader.Next())
314 AliDebug(1,Form(" no raw data found!!"));
315 else
316 {
38cbfa7c 317 for (Int_t i=0; i<24; i++)
318 {
319 timeCFD[i]=0; timeLED[i]=0; chargeQT0[i]=0; chargeQT1[i]=0;
320 }
321 Int_t fBCID=Int_t (rawReader->GetBCID());
8f620945 322 Int_t trmbunch= myrawreader.GetTRMBunchID();
86fd0587 323 AliDebug(10,Form(" CDH BC ID %i, TRM BC ID %i \n", fBCID, trmbunch ));
324
38cbfa7c 325 if(type == 7 ) { //only physics
669dc07f 326 for (Int_t i=0; i<107; i++) {
bce12dc5 327 for (Int_t iHit=0; iHit<5; iHit++)
328 {
329 allData[i][iHit] = myrawreader.GetData(i,iHit);
330 }
8f620945 331 }
332 Int_t ref=0;
333 if (refPoint>0)
334 ref = allData[refPoint][0]-5000;
335
336 Float_t channelWidth = fParam->GetChannelWidth() ;
337
338 // Int_t meanT0 = fParam->GetMeanT0();
339
85f61e3b 340 for (Int_t in=0; in<12; in++)
341 {
342 for (Int_t iHit=0; iHit<5; iHit++)
38cbfa7c 343 {
85f61e3b 344 if(allData[in+1][iHit] > low[in+1] &&
345 allData[in+1][iHit] < high[in+1])
38cbfa7c 346 {
85f61e3b 347 timeCFD[in] = allData[in+1][iHit] ;
348 break;
38cbfa7c 349 }
85f61e3b 350 }
351 for (Int_t iHit=0; iHit<5; iHit++)
352 {
353 if(allData[in+12+1][iHit] > low[in+12+1] &&
354 allData[in+1+12][iHit] < high[in+12+1])
38cbfa7c 355 {
38cbfa7c 356 timeLED[in] = allData[in+12+1][iHit] ;
357 break;
38cbfa7c 358 }
85f61e3b 359 }
360 for (Int_t iHit=0; iHit<5; iHit++)
361 {
362 if(allData[in+1+56][iHit] > low[in+1+56] &&
363 allData[in+1+56][iHit] < high[in+1+56])
38cbfa7c 364 {
85f61e3b 365 timeCFD[in+12] = allData[in+56+1][iHit] ;
366 break;
38cbfa7c 367 }
38cbfa7c 368 }
369
85f61e3b 370 for (Int_t iHit=0; iHit<5; iHit++)
38cbfa7c 371 {
85f61e3b 372 if(allData[in+1+68][iHit] > low[in+1+68] &&
373 allData[in+1+68][iHit] < high[in+1+68])
374 {
669dc07f 375
85f61e3b 376 timeLED[in+12] = allData[in+68+1][iHit] ;
377 break;
378 }
38cbfa7c 379 }
669dc07f 380 AliDebug(5, Form(" readed i %i cfdC %i cfdA %i ledC %i ledA%i ",
85f61e3b 381 in, timeCFD[in],timeCFD[in+12],timeLED[in],
382 timeLED[in+12]));
38cbfa7c 383
8f620945 384 }
385
8f620945 386
85f61e3b 387 for (Int_t in=0; in<12; in++)
388 {
389 chargeQT0[in]=allData[2*in+25][0];
390 chargeQT1[in]=allData[2*in+26][0];
391 AliDebug(10, Form(" readed Raw %i %i %i",
392 in, chargeQT0[in],chargeQT1[in]));
393 }
394 for (Int_t in=12; in<24; in++)
395 {
396 chargeQT0[in]=allData[2*in+57][0];
397 chargeQT1[in]=allData[2*in+58][0];
398 AliDebug(10, Form(" readed Raw %i %i %i",
399 in, chargeQT0[in],chargeQT1[in]));
400
401 }
402
403 for (Int_t iHit=0; iHit<5; iHit++)
38cbfa7c 404 {
85f61e3b 405 if(allData[49][iHit] > low[49] &&
406 allData[49][iHit] < high[49]){
407 onlineMean = allData[49][iHit];
408 break;
409 }
38cbfa7c 410 }
73df58ab 411 Double32_t time[24], adc[24], noncalibtime[24];
8f620945 412 for (Int_t ipmt=0; ipmt<24; ipmt++) {
4cbe597e 413 if(timeCFD[ipmt]>0 && ipmt != badpmt ){
bce12dc5 414 //for simulated data
d0bcd1fb 415 //for physics data
73df58ab 416 if(( chargeQT0[ipmt] - chargeQT1[ipmt])>0) {
541b42c4 417 adc[ipmt] = chargeQT0[ipmt] - chargeQT1[ipmt];
73df58ab 418 }
d0bcd1fb 419 else
420 adc[ipmt] = 0;
38cbfa7c 421 time[ipmt] = fCalib-> WalkCorrection(Int_t (refAmp), ipmt, Int_t(adc[ipmt]), timeCFD[ipmt] ) ;
bce12dc5 422
d0bcd1fb 423 Double_t sl = timeLED[ipmt] - timeCFD[ipmt];
8f620945 424 // time[ipmt] = fCalib-> WalkCorrection( refAmp,ipmt, Int_t(sl), timeCFD[ipmt] ) ;
73df58ab 425 AliDebug(5,Form(" ipmt %i QTC %i , time in chann %i (led-cfd) %i ",
d0bcd1fb 426 ipmt, Int_t(adc[ipmt]) ,Int_t(time[ipmt]),Int_t( sl)));
427 Double_t ampMip =( (TGraph*)fAmpLED.At(ipmt))->Eval(sl);
428 Double_t qtMip = ((TGraph*)fQTC.At(ipmt))->Eval(adc[ipmt]);
345f03db 429 AliDebug(10,Form(" Amlitude in MIPS LED %f ; QTC %f; in channels %f\n ",ampMip,qtMip, adc[ipmt]));
73df58ab 430 //bad peak removing
73df58ab 431 frecpoints->SetTime(ipmt, Float_t(time[ipmt]) );
432 // frecpoints->SetTime(ipmt,Double32_t(timeCFD[ipmt]));
345f03db 433 frecpoints->SetAmp(ipmt, Double32_t( qtMip)); //for cosmic &pp beam
434 frecpoints->SetAmpLED(ipmt, Double32_t(ampMip));
73df58ab 435 noncalibtime[ipmt]= Double32_t (timeCFD[ipmt]);
2e6a5ee0 436 }
437 else {
438 time[ipmt] = 0;
439 adc[ipmt] = 0;
73df58ab 440 noncalibtime[ipmt] = 0;
2e6a5ee0 441 }
442 }
73df58ab 443 fESDTZEROfriend->SetT0timeCorr(noncalibtime) ;
2e6a5ee0 444 for (Int_t ipmt=0; ipmt<12; ipmt++){
36da3ca3 445 if(time[ipmt] > 1 && ipmt != badpmt && adc[ipmt]>lowAmpThreshold && adc[ipmt]<highAmpThreshold)
73df58ab 446 {
447 if(time[ipmt]<besttimeC){
669dc07f 448 besttimeC=time[ipmt]; //timeC
449 pmtBestC=ipmt;
73df58ab 450 }
2e6a5ee0 451 }
2e6a5ee0 452 }
73df58ab 453 for ( Int_t ipmt=12; ipmt<24; ipmt++)
454 {
36da3ca3 455 if(time[ipmt] > 1 && ipmt != badpmt && adc[ipmt]>lowAmpThreshold && adc[ipmt]<highAmpThreshold)
73df58ab 456 {
457 if(time[ipmt]<besttimeA) {
458 besttimeA=time[ipmt]; //timeA
459 pmtBestA=ipmt;
460 }
461 }
2e6a5ee0 462 }
adf36b9d 463 if(besttimeA < 999999)
669dc07f 464 frecpoints->SetTimeBestA(besttimeA * channelWidth - 1000.*fLatencyHPTDC + 1000.*fLatencyL1A - 1000.*fGRPdelays - fTimeMeanShift[1]);
465
adf36b9d 466 if( besttimeC < 999999 )
669dc07f 467 frecpoints->SetTimeBestC(besttimeC * channelWidth - 1000.*fLatencyHPTDC +1000.*fLatencyL1C - 1000.*fGRPdelays - fTimeMeanShift[2]);
468 AliDebug(5,Form(" pmtA %i besttimeA %f shift A %f ps, pmtC %i besttimeC %f shiftC %f ps",
469 pmtBestA,besttimeA, fTimeMeanShift[1],
1b9fc3b4 470
669dc07f 471 pmtBestC, besttimeC,fTimeMeanShift[2]));
adf36b9d 472 if(besttimeA <999999 && besttimeC < 999999 ){
73df58ab 473 timeDiff = ( besttimeA - besttimeC)* 0.001* channelWidth + fLatencyL1A - fLatencyL1C;
669dc07f 474 timeclock = channelWidth * Float_t( besttimeA+besttimeC)/2. - 1000.*fLatencyHPTDC + 1000.*fLatencyL1 - 1000.*fGRPdelays - fTimeMeanShift[0];
adf36b9d 475 meanTime = (besttimeA+besttimeC-2.*Float_t(ref))/2.;
9480f05f 476 vertex = meanVertex - c*(timeDiff)/2. ; //+ (fdZonA - fdZonC)/2;
adf36b9d 477 }
776de217 478 } //if phys event
291f31a1 479 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 480 frecpoints->SetT0clock(timeclock);
481 frecpoints->SetVertex(vertex);
adf36b9d 482 frecpoints->SetMeanTime(meanTime);
776de217 483 frecpoints->SetOnlineMean(Int_t(onlineMean));
adf36b9d 484 // Set triggers
485
486 Bool_t tr[5];
487 Int_t trchan[5]= {50,51,52,55,56};
488 for (Int_t i=0; i<5; i++) tr[i]=false;
489 for (Int_t itr=0; itr<5; itr++) {
38cbfa7c 490 for (Int_t iHit=0; iHit<5; iHit++)
491 {
492 Int_t trr=trchan[itr];
669dc07f 493 if( allData[trr][iHit] > 0) tr[itr]=true;
38cbfa7c 494 }
adf36b9d 495 }
38cbfa7c 496 frecpoints->SetT0Trig(tr);
669dc07f 497
498 //Set MPD
499 if(allData[53][0]>0 && allData[54][0])
500 frecpoints->SetMultA(allData[53][0]-allData[54][0]);
501 if(allData[105][0]>0 && allData[106][0])
502 frecpoints->SetMultC(allData[105][0]-allData[106][0]);
503
504
505 } // if (else )raw data
58bd3a16 506 recTree->Fill();
507 if(frecpoints) delete frecpoints;
508}
adf36b9d 509
510
511 //____________________________________________________________
512
513 void AliT0Reconstructor::FillESD(TTree */*digitsTree*/, TTree *clustersTree, AliESDEvent *pESD) const
514 {
dc7ca31d 515
516 /***************************************************
517 Resonstruct digits to vertex position
518 ****************************************************/
519
dc7ca31d 520 AliDebug(1,Form("Start FillESD T0"));
36da3ca3 521
4cbe597e 522 pESD ->SetT0spread(fTimeSigmaShift);
523
58bd3a16 524 Float_t channelWidth = fParam->GetChannelWidth() ;
f7c2c2fc 525 Float_t c = 0.0299792458; // cm/ps
adf36b9d 526 Float_t currentVertex=0, shift=0;
291f31a1 527 Int_t ncont=-1;
adf36b9d 528 const AliESDVertex* vertex = pESD->GetPrimaryVertex();
529 if (!vertex) vertex = pESD->GetPrimaryVertexSPD();
530 if (!vertex) vertex = pESD->GetPrimaryVertexTPC();
531 if (!vertex) vertex = pESD->GetVertex();
532
533 if (vertex) {
534 AliDebug(2, Form("Got %s (%s) from ESD: %f",
535 vertex->GetName(), vertex->GetTitle(), vertex->GetZ()));
536 currentVertex = vertex->GetZ();
537
538 ncont = vertex->GetNContributors();
85f61e3b 539 // cout<<"@@ spdver "<<spdver<<" ncont "<<ncont<<endl;
291f31a1 540 if(ncont>0 ) {
adf36b9d 541 shift = currentVertex/c;
adf36b9d 542 }
543 }
d76c31f4 544 TTree *treeR = clustersTree;
dc7ca31d 545
73df58ab 546 AliT0RecPoint* frecpoints= new AliT0RecPoint ();
547 if (!frecpoints) {
dc7ca31d 548 AliError("Reconstruct Fill ESD >> no recpoints found");
549 return;
550 }
551
552 AliDebug(1,Form("Start FillESD T0"));
553 TBranch *brRec = treeR->GetBranch("T0");
554 if (brRec) {
555 brRec->SetAddress(&frecpoints);
556 }else{
f16935f7 557 AliError(Form("EXEC Branch T0 rec not found"));
dc7ca31d 558 return;
559 }
73df58ab 560
561 brRec->GetEntry(0);
562 Double32_t amp[24], time[24], ampQTC[24], timecorr[24];
563 Double32_t* tcorr;
564 for(Int_t i=0; i<24; i++)
565 amp[i]=time[i]=ampQTC[i]=timecorr[i]=0;
566
669dc07f 567
73df58ab 568 Double32_t timeClock[3];
569 Double32_t zPosition = frecpoints -> GetVertex();
570 Double32_t timeStart = frecpoints -> GetMeanTime();
571 timeClock[0] = frecpoints -> GetT0clock() ;
572 timeClock[1] = frecpoints -> GetBestTimeA() + shift;
573 timeClock[2] = frecpoints -> GetBestTimeC() - shift;
574 for ( Int_t i=0; i<24; i++) {
575 time[i] = frecpoints -> GetTime(i); // ps to ns
576 if ( time[i] >1) {
345f03db 577 ampQTC[i] = frecpoints -> GetAmp(i);
578 amp[i] = frecpoints -> AmpLED(i);
36da3ca3 579 AliDebug(10,Form("T0: time %f ampQTC %f ampLED %f \n", time[i], ampQTC[i], amp[i]));
85f61e3b 580 }
73df58ab 581 }
582 Int_t trig= frecpoints ->GetT0Trig();
583 pESD->SetT0Trig(trig);
584
585 pESD->SetT0zVertex(zPosition); //vertex Z position
669dc07f 586
587 Double32_t multA=frecpoints ->GetMultA();
588 Double32_t multC=frecpoints ->GetMultC();
3050a127 589 // pESD->SetT0MultC(multC); // multiplicity Cside
590 // pESD->SetT0MultA(multA); // multiplicity Aside
1b9fc3b4 591 pESD->SetT0(multA); // for backward compatubility
592 pESD->SetT0clock(multC); // for backward compatubility
669dc07f 593
73df58ab 594 for(Int_t i=0; i<3; i++)
595 pESD->SetT0TOF(i,timeClock[i]); // interaction time (ns)
596 pESD->SetT0time(time); // best TOF on each PMT
345f03db 597 pESD->SetT0amplitude(ampQTC); // number of particles(MIPs) on each PMT
73df58ab 598
599 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));
600
601 if (pESD) {
adf36b9d 602
73df58ab 603 AliESDfriend *fr = (AliESDfriend*)pESD->FindListObject("AliESDfriend");
604 if (fr) {
36da3ca3 605 AliDebug(10, Form("Writing TZERO friend data to ESD tree"));
73df58ab 606
85f61e3b 607 // if (ncont>2) {
73df58ab 608 tcorr = fESDTZEROfriend->GetT0timeCorr();
609 for ( Int_t i=0; i<24; i++) {
85f61e3b 610 if(i<12 && time[i]>1) timecorr[i] = tcorr[i] - shift/channelWidth;
611 if(i>11 && time[i]>1) timecorr[i] = tcorr[i] + shift/channelWidth;
669dc07f 612 if(time[i]>1) AliDebug(10,Form("T0 friend : time %f ampQTC %f ampLED %f \n", timecorr[i], ampQTC[i], amp[i]));
58bd3a16 613 }
73df58ab 614 fESDTZEROfriend->SetT0timeCorr( timecorr) ;
615 fESDTZEROfriend->SetT0ampLEDminCFD(amp);
616 fESDTZEROfriend->SetT0ampQTC(ampQTC);
85f61e3b 617 fr->SetTZEROfriend(fESDTZEROfriend);
618 // }//
58bd3a16 619 }
620 }
73df58ab 621
622
623
dc7ca31d 624} // vertex in 3 sigma
625
626
627
628
629
630