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 **************************************************************************/
18 #include <Riostream.h>
20 #include <TDirectory.h>
22 #include "AliRunLoader.h"
23 #include <AliESDEvent.h>
25 #include "AliT0Loader.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 "AliCDBLocal.h"
34 #include "AliCDBStorage.h"
35 #include "AliCDBManager.h"
36 #include "AliCDBEntry.h"
41 //#include <TGeoManager.h>
42 //#include <TClonesArray.h>
43 //#include <TString.h>
44 //#include <TGeoPNEntry.h>
45 //#include <TGeoPhysicalNode.h>
46 //#include <TGeoHMatrix.h>
48 ClassImp(AliT0Reconstructor)
50 AliT0Reconstructor:: AliT0Reconstructor(): AliReconstructor(),
57 AliDebug(1,"Start reconstructor ");
59 fParam = AliT0Parameters::Instance();
61 for (Int_t i=0; i<24; i++){
62 TGraph* gr = fParam ->GetAmpLEDRec(i);
63 fAmpLEDrec.AddAtAndExpand(gr,i) ;
64 fTime0vertex[i]= fParam->GetTimeDelayDA(i);
66 fdZ_C = TMath::Abs(fParam->GetZPositionShift("T0/C/PMT1"));
67 fdZ_A = TMath::Abs(fParam->GetZPositionShift("T0/A/PMT15"));
70 //____________________________________________________________________
72 AliT0Reconstructor::AliT0Reconstructor(const AliT0Reconstructor &r):
81 // AliT0Reconstructor copy constructor
84 ((AliT0Reconstructor &) r).Copy(*this);
88 //_____________________________________________________________________________
89 AliT0Reconstructor &AliT0Reconstructor::operator=(const AliT0Reconstructor &r)
92 // Assignment operator
95 if (this != &r) ((AliT0Reconstructor &) r).Copy(*this);
100 //_____________________________________________________________________________
102 void AliT0Reconstructor::Reconstruct(TTree*digitsTree, TTree*clustersTree) const
105 // T0 digits reconstruction
106 // T0RecPoint writing
109 TArrayI * timeCFD = new TArrayI(24);
110 TArrayI * timeLED = new TArrayI(24);
111 TArrayI * chargeQT0 = new TArrayI(24);
112 TArrayI * chargeQT1 = new TArrayI(24);
114 AliT0Calibrator *calib=new AliT0Calibrator();
116 // Int_t mV2Mip = param->GetmV2Mip();
117 //mV2Mip = param->GetmV2Mip();
118 Int_t channelWidth = fParam->GetChannelWidth() ;
119 Int_t meanT0 = fParam->GetMeanT0();
121 AliDebug(1,Form("Start DIGITS reconstruction "));
123 TBranch *brDigits=digitsTree->GetBranch("T0");
124 AliT0digit *fDigits = new AliT0digit() ;
126 brDigits->SetAddress(&fDigits);
128 cerr<<"EXEC Branch T0 digits not found"<<endl;
132 digitsTree->GetEvent(0);
133 digitsTree->GetEntry(0);
134 brDigits->GetEntry(0);
135 fDigits->GetTimeCFD(*timeCFD);
136 fDigits->GetTimeLED(*timeLED);
137 fDigits->GetQT0(*chargeQT0);
138 fDigits->GetQT1(*chargeQT1);
140 Float_t besttimeA=999999;
141 Float_t besttimeC=999999;
142 Int_t pmtBestA=99999;
143 Int_t pmtBestC=99999;
144 Float_t timeDiff=999999, meanTime=0;
148 AliT0RecPoint* frecpoints= new AliT0RecPoint ();
149 clustersTree->Branch( "T0", "AliT0RecPoint" ,&frecpoints, 405,1);
151 Float_t time[24], adc[24];
152 for (Int_t ipmt=0; ipmt<24; ipmt++) {
153 if(timeCFD->At(ipmt)>0 ){
154 Double_t qt0 = Double_t(chargeQT0->At(ipmt));
155 Double_t qt1 = Double_t(chargeQT1->At(ipmt));
156 if((qt1-qt0)>0) adc[ipmt] = TMath::Exp( Double_t (channelWidth*(qt1-qt0)/1000));
157 time[ipmt] = calib-> WalkCorrection( ipmt,Int_t(qt1) , timeCFD->At(ipmt) ) ;
160 Double_t sl = (timeLED->At(ipmt) - time[ipmt])*channelWidth;
161 Double_t qt=((TGraph*)fAmpLEDrec.At(ipmt))->Eval(sl/1000.);
162 frecpoints->SetTime(ipmt,time[ipmt]);
163 frecpoints->SetAmp(ipmt,adc[ipmt]);
164 frecpoints->SetAmpLED(ipmt,qt);
172 for (Int_t ipmt=0; ipmt<12; ipmt++){
173 if(time[ipmt] > 1 ) {
174 if(time[ipmt]<besttimeC){
175 besttimeC=time[ipmt]; //timeC
180 for ( Int_t ipmt=12; ipmt<24; ipmt++){
182 if(time[ipmt]<besttimeA) {
183 besttimeA=time[ipmt]; //timeA
187 if(besttimeA !=999999) frecpoints->SetTimeBestA(Int_t(besttimeA));
188 if( besttimeC != 999999 ) frecpoints->SetTimeBestC(Int_t(besttimeC));
189 AliDebug(1,Form(" besttimeA %f ps, besttimeC %f ps",besttimeA, besttimeC));
190 Float_t c = 0.0299792; // cm/ps
192 if(besttimeA !=999999 && besttimeC != 999999 ){
193 timeDiff =(besttimeC - besttimeA)*channelWidth;
194 meanTime = (meanT0 - (besttimeA + besttimeC)/2) * channelWidth;
195 vertex = c*(timeDiff)/2. + (fdZ_A - fdZ_C)/2; //-(lenr-lenl))/2;
196 AliDebug(1,Form(" timeDiff %f ps, meanTime %f ps, vertex %f cm",timeDiff, meanTime,vertex ));
197 frecpoints->SetVertex(vertex);
198 frecpoints->SetMeanTime(Int_t(meanTime));
201 //time in each channel as time[ipmt]-MeanTimeinThisChannel(with vertex=0)
202 for (Int_t ipmt=0; ipmt<24; ipmt++) {
204 time[ipmt] = (time[ipmt] - fTime0vertex[ipmt])*channelWidth;
205 frecpoints->SetTime(ipmt,time[ipmt]);
208 clustersTree->Fill();
217 //_______________________________________________________________________
219 void AliT0Reconstructor::Reconstruct(AliRawReader* rawReader, TTree*recTree) const
222 // T0RecPoint writing
224 //Q->T-> coefficients !!!! should be measured!!!
225 Int_t allData[110][5];
227 TArrayI * timeCFD = new TArrayI(24);
228 TArrayI * timeLED = new TArrayI(24);
229 TArrayI * chargeQT0 = new TArrayI(24);
230 TArrayI * chargeQT1 = new TArrayI(24);
232 for (Int_t i=0; i<110; i++) {
236 AliT0RawReader myrawreader(rawReader);
237 if (!myrawreader.Next())
238 AliDebug(1,Form(" no raw data found!! %i", myrawreader.Next()));
239 for (Int_t i=0; i<110; i++) {
240 allData[i][0]=myrawreader.GetData(i,0);
242 AliT0Calibrator *calib = new AliT0Calibrator();
244 // Int_t mV2Mip = param->GetmV2Mip();
245 //mV2Mip = param->GetmV2Mip();
246 Int_t channelWidth = fParam->GetChannelWidth() ;
247 Int_t meanT0 = fParam->GetMeanT0();
249 for (Int_t in=0; in<24; in++)
251 timeLED->AddAt(allData[in+1][0],in);
252 timeCFD->AddAt(allData[in+25][0],in);
253 chargeQT1->AddAt(allData[in+57][0],in);
254 chargeQT0->AddAt(allData[in+80][0],in);
255 AliDebug(10, Form(" readed Raw %i %i %i %i %i", in, timeLED->At(in),timeCFD->At(in),chargeQT0->At(in),chargeQT1->At(in)));
258 Float_t besttimeA=999999;
259 Float_t besttimeC=999999;
260 Int_t pmtBestA=99999;
261 Int_t pmtBestC=99999;
262 Float_t timeDiff=999999, meanTime=0;
265 AliT0RecPoint* frecpoints= new AliT0RecPoint ();
267 recTree->Branch( "T0", "AliT0RecPoint" ,&frecpoints, 405,1);
270 Float_t time[24], adc[24];
271 for (Int_t ipmt=0; ipmt<24; ipmt++) {
272 if(timeCFD->At(ipmt)>0 ){
273 Double_t qt0 = Double_t(chargeQT0->At(ipmt));
274 Double_t qt1 = Double_t(chargeQT1->At(ipmt));
275 if((qt1-qt0)>0) adc[ipmt] = TMath::Exp( Double_t (channelWidth*(qt1-qt0)/1000));
276 // time[ipmt] = channelWidth * (calib-> WalkCorrection( ipmt,qt1 , timeCFD->At(ipmt) ) ) ;
277 time[ipmt] = calib-> WalkCorrection( ipmt,Int_t(qt1) , timeCFD->At(ipmt) ) ;
278 Double_t sl = (timeLED->At(ipmt) - time[ipmt])*channelWidth;
279 Double_t qt=((TGraph*)fAmpLEDrec.At(ipmt))->Eval(sl/1000.);
280 frecpoints->SetTime(ipmt,time[ipmt]);
281 frecpoints->SetAmp(ipmt,adc[ipmt]);
282 frecpoints->SetAmpLED(ipmt,qt);
290 for (Int_t ipmt=0; ipmt<12; ipmt++){
291 if(time[ipmt] > 1 ) {
292 if(time[ipmt]<besttimeC){
293 besttimeC=time[ipmt]; //timeC
298 for ( Int_t ipmt=12; ipmt<24; ipmt++){
300 if(time[ipmt]<besttimeA) {
301 besttimeA=time[ipmt]; //timeA
305 if(besttimeA !=999999) frecpoints->SetTimeBestA(Int_t(besttimeA));
306 if( besttimeC != 999999 ) frecpoints->SetTimeBestC(Int_t(besttimeC));
307 AliDebug(1,Form(" besttimeA %f ps, besttimeC %f ps",besttimeA, besttimeC));
308 Float_t c = 0.0299792; // cm/ps
310 if(besttimeA !=999999 && besttimeC != 999999 ){
311 timeDiff = (besttimeC - besttimeA)*channelWidth;
312 // meanTime = (besttimeA + besttimeC)/2.;
313 meanTime = (meanT0 - (besttimeA + besttimeC)/2) * channelWidth;
314 vertex = c*(timeDiff)/2. + (fdZ_A - fdZ_C)/2; //-(lenr-lenl))/2;
315 AliDebug(1,Form(" timeDiff %f ps, meanTime %f ps, vertex %f cm",timeDiff, meanTime,vertex ));
316 frecpoints->SetVertex(vertex);
317 frecpoints->SetMeanTime(Int_t(meanTime));
320 //time in each channel as time[ipmt]-MeanTimeinThisChannel(with vertex=0)
321 for (Int_t ipmt=0; ipmt<24; ipmt++) {
323 time[ipmt] = (time[ipmt] - fTime0vertex[ipmt])*channelWidth;
324 frecpoints->SetTime(ipmt,time[ipmt]);
336 //____________________________________________________________
338 void AliT0Reconstructor::FillESD(TTree */*digitsTree*/, TTree *clustersTree, AliESDEvent *pESD) const
341 /***************************************************
342 Resonstruct digits to vertex position
343 ****************************************************/
345 AliDebug(1,Form("Start FillESD T0"));
347 TTree *treeR = clustersTree;
349 AliT0RecPoint* frecpoints= new AliT0RecPoint ();
351 AliError("Reconstruct Fill ESD >> no recpoints found");
355 AliDebug(1,Form("Start FillESD T0"));
356 TBranch *brRec = treeR->GetBranch("T0");
358 brRec->SetAddress(&frecpoints);
360 cerr<<"EXEC Branch T0 rec not found"<<endl;
366 Float_t timeStart, Zposition, amp[24], time[24];
368 Zposition = frecpoints -> GetVertex();
369 timeStart = frecpoints -> GetMeanTime() ;
370 for ( i=0; i<24; i++) {
371 time[i] = Float_t (frecpoints -> GetTime(i)); // ps to ns
372 amp[i] = frecpoints -> GetAmp(i);
374 pESD->SetT0zVertex(Zposition); //vertex Z position
375 pESD->SetT0(timeStart); // interaction time
376 pESD->SetT0time(time); // best TOF on each PMT
377 pESD->SetT0amplitude(amp); // number of particles(MIPs) on each PMT
379 AliDebug(1,Form(" Z position %f cm, T0 %f ps",Zposition , timeStart));
381 } // vertex in 3 sigma