Updating DP aliases for test setup
[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$ */
72e48d95 17/*********************************************************************
18 * T0 reconstruction and filling ESD
19 * - reconstruct mean time (interation time)
20 * - vertex position
21 * - multiplicity
22 ********************************************************************/
dc7ca31d 23
af885e0f 24#include <AliESDEvent.h>
dc7ca31d 25#include "AliLog.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
34#include <TArrayI.h>
35#include <TGraph.h>
aad72f45 36#include <TMath.h>
2e6a5ee0 37#include <iostream.h>
dc7ca31d 38
39ClassImp(AliT0Reconstructor)
40
c41ceaac 41 AliT0Reconstructor:: AliT0Reconstructor(): AliReconstructor(),
f16935f7 42 fdZonA(0),
43 fdZonC(0),
44 fZposition(0),
45 fParam(NULL),
2e6a5ee0 46 fAmpLEDrec(),
47 fCalib()
e0bba6cc 48{
72e48d95 49 //constructor
50
c41ceaac 51 AliDebug(1,"Start reconstructor ");
74adb36a 52
53 fParam = AliT0Parameters::Instance();
54 fParam->Init();
2e6a5ee0 55 /*
74adb36a 56 for (Int_t i=0; i<24; i++){
2e6a5ee0 57 TGraph* gr = fParam ->GetAmpLEDRec(i);
58 if (gr) fAmpLEDrec.AddAtAndExpand(gr,i) ;
59 }
60 */
f16935f7 61 fdZonC = TMath::Abs(fParam->GetZPositionShift("T0/C/PMT1"));
62 fdZonA = TMath::Abs(fParam->GetZPositionShift("T0/A/PMT15"));
2e6a5ee0 63 fCalib = new AliT0Calibrator();
74adb36a 64
c41ceaac 65}
66//____________________________________________________________________
e0bba6cc 67
c41ceaac 68AliT0Reconstructor::AliT0Reconstructor(const AliT0Reconstructor &r):
d76c31f4 69 AliReconstructor(r),
f16935f7 70 fdZonA(0),
71 fdZonC(0),
72 fZposition(0),
73 fParam(NULL),
2e6a5ee0 74 fAmpLEDrec(),
75 fCalib()
76
f16935f7 77 {
c41ceaac 78 //
79 // AliT0Reconstructor copy constructor
80 //
e0bba6cc 81
c41ceaac 82 ((AliT0Reconstructor &) r).Copy(*this);
e0bba6cc 83
84}
85
c41ceaac 86//_____________________________________________________________________________
87AliT0Reconstructor &AliT0Reconstructor::operator=(const AliT0Reconstructor &r)
dc7ca31d 88{
c41ceaac 89 //
90 // Assignment operator
91 //
92
93 if (this != &r) ((AliT0Reconstructor &) r).Copy(*this);
94 return *this;
e0bba6cc 95
dc7ca31d 96}
c41ceaac 97
98//_____________________________________________________________________________
99
dc7ca31d 100void AliT0Reconstructor::Reconstruct(TTree*digitsTree, TTree*clustersTree) const
94c27e4f 101
dc7ca31d 102{
94c27e4f 103 // T0 digits reconstruction
104 // T0RecPoint writing
c41ceaac 105
74adb36a 106
c41ceaac 107 TArrayI * timeCFD = new TArrayI(24);
108 TArrayI * timeLED = new TArrayI(24);
109 TArrayI * chargeQT0 = new TArrayI(24);
110 TArrayI * chargeQT1 = new TArrayI(24);
74adb36a 111
dc7ca31d 112
94c27e4f 113 // Int_t mV2Mip = param->GetmV2Mip();
dc7ca31d 114 //mV2Mip = param->GetmV2Mip();
8955c6b4 115 Float_t channelWidth = fParam->GetChannelWidth() ;
74adb36a 116 Int_t meanT0 = fParam->GetMeanT0();
94c27e4f 117
dc7ca31d 118 AliDebug(1,Form("Start DIGITS reconstruction "));
94c27e4f 119
2e6a5ee0 120
121 TBranch *brDigits=digitsTree->GetBranch("T0");
e0bba6cc 122 AliT0digit *fDigits = new AliT0digit() ;
dc7ca31d 123 if (brDigits) {
124 brDigits->SetAddress(&fDigits);
125 }else{
f16935f7 126 AliError(Form("EXEC Branch T0 digits not found"));
127 return;
dc7ca31d 128 }
e0bba6cc 129
c41ceaac 130 digitsTree->GetEvent(0);
131 digitsTree->GetEntry(0);
132 brDigits->GetEntry(0);
133 fDigits->GetTimeCFD(*timeCFD);
134 fDigits->GetTimeLED(*timeLED);
135 fDigits->GetQT0(*chargeQT0);
136 fDigits->GetQT1(*chargeQT1);
c32fcee0 137
c41ceaac 138
139 Float_t besttimeA=999999;
140 Float_t besttimeC=999999;
141 Int_t pmtBestA=99999;
142 Int_t pmtBestC=99999;
dc7ca31d 143 Float_t timeDiff=999999, meanTime=0;
144
e0bba6cc 145
94c27e4f 146 AliT0RecPoint* frecpoints= new AliT0RecPoint ();
147 clustersTree->Branch( "T0", "AliT0RecPoint" ,&frecpoints, 405,1);
148
dc7ca31d 149 Float_t time[24], adc[24];
150 for (Int_t ipmt=0; ipmt<24; ipmt++) {
c41ceaac 151 if(timeCFD->At(ipmt)>0 ){
29d3e0eb 152 Double_t qt0 = Double_t(chargeQT0->At(ipmt));
153 Double_t qt1 = Double_t(chargeQT1->At(ipmt));
c41ceaac 154 if((qt1-qt0)>0) adc[ipmt] = TMath::Exp( Double_t (channelWidth*(qt1-qt0)/1000));
2e6a5ee0 155 time[ipmt] = fCalib-> WalkCorrection( ipmt, Int_t(qt1) , timeCFD->At(ipmt), "pdc" ) ;
c41ceaac 156
157 //LED
29d3e0eb 158 Double_t sl = (timeLED->At(ipmt) - time[ipmt])*channelWidth;
74adb36a 159 Double_t qt=((TGraph*)fAmpLEDrec.At(ipmt))->Eval(sl/1000.);
29d3e0eb 160 frecpoints->SetTime(ipmt,time[ipmt]);
dc7ca31d 161 frecpoints->SetAmp(ipmt,adc[ipmt]);
c41ceaac 162 frecpoints->SetAmpLED(ipmt,qt);
dc7ca31d 163 }
164 else {
165 time[ipmt] = 0;
166 adc[ipmt] = 0;
167 }
168 }
94c27e4f 169
dc7ca31d 170 for (Int_t ipmt=0; ipmt<12; ipmt++){
171 if(time[ipmt] > 1 ) {
c41ceaac 172 if(time[ipmt]<besttimeC){
173 besttimeC=time[ipmt]; //timeC
174 pmtBestC=ipmt;
dc7ca31d 175 }
176 }
177 }
178 for ( Int_t ipmt=12; ipmt<24; ipmt++){
179 if(time[ipmt] > 1) {
c41ceaac 180 if(time[ipmt]<besttimeA) {
181 besttimeA=time[ipmt]; //timeA
182 pmtBestA=ipmt;}
dc7ca31d 183 }
184 }
c41ceaac 185 if(besttimeA !=999999) frecpoints->SetTimeBestA(Int_t(besttimeA));
186 if( besttimeC != 999999 ) frecpoints->SetTimeBestC(Int_t(besttimeC));
187 AliDebug(1,Form(" besttimeA %f ps, besttimeC %f ps",besttimeA, besttimeC));
dc7ca31d 188 Float_t c = 0.0299792; // cm/ps
189 Float_t vertex = 0;
c41ceaac 190 if(besttimeA !=999999 && besttimeC != 999999 ){
94c27e4f 191 timeDiff =(besttimeC - besttimeA)*channelWidth;
192 meanTime = (meanT0 - (besttimeA + besttimeC)/2) * channelWidth;
f16935f7 193 vertex = c*(timeDiff)/2. + (fdZonA - fdZonC)/2; //-(lenr-lenl))/2;
dc7ca31d 194 AliDebug(1,Form(" timeDiff %f ps, meanTime %f ps, vertex %f cm",timeDiff, meanTime,vertex ));
195 frecpoints->SetVertex(vertex);
196 frecpoints->SetMeanTime(Int_t(meanTime));
197
198 }
94c27e4f 199 //time in each channel as time[ipmt]-MeanTimeinThisChannel(with vertex=0)
200 for (Int_t ipmt=0; ipmt<24; ipmt++) {
201 if(time[ipmt]>1) {
c32fcee0 202// time[ipmt] = (time[ipmt] - fTime0vertex[ipmt])*channelWidth;
203 time[ipmt] = time[ipmt] * channelWidth;
94c27e4f 204 frecpoints->SetTime(ipmt,time[ipmt]);
205 }
206 }
dc7ca31d 207 clustersTree->Fill();
bd375212 208
209 delete timeCFD;
210 delete timeLED;
211 delete chargeQT0;
212 delete chargeQT1;
dc7ca31d 213}
214
215
c41ceaac 216//_______________________________________________________________________
217
218void AliT0Reconstructor::Reconstruct(AliRawReader* rawReader, TTree*recTree) const
219{
94c27e4f 220 // T0 raw ->
221 // T0RecPoint writing
222
223 //Q->T-> coefficients !!!! should be measured!!!
e8ed1cd0 224 Int_t allData[110][5];
2e6a5ee0 225
e8ed1cd0 226 Int_t timeCFD[24], timeLED[24], chargeQT0[24], chargeQT1[24];
aaa0a98f 227 TString option = GetOption();
2e6a5ee0 228 AliDebug(10,Form("Option: %s\n", option.Data()));
229
230 for (Int_t i0=0; i0<105; i0++)
231 {
232 for (Int_t j0=0; j0<5; j0++) allData[i0][j0]=0;
233 }
234
235 Int_t besttimeA=9999999;
236 Int_t besttimeC=9999999;
237 Int_t pmtBestA=99999;
238 Int_t pmtBestC=99999;
239 Int_t timeDiff=9999999, meanTime=0;
240 Double_t qt=0;
241
242 AliT0RecPoint* frecpoints= new AliT0RecPoint ();
243
244 recTree->Branch( "T0", "AliT0RecPoint" ,&frecpoints, 405,1);
245
246
247 AliDebug(10," before read data ");
248 AliT0RawReader myrawreader(rawReader);
249 if (!myrawreader.Next())
250 AliDebug(1,Form(" no raw data found!!"));
251 else
252 {
253 for (Int_t i=0; i<105; i++) {
254 for (Int_t iHit=0; iHit<5; iHit++)
255 {
256 allData[i][iHit] = myrawreader.GetData(i,iHit);
257 }
258 }
259
260 Float_t channelWidth = fParam->GetChannelWidth() ;
261
262 Int_t meanT0 = fParam->GetMeanT0();
263 if(option == "pdc"){
264 for (Int_t in=0; in<24; in++)
265 {
266
267 timeLED[in] = allData[in+1][0] ;
268 timeCFD[in] = allData[in+25][0] ;
269 chargeQT1[in] = allData[in+57][0] ;
270 chargeQT0[in] = allData[in+80][0] ;
271 }
272 }
273
274 if(option == "cosmic") {
275 for (Int_t in=0; in<12; in++)
276 {
277 timeCFD[in] = allData[in+1][0] ;
278 timeCFD[in+12] = allData[in+56+1][0] ;
279 timeLED[in] = allData[in+12+1][0] ;
280 timeLED[in+12] = allData[in+68+1][0] ;
281 }
282
283 for (Int_t in=0; in<24; in=in+2)
284 {
285 Int_t cc=in/2;
286 chargeQT1[cc]=allData[in+25][0];
287 chargeQT0[cc]=allData[in+26][0];
288 }
289 for (Int_t in=24; in<48; in=in+2)
290 {
291 Int_t cc=in/2;
292 chargeQT1[cc]=allData[in+57][0];
293 chargeQT0[cc]=allData[in+58][0];
294 }
295
296 }
297 for (Int_t in=0; in<24; in++)
298 AliDebug(10, Form(" readed Raw %i %i %i %i %i", in, timeLED[in],timeCFD[in],chargeQT0[in],chargeQT1[in]));
299
300
301 Int_t time[24], adc[24];
302 for (Int_t ipmt=0; ipmt<24; ipmt++) {
303 if(timeCFD[ipmt]>0 && timeLED[ipmt]>0){
304
305 if(option == "pdc"){
306 Double_t qt0 = Double_t(chargeQT0[ipmt]);
307 Double_t qt1 = Double_t(chargeQT1[ipmt]);
308 if((qt1-qt0)>0) adc[ipmt] = Int_t(TMath::Exp( Double_t (channelWidth*(qt1-qt0)/1000)));
309
310 time[ipmt] = fCalib-> WalkCorrection( ipmt,Int_t(qt1) , timeCFD[ipmt], "pdc" ) ;
311 Double_t sl = (timeLED[ipmt] - time[ipmt])*channelWidth;
312 if(fAmpLEDrec.At(ipmt))
313 qt=((TGraph*)fAmpLEDrec.At(ipmt))->Eval(sl/1000.);
314 frecpoints->SetTime(ipmt,time[ipmt]);
315 frecpoints->SetAmp(ipmt,adc[ipmt]);
316 frecpoints->SetAmpLED(ipmt,qt);
317 AliDebug(1,Form(" QTC %f mv, time in chann %f ",adc[ipmt] ,time[ipmt]));
318 }
319 if(option == "cosmic") {
320 // if(ipmt == 15) continue; //skip crashed PMT
321 if(( chargeQT1[ipmt] - chargeQT0[ipmt])>0)
322 adc[ipmt] = chargeQT1[ipmt] - chargeQT0[ipmt];
323 else
324 adc[ipmt] = 0;
325 // time[ipmt] = fCalib-> WalkCorrection( ipmt, adc[ipmt], timeCFD[ipmt],"cosmic" ) ;
326 // time[ipmt] = timeCFD[ipmt] ;
327 Double_t sl = timeLED[ipmt] - timeCFD[ipmt];
328 time[ipmt] = fCalib-> WalkCorrection( ipmt, Int_t(sl), timeCFD[ipmt],"cosmic" ) ;
329 // if(fAmpLEDrec.At(ipmt))
330 // qt=((TGraph*)fAmpLEDrec.At(ipmt))->Eval(sl);
331 time[ipmt] = time[ipmt] - allData[0][0] + 5000;
332 AliDebug(10,Form(" ipmt %i QTC %i , time in chann %i (led-cfd) %i ",
333 ipmt, Int_t(adc[ipmt]) ,Int_t(time[ipmt]),Int_t( sl)));
334 frecpoints->SetTime(ipmt, Float_t(time[ipmt]) );
335 frecpoints->SetAmp(ipmt, Float_t(adc[ipmt]));
336 frecpoints->SetAmpLED(ipmt, Float_t(qt));
337 }
338
339 }
340 else {
341 time[ipmt] = 0;
342 adc[ipmt] = 0;
343 }
344 }
345
346 for (Int_t ipmt=0; ipmt<12; ipmt++){
347 if(time[ipmt] > 1 ) {
348 if(time[ipmt]<besttimeC){
349 besttimeC=time[ipmt]; //timeC
350 pmtBestC=ipmt;
351 }
352 }
353 }
354 for ( Int_t ipmt=12; ipmt<24; ipmt++){
355 if(time[ipmt] > 1) {
356 if(time[ipmt]<besttimeA) {
357 besttimeA=time[ipmt]; //timeA
358 pmtBestA=ipmt;}
359 }
360 }
361 if(besttimeA !=9999999) frecpoints->SetTimeBestA(Int_t(besttimeA));
362 if( besttimeC != 9999999 ) frecpoints->SetTimeBestC(Int_t(besttimeC));
363 AliDebug(1,Form(" besttimeA %f ps, besttimeC %f ps",besttimeA, besttimeC));
364 Float_t c = 0.0299792; // cm/ps
365 Float_t vertex = 99999;
366 if(besttimeA <9999999 && besttimeC < 9999999 ){
367 timeDiff =Int_t (( besttimeC - besttimeA) *channelWidth);
368 if(option == "pdc")
369 meanTime = Int_t((meanT0 - (besttimeA + besttimeC)/2) * channelWidth);
370 if(option == "cosmic") meanTime = (besttimeA + besttimeC)/2;
371 vertex = c*(Float_t(timeDiff))/2.+ (fdZonA - fdZonC)/2;
372 AliDebug(1,Form(" timeDiff %i ps, meanTime %i ps, vertex %f cm",timeDiff, meanTime,vertex ));
373 frecpoints->SetVertex(vertex);
374 frecpoints->SetMeanTime(Int_t(meanTime));
375
376 }
377 } // if (else )raw data
378 recTree->Fill();
379 if(frecpoints) delete frecpoints;
c41ceaac 380}
381//____________________________________________________________
382
d76c31f4 383void AliT0Reconstructor::FillESD(TTree */*digitsTree*/, TTree *clustersTree, AliESDEvent *pESD) const
dc7ca31d 384{
385
386 /***************************************************
387 Resonstruct digits to vertex position
388 ****************************************************/
389
dc7ca31d 390 AliDebug(1,Form("Start FillESD T0"));
391
d76c31f4 392 TTree *treeR = clustersTree;
dc7ca31d 393
394 AliT0RecPoint* frecpoints= new AliT0RecPoint ();
395 if (!frecpoints) {
396 AliError("Reconstruct Fill ESD >> no recpoints found");
397 return;
398 }
399
400 AliDebug(1,Form("Start FillESD T0"));
401 TBranch *brRec = treeR->GetBranch("T0");
402 if (brRec) {
403 brRec->SetAddress(&frecpoints);
404 }else{
f16935f7 405 AliError(Form("EXEC Branch T0 rec not found"));
dc7ca31d 406 return;
407 }
408
409 brRec->GetEntry(0);
f16935f7 410 Float_t amp[24], time[24];
411 Float_t zPosition = frecpoints -> GetVertex();
412 Float_t timeStart = frecpoints -> GetMeanTime() ;
413 for ( Int_t i=0; i<24; i++) {
94c27e4f 414 time[i] = Float_t (frecpoints -> GetTime(i)); // ps to ns
dc7ca31d 415 amp[i] = frecpoints -> GetAmp(i);
416 }
f16935f7 417 pESD->SetT0zVertex(zPosition); //vertex Z position
dc7ca31d 418 pESD->SetT0(timeStart); // interaction time
419 pESD->SetT0time(time); // best TOF on each PMT
420 pESD->SetT0amplitude(amp); // number of particles(MIPs) on each PMT
5325480c 421
f16935f7 422 AliDebug(1,Form(" Z position %f cm, T0 %f ps",zPosition , timeStart));
dc7ca31d 423
dc7ca31d 424} // vertex in 3 sigma
425
426
427
428
429
430