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"
37 #include <Riostream.h>
39 ClassImp(AliT0Reconstructor)
41 AliT0Reconstructor:: AliT0Reconstructor(): AliReconstructor(),
53 fParam = AliT0Parameters::Instance();
56 for (Int_t i=0; i<24; i++){
57 TGraph* gr = fParam ->GetAmpLEDRec(i);
58 if (gr) fAmpLEDrec.AddAtAndExpand(gr,i) ;
59 TGraph* gr1 = fParam ->GetAmpLED(i);
60 if (gr1) fAmpLED.AddAtAndExpand(gr1,i) ;
61 TGraph* gr2 = fParam ->GetQTC(i);
62 if (gr2) fQTC.AddAtAndExpand(gr2,i) ;
66 // fdZonC = TMath::Abs(fParam->GetZPositionShift("T0/C/PMT1"));
67 //fdZonA = TMath::Abs(fParam->GetZPositionShift("T0/A/PMT15"));
70 fCalib = new AliT0Calibrator();
74 //_____________________________________________________________________________
75 void AliT0Reconstructor::Reconstruct(TTree*digitsTree, TTree*clustersTree) const
78 // T0 digits reconstruction
79 Int_t refAmp = GetRecoParam()->GetRefAmp();
81 TArrayI * timeCFD = new TArrayI(24);
82 TArrayI * timeLED = new TArrayI(24);
83 TArrayI * chargeQT0 = new TArrayI(24);
84 TArrayI * chargeQT1 = new TArrayI(24);
87 Float_t channelWidth = fParam->GetChannelWidth() ;
88 Float_t meanVertex = fParam->GetMeanVertex();
89 Float_t c = 0.0299792; // cm/ps
90 Double32_t vertex = 9999999;
91 Double32_t timeDiff=999999, meanTime=999999, timeclock=999999;
94 AliDebug(1,Form("Start DIGITS reconstruction "));
97 TBranch *brDigits=digitsTree->GetBranch("T0");
98 AliT0digit *fDigits = new AliT0digit() ;
100 brDigits->SetAddress(&fDigits);
102 AliError(Form("EXEC Branch T0 digits not found"));
106 digitsTree->GetEvent(0);
107 digitsTree->GetEntry(0);
108 brDigits->GetEntry(0);
109 fDigits->GetTimeCFD(*timeCFD);
110 fDigits->GetTimeLED(*timeLED);
111 fDigits->GetQT0(*chargeQT0);
112 fDigits->GetQT1(*chargeQT1);
113 Int_t onlineMean = fDigits->MeanTime();
116 for (Int_t i=0; i<5; i++) tr[i]=false;
118 Double32_t besttimeA=999999;
119 Double32_t besttimeC=999999;
120 Int_t pmtBestA=99999;
121 Int_t pmtBestC=99999;
123 AliT0RecPoint* frecpoints= new AliT0RecPoint ();
124 clustersTree->Branch( "T0", "AliT0RecPoint" ,&frecpoints, 405,1);
126 Float_t time[24], adc[24];
127 for (Int_t ipmt=0; ipmt<24; ipmt++) {
128 if(timeCFD->At(ipmt)>0 ){
129 if(( chargeQT1->At(ipmt) - chargeQT0->At(ipmt))>0)
130 adc[ipmt] = chargeQT1->At(ipmt) - chargeQT0->At(ipmt);
134 // time[ipmt] = fCalib-> WalkCorrection(refAmp, ipmt, adc[ipmt], timeCFD->At(ipmt)) ;
136 Double_t sl = Double_t(timeLED->At(ipmt) - timeCFD->At(ipmt));
137 time[ipmt] = fCalib-> WalkCorrection( refAmp,ipmt, Int_t(sl), timeCFD->At(ipmt) ) ;
138 AliDebug(10,Form(" ipmt %i QTC %i , time in chann %i (led-cfd) %i ",
139 ipmt, Int_t(adc[ipmt]) ,Int_t(time[ipmt]),Int_t( sl)));
141 Double_t ampMip =((TGraph*)fAmpLED.At(ipmt))->Eval(sl);
142 Double_t qtMip = ((TGraph*)fQTC.At(ipmt))->Eval(adc[ipmt]);
143 AliDebug(10,Form(" Amlitude in MIPS LED %f , QTC %f in channels %i\n ",ampMip,qtMip, adc[ipmt]));
145 frecpoints->SetTime(ipmt, Float_t(time[ipmt]) );
146 frecpoints->SetAmp(ipmt, Float_t( ampMip)); //for cosmic &pp beam
147 frecpoints->SetAmpLED(ipmt, Float_t(qtMip));
156 for (Int_t ipmt=0; ipmt<12; ipmt++){
157 if(time[ipmt] > 1 ) {
158 if(time[ipmt]<besttimeC){
159 besttimeC=time[ipmt]; //timeC
164 for ( Int_t ipmt=12; ipmt<24; ipmt++){
166 if(time[ipmt]<besttimeA) {
167 besttimeA=time[ipmt]; //timeA
171 if(besttimeA < 999999) {
172 frecpoints->SetTimeBestA(Int_t(besttimeA *channelWidth));
175 if( besttimeC < 999999 ) {
176 frecpoints->SetTimeBestC(Int_t(besttimeC *channelWidth));
179 AliDebug(10,Form(" besttimeA %f ch, besttimeC %f ch",besttimeA, besttimeC));
180 if(besttimeA <999999 && besttimeC < 999999 ){
181 // timeDiff = (besttimeC - besttimeA)*channelWidth;
182 timeDiff = (besttimeA - besttimeC)*channelWidth;
183 meanTime = (besttimeA + besttimeC)/2;// * channelWidth);
184 timeclock = meanTime *channelWidth ;
185 vertex = meanVertex - c*(timeDiff)/2.;// + (fdZonA - fdZonC)/2;
188 frecpoints->SetVertex(vertex);
189 frecpoints->SetMeanTime(meanTime);
190 frecpoints->SetT0clock(timeclock);
191 frecpoints->SetT0Trig(tr);
193 for (Int_t i=0; i<5; i++) {
194 printf(" T0 trigers %i ",tr[i]);
199 frecpoints->SetOnlineMean(Int_t(onlineMean));
200 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));
206 clustersTree->Fill();
215 //_______________________________________________________________________
217 void AliT0Reconstructor::Reconstruct(AliRawReader* rawReader, TTree*recTree) const
221 // reference amplitude and time ref. point from reco param
223 Int_t refAmp = GetRecoParam()->GetRefAmp();
224 Int_t refPoint = GetRecoParam()->GetRefPoint();
225 Float_t latencyL1 = GetRecoParam()->GetLatencyL1();
226 Float_t latencyL1A = GetRecoParam()->GetLatencyL1A();
227 Float_t latencyL1C = GetRecoParam()->GetLatencyL1C();
228 Float_t latencyHPTDC = GetRecoParam()->GetLatencyHPTDC();
229 AliDebug(10,Form(" LatencyL1 %f latencyL1A %f latencyL1C %f latencyHPTDC %f \n",latencyL1,latencyL1A,latencyL1C, latencyHPTDC));
230 Int_t allData[110][5];
232 Int_t timeCFD[24], timeLED[24], chargeQT0[24], chargeQT1[24];
233 Double32_t timeDiff=999999, meanTime=999999, timeclock=999999;
234 Float_t c = 29.9792458; // cm/ns
235 Double32_t vertex = 9999999;
237 // Float_t meanVertex = fParam->GetMeanVertex();
238 Float_t meanVertex = 0;
240 for (Int_t i0=0; i0<105; i0++)
242 for (Int_t j0=0; j0<5; j0++) allData[i0][j0]=0;
245 Double32_t besttimeA=9999999;
246 Double32_t besttimeC=9999999;
247 Int_t pmtBestA=99999;
248 Int_t pmtBestC=99999;
250 AliT0RecPoint* frecpoints= new AliT0RecPoint ();
252 recTree->Branch( "T0", "AliT0RecPoint" ,&frecpoints, 405,1);
254 AliDebug(10," before read data ");
255 AliT0RawReader myrawreader(rawReader);
257 UInt_t type =rawReader->GetType();
259 if (!myrawreader.Next())
260 AliDebug(1,Form(" no raw data found!!"));
263 if(type == 7) { //only physics
264 for (Int_t i=0; i<105; i++) {
265 for (Int_t iHit=0; iHit<5; iHit++)
267 allData[i][iHit] = myrawreader.GetData(i,iHit);
272 ref = allData[refPoint][0]-5000;
274 Float_t channelWidth = fParam->GetChannelWidth() ;
276 // Int_t meanT0 = fParam->GetMeanT0();
279 for (Int_t in=0; in<12; in++)
281 timeCFD[in] = allData[in+1][0] ;
282 timeCFD[in+12] = allData[in+56+1][0] ;
283 timeLED[in] = allData[in+12+1][0] ;
284 timeLED[in+12] = allData[in+68+1][0] ;
285 AliDebug(10, Form(" readed i %i cfdC %i cfdA %i ledC %i ledA%i ",
286 in, timeCFD[in],timeCFD[in+12],timeLED[in],
290 for (Int_t in=0; in<12; in++)
292 chargeQT0[in]=allData[2*in+25][0];
293 chargeQT1[in]=allData[2*in+26][0];
296 for (Int_t in=12; in<24; in++)
298 chargeQT0[in]=allData[2*in+57][0];
299 chargeQT1[in]=allData[2*in+58][0];
302 // } //cosmic with physics event
303 for (Int_t in=0; in<24; in++)
304 AliDebug(10, Form(" readed Raw %i %i %i %i %i",
305 in, timeLED[in],timeCFD[in],chargeQT0[in],chargeQT1[in]));
306 onlineMean = allData[49][0];
308 Double32_t time[24], adc[24];
309 for (Int_t ipmt=0; ipmt<24; ipmt++) {
310 if(timeCFD[ipmt]>0 && timeLED[ipmt]>0){
313 if(( chargeQT1[ipmt] - chargeQT0[ipmt])>0)
314 adc[ipmt] = chargeQT0[ipmt] - chargeQT1[ipmt];
319 // time[ipmt] = fCalib-> WalkCorrection(refAmp, ipmt, adc[ipmt], timeCFD[ipmt] ) ;
321 Double_t sl = timeLED[ipmt] - timeCFD[ipmt];
322 time[ipmt] = fCalib-> WalkCorrection( refAmp,ipmt, Int_t(sl), timeCFD[ipmt] ) ;
323 AliDebug(10,Form(" ipmt %i QTC %i , time in chann %i (led-cfd) %i ",
324 ipmt, Int_t(adc[ipmt]) ,Int_t(time[ipmt]),Int_t( sl)));
325 Double_t ampMip =( (TGraph*)fAmpLED.At(ipmt))->Eval(sl);
326 Double_t qtMip = ((TGraph*)fQTC.At(ipmt))->Eval(adc[ipmt]);
327 AliDebug(10,Form(" Amlitude in MIPS LED %f ; QTC %f; in channels %i\n ",ampMip,qtMip, adc[ipmt]));
329 frecpoints->SetTime(ipmt, Float_t(time[ipmt]) );
330 // frecpoints->SetTime(ipmt,Double32_t(timeCFD[ipmt]));
331 frecpoints->SetAmpLED(ipmt, Double32_t( qtMip)); //for cosmic &pp beam
332 frecpoints->SetAmp(ipmt, Double32_t(ampMip));
341 for (Int_t ipmt=0; ipmt<12; ipmt++){
342 if(time[ipmt] > 1 ) {
343 if(time[ipmt]<besttimeC){
344 besttimeC=time[ipmt]; //timeC
349 for ( Int_t ipmt=12; ipmt<24; ipmt++){
351 if(time[ipmt]<besttimeA) {
352 besttimeA=time[ipmt]; //timeA
356 if(besttimeA < 999999)
357 frecpoints->SetTimeBestA(0.001* besttimeA * channelWidth - latencyHPTDC + latencyL1A);
358 if( besttimeC < 999999 )
359 frecpoints->SetTimeBestC( 0.001 *besttimeC * channelWidth - latencyHPTDC + latencyL1C);
360 AliDebug(10,Form(" pmtA %i besttimeA %f ps, pmtC %i besttimeC %f ps",
361 pmtBestA,besttimeA, pmtBestC, besttimeC));
362 if(besttimeA <999999 && besttimeC < 999999 ){
363 timeDiff = ( besttimeA - besttimeC) *0.001 * channelWidth + latencyL1A - latencyL1C;
364 timeclock = 0.001*channelWidth * Float_t( besttimeA+besttimeC)/2. - latencyHPTDC + latencyL1;
365 meanTime = (besttimeA+besttimeC-2.*Float_t(ref))/2.;
366 vertex = meanVertex - c*(timeDiff)/2. ; //+ (fdZonA - fdZonC)/2;
369 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));
370 frecpoints->SetT0clock(timeclock);
371 frecpoints->SetVertex(vertex);
372 frecpoints->SetMeanTime(meanTime);
373 frecpoints->SetOnlineMean(Int_t(onlineMean));
377 Int_t trchan[5]= {50,51,52,55,56};
378 for (Int_t i=0; i<5; i++) tr[i]=false;
379 for (Int_t itr=0; itr<5; itr++) {
380 if(allData[trchan[itr]][0]>0) tr[itr]=true;
381 frecpoints->SetT0Trig(tr);
383 for (Int_t i=0; i<5; i++)
384 printf(" T0 trigers %i ",tr[i]);
388 } // if (else )raw data
390 if(frecpoints) delete frecpoints;
394 //____________________________________________________________
396 void AliT0Reconstructor::FillESD(TTree */*digitsTree*/, TTree *clustersTree, AliESDEvent *pESD) const
399 /***************************************************
400 Resonstruct digits to vertex position
401 ****************************************************/
403 AliDebug(1,Form("Start FillESD T0"));
405 Float_t c = 29.9792458; // cm/ns
406 Float_t currentVertex=0, shift=0;
408 const AliESDVertex* vertex = pESD->GetPrimaryVertex();
409 if (!vertex) vertex = pESD->GetPrimaryVertexSPD();
410 if (!vertex) vertex = pESD->GetPrimaryVertexTPC();
411 if (!vertex) vertex = pESD->GetVertex();
414 AliDebug(2, Form("Got %s (%s) from ESD: %f",
415 vertex->GetName(), vertex->GetTitle(), vertex->GetZ()));
416 currentVertex = vertex->GetZ();
418 ncont = vertex->GetNContributors();
419 // cout<<" spdver "<<spdver<<" ncont "<<ncont<<endl;
421 // hVertexSPD->Fill(spdver);
422 shift = currentVertex/c;
423 // cout<<" vertex shif "<<shift<<" vertex "<<spdver<<" IsFromVertexer3D "<<fverSPD->IsFromVertexer3D()<<endl;
426 TTree *treeR = clustersTree;
428 AliT0RecPoint* frecpoints= new AliT0RecPoint ();
430 AliError("Reconstruct Fill ESD >> no recpoints found");
434 AliDebug(1,Form("Start FillESD T0"));
435 TBranch *brRec = treeR->GetBranch("T0");
437 brRec->SetAddress(&frecpoints);
439 AliError(Form("EXEC Branch T0 rec not found"));
444 Double32_t amp[24], time[24];
445 Double32_t timeClock[3];
446 Double32_t zPosition = frecpoints -> GetVertex();
447 Double32_t timeStart = frecpoints -> GetMeanTime();
448 timeClock[0] = frecpoints -> GetT0clock() ;
449 timeClock[1] = frecpoints -> GetBestTimeA() + shift;
450 timeClock[2] = frecpoints -> GetBestTimeC() - shift;
451 for ( Int_t i=0; i<24; i++) {
452 time[i] = frecpoints -> GetTime(i); // ps to ns
453 amp[i] = frecpoints -> GetAmp(i);
455 Int_t trig= frecpoints ->GetT0Trig();
456 pESD->SetT0Trig(trig);
458 pESD->SetT0zVertex(zPosition); //vertex Z position
459 pESD->SetT0(timeStart); // interaction time
460 for(Int_t i=0; i<3; i++)
461 pESD->SetT0TOF(i,timeClock[i]); // interaction time (ns)
462 pESD->SetT0time(time); // best TOF on each PMT
463 pESD->SetT0amplitude(amp); // number of particles(MIPs) on each PMT
465 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));
468 } // vertex in 3 sigma