1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 /*********************************************************************
18 * T0 reconstruction and filling ESD
19 * - reconstruct mean time (interation time)
22 ********************************************************************/
24 #include <AliESDEvent.h>
26 #include "AliT0RecPoint.h"
27 #include "AliRawReader.h"
28 #include "AliT0RawReader.h"
29 #include "AliT0digit.h"
30 #include "AliT0Reconstructor.h"
31 #include "AliT0Parameters.h"
32 #include "AliT0Calibrator.h"
33 #include "AliESDfriend.h"
38 #include <Riostream.h>
40 ClassImp(AliT0Reconstructor)
42 AliT0Reconstructor:: AliT0Reconstructor(): AliReconstructor(),
59 fParam = AliT0Parameters::Instance();
62 for (Int_t i=0; i<24; i++){
63 TGraph* gr = fParam ->GetAmpLEDRec(i);
64 if (gr) fAmpLEDrec.AddAtAndExpand(gr,i) ;
65 TGraph* gr1 = fParam ->GetAmpLED(i);
66 if (gr1) fAmpLED.AddAtAndExpand(gr1,i) ;
67 TGraph* gr2 = fParam ->GetQTC(i);
68 if (gr2) fQTC.AddAtAndExpand(gr2,i) ;
71 fLatencyL1 = fParam->GetLatencyL1();
72 fLatencyL1A = fParam->GetLatencyL1A();
73 fLatencyL1C = fParam->GetLatencyL1C();
74 fLatencyHPTDC = fParam->GetLatencyHPTDC();
75 AliDebug(10,Form(" LatencyL1 %f latencyL1A %f latencyL1C %f latencyHPTDC %f \n",fLatencyL1, fLatencyL1A, fLatencyL1C, fLatencyHPTDC));
77 // fdZonC = TMath::Abs(fParam->GetZPositionShift("T0/C/PMT1"));
78 //fdZonA = TMath::Abs(fParam->GetZPositionShift("T0/A/PMT15"));
81 fCalib = new AliT0Calibrator();
85 //_____________________________________________________________________________
86 void AliT0Reconstructor::Reconstruct(TTree*digitsTree, TTree*clustersTree) const
89 // T0 digits reconstruction
90 Int_t refAmp = GetRecoParam()->GetRefAmp();
92 TArrayI * timeCFD = new TArrayI(24);
93 TArrayI * timeLED = new TArrayI(24);
94 TArrayI * chargeQT0 = new TArrayI(24);
95 TArrayI * chargeQT1 = new TArrayI(24);
98 Float_t channelWidth = fParam->GetChannelWidth() ;
99 Float_t meanVertex = fParam->GetMeanVertex();
100 Float_t c = 0.0299792; // cm/ps
101 Double32_t vertex = 9999999;
102 Double32_t timeDiff=999999, meanTime=999999, timeclock=999999;
105 AliDebug(1,Form("Start DIGITS reconstruction "));
108 TBranch *brDigits=digitsTree->GetBranch("T0");
109 AliT0digit *fDigits = new AliT0digit() ;
111 brDigits->SetAddress(&fDigits);
113 AliError(Form("EXEC Branch T0 digits not found"));
117 digitsTree->GetEvent(0);
118 digitsTree->GetEntry(0);
119 brDigits->GetEntry(0);
120 fDigits->GetTimeCFD(*timeCFD);
121 fDigits->GetTimeLED(*timeLED);
122 fDigits->GetQT0(*chargeQT0);
123 fDigits->GetQT1(*chargeQT1);
124 Int_t onlineMean = fDigits->MeanTime();
127 for (Int_t i=0; i<5; i++) tr[i]=false;
129 Double32_t besttimeA=999999;
130 Double32_t besttimeC=999999;
131 Int_t pmtBestA=99999;
132 Int_t pmtBestC=99999;
134 AliT0RecPoint* frecpoints= new AliT0RecPoint ();
135 clustersTree->Branch( "T0", "AliT0RecPoint" ,&frecpoints, 405,1);
137 Float_t time[24], adc[24];
138 for (Int_t ipmt=0; ipmt<24; ipmt++) {
139 if(timeCFD->At(ipmt)>0 ){
140 if(( chargeQT1->At(ipmt) - chargeQT0->At(ipmt))>0)
141 adc[ipmt] = chargeQT1->At(ipmt) - chargeQT0->At(ipmt);
145 // time[ipmt] = fCalib-> WalkCorrection(refAmp, ipmt, adc[ipmt], timeCFD->At(ipmt)) ;
147 Double_t sl = Double_t(timeLED->At(ipmt) - timeCFD->At(ipmt));
148 time[ipmt] = fCalib-> WalkCorrection( refAmp,ipmt, Int_t(sl), timeCFD->At(ipmt) ) ;
149 AliDebug(10,Form(" ipmt %i QTC %i , time in chann %i (led-cfd) %i ",
150 ipmt, Int_t(adc[ipmt]) ,Int_t(time[ipmt]),Int_t( sl)));
152 Double_t ampMip =((TGraph*)fAmpLED.At(ipmt))->Eval(sl);
153 Double_t qtMip = ((TGraph*)fQTC.At(ipmt))->Eval(adc[ipmt]);
154 AliDebug(10,Form(" Amlitude in MIPS LED %f , QTC %f in channels %i\n ",ampMip,qtMip, adc[ipmt]));
156 frecpoints->SetTime(ipmt, Float_t(time[ipmt]) );
157 frecpoints->SetAmp(ipmt, Float_t( ampMip)); //for cosmic &pp beam
158 frecpoints->SetAmpLED(ipmt, Float_t(qtMip));
167 for (Int_t ipmt=0; ipmt<12; ipmt++){
168 if(time[ipmt] > 1 ) {
169 if(time[ipmt]<besttimeC){
170 besttimeC=time[ipmt]; //timeC
175 for ( Int_t ipmt=12; ipmt<24; ipmt++){
177 if(time[ipmt]<besttimeA) {
178 besttimeA=time[ipmt]; //timeA
182 if(besttimeA < 999999) {
183 frecpoints->SetTimeBestA(Int_t(besttimeA *channelWidth));
186 if( besttimeC < 999999 ) {
187 frecpoints->SetTimeBestC(Int_t(besttimeC *channelWidth));
190 AliDebug(10,Form(" besttimeA %f ch, besttimeC %f ch",besttimeA, besttimeC));
191 if(besttimeA <999999 && besttimeC < 999999 ){
192 // timeDiff = (besttimeC - besttimeA)*channelWidth;
193 timeDiff = (besttimeA - besttimeC)*channelWidth;
194 meanTime = (besttimeA + besttimeC)/2;// * channelWidth);
195 timeclock = meanTime *channelWidth ;
196 vertex = meanVertex - c*(timeDiff)/2.;// + (fdZonA - fdZonC)/2;
199 frecpoints->SetVertex(vertex);
200 frecpoints->SetMeanTime(meanTime);
201 frecpoints->SetT0clock(timeclock);
202 frecpoints->SetT0Trig(tr);
204 for (Int_t i=0; i<5; i++) {
205 printf(" T0 trigers %i ",tr[i]);
210 frecpoints->SetOnlineMean(Int_t(onlineMean));
211 AliDebug(10,Form(" timeDiff %i #channel, meanTime %i #channel, vertex %f cm online mean %i timeclock %i ps",timeDiff, meanTime,vertex, Int_t(onlineMean), timeclock));
217 clustersTree->Fill();
226 //_______________________________________________________________________
228 void AliT0Reconstructor::Reconstruct(AliRawReader* rawReader, TTree*recTree) const
232 // reference amplitude and time ref. point from reco param
234 Int_t refAmp = GetRecoParam()->GetRefAmp();
235 Int_t refPoint = GetRecoParam()->GetRefPoint();
237 Int_t allData[110][5];
239 Int_t timeCFD[24], timeLED[24], chargeQT0[24], chargeQT1[24];
240 Double32_t timeDiff=999999, meanTime=999999, timeclock=999999;
241 Float_t c = 29.9792458; // cm/ns
242 Double32_t vertex = 9999999;
244 // Float_t meanVertex = fParam->GetMeanVertex();
245 Float_t meanVertex = 0;
247 cout<<" @@@@ Latency "<<fLatencyL1<<endl;
248 for (Int_t i0=0; i0<105; i0++)
250 for (Int_t j0=0; j0<5; j0++) allData[i0][j0]=0;
253 Double32_t besttimeA=9999999;
254 Double32_t besttimeC=9999999;
255 Int_t pmtBestA=99999;
256 Int_t pmtBestC=99999;
258 AliT0RecPoint* frecpoints= new AliT0RecPoint ();
260 recTree->Branch( "T0", "AliT0RecPoint" ,&frecpoints, 405,1);
262 AliDebug(10," before read data ");
263 AliT0RawReader myrawreader(rawReader);
265 UInt_t type =rawReader->GetType();
267 if (!myrawreader.Next())
268 AliDebug(1,Form(" no raw data found!!"));
271 if(type == 7) { //only physics
272 for (Int_t i=0; i<105; i++) {
273 for (Int_t iHit=0; iHit<5; iHit++)
275 allData[i][iHit] = myrawreader.GetData(i,iHit);
280 ref = allData[refPoint][0]-5000;
282 Float_t channelWidth = fParam->GetChannelWidth() ;
284 // Int_t meanT0 = fParam->GetMeanT0();
287 for (Int_t in=0; in<12; in++)
289 timeCFD[in] = allData[in+1][0] ;
290 timeCFD[in+12] = allData[in+56+1][0] ;
291 timeLED[in] = allData[in+12+1][0] ;
292 timeLED[in+12] = allData[in+68+1][0] ;
293 AliDebug(10, Form(" readed i %i cfdC %i cfdA %i ledC %i ledA%i ",
294 in, timeCFD[in],timeCFD[in+12],timeLED[in],
298 for (Int_t in=0; in<12; in++)
300 chargeQT0[in]=allData[2*in+25][0];
301 chargeQT1[in]=allData[2*in+26][0];
304 for (Int_t in=12; in<24; in++)
306 chargeQT0[in]=allData[2*in+57][0];
307 chargeQT1[in]=allData[2*in+58][0];
310 // } //cosmic with physics event
311 for (Int_t in=0; in<24; in++)
312 AliDebug(10, Form(" readed Raw %i %i %i %i %i",
313 in, timeLED[in],timeCFD[in],chargeQT0[in],chargeQT1[in]));
314 onlineMean = allData[49][0];
316 Double32_t time[24], adc[24];
317 for (Int_t ipmt=0; ipmt<24; ipmt++) {
318 if(timeCFD[ipmt]>0 && timeLED[ipmt]>0){
321 if(( chargeQT1[ipmt] - chargeQT0[ipmt])>0)
322 adc[ipmt] = chargeQT0[ipmt] - chargeQT1[ipmt];
327 // time[ipmt] = fCalib-> WalkCorrection(refAmp, ipmt, adc[ipmt], timeCFD[ipmt] ) ;
329 Double_t sl = timeLED[ipmt] - timeCFD[ipmt];
330 time[ipmt] = fCalib-> WalkCorrection( refAmp,ipmt, Int_t(sl), timeCFD[ipmt] ) ;
331 AliDebug(10,Form(" ipmt %i QTC %i , time in chann %i (led-cfd) %i ",
332 ipmt, Int_t(adc[ipmt]) ,Int_t(time[ipmt]),Int_t( sl)));
333 Double_t ampMip =( (TGraph*)fAmpLED.At(ipmt))->Eval(sl);
334 Double_t qtMip = ((TGraph*)fQTC.At(ipmt))->Eval(adc[ipmt]);
335 AliDebug(10,Form(" Amlitude in MIPS LED %f ; QTC %f; in channels %i\n ",ampMip,qtMip, adc[ipmt]));
337 frecpoints->SetTime(ipmt, Float_t(time[ipmt]) );
338 // frecpoints->SetTime(ipmt,Double32_t(timeCFD[ipmt]));
339 frecpoints->SetAmpLED(ipmt, Double32_t( qtMip)); //for cosmic &pp beam
340 frecpoints->SetAmp(ipmt, Double32_t(ampMip));
349 for (Int_t ipmt=0; ipmt<12; ipmt++){
350 if(time[ipmt] > 1 ) {
351 if(time[ipmt]<besttimeC){
352 besttimeC=time[ipmt]; //timeC
357 for ( Int_t ipmt=12; ipmt<24; ipmt++){
359 if(time[ipmt]<besttimeA) {
360 besttimeA=time[ipmt]; //timeA
364 if(besttimeA < 999999)
365 frecpoints->SetTimeBestA(0.001* besttimeA * channelWidth - fLatencyHPTDC + fLatencyL1A);
366 if( besttimeC < 999999 )
367 frecpoints->SetTimeBestC( 0.001 *besttimeC * channelWidth - fLatencyHPTDC + fLatencyL1C);
368 AliDebug(10,Form(" pmtA %i besttimeA %f ps, pmtC %i besttimeC %f ps",
369 pmtBestA,besttimeA, pmtBestC, besttimeC));
370 if(besttimeA <999999 && besttimeC < 999999 ){
371 timeDiff = ( besttimeA - besttimeC) *0.001 * channelWidth + fLatencyL1A - fLatencyL1C;
372 timeclock = 0.001*channelWidth * Float_t( besttimeA+besttimeC)/2. - fLatencyHPTDC + fLatencyL1;
373 meanTime = (besttimeA+besttimeC-2.*Float_t(ref))/2.;
374 vertex = meanVertex - c*(timeDiff)/2. ; //+ (fdZonA - fdZonC)/2;
377 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));
378 frecpoints->SetT0clock(timeclock);
379 frecpoints->SetVertex(vertex);
380 frecpoints->SetMeanTime(meanTime);
381 frecpoints->SetOnlineMean(Int_t(onlineMean));
385 Int_t trchan[5]= {50,51,52,55,56};
386 for (Int_t i=0; i<5; i++) tr[i]=false;
387 for (Int_t itr=0; itr<5; itr++) {
388 if(allData[trchan[itr]][0]>0) tr[itr]=true;
389 frecpoints->SetT0Trig(tr);
392 } // if (else )raw data
394 if(frecpoints) delete frecpoints;
398 //____________________________________________________________
400 void AliT0Reconstructor::FillESD(TTree */*digitsTree*/, TTree *clustersTree, AliESDEvent *pESD) const
403 /***************************************************
404 Resonstruct digits to vertex position
405 ****************************************************/
407 AliDebug(1,Form("Start FillESD T0"));
408 Float_t channelWidth = fParam->GetChannelWidth() ;
409 Float_t c = 29.9792458; // cm/ns
410 Float_t currentVertex=0, shift=0;
412 const AliESDVertex* vertex = pESD->GetPrimaryVertex();
413 if (!vertex) vertex = pESD->GetPrimaryVertexSPD();
414 if (!vertex) vertex = pESD->GetPrimaryVertexTPC();
415 if (!vertex) vertex = pESD->GetVertex();
418 AliDebug(2, Form("Got %s (%s) from ESD: %f",
419 vertex->GetName(), vertex->GetTitle(), vertex->GetZ()));
420 currentVertex = vertex->GetZ();
422 ncont = vertex->GetNContributors();
423 // cout<<" spdver "<<spdver<<" ncont "<<ncont<<endl;
425 shift = currentVertex/c;
426 // cout<<" vertex shif "<<shift<<" vertex "<<spdver<<" IsFromVertexer3D "<<fverSPD->IsFromVertexer3D()<<endl;
429 TTree *treeR = clustersTree;
431 AliT0RecPoint* frecpoints= new AliT0RecPoint ();
433 AliError("Reconstruct Fill ESD >> no recpoints found");
437 AliDebug(1,Form("Start FillESD T0"));
438 TBranch *brRec = treeR->GetBranch("T0");
440 brRec->SetAddress(&frecpoints);
442 AliError(Form("EXEC Branch T0 rec not found"));
447 Double32_t amp[24], time[24], ampQTC[24], timecorr[24];
448 Double32_t timeClock[3];
449 Double32_t zPosition = frecpoints -> GetVertex();
450 Double32_t timeStart = frecpoints -> GetMeanTime();
451 timeClock[0] = frecpoints -> GetT0clock() ;
452 timeClock[1] = frecpoints -> GetBestTimeA() + shift;
453 timeClock[2] = frecpoints -> GetBestTimeC() - shift;
454 for ( Int_t i=0; i<24; i++) {
455 time[i] = frecpoints -> GetTime(i); // ps to ns
456 amp[i] = frecpoints -> GetAmp(i);
457 ampQTC[i] = frecpoints -> AmpLED(i);
459 Int_t trig= frecpoints ->GetT0Trig();
460 pESD->SetT0Trig(trig);
462 pESD->SetT0zVertex(zPosition); //vertex Z position
463 pESD->SetT0(timeStart); // interaction time
464 for(Int_t i=0; i<3; i++)
465 pESD->SetT0TOF(i,timeClock[i]); // interaction time (ns)
466 pESD->SetT0time(time); // best TOF on each PMT
467 pESD->SetT0amplitude(amp); // number of particles(MIPs) on each PMT
469 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));
472 AliESDfriend *fr = (AliESDfriend*)pESD->FindListObject("AliESDfriend");
474 AliDebug(1, Form("Writing TZERO friend data to ESD tree"));
477 for ( Int_t i=0; i<24; i++) {
478 if(i<12) timecorr[i]=time[i]-shift*channelWidth;
479 if(i>11) timecorr[i]=time[i]-shift*channelWidth;
480 fr->SetT0timeCorr(timecorr) ;
482 fr->SetT0ampLEDminCFD(amp);
483 fr->SetT0ampQTC(ampQTC);
490 } // vertex in 3 sigma