Loading the geometry (Andrea)
[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"
dc7ca31d 23#include <AliESD.h>
24#include "AliLog.h"
c41ceaac 25#include "AliT0Loader.h"
dc7ca31d 26#include <TClonesArray.h>
27#include "AliT0RecPoint.h"
28#include "AliRawReader.h"
29#include "AliT0RawReader.h"
dc7ca31d 30#include "AliT0digit.h"
31#include "AliT0Reconstructor.h"
32#include "AliT0Parameters.h"
c41ceaac 33#include "AliT0Calibrator.h"
dc7ca31d 34#include "AliCDBLocal.h"
35#include "AliCDBStorage.h"
36#include "AliCDBManager.h"
37#include "AliCDBEntry.h"
38
39#include <TArrayI.h>
40#include <TGraph.h>
41
42ClassImp(AliT0Reconstructor)
43
c41ceaac 44 AliT0Reconstructor:: AliT0Reconstructor(): AliReconstructor(),
45 fDigits(NULL),
46 fTree(0x0),
47 fZposition(0)
48
e0bba6cc 49{
c41ceaac 50 AliDebug(1,"Start reconstructor ");
51}
52//____________________________________________________________________
e0bba6cc 53
c41ceaac 54AliT0Reconstructor::AliT0Reconstructor(const AliT0Reconstructor &r):
55 fDigits(NULL),
56 fTree(0x0),
57 fZposition(0)
58
59{
60 //
61 // AliT0Reconstructor copy constructor
62 //
e0bba6cc 63
c41ceaac 64 ((AliT0Reconstructor &) r).Copy(*this);
e0bba6cc 65
66}
67
c41ceaac 68//_____________________________________________________________________________
69AliT0Reconstructor &AliT0Reconstructor::operator=(const AliT0Reconstructor &r)
dc7ca31d 70{
c41ceaac 71 //
72 // Assignment operator
73 //
74
75 if (this != &r) ((AliT0Reconstructor &) r).Copy(*this);
76 return *this;
e0bba6cc 77
dc7ca31d 78}
c41ceaac 79
80//_____________________________________________________________________________
81
dc7ca31d 82void AliT0Reconstructor::Reconstruct(TTree*digitsTree, TTree*clustersTree) const
c41ceaac 83
dc7ca31d 84{
85// T0 digits reconstruction
86// T0RecPoint writing
87
c41ceaac 88
89 Float_t timeDelayLED[24];
dc7ca31d 90 Float_t zdetA,zdetC;
c41ceaac 91 TObjArray slewingLEDrec;
92 TObjArray walk;
dc7ca31d 93
c41ceaac 94 TArrayI * timeCFD = new TArrayI(24);
95 TArrayI * timeLED = new TArrayI(24);
96 TArrayI * chargeQT0 = new TArrayI(24);
97 TArrayI * chargeQT1 = new TArrayI(24);
98
dc7ca31d 99 AliT0Parameters* param = AliT0Parameters::Instance();
100 param->Init();
c41ceaac 101 AliT0Calibrator *calib=new AliT0Calibrator();
dc7ca31d 102
103 Int_t mV2Mip = param->GetmV2Mip();
104 //mV2Mip = param->GetmV2Mip();
105 Int_t channelWidth = param->GetChannelWidth() ;
106
107 for (Int_t i=0; i<24; i++){
c41ceaac 108 TGraph* gr = param ->GetSlewRec(i);
109 slewingLEDrec.AddAtAndExpand(gr,i) ;
dc7ca31d 110 }
111 zdetC = param->GetZposition(0);
112 zdetA = param->GetZposition(1);
113
114 AliDebug(1,Form("Start DIGITS reconstruction "));
e0bba6cc 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
141 AliT0RecPoint* frecpoints= new AliT0RecPoint ();
142 clustersTree->Branch( "T0", "AliT0RecPoint" ,&frecpoints, 405,1);
dc7ca31d 143
144 Float_t time[24], adc[24];
145 for (Int_t ipmt=0; ipmt<24; ipmt++) {
c41ceaac 146 if(timeCFD->At(ipmt)>0 ){
147 Int_t qt0= chargeQT0->At(ipmt);
148 Int_t qt1= chargeQT1->At(ipmt);
149 if((qt1-qt0)>0) adc[ipmt] = TMath::Exp( Double_t (channelWidth*(qt1-qt0)/1000));
150 time[ipmt] = channelWidth * (calib-> WalkCorrection( ipmt,qt1 , timeCFD->At(ipmt) ) ) ;
151
152 //LED
153 Double_t sl = (timeLED->At(ipmt) - timeCFD->At(ipmt)- (1000.*timeDelayLED[ipmt]/channelWidth))*channelWidth;
154 Double_t qt=((TGraph*)slewingLEDrec.At(ipmt))->Eval(sl/1000.);
dc7ca31d 155 frecpoints->SetTime(ipmt,time[ipmt]);
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 }
e0bba6cc 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 ){
186 timeDiff = besttimeC - besttimeA;
187 meanTime = (besttimeA + besttimeC)/2.;
dc7ca31d 188 vertex = c*(timeDiff)/2.; //-(lenr-lenl))/2;
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 }
194 clustersTree->Fill();
195}
196
197
c41ceaac 198//_______________________________________________________________________
199
200void AliT0Reconstructor::Reconstruct(AliRawReader* rawReader, TTree*recTree) const
201{
202// T0 raw ->
203// T0RecPoint writing
204
205 //Q->T-> coefficients !!!! should be asked!!!
206 Float_t timeDelayLED[24];
207 Float_t zdetA,zdetC;
208 TObjArray slewingLEDrec;
209 TObjArray walk;
210
211 TArrayI * timeCFD = new TArrayI(24);
212 TArrayI * timeLED = new TArrayI(24);
213 TArrayI * chargeQT0 = new TArrayI(24);
214 TArrayI * chargeQT1 = new TArrayI(24);
215
216 AliT0RawReader myrawreader(rawReader);
217 if (!myrawreader.Next())
218 AliDebug(1,Form(" no raw data found!! %i", myrawreader.Next()));
219 Int_t allData[110][5];
220 for (Int_t i=0; i<110; i++) {
221 allData[i][0]=myrawreader.GetData(i,0);
222 }
223
224 AliT0Parameters* param = AliT0Parameters::Instance();
225 param->Init();
226 AliT0Calibrator *calib=new AliT0Calibrator();
227
228 Int_t mV2Mip = param->GetmV2Mip();
229 //mV2Mip = param->GetmV2Mip();
230 Int_t channelWidth = param->GetChannelWidth() ;
231
232 for (Int_t i=0; i<24; i++){
233 TGraph* gr = param ->GetSlewRec(i);
234 slewingLEDrec.AddAtAndExpand(gr,i) ;
235 }
236
237 zdetC = param->GetZposition(0);
238 zdetA = param->GetZposition(1);
239
240 for (Int_t in=0; in<24; in++)
241 {
242 timeLED->AddAt(allData[in+1][0],in);
243 timeCFD->AddAt(allData[in+25][0],in);
244 chargeQT1->AddAt(allData[in+55][0],in);
245 chargeQT0->AddAt(allData[in+79][0],in);
246 AliDebug(10, Form(" readed Raw %i %i %i %i %i", in, timeLED->At(in),timeCFD->At(in),chargeQT0->At(in),chargeQT1->At(in)));
247 }
248
249 Float_t besttimeA=999999;
250 Float_t besttimeC=999999;
251 Int_t pmtBestA=99999;
252 Int_t pmtBestC=99999;
253 Float_t timeDiff=999999, meanTime=0;
254
255
256 AliT0RecPoint* frecpoints= new AliT0RecPoint ();
257
258 recTree->Branch( "T0", "AliT0RecPoint" ,&frecpoints, 405,1);
259
260
261 Float_t time[24], adc[24];
262 for (Int_t ipmt=0; ipmt<24; ipmt++) {
263 if(timeCFD->At(ipmt)>0 ){
264 Int_t qt0= chargeQT0->At(ipmt);
265 Int_t qt1= chargeQT1->At(ipmt);
266 if((qt1-qt0)>0) adc[ipmt] = TMath::Exp( Double_t (channelWidth*(qt1-qt0)/1000));
267 time[ipmt] = channelWidth * (calib-> WalkCorrection( ipmt,qt1 , timeCFD->At(ipmt) ) ) ;
268 Double_t sl = (timeLED->At(ipmt) - timeCFD->At(ipmt)- (1000.*timeDelayLED[ipmt]/channelWidth))*channelWidth;
269 Double_t qt=((TGraph*)slewingLEDrec.At(ipmt))->Eval(sl/1000.);
270 frecpoints->SetTime(ipmt,time[ipmt]);
271 frecpoints->SetAmp(ipmt,adc[ipmt]);
272 frecpoints->SetAmpLED(ipmt,qt);
273 }
274 else {
275 time[ipmt] = 0;
276 adc[ipmt] = 0;
277 }
278 }
279
280 for (Int_t ipmt=0; ipmt<12; ipmt++){
281 if(time[ipmt] > 1 ) {
282 if(time[ipmt]<besttimeC){
283 besttimeC=time[ipmt]; //timeC
284 pmtBestC=ipmt;
285 }
286 }
287 }
288 for ( Int_t ipmt=12; ipmt<24; ipmt++){
289 if(time[ipmt] > 1) {
290 if(time[ipmt]<besttimeA) {
291 besttimeA=time[ipmt]; //timeA
292 pmtBestA=ipmt;}
293 }
294 }
295 if(besttimeA !=999999) frecpoints->SetTimeBestA(Int_t(besttimeA));
296 if( besttimeC != 999999 ) frecpoints->SetTimeBestC(Int_t(besttimeC));
297 AliDebug(1,Form(" besttimeA %f ps, besttimeC %f ps",besttimeA, besttimeC));
298 Float_t c = 0.0299792; // cm/ps
299 Float_t vertex = 0;
300 if(besttimeA !=999999 && besttimeC != 999999 ){
301 timeDiff = besttimeC - besttimeA;
302 meanTime = (besttimeA + besttimeC)/2.;
303 vertex = c*(timeDiff)/2.; //-(lenr-lenl))/2;
304 AliDebug(1,Form(" timeDiff %f ps, meanTime %f ps, vertex %f cm",timeDiff, meanTime,vertex ));
305 frecpoints->SetVertex(vertex);
306 frecpoints->SetMeanTime(Int_t(meanTime));
307
308 }
309 recTree->Fill();
310}
311//____________________________________________________________
312
dc7ca31d 313void AliT0Reconstructor::FillESD(AliRunLoader* runLoader, AliESD *pESD) const
314{
315
316 /***************************************************
317 Resonstruct digits to vertex position
318 ****************************************************/
319
320
321 if (!runLoader) {
322 AliError("Reconstruct >> No run loader");
323 return;
324 }
325
326 AliDebug(1,Form("Start FillESD T0"));
327
328 AliT0Loader* pStartLoader = (AliT0Loader*) runLoader->GetLoader("T0Loader");
329
330 pStartLoader->LoadRecPoints("READ");
331
332 TTree *treeR = pStartLoader->TreeR();
333
334 AliT0RecPoint* frecpoints= new AliT0RecPoint ();
335 if (!frecpoints) {
336 AliError("Reconstruct Fill ESD >> no recpoints found");
337 return;
338 }
339
340 AliDebug(1,Form("Start FillESD T0"));
341 TBranch *brRec = treeR->GetBranch("T0");
342 if (brRec) {
343 brRec->SetAddress(&frecpoints);
344 }else{
345 cerr<<"EXEC Branch T0 rec not found"<<endl;
346 // exit(111);
347 return;
348 }
349
350 brRec->GetEntry(0);
351 Float_t timeStart, Zposition, amp[24], time[24];
c41ceaac 352 Int_t mean0 = 12450;
dc7ca31d 353 Int_t i;
354 Zposition = frecpoints -> GetVertex();
c41ceaac 355 timeStart = frecpoints -> GetMeanTime() - mean0;
dc7ca31d 356 for ( i=0; i<24; i++) {
357 time[i] = Float_t (frecpoints -> GetTime(i)) / 1000.; // ps to ns
358 amp[i] = frecpoints -> GetAmp(i);
359 }
360 pESD->SetT0zVertex(Zposition); //vertex Z position
361 pESD->SetT0(timeStart); // interaction time
362 pESD->SetT0time(time); // best TOF on each PMT
363 pESD->SetT0amplitude(amp); // number of particles(MIPs) on each PMT
364 cout<<" ESD >> "<<Zposition<<" "<<timeStart<<endl;
365
366 pStartLoader->UnloadRecPoints();
367
368} // vertex in 3 sigma
369
370
371
372
373
374