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"
39 ClassImp(AliT0Reconstructor)
41 AliT0Reconstructor:: AliT0Reconstructor(): AliReconstructor(),
51 AliDebug(1,"Start reconstructor ");
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) ;
61 fdZonC = TMath::Abs(fParam->GetZPositionShift("T0/C/PMT1"));
62 fdZonA = TMath::Abs(fParam->GetZPositionShift("T0/A/PMT15"));
63 fCalib = new AliT0Calibrator();
65 //____________________________________________________________________
67 AliT0Reconstructor::AliT0Reconstructor(const AliT0Reconstructor &r):
78 // AliT0Reconstructor copy constructor
81 ((AliT0Reconstructor &) r).Copy(*this);
85 //_____________________________________________________________________________
86 AliT0Reconstructor &AliT0Reconstructor::operator=(const AliT0Reconstructor &r)
89 // Assignment operator
92 if (this != &r) ((AliT0Reconstructor &) r).Copy(*this);
97 //_____________________________________________________________________________
99 void AliT0Reconstructor::Reconstruct(TTree*digitsTree, TTree*clustersTree) const
102 // T0 digits reconstruction
103 // T0RecPoint writing
106 TArrayI * timeCFD = new TArrayI(24);
107 TArrayI * timeLED = new TArrayI(24);
108 TArrayI * chargeQT0 = new TArrayI(24);
109 TArrayI * chargeQT1 = new TArrayI(24);
112 // Int_t mV2Mip = param->GetmV2Mip();
113 //mV2Mip = param->GetmV2Mip();
114 Float_t channelWidth = fParam->GetChannelWidth() ;
115 Int_t meanT0 = fParam->GetMeanT0();
117 AliDebug(1,Form("Start DIGITS reconstruction "));
120 TBranch *brDigits=digitsTree->GetBranch("T0");
121 AliT0digit *fDigits = new AliT0digit() ;
123 brDigits->SetAddress(&fDigits);
125 AliError(Form("EXEC Branch T0 digits not found"));
129 digitsTree->GetEvent(0);
130 digitsTree->GetEntry(0);
131 brDigits->GetEntry(0);
132 fDigits->GetTimeCFD(*timeCFD);
133 fDigits->GetTimeLED(*timeLED);
134 fDigits->GetQT0(*chargeQT0);
135 fDigits->GetQT1(*chargeQT1);
138 Float_t besttimeA=999999;
139 Float_t besttimeC=999999;
140 Int_t pmtBestA=99999;
141 Int_t pmtBestC=99999;
142 Float_t timeDiff=999999, meanTime=0;
145 AliT0RecPoint* frecpoints= new AliT0RecPoint ();
146 clustersTree->Branch( "T0", "AliT0RecPoint" ,&frecpoints, 405,1);
148 Float_t time[24], adc[24];
149 for (Int_t ipmt=0; ipmt<24; ipmt++) {
150 if(timeCFD->At(ipmt)>0 ){
151 Double_t qt0 = Double_t(chargeQT0->At(ipmt));
152 Double_t qt1 = Double_t(chargeQT1->At(ipmt));
153 if((qt1-qt0)>0) adc[ipmt] = TMath::Exp( Double_t (channelWidth*(qt1-qt0)/1000));
154 time[ipmt] = fCalib-> WalkCorrection( ipmt, Int_t(qt1) , timeCFD->At(ipmt), "pdc" ) ;
157 Double_t sl = (timeLED->At(ipmt) - time[ipmt])*channelWidth;
158 Double_t qt=((TGraph*)fAmpLEDrec.At(ipmt))->Eval(sl/1000.);
159 frecpoints->SetTime(ipmt,time[ipmt]);
160 frecpoints->SetAmp(ipmt,adc[ipmt]);
161 frecpoints->SetAmpLED(ipmt,qt);
169 for (Int_t ipmt=0; ipmt<12; ipmt++){
170 if(time[ipmt] > 1 ) {
171 if(time[ipmt]<besttimeC){
172 besttimeC=time[ipmt]; //timeC
177 for ( Int_t ipmt=12; ipmt<24; ipmt++){
179 if(time[ipmt]<besttimeA) {
180 besttimeA=time[ipmt]; //timeA
184 if(besttimeA !=999999) frecpoints->SetTimeBestA(Int_t(besttimeA));
185 if( besttimeC != 999999 ) frecpoints->SetTimeBestC(Int_t(besttimeC));
186 AliDebug(1,Form(" besttimeA %f ps, besttimeC %f ps",besttimeA, besttimeC));
187 Float_t c = 0.0299792; // cm/ps
189 if(besttimeA !=999999 && besttimeC != 999999 ){
190 timeDiff =(besttimeC - besttimeA)*channelWidth;
191 meanTime = (meanT0 - (besttimeA + besttimeC)/2) * channelWidth;
192 vertex = c*(timeDiff)/2. + (fdZonA - fdZonC)/2; //-(lenr-lenl))/2;
193 AliDebug(1,Form(" timeDiff %f ps, meanTime %f ps, vertex %f cm",timeDiff, meanTime,vertex ));
194 frecpoints->SetVertex(vertex);
195 frecpoints->SetMeanTime(Int_t(meanTime));
198 //time in each channel as time[ipmt]-MeanTimeinThisChannel(with vertex=0)
199 for (Int_t ipmt=0; ipmt<24; ipmt++) {
201 // time[ipmt] = (time[ipmt] - fTime0vertex[ipmt])*channelWidth;
202 time[ipmt] = time[ipmt] * channelWidth;
203 frecpoints->SetTime(ipmt,time[ipmt]);
206 clustersTree->Fill();
215 //_______________________________________________________________________
217 void AliT0Reconstructor::Reconstruct(AliRawReader* rawReader, TTree*recTree) const
220 // T0RecPoint writing
222 //Q->T-> coefficients !!!! should be measured!!!
223 Int_t allData[110][5];
225 Int_t timeCFD[24], timeLED[24], chargeQT0[24], chargeQT1[24];
226 TString option = GetOption();
227 AliDebug(10,Form("Option: %s\n", option.Data()));
229 for (Int_t i0=0; i0<105; i0++)
231 for (Int_t j0=0; j0<5; j0++) allData[i0][j0]=0;
234 Int_t besttimeA=9999999;
235 Int_t besttimeC=9999999;
236 Int_t pmtBestA=99999;
237 Int_t pmtBestC=99999;
238 Int_t timeDiff=9999999, meanTime=0;
241 AliT0RecPoint* frecpoints= new AliT0RecPoint ();
243 recTree->Branch( "T0", "AliT0RecPoint" ,&frecpoints, 405,1);
246 AliDebug(10," before read data ");
247 AliT0RawReader myrawreader(rawReader);
248 if (!myrawreader.Next())
249 AliDebug(1,Form(" no raw data found!!"));
252 for (Int_t i=0; i<105; i++) {
253 for (Int_t iHit=0; iHit<5; iHit++)
255 allData[i][iHit] = myrawreader.GetData(i,iHit);
259 Float_t channelWidth = fParam->GetChannelWidth() ;
261 Int_t meanT0 = fParam->GetMeanT0();
263 for (Int_t in=0; in<24; in++)
266 timeLED[in] = allData[in+1][0] ;
267 timeCFD[in] = allData[in+25][0] ;
268 chargeQT1[in] = allData[in+57][0] ;
269 chargeQT0[in] = allData[in+80][0] ;
273 if(option == "cosmic") {
274 for (Int_t in=0; in<12; in++)
276 timeCFD[in] = allData[in+1][0] ;
277 timeCFD[in+12] = allData[in+56+1][0] ;
278 timeLED[in] = allData[in+12+1][0] ;
279 timeLED[in+12] = allData[in+68+1][0] ;
282 for (Int_t in=0; in<24; in=in+2)
285 chargeQT1[cc]=allData[in+25][0];
286 chargeQT0[cc]=allData[in+26][0];
288 for (Int_t in=24; in<48; in=in+2)
291 chargeQT1[cc]=allData[in+57][0];
292 chargeQT0[cc]=allData[in+58][0];
296 for (Int_t in=0; in<24; in++)
297 AliDebug(10, Form(" readed Raw %i %i %i %i %i", in, timeLED[in],timeCFD[in],chargeQT0[in],chargeQT1[in]));
300 Int_t time[24], adc[24];
301 for (Int_t ipmt=0; ipmt<24; ipmt++) {
302 if(timeCFD[ipmt]>0 && timeLED[ipmt]>0){
305 Double_t qt0 = Double_t(chargeQT0[ipmt]);
306 Double_t qt1 = Double_t(chargeQT1[ipmt]);
307 if((qt1-qt0)>0) adc[ipmt] = Int_t(TMath::Exp( Double_t (channelWidth*(qt1-qt0)/1000.)));
308 time[ipmt] = fCalib-> WalkCorrection( ipmt,Int_t(qt1) , timeCFD[ipmt], "pdc" ) ;
309 Double_t sl = (timeLED[ipmt] - time[ipmt])*channelWidth;
310 if(fAmpLEDrec.At(ipmt))
311 qt=((TGraph*)fAmpLEDrec.At(ipmt))->Eval(sl/1000.);
312 frecpoints->SetTime(ipmt,time[ipmt]);
313 frecpoints->SetAmp(ipmt,adc[ipmt]);
314 frecpoints->SetAmpLED(ipmt,qt);
315 AliDebug(10,Form(" QTC %i mv, time in chann %i ",adc[ipmt] ,time[ipmt]));
317 if(option == "cosmic") {
318 // if(ipmt == 15) continue; //skip crashed PMT
319 if(( chargeQT1[ipmt] - chargeQT0[ipmt])>0)
320 adc[ipmt] = chargeQT1[ipmt] - chargeQT0[ipmt];
323 // time[ipmt] = fCalib-> WalkCorrection( ipmt, adc[ipmt], timeCFD[ipmt],"cosmic" ) ;
324 // time[ipmt] = timeCFD[ipmt] ;
325 Double_t sl = timeLED[ipmt] - timeCFD[ipmt];
326 time[ipmt] = fCalib-> WalkCorrection( ipmt, Int_t(sl), timeCFD[ipmt],"cosmic" ) ;
327 // if(fAmpLEDrec.At(ipmt))
328 // qt=((TGraph*)fAmpLEDrec.At(ipmt))->Eval(sl);
329 time[ipmt] = time[ipmt] - allData[0][0] + 5000;
330 AliDebug(10,Form(" ipmt %i QTC %i , time in chann %i (led-cfd) %i ",
331 ipmt, Int_t(adc[ipmt]) ,Int_t(time[ipmt]),Int_t( sl)));
332 frecpoints->SetTime(ipmt, Float_t(time[ipmt]) );
333 frecpoints->SetAmp(ipmt, Float_t(adc[ipmt]));
334 frecpoints->SetAmpLED(ipmt, Float_t(qt));
344 for (Int_t ipmt=0; ipmt<12; ipmt++){
345 if(time[ipmt] > 1 ) {
346 if(time[ipmt]<besttimeC){
347 besttimeC=time[ipmt]; //timeC
352 for ( Int_t ipmt=12; ipmt<24; ipmt++){
354 if(time[ipmt]<besttimeA) {
355 besttimeA=time[ipmt]; //timeA
359 if(besttimeA !=9999999) frecpoints->SetTimeBestA(Int_t(besttimeA));
360 if( besttimeC != 9999999 ) frecpoints->SetTimeBestC(Int_t(besttimeC));
361 AliDebug(1,Form(" besttimeA %i ps, besttimeC %i ps",besttimeA, besttimeC));
362 Float_t c = 0.0299792; // cm/ps
363 Float_t vertex = 99999;
364 if(besttimeA <9999999 && besttimeC < 9999999 ){
365 timeDiff =Int_t (( besttimeC - besttimeA) *channelWidth);
367 meanTime = Int_t((meanT0 - (besttimeA + besttimeC)/2) * channelWidth);
368 if(option == "cosmic") meanTime = (besttimeA + besttimeC)/2;
369 vertex = c*(Float_t(timeDiff))/2.+ (fdZonA - fdZonC)/2;
370 AliDebug(1,Form(" timeDiff %i ps, meanTime %i ps, vertex %f cm",timeDiff, meanTime,vertex ));
371 frecpoints->SetVertex(vertex);
372 frecpoints->SetMeanTime(Int_t(meanTime));
375 } // if (else )raw data
377 if(frecpoints) delete frecpoints;
379 //____________________________________________________________
381 void AliT0Reconstructor::FillESD(TTree */*digitsTree*/, TTree *clustersTree, AliESDEvent *pESD) const
384 /***************************************************
385 Resonstruct digits to vertex position
386 ****************************************************/
388 AliDebug(1,Form("Start FillESD T0"));
390 TTree *treeR = clustersTree;
392 AliT0RecPoint* frecpoints= new AliT0RecPoint ();
394 AliError("Reconstruct Fill ESD >> no recpoints found");
398 AliDebug(1,Form("Start FillESD T0"));
399 TBranch *brRec = treeR->GetBranch("T0");
401 brRec->SetAddress(&frecpoints);
403 AliError(Form("EXEC Branch T0 rec not found"));
408 Float_t amp[24], time[24];
409 Float_t zPosition = frecpoints -> GetVertex();
410 Float_t timeStart = frecpoints -> GetMeanTime() ;
411 for ( Int_t i=0; i<24; i++) {
412 time[i] = Float_t (frecpoints -> GetTime(i)); // ps to ns
413 amp[i] = frecpoints -> GetAmp(i);
415 pESD->SetT0zVertex(zPosition); //vertex Z position
416 pESD->SetT0(timeStart); // interaction time
417 pESD->SetT0time(time); // best TOF on each PMT
418 pESD->SetT0amplitude(amp); // number of particles(MIPs) on each PMT
420 AliDebug(1,Form(" Z position %f cm, T0 %f ps",zPosition , timeStart));
422 } // vertex in 3 sigma