Line data Source code
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 : ///////////////////////////////////////////////////////////////////////////////
19 : // //
20 : // T0 (T-Zero) Detector //
21 : // This class contains the base procedures for the T0 //
22 : // detector //
23 : // //
24 : //Begin_Html
25 : /*
26 : <img src="gif/AliT0Class.gif">
27 : </pre>
28 : <br clear=left>
29 : <font size=+2 color=red>
30 : <p>The responsible person for this module is
31 : <a href="mailto:Alla.Maevskaia@cern.ch">Alla Maevskaia</a>.
32 : </font>
33 : <pre>
34 : */
35 : //End_Html
36 : // //
37 : // //
38 : ///////////////////////////////////////////////////////////////////////////////
39 :
40 : #include "TClonesArray.h"
41 : #include "TString.h"
42 :
43 : #include "AliLoader.h"
44 : #include "AliLog.h"
45 : #include "AliLog.h"
46 : #include "AliMC.h"
47 : #include "AliRun.h"
48 : #include "AliT0.h"
49 : #include "AliT0Digitizer.h"
50 : #include "AliT0RawData.h"
51 : #include "AliT0RecPoint.h"
52 : #include "AliT0digit.h"
53 : #include "AliT0hit.h"
54 20 : ClassImp(AliT0)
55 :
56 : //static AliT0digit *digits;
57 :
58 : //_____________________________________________________________________________
59 : AliT0::AliT0()
60 24 : : AliDetector(), fIdSens(0), fDigits(NULL), fRecPoints(NULL)
61 36 : {
62 : //
63 : // Default constructor for class AliT0
64 : //
65 12 : fIshunt = 1;
66 12 : fHits = 0;
67 12 : fDigits = 0;
68 12 : fRecPoints = 0;
69 12 : }
70 :
71 : //_____________________________________________________________________________
72 : AliT0::AliT0(const char *name, const char *title)
73 6 : : AliDetector(name,title), fIdSens(0), fDigits(new AliT0digit()), fRecPoints(new AliT0RecPoint())
74 3 : {
75 : //
76 : // Standard constructor for T0 Detector
77 : //
78 :
79 :
80 : //
81 : // Initialise Hit array
82 3 : fHits = new TClonesArray("AliT0hit", 405);
83 1 : gAlice->GetMCApp()->AddHitList(fHits);
84 : // fDigits = new AliT0digit();
85 : // fRecPoints = new AliT0RecPoint();
86 1 : fIshunt = 1;
87 : // fIdSens = 0;
88 : //PH SetMarkerColor(kRed);
89 1 : }
90 :
91 : //_____________________________________________________________________________
92 26 : AliT0::~AliT0() {
93 :
94 : //destructor
95 13 : if (fHits) {
96 3 : fHits->Delete();
97 6 : delete fHits;
98 : }
99 : /*
100 : if (fDigits) {
101 : fDigits->Delete();
102 : delete fDigits;
103 : cout<<" delete fDigits; "<<endl;
104 : }
105 : if (fRecPoints) {
106 : fRecPoints ->Delete();
107 : delete fRecPoints;
108 : cout<<" delete fRecPoints; "<<endl;
109 : }
110 : */
111 13 : }
112 :
113 : //_____________________________________________________________________________
114 : void AliT0::AddHit(Int_t track, Int_t *vol, Float_t *hits)
115 : {
116 : //
117 : // Add a T0 hit
118 : //
119 5488 : TClonesArray &lhits = *fHits;
120 2744 : new(lhits[fNhits++]) AliT0hit(fIshunt,track,vol,hits);
121 2744 : }
122 :
123 :
124 : //_____________________________________________________________________________
125 :
126 : void AliT0::AddDigit(Int_t besttimeright, Int_t besttimeleft, Int_t meantime,
127 : Int_t timediff, Int_t sumMult, Int_t refpoint,
128 : TArrayI *timeCFD, TArrayI *qt0, TArrayI *timeLED, TArrayI *qt1)
129 : {
130 :
131 : // Add a T0 digit to the list.
132 : //
133 :
134 8 : if (!fDigits) {
135 0 : fDigits = new AliT0digit();
136 0 : }
137 4 : fDigits-> SetTimeBestA(besttimeright);
138 4 : fDigits->SetTimeBestC(besttimeleft);
139 4 : fDigits-> SetMeanTime(meantime);
140 4 : fDigits-> SetDiffTime(timediff);
141 4 : fDigits-> SetSumMult(sumMult);
142 4 : fDigits->SetTimeCFD(*timeCFD);
143 4 : fDigits->SetTimeLED(*timeLED);
144 4 : fDigits->SetQT0(*qt0);
145 4 : fDigits->SetQT1(*qt1);
146 4 : fDigits->SetRefPoint(refpoint);
147 4 : }
148 :
149 : //-------------------------------------------------------------------------
150 : void AliT0::Init()
151 : {
152 : //
153 : // Initialis the T0 after it has been built
154 : Int_t i;
155 : //
156 2 : if(AliLog::GetGlobalDebugLevel()>0) {
157 0 : printf("\n%s: ",ClassName());
158 0 : for(i=0;i<35;i++) printf("*");
159 0 : printf(" T0_INIT ");
160 0 : for(i=0;i<35;i++) printf("*");
161 0 : printf("\n%s: ",ClassName());
162 : //
163 : // Here the T0 initialisation code (if any!)
164 0 : for(i=0;i<80;i++) printf("*");
165 0 : printf("\n");
166 0 : }
167 1 : }
168 :
169 : //---------------------------------------------------------------------------
170 : void AliT0::MakeBranch(Option_t* option)
171 : {
172 : //
173 : // Create Tree branches for the T0.
174 :
175 : // Options:
176 : //
177 : // H Make a branch of TClonesArray of AliT0Hit's
178 : // D Make a branch of TClonesArray of AliT0Digit's
179 : //
180 : // R Make a branch of AliT0RecPoints
181 : //
182 : // char branchname[20];
183 : // sprintf(branchname,"%s",GetName());
184 : // strncpy(branchname, GetName(), 20);
185 16 : TString branchname = Form("%s", GetName());
186 :
187 8 : const char *cH = strstr(option,"H");
188 8 : const char *cD = strstr(option,"D");
189 8 : const char *cR = strstr(option,"R");
190 8 : const char *cS = strstr(option,"S");
191 :
192 16 : if (cH && fLoader->TreeH())
193 : {
194 4 : if (fHits == 0x0) fHits = new TClonesArray("AliT0hit", 405);
195 4 : AliDetector::MakeBranch(option);
196 : }
197 :
198 :
199 16 : if (cD && fLoader->TreeD())
200 : {
201 4 : if (fDigits == 0x0) fDigits = new AliT0digit();
202 : // MakeBranchInTree(fLoader->TreeD(), branchname,
203 : // &fDigits, 405, 0);
204 12 : fLoader->TreeD()->Branch(branchname.Data(),"AliT0digit",&fDigits);
205 : // fLoader->TreeD()->Print();
206 : }
207 8 : if (cR && fLoader->TreeR())
208 : {
209 0 : if (fRecPoints == 0x0) fRecPoints = new AliT0RecPoint();
210 0 : MakeBranchInTree(fLoader->TreeR(), branchname, &fRecPoints);
211 : }
212 8 : if (cS && fLoader->TreeS())
213 : {
214 0 : if (fDigits == 0x0) fDigits = new AliT0digit();
215 : // MakeBranchInTree(fLoader->TreeD(), branchname,
216 : // &fDigits, 405, 0);
217 0 : fLoader->TreeS()->Branch(branchname,"AliT0digit",&fDigits);
218 : // fLoader->TreeD()->Print();
219 : }
220 :
221 8 : }
222 :
223 : //_____________________________________________________________________________
224 : void AliT0::ResetHits()
225 : {
226 : //
227 : //reset hits
228 : //
229 904 : AliDetector::ResetHits();
230 :
231 452 : }
232 : //____________________________________________________________________
233 : void AliT0::ResetDigits()
234 : {
235 : //
236 : // Reset number of digits and the digits array for this detector
237 : //
238 12 : if (fDigits) fDigits->Clear();
239 4 : }
240 :
241 : //_____________________________________________________________________________
242 : void AliT0::SetTreeAddress()
243 : {
244 :
245 330 : TTree *treeH = fLoader->TreeH();
246 :
247 165 : if (treeH)
248 : {
249 28 : if (fHits == 0x0) fHits = new TClonesArray("AliT0hit", 405);
250 : }
251 :
252 165 : AliDetector::SetTreeAddress();
253 165 : TTree *treeD = fLoader->TreeD();
254 165 : if (treeD) {
255 41 : if (fDigits == 0x0) fDigits = new AliT0digit();
256 41 : TBranch* branch = treeD->GetBranch ("T0");
257 82 : if (branch) branch->SetAddress(&fDigits);
258 41 : }
259 :
260 165 : TTree *treeR = fLoader->TreeR();
261 165 : if (treeR) {
262 16 : if (fRecPoints == 0x0) fRecPoints = new AliT0RecPoint() ;
263 16 : TBranch* branch = treeR->GetBranch ("T0");
264 28 : if (branch) branch->SetAddress(&fRecPoints);
265 16 : }
266 : // SDigitizer for Federico
267 165 : TTree *treeS = fLoader->TreeS();
268 165 : if (treeS) {
269 0 : if (fDigits == 0x0) fDigits = new AliT0digit();
270 0 : TBranch* branch = treeS->GetBranch ("T0");
271 0 : if (branch) branch->SetAddress(&fDigits);
272 0 : }
273 :
274 165 : }
275 :
276 :
277 : //_____________________________________________________________________________
278 : void AliT0::MakeBranchInTreeD(TTree *treeD, const char *file)
279 : {
280 : //
281 : // Create TreeD branches for the FMD
282 : //
283 : const Int_t kBufferSize = 4000;
284 : // char branchname[20];
285 : // strncpy(branchname, GetName(), 20);
286 0 : TString branchname = Form("%s", GetName());
287 : // sprintf(branchname,"%s",GetName());
288 0 : if(treeD)
289 : {
290 0 : MakeBranchInTree(treeD, branchname.Data(),&fDigits, kBufferSize, file);
291 : }
292 0 : }
293 :
294 : //_____________________________________________________________________________
295 : AliDigitizer* AliT0::CreateDigitizer(AliDigitizationInput* digInput) const
296 : {
297 3 : return new AliT0Digitizer(digInput);
298 0 : }
299 : //____________________________________________________________________________
300 : void AliT0::Digits2Raw()
301 : {
302 : //
303 : // Starting from the T0 digits, writes the Raw Data objects
304 : //
305 : // AliT0Loader* pStartLoader = (AliT0Loader*)fLoader;
306 8 : fLoader ->LoadDigits("read");
307 4 : TTree* treeD = fLoader->TreeD();
308 4 : if (!treeD) {
309 0 : AliError("no digits tree");
310 0 : return;
311 : }
312 4 : if (fDigits == 0x0) fDigits = new AliT0digit();
313 :
314 4 : TBranch *branch = treeD->GetBranch("T0");
315 4 : if (branch) {
316 4 : branch->SetAddress(&fDigits);
317 : }else{
318 0 : AliError("Branch T0 DIGIT not found");
319 0 : exit(111);
320 : }
321 4 : AliT0RawData rawWriter;
322 4 : rawWriter.SetVerbose(0);
323 :
324 20 : AliDebug(2,Form(" Formatting raw data for T0 "));
325 4 : branch->GetEntry(0);
326 : // rawWriter.RawDataT0(treeD->GetBranch("T0"));
327 4 : rawWriter.RawDataT0(fDigits);
328 :
329 :
330 4 : fLoader->UnloadDigits();
331 :
332 8 : }
333 :
334 : //____________________________________________________________________________
335 : void AliT0::Raw2Digits(AliRawReader *rawReader,TTree* digitsTree)
336 : {
337 :
338 : //T0 raw data-> digits conversion
339 : // reconstruct time information from raw data
340 : // cout<<" AliT0::Raw2Digits(AliRawReader *rawReader,TTree* digitsTree) "<<
341 : // rawReader<<" "<<digitsTree<<endl;
342 :
343 :
344 : // AliT0RawReader myrawreader(rawReader,digitsTree);
345 0 : AliT0RawReader myrawreader(rawReader);
346 0 : if (!myrawreader.Next())
347 0 : AliDebug(1,Form(" no raw data found!! %i", myrawreader.Next()));
348 0 : Int_t allData[110][5];
349 0 : for (Int_t i=0; i<110; i++) {
350 0 : allData[i][0]=myrawreader.GetData(i,0);
351 : }
352 :
353 :
354 0 : fDigits = new AliT0digit();
355 0 : digitsTree->Branch("T0","AliT0digit",&fDigits);
356 :
357 :
358 0 : TArrayI *timeLED = new TArrayI(24);
359 0 : TArrayI * timeCFD = new TArrayI(24);
360 0 : TArrayI *chargeQT0 = new TArrayI(24);
361 0 : TArrayI *chargeQT1 = new TArrayI(24);
362 :
363 0 : for (Int_t in=0; in<24; in++)
364 : {
365 0 : timeLED->AddAt(allData[in+1][0],in);
366 0 : timeCFD->AddAt(allData[in+25][0],in);
367 0 : chargeQT0->AddAt(allData[in+55][0],in);
368 0 : chargeQT1->AddAt(allData[in+79][0],in);
369 0 : AliDebug(2, Form(" readed Raw %i %i %i %i %i", in, timeLED->At(in),timeCFD->At(in),chargeQT0->At(in),chargeQT1->At(in)));
370 : }
371 :
372 0 : fDigits->SetTimeCFD(*timeCFD);
373 0 : fDigits->SetQT0(*chargeQT1);
374 :
375 0 : fDigits->SetTimeLED(*timeLED);
376 0 : fDigits->SetQT1(*chargeQT1);
377 :
378 0 : fDigits->SetMeanTime(allData[49][0]);
379 0 : fDigits->SetDiffTime(allData[50][0]);
380 0 : fDigits->SetTimeBestA(allData[51][0]);
381 0 : fDigits->SetTimeBestC(allData[52][0]);
382 0 : digitsTree->Fill();
383 0 : fDigits->Write();
384 :
385 0 : delete timeCFD ;
386 0 : delete chargeQT0;
387 0 : delete timeLED ;
388 0 : delete chargeQT1;
389 :
390 :
391 0 : }
|