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 AliDebug(1,"Start reconstructor ");
55 fParam = AliT0Parameters::Instance();
57 TString option = GetOption();
59 for (Int_t i=0; i<24; i++){
60 TGraph* gr = fParam ->GetAmpLEDRec(i);
61 if (gr) fAmpLEDrec.AddAtAndExpand(gr,i) ;
62 TGraph* gr1 = fParam ->GetAmpLED(i);
63 if (gr1) fAmpLED.AddAtAndExpand(gr1,i) ;
64 TGraph* gr2 = fParam ->GetQTC(i);
65 if (gr2) fQTC.AddAtAndExpand(gr2,i) ;
69 fdZonC = TMath::Abs(fParam->GetZPositionShift("T0/C/PMT1"));
70 fdZonA = TMath::Abs(fParam->GetZPositionShift("T0/A/PMT15"));
71 fCalib = new AliT0Calibrator();
74 //____________________________________________________________________
76 AliT0Reconstructor::AliT0Reconstructor(const AliT0Reconstructor &r):
89 // AliT0Reconstructor copy constructor
92 ((AliT0Reconstructor &) r).Copy(*this);
96 //_____________________________________________________________________________
97 AliT0Reconstructor &AliT0Reconstructor::operator=(const AliT0Reconstructor &r)
100 // Assignment operator
103 if (this != &r) ((AliT0Reconstructor &) r).Copy(*this);
108 //_____________________________________________________________________________
110 void AliT0Reconstructor::Reconstruct(TTree*digitsTree, TTree*clustersTree) const
113 // T0 digits reconstruction
114 // T0RecPoint writing
117 TArrayI * timeCFD = new TArrayI(24);
118 TArrayI * timeLED = new TArrayI(24);
119 TArrayI * chargeQT0 = new TArrayI(24);
120 TArrayI * chargeQT1 = new TArrayI(24);
123 Float_t channelWidth = fParam->GetChannelWidth() ;
124 Float_t meanVertex = fParam->GetMeanVertex();
126 AliDebug(1,Form("Start DIGITS reconstruction "));
129 TBranch *brDigits=digitsTree->GetBranch("T0");
130 AliT0digit *fDigits = new AliT0digit() ;
132 brDigits->SetAddress(&fDigits);
134 AliError(Form("EXEC Branch T0 digits not found"));
138 digitsTree->GetEvent(0);
139 digitsTree->GetEntry(0);
140 brDigits->GetEntry(0);
141 fDigits->GetTimeCFD(*timeCFD);
142 fDigits->GetTimeLED(*timeLED);
143 fDigits->GetQT0(*chargeQT0);
144 fDigits->GetQT1(*chargeQT1);
145 Int_t onlineMean = fDigits->MeanTime();
148 Float_t besttimeA=999999;
149 Float_t besttimeC=999999;
150 Int_t pmtBestA=99999;
151 Int_t pmtBestC=99999;
152 Float_t timeDiff=999999, meanTime=0;
154 // Int_t mv2MIP = fParam-> GetmV2Mip();
157 AliT0RecPoint* frecpoints= new AliT0RecPoint ();
158 clustersTree->Branch( "T0", "AliT0RecPoint" ,&frecpoints, 405,1);
160 Float_t time[24], adc[24];
161 for (Int_t ipmt=0; ipmt<24; ipmt++) {
162 if(timeCFD->At(ipmt)>0 ){
163 if(( chargeQT1->At(ipmt) - chargeQT0->At(ipmt))>0)
164 adc[ipmt] = chargeQT1->At(ipmt) - chargeQT0->At(ipmt);
168 time[ipmt] = fCalib-> WalkCorrection( ipmt, adc[ipmt], Float_t( timeCFD->At(ipmt))) ;
170 Double_t sl = Double_t(timeLED->At(ipmt) - timeCFD->At(ipmt));
171 // time[ipmt] = fCalib-> WalkCorrection( ipmt, Int_t(sl), timeCFD[ipmt],"cosmic" ) ;
172 AliDebug(10,Form(" ipmt %i QTC %i , time in chann %i (led-cfd) %i ",
173 ipmt, Int_t(adc[ipmt]) ,Int_t(time[ipmt]),Int_t( sl)));
174 Double_t ampMip =((TGraph*)fAmpLED.At(ipmt))->Eval(sl);
175 Double_t qtMip = ((TGraph*)fQTC.At(ipmt))->Eval(adc[ipmt]);
176 AliDebug(10,Form(" Amlitude in MIPS LED %f , QTC %f in channels %i\n ",ampMip,qtMip, adc[ipmt]));
178 frecpoints->SetTime(ipmt, Float_t(time[ipmt]) );
179 frecpoints->SetAmp(ipmt, Float_t( ampMip)); //for cosmic &pp beam
180 frecpoints->SetAmpLED(ipmt, Float_t(qtMip));
189 for (Int_t ipmt=0; ipmt<12; ipmt++){
190 if(time[ipmt] > 1 ) {
191 if(time[ipmt]<besttimeC){
192 besttimeC=time[ipmt]; //timeC
197 for ( Int_t ipmt=12; ipmt<24; ipmt++){
199 if(time[ipmt]<besttimeA) {
200 besttimeA=time[ipmt]; //timeA
204 if(besttimeA !=999999) frecpoints->SetTimeBestA(Int_t(besttimeA));
205 if( besttimeC != 999999 ) frecpoints->SetTimeBestC(Int_t(besttimeC));
206 AliDebug(10,Form(" besttimeA %f ch, besttimeC %f ch",besttimeA, besttimeC));
207 Float_t c = 0.0299792; // cm/ps
209 if(besttimeA !=999999 && besttimeC != 999999 ){
210 timeDiff = (besttimeC - besttimeA)*channelWidth;
211 meanTime = Float_t((besttimeA + besttimeC)/2);// * channelWidth);
212 // meanTime = (meanT0 - (besttimeA + besttimeC)/2) * channelWidth;
213 vertex = meanVertex - c*(timeDiff)/2.;// + (fdZonA - fdZonC)/2;
214 frecpoints->SetVertex(vertex);
215 frecpoints->SetMeanTime(Int_t(meanTime));
217 frecpoints->SetOnlineMean(Int_t(onlineMean));
218 AliDebug(10,Form(" timeDiff %f ps, meanTime %f ps, vertex %f cm online mean %i ps",timeDiff, meanTime,vertex, Int_t(onlineMean)));
222 clustersTree->Fill();
231 //_______________________________________________________________________
233 void AliT0Reconstructor::Reconstruct(AliRawReader* rawReader, TTree*recTree) const
236 // T0RecPoint writing
238 //Q->T-> coefficients !!!! should be measured!!!
239 Int_t allData[110][5];
241 Int_t timeCFD[24], timeLED[24], chargeQT0[24], chargeQT1[24];
242 TString option = GetOption();
243 AliDebug(1,Form("Option: %s\n", option.Data()));
246 for (Int_t i0=0; i0<105; i0++)
248 for (Int_t j0=0; j0<5; j0++) allData[i0][j0]=0;
251 Float_t besttimeA=9999999;
252 Float_t besttimeC=9999999;
253 Int_t pmtBestA=99999;
254 Int_t pmtBestC=99999;
255 Float_t timeDiff=9999999, meanTime=0;
257 // Int_t mv2MIP = fParam-> GetmV2Mip();
258 Float_t meanVertex = fParam->GetMeanVertex();
259 printf("meanVertex %f \n",meanVertex);
260 // UInt_t type =rawReader->GetType();
262 AliT0RecPoint* frecpoints= new AliT0RecPoint ();
264 recTree->Branch( "T0", "AliT0RecPoint" ,&frecpoints, 405,1);
267 AliDebug(10," before read data ");
268 AliT0RawReader myrawreader(rawReader);
269 if (!myrawreader.Next())
270 AliDebug(1,Form(" no raw data found!!"));
273 for (Int_t i=0; i<105; i++) {
274 for (Int_t iHit=0; iHit<5; iHit++)
276 allData[i][iHit] = myrawreader.GetData(i,iHit);
280 Float_t channelWidth = fParam->GetChannelWidth() ;
282 // Int_t meanT0 = fParam->GetMeanT0();
285 for (Int_t in=0; in<12; in++)
287 timeCFD[in] = allData[in+1][0] ;
288 timeCFD[in+12] = allData[in+56+1][0] ;
289 timeLED[in] = allData[in+12+1][0] ;
290 timeLED[in+12] = allData[in+68+1][0] ;
291 AliDebug(10, Form(" readed i %i cfdC %i cfdA %i ledC %i ledA%i ",
292 in, timeCFD[in],timeCFD[in+12],timeLED[in],
296 for (Int_t in=0; in<12; in++)
298 chargeQT0[in]=allData[2*in+25][0];
299 chargeQT1[in]=allData[2*in+26][0];
302 for (Int_t in=12; in<24; in++)
304 chargeQT0[in]=allData[2*in+57][0];
305 chargeQT1[in]=allData[2*in+58][0];
308 // } //cosmic with physics event
309 for (Int_t in=0; in<24; in++)
310 AliDebug(10, Form(" readed Raw %i %i %i %i %i",
311 in, timeLED[in],timeCFD[in],chargeQT0[in],chargeQT1[in]));
312 Int_t onlineMean = allData[49][0];
314 Float_t time[24], adc[24];
315 for (Int_t ipmt=0; ipmt<24; ipmt++) {
316 if(timeCFD[ipmt]>0 && timeLED[ipmt]>0){
319 if(( chargeQT1[ipmt] - chargeQT0[ipmt])>0)
320 adc[ipmt] = chargeQT1[ipmt] - chargeQT0[ipmt];
324 time[ipmt] = fCalib-> WalkCorrection( ipmt, adc[ipmt], timeCFD[ipmt],"cosmic" ) ;
326 Double_t sl = timeLED[ipmt] - timeCFD[ipmt];
327 // time[ipmt] = fCalib-> WalkCorrection( ipmt, Int_t(sl), timeCFD[ipmt],"cosmic" ) ;
328 AliDebug(10,Form(" ipmt %i QTC %i , time in chann %i (led-cfd) %i ",
329 ipmt, Int_t(adc[ipmt]) ,Int_t(time[ipmt]),Int_t( sl)));
330 Double_t ampMip =( (TGraph*)fAmpLED.At(ipmt))->Eval(sl);
331 Double_t qtMip = ((TGraph*)fQTC.At(ipmt))->Eval(adc[ipmt]);
332 AliDebug(10,Form(" Amlitude in MIPS LED %f ; QTC %f; in channels %i\n ",ampMip,qtMip, adc[ipmt]));
334 frecpoints->SetTime(ipmt, Float_t(time[ipmt]) );
335 frecpoints->SetAmp(ipmt, Float_t( ampMip)); //for cosmic &pp beam
336 frecpoints->SetAmpLED(ipmt, Float_t(qtMip));
345 for (Int_t ipmt=0; ipmt<12; ipmt++){
346 if(time[ipmt] > 1 ) {
347 if(time[ipmt]<besttimeC){
348 besttimeC=time[ipmt]; //timeC
353 for ( Int_t ipmt=12; ipmt<24; ipmt++){
355 if(time[ipmt]<besttimeA) {
356 besttimeA=time[ipmt]; //timeA
360 if(besttimeA !=9999999) frecpoints->SetTimeBestA(Int_t(besttimeA));
361 if( besttimeC != 9999999 ) frecpoints->SetTimeBestC(Int_t(besttimeC));
362 AliDebug(5,Form(" pmtA %i besttimeA %f ps, pmtC %i besttimeC %f ps",
363 pmtBestA,besttimeA, pmtBestC, besttimeC));
364 Float_t c = 0.0299792458; // cm/ps
365 Float_t vertex = 99999;
366 if(besttimeA <9999999 && besttimeC < 9999999 ){
367 timeDiff = ( besttimeC - besttimeA) *channelWidth;
368 meanTime = Float_t((besttimeA + besttimeC)/2.);
369 onlineMean = onlineMean ;
370 vertex = meanVertex - c*(timeDiff)/2.; //+ (fdZonA - fdZonC)/2;
371 frecpoints->SetVertex(vertex);
372 frecpoints->SetMeanTime(Int_t(meanTime));
373 frecpoints->SetOnlineMean(Int_t(onlineMean));
374 AliDebug(5,Form(" timeDiff %f ps, meanTime %f ps, vertex %f cm meanVertex %f online mean %i ",timeDiff, meanTime,vertex,meanVertex, onlineMean));
377 } // if (else )raw data
379 if(frecpoints) delete frecpoints;
383 //____________________________________________________________
385 void AliT0Reconstructor::FillESD(TTree */*digitsTree*/, TTree *clustersTree, AliESDEvent *pESD) const
388 /***************************************************
389 Resonstruct digits to vertex position
390 ****************************************************/
392 AliDebug(1,Form("Start FillESD T0"));
394 TTree *treeR = clustersTree;
396 AliT0RecPoint* frecpoints= new AliT0RecPoint ();
398 AliError("Reconstruct Fill ESD >> no recpoints found");
402 AliDebug(1,Form("Start FillESD T0"));
403 TBranch *brRec = treeR->GetBranch("T0");
405 brRec->SetAddress(&frecpoints);
407 AliError(Form("EXEC Branch T0 rec not found"));
412 Float_t amp[24], time[24];
413 Float_t zPosition = frecpoints -> GetVertex();
414 Float_t timeStart = frecpoints -> GetMeanTime() ;
415 for ( Int_t i=0; i<24; i++) {
416 time[i] = Float_t (frecpoints -> GetTime(i)); // ps to ns
417 amp[i] = frecpoints -> GetAmp(i);
419 pESD->SetT0zVertex(zPosition); //vertex Z position
420 pESD->SetT0(timeStart); // interaction time
421 pESD->SetT0time(time); // best TOF on each PMT
422 pESD->SetT0amplitude(amp); // number of particles(MIPs) on each PMT
424 AliDebug(1,Form(" Z position %f cm, T0 %f ps",zPosition , timeStart));
426 } // vertex in 3 sigma