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