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