bug fixed
[u/mrichter/AliRoot.git] / T0 / AliT0.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///////////////////////////////////////////////////////////////////////////////
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 <Riostream.h>
41
42#include <TFile.h>
43#include <TGeometry.h>
44#include <TMath.h>
45#include <TNode.h>
46#include <TParticle.h>
47#include <TRandom.h>
48#include <TTUBE.h>
49#include <TVirtualMC.h>
dc7ca31d 50
51#include "AliLog.h"
52#include "AliMC.h"
53#include "AliLoader.h"
54#include "AliRun.h"
55#include "TClonesArray.h"
56#include "AliT0.h"
57#include "AliT0Loader.h"
58#include "AliT0digit.h"
59#include "AliT0hit.h"
60#include "AliT0Digitizer.h"
61#include "AliT0RawData.h"
62#include "AliT0RecPoint.h"
e0bba6cc 63#include "AliT0Parameters.h"
dc7ca31d 64#include "AliLog.h"
65
66ClassImp(AliT0)
67
68 //static AliT0digit *digits;
69
70//_____________________________________________________________________________
71AliT0::AliT0()
72 : AliDetector(), fIdSens(0), fDigits(NULL), fRecPoints(NULL)
73{
74 //
75 // Default constructor for class AliT0
76 //
77 fIshunt = 1;
78 fHits = 0;
79 fDigits = 0;
80 fRecPoints = 0;
81}
82
83//_____________________________________________________________________________
84AliT0::AliT0(const char *name, const char *title)
85 : AliDetector(name,title), fIdSens(0), fDigits(new AliT0digit()), fRecPoints(new AliT0RecPoint())
86{
87 //
88 // Standard constructor for T0 Detector
89 //
90
91
92 //
93 // Initialise Hit array
94 fHits = new TClonesArray("AliT0hit", 405);
95 gAlice->GetMCApp()->AddHitList(fHits);
96 // fDigits = new AliT0digit();
97 // fRecPoints = new AliT0RecPoint();
98 fIshunt = 1;
99 // fIdSens = 0;
100 //PH SetMarkerColor(kRed);
101}
102
103//_____________________________________________________________________________
104AliT0::~AliT0() {
105
106 if (fHits) {
107 fHits->Delete();
108 delete fHits;
109 }
110 /*
111 if (fDigits) {
112 fDigits->Delete();
113 delete fDigits;
114 cout<<" delete fDigits; "<<endl;
115 }
116 if (fRecPoints) {
117 fRecPoints ->Delete();
118 delete fRecPoints;
119 cout<<" delete fRecPoints; "<<endl;
120 }
121 */
122}
123
124//_____________________________________________________________________________
125void AliT0::AddHit(Int_t track, Int_t *vol, Float_t *hits)
126{
127 //
128 // Add a T0 hit
129 //
130 TClonesArray &lhits = *fHits;
131 new(lhits[fNhits++]) AliT0hit(fIshunt,track,vol,hits);
132}
133
134
135//_____________________________________________________________________________
136
137void AliT0::AddDigit(Int_t besttimeright, Int_t besttimeleft, Int_t meantime,
740f0839 138 Int_t timediff, Int_t sumMult, Int_t refpoint,
c41ceaac 139 TArrayI *timeCFD, TArrayI *qt0, TArrayI *timeLED, TArrayI *qt1)
dc7ca31d 140{
141
142 // Add a T0 digit to the list.
143 //
144
145 if (!fDigits) {
146 fDigits = new AliT0digit();
147 }
c41ceaac 148 fDigits-> SetTimeBestA(besttimeright);
149 fDigits->SetTimeBestC(besttimeleft);
dc7ca31d 150 fDigits-> SetMeanTime(meantime);
151 fDigits-> SetDiffTime(timediff);
152 fDigits-> SetSumMult(sumMult);
c41ceaac 153 fDigits->SetTimeCFD(*timeCFD);
154 fDigits->SetTimeLED(*timeLED);
155 fDigits->SetQT0(*qt0);
156 fDigits->SetQT1(*qt1);
740f0839 157 fDigits->SetRefPoint(refpoint);
dc7ca31d 158}
159
160
161//_____________________________________________________________________________
162void AliT0::BuildGeometry()
163{
164 //
165 // Build simple ROOT TNode geometry for event display
166 //
167 TNode *node, *top;
168 const int kColorT0 = 19;
169
170 top=gAlice->GetGeometry()->GetNode("alice");
171
172 // T0 define the different volumes
173 new TRotMatrix("rotx999","rot999", 90,0,90,90,180,0);
174
175 new TTUBE("S_0ST1","T0 volume 1","void",5.,10.7,5.3);
176 top->cd();
177 node = new TNode("0ST1","0ST01","S_0ST1",0,0,-69.7,"");
178 node->SetLineColor(kColorT0);
179 fNodes->Add(node);
180
181 new TTUBE("S_0ST2","T0 volume 2","void",5.,10.7,5.3);
182 top->cd();
183 node = new TNode("0ST2","0ST2","S_0ST2",0,0,350,"rotx999");
184 node->SetLineColor(kColorT0);
185 fNodes->Add(node);
186}
187
188//_____________________________________________________________________________
189Int_t AliT0::DistanceToPrimitive(Int_t /*px*/, Int_t /*py*/)
190{
191 //
192 // Calculate the distance from the mouse to the T0 on the screen
193 // Dummy routine
194 //
195 return 9999;
196}
197
198//-------------------------------------------------------------------------
199void AliT0::Init()
200{
201 //
202 // Initialis the T0 after it has been built
203 Int_t i;
204 //
205 if(AliLog::GetGlobalDebugLevel()>0) {
206 printf("\n%s: ",ClassName());
207 for(i=0;i<35;i++) printf("*");
208 printf(" T0_INIT ");
209 for(i=0;i<35;i++) printf("*");
210 printf("\n%s: ",ClassName());
211 //
212 // Here the T0 initialisation code (if any!)
213 for(i=0;i<80;i++) printf("*");
214 printf("\n");
215 }
216}
217
218//---------------------------------------------------------------------------
219void AliT0::MakeBranch(Option_t* option)
220{
221 //
222// Create Tree branches for the T0.
223
224 // Options:
225 //
226 // H Make a branch of TClonesArray of AliT0Hit's
227 // D Make a branch of TClonesArray of AliT0Digit's
228 //
229 // R Make a branch of AliT0RecPoints
230 //
231 char branchname[20];
232 sprintf(branchname,"%s",GetName());
233
234 const char *cH = strstr(option,"H");
235 const char *cD = strstr(option,"D");
236 const char *cR = strstr(option,"R");
237
238 if (cH && fLoader->TreeH())
239 {
240 if (fHits == 0x0) fHits = new TClonesArray("AliT0hit", 405);
241 AliDetector::MakeBranch(option);
242 }
243
244
245 if (cD && fLoader->TreeD())
246 {
247 if (fDigits == 0x0) fDigits = new AliT0digit();
248 // MakeBranchInTree(fLoader->TreeD(), branchname,
249 // &fDigits, 405, 0);
250 fLoader->TreeD()->Branch(branchname,"AliT0digit",&fDigits,405,1);
251 // fLoader->TreeD()->Print();
252 }
253 if (cR && fLoader->TreeR())
254 {
255 if (fRecPoints == 0x0) fRecPoints = new AliT0RecPoint();
256 MakeBranchInTree(fLoader->TreeR(), branchname,
257 &fRecPoints, 405, 0);
258 }
259
260}
261
262//_____________________________________________________________________________
263void AliT0::ResetHits()
264{
265 AliDetector::ResetHits();
266
267}
268//____________________________________________________________________
269void AliT0::ResetDigits()
270{
271 //
272 // Reset number of digits and the digits array for this detector
273 //
274 if (fDigits) fDigits->Clear();
275}
276
277//_____________________________________________________________________________
278void AliT0::SetTreeAddress()
279{
280
281 TTree *treeH;
282 treeH = TreeH();
283
284 if (treeH)
285 {
286 if (fHits == 0x0) fHits = new TClonesArray("AliT0hit", 405);
287 }
288
289 AliDetector::SetTreeAddress();
290 TTree *treeD = fLoader->TreeD();
291 if (treeD) {
292 if (fDigits == 0x0) fDigits = new AliT0digit();
293 TBranch* branch = treeD->GetBranch ("T0");
294 if (branch) branch->SetAddress(&fDigits);
295 }
296
297 TTree *treeR = fLoader->TreeR();
298 if (treeR) {
299 if (fRecPoints == 0x0) fRecPoints = new AliT0RecPoint() ;
300 TBranch* branch = treeR->GetBranch ("T0");
301 if (branch) branch->SetAddress(&fRecPoints);
302 }
303
304}
305
306
307//_____________________________________________________________________________
308void AliT0::MakeBranchInTreeD(TTree *treeD, const char *file)
309{
310 //
311 // Create TreeD branches for the FMD
312 //
313 const Int_t kBufferSize = 4000;
314 char branchname[20];
315 sprintf(branchname,"%s",GetName());
316 if(treeD)
317 {
318 MakeBranchInTree(treeD, branchname,&fDigits, kBufferSize, file);
319 }
320}
321
322//_____________________________________________________________________________
323AliDigitizer* AliT0::CreateDigitizer(AliRunDigitizer* manager) const
324{
325 return new AliT0Digitizer(manager);
326}
327//____________________________________________________________________________
328void AliT0::Digits2Raw()
329{
330//
331// Starting from the T0 digits, writes the Raw Data objects
332//
333// AliT0Loader* pStartLoader = (AliT0Loader*)fLoader;
334 fLoader ->LoadDigits("read");
335 TTree* treeD = fLoader->TreeD();
336 if (!treeD) {
337 AliError("no digits tree");
338 return;
339 }
340 if (fDigits == 0x0) fDigits = new AliT0digit();
341
342 TBranch *branch = treeD->GetBranch("T0");
343 if (branch) {
344 branch->SetAddress(&fDigits);
345 }else{
346 AliError("Branch T0 DIGIT not found");
347 exit(111);
348 }
349 AliT0RawData rawWriter;
350 rawWriter.SetVerbose(0);
351
352 AliDebug(2,Form(" Formatting raw data for T0 "));
353 branch->GetEntry(0);
354 // rawWriter.RawDataT0(treeD->GetBranch("T0"));
355 rawWriter.RawDataT0(fDigits);
356
357
358 fLoader->UnloadDigits();
359
360}
e0bba6cc 361
362//____________________________________________________________________________
363void AliT0::Raw2Digits(AliRawReader *rawReader,TTree* digitsTree)
364{
365
366 //T0 raw data-> digits conversion
367 // reconstruct time information from raw data
368 // cout<<" AliT0::Raw2Digits(AliRawReader *rawReader,TTree* digitsTree) "<<
369 // rawReader<<" "<<digitsTree<<endl;
370
371
372 // AliT0RawReader myrawreader(rawReader,digitsTree);
373 AliT0RawReader myrawreader(rawReader);
374 if (!myrawreader.Next())
375 AliDebug(1,Form(" no raw data found!! %i", myrawreader.Next()));
376 Int_t allData[110][5];
377 for (Int_t i=0; i<110; i++) {
378 allData[i][0]=myrawreader.GetData(i,0);
379 }
380
381
382 AliT0digit* fDigits = new AliT0digit();
383 digitsTree->Branch("T0","AliT0digit",&fDigits,405,1);
384
385
386 TArrayI *timeLED = new TArrayI(24);
387 TArrayI * timeCFD = new TArrayI(24);
388 TArrayI *chargeQT0 = new TArrayI(24);
389 TArrayI *chargeQT1 = new TArrayI(24);
390
391 for (Int_t in=0; in<24; in++)
392 {
393 timeLED->AddAt(allData[in+1][0],in);
394 timeCFD->AddAt(allData[in+25][0],in);
395 chargeQT0->AddAt(allData[in+55][0],in);
396 chargeQT1->AddAt(allData[in+79][0],in);
397 AliDebug(2, Form(" readed Raw %i %i %i %i %i", in, timeLED->At(in),timeCFD->At(in),chargeQT0->At(in),chargeQT1->At(in)));
398 }
399
c41ceaac 400 fDigits->SetTimeCFD(*timeCFD);
401 fDigits->SetQT0(*chargeQT1);
e0bba6cc 402
c41ceaac 403 fDigits->SetTimeLED(*timeLED);
404 fDigits->SetQT1(*chargeQT1);
e0bba6cc 405
406 fDigits->SetMeanTime(allData[49][0]);
407 fDigits->SetDiffTime(allData[50][0]);
c41ceaac 408 fDigits->SetTimeBestA(allData[51][0]);
409 fDigits->SetTimeBestC(allData[52][0]);
e0bba6cc 410 digitsTree->Fill();
411 fDigits->Write();
412
413 delete timeCFD ;
414 delete chargeQT0;
415 delete timeLED ;
416 delete chargeQT1;
417
418
419}