changes for FIT
[u/mrichter/AliRoot.git] / FIT / AliFITReconstructor.cxx
CommitLineData
c1c44db3 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/*********************************************************************
17 * FIT reconstruction and filling ESD
18 * - reconstruct mean time (interation time)
19 * - vertex position
20 * - multiplicity
21 ********************************************************************/
22
23#include <AliESDEvent.h>
24#include "AliLog.h"
25#include "AliFITRecPoint.h"
26#include "AliFITDigit.h"
27#include "AliFITReconstructor.h"
28#include "AliESDFIT.h"
29#include "AliLog.h"
30#include "AliESDRun.h"
31#include "AliFITRawReader.h"
32
33#include <TArrayI.h>
34#include <TGraph.h>
35#include <TMath.h>
36#include <Riostream.h>
37
38ClassImp(AliFITReconstructor)
39
40AliFITReconstructor:: AliFITReconstructor(): AliReconstructor(),
41 fESD(NULL),
42 fESDFIT(NULL)
43
44{
45
46 //constructor
47
48
49 fESDFIT = new AliESDFIT();
50
51
52}
53//_____________________________________________________________________________
54void AliFITReconstructor::Init()
55{
56// initializer
57
58 fESDFIT = new AliESDFIT;
59 }
60
61//______________________________________________________________________
62void AliFITReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
63{
64// converts RAW to digits
65 cout<<" AliFITReconstructor::ConvertDigits "<<rawReader<<" "<<digitsTree<<endl;
66 if (!digitsTree) {
67 AliError("No digits tree!");
68 return;
69 }
70
71 fDigits = new TClonesArray ("AliFITDigit", 100);
72 digitsTree->Branch("FIT", &fDigits);
73
74 AliFITRawReader myrawreader(rawReader);
75 if (myrawreader.Next())
76 {
77 Int_t allData[500];
78 for (Int_t i=0; i<500; i++) allData[i]=0;
79 for (Int_t i=0; i<500; i++)
80 if(myrawreader.GetData(i)>0) {
81 allData[i]=myrawreader.GetData(i);
82 }
83
84 Int_t timeCFD, timeLED, timeQT1, timeQT0;
85 for (Int_t ipmt=0; ipmt<160; ipmt++) {
86 if(allData[ipmt]>0) {
87 timeCFD = allData[ipmt];
88 timeLED = allData[ipmt];
89 timeQT0= allData[ipmt+160];
90 timeQT1 = allData[ipmt+320];
91 //add digit
92 new((*fDigits)[fDigits->GetEntriesFast()] )
93 AliFITDigit( ipmt,timeCFD, timeLED, timeQT0, timeQT1, 0);
94 }
95 }
96
97
98
99 digitsTree->Fill();
100 }
101
102
103}
104
105 //____________________________________________________________
106void AliFITReconstructor::FillESD(TTree *digitsTree, TTree *clustersTree, AliESDEvent *pESD) const
107{
108
109 /***************************************************
110 Resonstruct digits to vertex position
111 ****************************************************/
112
113 AliDebug(1,Form("Start FillESD FIT"));
114 if(!pESD) {
115 AliError("No ESD Event");
116 return;
117 }
118
119 Float_t channelWidth = 24.4;
120 Float_t c = 0.0299792458; // cm/ps
121 Float_t currentVertex=0, shift=0;
122 Int_t ncont=-1;
123 /* const AliESDVertex* vertex = pESD->GetPrimaryVertex();
124 if (!vertex) vertex = pESD->GetPrimaryVertexSPD();
125 if (!vertex) vertex = pESD->GetPrimaryVertexTPC();
126 if (!vertex) vertex = pESD->GetVertex();
127
128 if (vertex) {
129 AliDebug(2, Form("Got %s (%s) from ESD: %f",
130 vertex->GetName(), vertex->GetTitle(), vertex->GetZ()));
131 currentVertex = vertex->GetZ();
132
133 ncont = vertex->GetNContributors();
134 if(ncont>0 ) {
135 shift = currentVertex/c;
136 }
137 } //vertex
138
139 */
140 // FIT digits reconstruction
141
142 if (!digitsTree) {
143 AliError("No digits tree!");
144 return;
145 }
146
147 fDigits = new TClonesArray("AliFITDigit", 100);
148 // digitsTree->Print();
149 TBranch *brDigits=digitsTree->GetBranch("FIT");
150 if (brDigits)
151 brDigits->SetAddress(&fDigits);
152 else {
153 AliError("no FIT branch");
154 return;
155 }
156 const Float_t max_time = 1e7;
157 Int_t pmt=-1;
158 Float_t time[160],amp[160];
159 for(Int_t i=0; i<160; i++) { time[i]=max_time; amp[i]=0;}
160
161 Int_t nEntries = (Int_t)digitsTree->GetEntries();
162 for (Int_t iev=0; iev<nEntries; iev++) {
163 digitsTree->GetEvent(iev,1);
164 brDigits->GetEvent(iev);
165 Int_t nDigits = fDigits->GetEntriesFast();
166 for (Int_t dig=0; dig<nDigits; dig++) {
167 AliFITDigit* digit = (AliFITDigit*) fDigits->At(dig);
168 pmt = digit->NPMT();
169 time[pmt] = Float_t (digit->TimeCFD() );
170 amp[pmt] = Float_t (digit->TimeQT1() - digit->TimeQT0() );
171 }
172 fESDFIT->SetFITtime(time); // best TOF on each PMT
173 fESDFIT->SetFITamplitude(amp); // number of particles(MIPs) on each
174
175 Float_t firsttime[3] = {max_time,max_time,max_time};
176
177 Float_t vertexFIT = 9999999;
178 for (Int_t ipmt=0; ipmt<80; ipmt++)//timeC
179 if(time[ipmt]<firsttime[2]) firsttime[2]=time[ipmt];
180
181 for ( Int_t ipmt=80; ipmt<160; ipmt++)
182 if(time[ipmt]<firsttime[1]) firsttime[1]=time[ipmt];
183
184
185 AliDebug(5,Form("1stimeA %f , 1sttimeC %f ",
186 firsttime[1],
187 firsttime[2] ) );
188 if (firsttime[1]<max_time && firsttime[2]<max_time) {
189 firsttime[0] = channelWidth *(firsttime[1] + firsttime[2])/2;
190 vertexFIT = c*channelWidth*(firsttime[1] - firsttime[2])/2;
191 }
192 if (firsttime[1]<max_time)
193 firsttime[1] = firsttime[1] * channelWidth + shift;
194
195 if (firsttime[2]<max_time)
196 firsttime[2] = firsttime[2] * channelWidth - shift;
197
198
199
200 for(Int_t i=0; i<3; i++) {
201 fESDFIT->SetFITT0(i,firsttime[i]); // interaction time (ns)
202 }
203 fESDFIT->SetFITzVertex(vertexFIT); //vertex Z position
204
205
206 AliDebug(1,Form("FIT: SPDshift %f Vertex %f FITsignal %f ps FITA %f ps FITC %f ps \n",shift, vertexFIT, firsttime[0], firsttime[1],firsttime[2]));
207 }
208
209 }