]> git.uio.no Git - u/mrichter/AliRoot.git/blame - T0/AliT0Reconstructor.cxx
Fix to AliFMDInput for new AliESDEvent - thanks Hans
[u/mrichter/AliRoot.git] / T0 / AliT0Reconstructor.cxx
CommitLineData
dc7ca31d 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16/* $Id$ */
17
18#include <Riostream.h>
19
20#include <TDirectory.h>
21
22#include "AliRunLoader.h"
af885e0f 23#include <AliESDEvent.h>
dc7ca31d 24#include "AliLog.h"
c41ceaac 25#include "AliT0Loader.h"
dc7ca31d 26#include "AliT0RecPoint.h"
27#include "AliRawReader.h"
28#include "AliT0RawReader.h"
dc7ca31d 29#include "AliT0digit.h"
30#include "AliT0Reconstructor.h"
31#include "AliT0Parameters.h"
c41ceaac 32#include "AliT0Calibrator.h"
dc7ca31d 33#include "AliCDBLocal.h"
34#include "AliCDBStorage.h"
35#include "AliCDBManager.h"
36#include "AliCDBEntry.h"
37
38#include <TArrayI.h>
39#include <TGraph.h>
aad72f45 40#include <TMath.h>
bd375212 41//#include <TGeoManager.h>
42//#include <TClonesArray.h>
43//#include <TString.h>
44//#include <TGeoPNEntry.h>
45//#include <TGeoPhysicalNode.h>
46//#include <TGeoHMatrix.h>
dc7ca31d 47
48ClassImp(AliT0Reconstructor)
49
c41ceaac 50 AliT0Reconstructor:: AliT0Reconstructor(): AliReconstructor(),
bd375212 51 fZposition(0)
c41ceaac 52
e0bba6cc 53{
c41ceaac 54 AliDebug(1,"Start reconstructor ");
74adb36a 55
56 fParam = AliT0Parameters::Instance();
57 fParam->Init();
74adb36a 58 for (Int_t i=0; i<24; i++){
59 TGraph* gr = fParam ->GetAmpLEDRec(i);
60 fAmpLEDrec.AddAtAndExpand(gr,i) ;
61 fTime0vertex[i]= fParam->GetTimeDelayDA(i);
62 }
29d3e0eb 63 fdZ_C = TMath::Abs(fParam->GetZPositionShift("T0/C/PMT1"));
64 fdZ_A = TMath::Abs(fParam->GetZPositionShift("T0/A/PMT15"));
74adb36a 65
c41ceaac 66}
67//____________________________________________________________________
e0bba6cc 68
c41ceaac 69AliT0Reconstructor::AliT0Reconstructor(const AliT0Reconstructor &r):
c41ceaac 70 fZposition(0)
71
72{
73 //
74 // AliT0Reconstructor copy constructor
75 //
e0bba6cc 76
c41ceaac 77 ((AliT0Reconstructor &) r).Copy(*this);
e0bba6cc 78
79}
80
c41ceaac 81//_____________________________________________________________________________
82AliT0Reconstructor &AliT0Reconstructor::operator=(const AliT0Reconstructor &r)
dc7ca31d 83{
c41ceaac 84 //
85 // Assignment operator
86 //
87
88 if (this != &r) ((AliT0Reconstructor &) r).Copy(*this);
89 return *this;
e0bba6cc 90
dc7ca31d 91}
c41ceaac 92
93//_____________________________________________________________________________
94
dc7ca31d 95void AliT0Reconstructor::Reconstruct(TTree*digitsTree, TTree*clustersTree) const
94c27e4f 96
dc7ca31d 97{
94c27e4f 98 // T0 digits reconstruction
99 // T0RecPoint writing
c41ceaac 100
74adb36a 101
c41ceaac 102 TArrayI * timeCFD = new TArrayI(24);
103 TArrayI * timeLED = new TArrayI(24);
104 TArrayI * chargeQT0 = new TArrayI(24);
105 TArrayI * chargeQT1 = new TArrayI(24);
74adb36a 106
c41ceaac 107 AliT0Calibrator *calib=new AliT0Calibrator();
dc7ca31d 108
94c27e4f 109 // Int_t mV2Mip = param->GetmV2Mip();
dc7ca31d 110 //mV2Mip = param->GetmV2Mip();
74adb36a 111 Int_t channelWidth = fParam->GetChannelWidth() ;
112 Int_t meanT0 = fParam->GetMeanT0();
94c27e4f 113
dc7ca31d 114 AliDebug(1,Form("Start DIGITS reconstruction "));
94c27e4f 115
dc7ca31d 116 TBranch *brDigits=digitsTree->GetBranch("T0");
e0bba6cc 117 AliT0digit *fDigits = new AliT0digit() ;
dc7ca31d 118 if (brDigits) {
119 brDigits->SetAddress(&fDigits);
120 }else{
121 cerr<<"EXEC Branch T0 digits not found"<<endl;
122 return;
123 }
e0bba6cc 124
c41ceaac 125 digitsTree->GetEvent(0);
126 digitsTree->GetEntry(0);
127 brDigits->GetEntry(0);
128 fDigits->GetTimeCFD(*timeCFD);
129 fDigits->GetTimeLED(*timeLED);
130 fDigits->GetQT0(*chargeQT0);
131 fDigits->GetQT1(*chargeQT1);
132
133 Float_t besttimeA=999999;
134 Float_t besttimeC=999999;
135 Int_t pmtBestA=99999;
136 Int_t pmtBestC=99999;
dc7ca31d 137 Float_t timeDiff=999999, meanTime=0;
138
e0bba6cc 139
140
94c27e4f 141 AliT0RecPoint* frecpoints= new AliT0RecPoint ();
142 clustersTree->Branch( "T0", "AliT0RecPoint" ,&frecpoints, 405,1);
143
dc7ca31d 144 Float_t time[24], adc[24];
145 for (Int_t ipmt=0; ipmt<24; ipmt++) {
c41ceaac 146 if(timeCFD->At(ipmt)>0 ){
29d3e0eb 147 Double_t qt0 = Double_t(chargeQT0->At(ipmt));
148 Double_t qt1 = Double_t(chargeQT1->At(ipmt));
c41ceaac 149 if((qt1-qt0)>0) adc[ipmt] = TMath::Exp( Double_t (channelWidth*(qt1-qt0)/1000));
29d3e0eb 150 time[ipmt] = calib-> WalkCorrection( ipmt,Int_t(qt1) , timeCFD->At(ipmt) ) ;
c41ceaac 151
152 //LED
29d3e0eb 153 Double_t sl = (timeLED->At(ipmt) - time[ipmt])*channelWidth;
74adb36a 154 Double_t qt=((TGraph*)fAmpLEDrec.At(ipmt))->Eval(sl/1000.);
29d3e0eb 155 frecpoints->SetTime(ipmt,time[ipmt]);
dc7ca31d 156 frecpoints->SetAmp(ipmt,adc[ipmt]);
c41ceaac 157 frecpoints->SetAmpLED(ipmt,qt);
dc7ca31d 158 }
159 else {
160 time[ipmt] = 0;
161 adc[ipmt] = 0;
162 }
163 }
94c27e4f 164
dc7ca31d 165 for (Int_t ipmt=0; ipmt<12; ipmt++){
166 if(time[ipmt] > 1 ) {
c41ceaac 167 if(time[ipmt]<besttimeC){
168 besttimeC=time[ipmt]; //timeC
169 pmtBestC=ipmt;
dc7ca31d 170 }
171 }
172 }
173 for ( Int_t ipmt=12; ipmt<24; ipmt++){
174 if(time[ipmt] > 1) {
c41ceaac 175 if(time[ipmt]<besttimeA) {
176 besttimeA=time[ipmt]; //timeA
177 pmtBestA=ipmt;}
dc7ca31d 178 }
179 }
c41ceaac 180 if(besttimeA !=999999) frecpoints->SetTimeBestA(Int_t(besttimeA));
181 if( besttimeC != 999999 ) frecpoints->SetTimeBestC(Int_t(besttimeC));
182 AliDebug(1,Form(" besttimeA %f ps, besttimeC %f ps",besttimeA, besttimeC));
dc7ca31d 183 Float_t c = 0.0299792; // cm/ps
184 Float_t vertex = 0;
c41ceaac 185 if(besttimeA !=999999 && besttimeC != 999999 ){
94c27e4f 186 timeDiff =(besttimeC - besttimeA)*channelWidth;
187 meanTime = (meanT0 - (besttimeA + besttimeC)/2) * channelWidth;
29d3e0eb 188 vertex = c*(timeDiff)/2. + (fdZ_A - fdZ_C)/2; //-(lenr-lenl))/2;
dc7ca31d 189 AliDebug(1,Form(" timeDiff %f ps, meanTime %f ps, vertex %f cm",timeDiff, meanTime,vertex ));
190 frecpoints->SetVertex(vertex);
191 frecpoints->SetMeanTime(Int_t(meanTime));
192
193 }
94c27e4f 194 //time in each channel as time[ipmt]-MeanTimeinThisChannel(with vertex=0)
195 for (Int_t ipmt=0; ipmt<24; ipmt++) {
196 if(time[ipmt]>1) {
74adb36a 197 time[ipmt] = (time[ipmt] - fTime0vertex[ipmt])*channelWidth;
94c27e4f 198 frecpoints->SetTime(ipmt,time[ipmt]);
199 }
200 }
dc7ca31d 201 clustersTree->Fill();
bd375212 202
203 delete timeCFD;
204 delete timeLED;
205 delete chargeQT0;
206 delete chargeQT1;
dc7ca31d 207}
208
209
c41ceaac 210//_______________________________________________________________________
211
212void AliT0Reconstructor::Reconstruct(AliRawReader* rawReader, TTree*recTree) const
213{
94c27e4f 214 // T0 raw ->
215 // T0RecPoint writing
216
217 //Q->T-> coefficients !!!! should be measured!!!
5325480c 218 Int_t allData[110][5];
94c27e4f 219
c41ceaac 220 TArrayI * timeCFD = new TArrayI(24);
221 TArrayI * timeLED = new TArrayI(24);
222 TArrayI * chargeQT0 = new TArrayI(24);
223 TArrayI * chargeQT1 = new TArrayI(24);
224
5325480c 225 for (Int_t i=0; i<110; i++) {
226 allData[i][0]=0;
227 }
228
c41ceaac 229 AliT0RawReader myrawreader(rawReader);
230 if (!myrawreader.Next())
231 AliDebug(1,Form(" no raw data found!! %i", myrawreader.Next()));
c41ceaac 232 for (Int_t i=0; i<110; i++) {
233 allData[i][0]=myrawreader.GetData(i,0);
234 }
74adb36a 235 AliT0Calibrator *calib = new AliT0Calibrator();
c41ceaac 236
74adb36a 237 // Int_t mV2Mip = param->GetmV2Mip();
c41ceaac 238 //mV2Mip = param->GetmV2Mip();
74adb36a 239 Int_t channelWidth = fParam->GetChannelWidth() ;
240 Int_t meanT0 = fParam->GetMeanT0();
241
5325480c 242 for (Int_t in=0; in<24; in++)
c41ceaac 243 {
244 timeLED->AddAt(allData[in+1][0],in);
245 timeCFD->AddAt(allData[in+25][0],in);
29d3e0eb 246 chargeQT1->AddAt(allData[in+57][0],in);
247 chargeQT0->AddAt(allData[in+80][0],in);
c41ceaac 248 AliDebug(10, Form(" readed Raw %i %i %i %i %i", in, timeLED->At(in),timeCFD->At(in),chargeQT0->At(in),chargeQT1->At(in)));
249 }
250
251 Float_t besttimeA=999999;
252 Float_t besttimeC=999999;
253 Int_t pmtBestA=99999;
254 Int_t pmtBestC=99999;
255 Float_t timeDiff=999999, meanTime=0;
256
257
258 AliT0RecPoint* frecpoints= new AliT0RecPoint ();
259
260 recTree->Branch( "T0", "AliT0RecPoint" ,&frecpoints, 405,1);
261
262
263 Float_t time[24], adc[24];
264 for (Int_t ipmt=0; ipmt<24; ipmt++) {
265 if(timeCFD->At(ipmt)>0 ){
29d3e0eb 266 Double_t qt0 = Double_t(chargeQT0->At(ipmt));
267 Double_t qt1 = Double_t(chargeQT1->At(ipmt));
c41ceaac 268 if((qt1-qt0)>0) adc[ipmt] = TMath::Exp( Double_t (channelWidth*(qt1-qt0)/1000));
94c27e4f 269 // time[ipmt] = channelWidth * (calib-> WalkCorrection( ipmt,qt1 , timeCFD->At(ipmt) ) ) ;
29d3e0eb 270 time[ipmt] = calib-> WalkCorrection( ipmt,Int_t(qt1) , timeCFD->At(ipmt) ) ;
271 Double_t sl = (timeLED->At(ipmt) - time[ipmt])*channelWidth;
74adb36a 272 Double_t qt=((TGraph*)fAmpLEDrec.At(ipmt))->Eval(sl/1000.);
c41ceaac 273 frecpoints->SetTime(ipmt,time[ipmt]);
274 frecpoints->SetAmp(ipmt,adc[ipmt]);
275 frecpoints->SetAmpLED(ipmt,qt);
276 }
277 else {
278 time[ipmt] = 0;
279 adc[ipmt] = 0;
280 }
281 }
282
283 for (Int_t ipmt=0; ipmt<12; ipmt++){
284 if(time[ipmt] > 1 ) {
285 if(time[ipmt]<besttimeC){
286 besttimeC=time[ipmt]; //timeC
287 pmtBestC=ipmt;
288 }
289 }
290 }
291 for ( Int_t ipmt=12; ipmt<24; ipmt++){
292 if(time[ipmt] > 1) {
293 if(time[ipmt]<besttimeA) {
294 besttimeA=time[ipmt]; //timeA
295 pmtBestA=ipmt;}
296 }
297 }
298 if(besttimeA !=999999) frecpoints->SetTimeBestA(Int_t(besttimeA));
299 if( besttimeC != 999999 ) frecpoints->SetTimeBestC(Int_t(besttimeC));
300 AliDebug(1,Form(" besttimeA %f ps, besttimeC %f ps",besttimeA, besttimeC));
301 Float_t c = 0.0299792; // cm/ps
302 Float_t vertex = 0;
303 if(besttimeA !=999999 && besttimeC != 999999 ){
94c27e4f 304 timeDiff = (besttimeC - besttimeA)*channelWidth;
305 // meanTime = (besttimeA + besttimeC)/2.;
306 meanTime = (meanT0 - (besttimeA + besttimeC)/2) * channelWidth;
29d3e0eb 307 vertex = c*(timeDiff)/2. + (fdZ_A - fdZ_C)/2; //-(lenr-lenl))/2;
c41ceaac 308 AliDebug(1,Form(" timeDiff %f ps, meanTime %f ps, vertex %f cm",timeDiff, meanTime,vertex ));
309 frecpoints->SetVertex(vertex);
310 frecpoints->SetMeanTime(Int_t(meanTime));
311
312 }
94c27e4f 313 //time in each channel as time[ipmt]-MeanTimeinThisChannel(with vertex=0)
314 for (Int_t ipmt=0; ipmt<24; ipmt++) {
315 if(time[ipmt]>1) {
74adb36a 316 time[ipmt] = (time[ipmt] - fTime0vertex[ipmt])*channelWidth;
94c27e4f 317 frecpoints->SetTime(ipmt,time[ipmt]);
318 }
319 }
c41ceaac 320 recTree->Fill();
94c27e4f 321
bd375212 322
323 delete timeCFD;
324 delete timeLED;
325 delete chargeQT0;
326 delete chargeQT1;
327
c41ceaac 328}
329//____________________________________________________________
330
af885e0f 331void AliT0Reconstructor::FillESD(AliRunLoader* runLoader, AliESDEvent *pESD) const
dc7ca31d 332{
333
334 /***************************************************
335 Resonstruct digits to vertex position
336 ****************************************************/
337
338
339 if (!runLoader) {
340 AliError("Reconstruct >> No run loader");
341 return;
342 }
343
344 AliDebug(1,Form("Start FillESD T0"));
345
346 AliT0Loader* pStartLoader = (AliT0Loader*) runLoader->GetLoader("T0Loader");
347
348 pStartLoader->LoadRecPoints("READ");
349
350 TTree *treeR = pStartLoader->TreeR();
351
352 AliT0RecPoint* frecpoints= new AliT0RecPoint ();
353 if (!frecpoints) {
354 AliError("Reconstruct Fill ESD >> no recpoints found");
355 return;
356 }
357
358 AliDebug(1,Form("Start FillESD T0"));
359 TBranch *brRec = treeR->GetBranch("T0");
360 if (brRec) {
361 brRec->SetAddress(&frecpoints);
362 }else{
363 cerr<<"EXEC Branch T0 rec not found"<<endl;
364 // exit(111);
365 return;
366 }
367
368 brRec->GetEntry(0);
369 Float_t timeStart, Zposition, amp[24], time[24];
370 Int_t i;
371 Zposition = frecpoints -> GetVertex();
94c27e4f 372 timeStart = frecpoints -> GetMeanTime() ;
dc7ca31d 373 for ( i=0; i<24; i++) {
94c27e4f 374 time[i] = Float_t (frecpoints -> GetTime(i)); // ps to ns
dc7ca31d 375 amp[i] = frecpoints -> GetAmp(i);
376 }
377 pESD->SetT0zVertex(Zposition); //vertex Z position
378 pESD->SetT0(timeStart); // interaction time
379 pESD->SetT0time(time); // best TOF on each PMT
380 pESD->SetT0amplitude(amp); // number of particles(MIPs) on each PMT
5325480c 381
382 AliDebug(1,Form(" Z position %f cm, T0 %f ps",Zposition , timeStart));
dc7ca31d 383
384 pStartLoader->UnloadRecPoints();
385
386} // vertex in 3 sigma
387
388
389
390
391
392