1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 // T0 (T-Zero) Detector //
21 // This class contains the base procedures for the T0 //
26 <img src="gif/AliT0Class.gif">
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>.
38 ///////////////////////////////////////////////////////////////////////////////
40 #include <Riostream.h>
43 #include <TGeometry.h>
46 #include <TParticle.h>
49 #include <TVirtualMC.h>
53 #include "AliLoader.h"
55 #include "TClonesArray.h"
57 #include "AliT0Loader.h"
58 #include "AliT0digit.h"
60 #include "AliT0Digitizer.h"
61 #include "AliT0RawData.h"
62 #include "AliT0RecPoint.h"
63 #include "AliT0Parameters.h"
68 //static AliT0digit *digits;
70 //_____________________________________________________________________________
72 : AliDetector(), fIdSens(0), fDigits(NULL), fRecPoints(NULL)
75 // Default constructor for class AliT0
83 //_____________________________________________________________________________
84 AliT0::AliT0(const char *name, const char *title)
85 : AliDetector(name,title), fIdSens(0), fDigits(new AliT0digit()), fRecPoints(new AliT0RecPoint())
88 // Standard constructor for T0 Detector
93 // Initialise Hit array
94 fHits = new TClonesArray("AliT0hit", 405);
95 gAlice->GetMCApp()->AddHitList(fHits);
96 // fDigits = new AliT0digit();
97 // fRecPoints = new AliT0RecPoint();
100 //PH SetMarkerColor(kRed);
103 //_____________________________________________________________________________
114 cout<<" delete fDigits; "<<endl;
117 fRecPoints ->Delete();
119 cout<<" delete fRecPoints; "<<endl;
124 //_____________________________________________________________________________
125 void AliT0::AddHit(Int_t track, Int_t *vol, Float_t *hits)
130 TClonesArray &lhits = *fHits;
131 new(lhits[fNhits++]) AliT0hit(fIshunt,track,vol,hits);
135 //_____________________________________________________________________________
137 void AliT0::AddDigit(Int_t besttimeright, Int_t besttimeleft, Int_t meantime,
138 Int_t timediff, Int_t sumMult,
139 TArrayI *timeCFD, TArrayI *qt0, TArrayI *timeLED, TArrayI *qt1)
142 // Add a T0 digit to the list.
146 fDigits = new AliT0digit();
148 fDigits-> SetTimeBestA(besttimeright);
149 fDigits->SetTimeBestC(besttimeleft);
150 fDigits-> SetMeanTime(meantime);
151 fDigits-> SetDiffTime(timediff);
152 fDigits-> SetSumMult(sumMult);
153 fDigits->SetTimeCFD(*timeCFD);
154 fDigits->SetTimeLED(*timeLED);
155 fDigits->SetQT0(*qt0);
156 fDigits->SetQT1(*qt1);
160 //_____________________________________________________________________________
161 void AliT0::BuildGeometry()
164 // Build simple ROOT TNode geometry for event display
167 const int kColorT0 = 19;
169 top=gAlice->GetGeometry()->GetNode("alice");
171 // T0 define the different volumes
172 new TRotMatrix("rotx999","rot999", 90,0,90,90,180,0);
174 new TTUBE("S_0ST1","T0 volume 1","void",5.,10.7,5.3);
176 node = new TNode("0ST1","0ST01","S_0ST1",0,0,-69.7,"");
177 node->SetLineColor(kColorT0);
180 new TTUBE("S_0ST2","T0 volume 2","void",5.,10.7,5.3);
182 node = new TNode("0ST2","0ST2","S_0ST2",0,0,350,"rotx999");
183 node->SetLineColor(kColorT0);
187 //_____________________________________________________________________________
188 Int_t AliT0::DistanceToPrimitive(Int_t /*px*/, Int_t /*py*/)
191 // Calculate the distance from the mouse to the T0 on the screen
197 //-------------------------------------------------------------------------
201 // Initialis the T0 after it has been built
204 if(AliLog::GetGlobalDebugLevel()>0) {
205 printf("\n%s: ",ClassName());
206 for(i=0;i<35;i++) printf("*");
208 for(i=0;i<35;i++) printf("*");
209 printf("\n%s: ",ClassName());
211 // Here the T0 initialisation code (if any!)
212 for(i=0;i<80;i++) printf("*");
217 //---------------------------------------------------------------------------
218 void AliT0::MakeBranch(Option_t* option)
221 // Create Tree branches for the T0.
225 // H Make a branch of TClonesArray of AliT0Hit's
226 // D Make a branch of TClonesArray of AliT0Digit's
228 // R Make a branch of AliT0RecPoints
231 sprintf(branchname,"%s",GetName());
233 const char *cH = strstr(option,"H");
234 const char *cD = strstr(option,"D");
235 const char *cR = strstr(option,"R");
237 if (cH && fLoader->TreeH())
239 if (fHits == 0x0) fHits = new TClonesArray("AliT0hit", 405);
240 AliDetector::MakeBranch(option);
244 if (cD && fLoader->TreeD())
246 if (fDigits == 0x0) fDigits = new AliT0digit();
247 // MakeBranchInTree(fLoader->TreeD(), branchname,
248 // &fDigits, 405, 0);
249 fLoader->TreeD()->Branch(branchname,"AliT0digit",&fDigits,405,1);
250 // fLoader->TreeD()->Print();
252 if (cR && fLoader->TreeR())
254 if (fRecPoints == 0x0) fRecPoints = new AliT0RecPoint();
255 MakeBranchInTree(fLoader->TreeR(), branchname,
256 &fRecPoints, 405, 0);
261 //_____________________________________________________________________________
262 void AliT0::ResetHits()
264 AliDetector::ResetHits();
267 //____________________________________________________________________
268 void AliT0::ResetDigits()
271 // Reset number of digits and the digits array for this detector
273 if (fDigits) fDigits->Clear();
276 //_____________________________________________________________________________
277 void AliT0::SetTreeAddress()
285 if (fHits == 0x0) fHits = new TClonesArray("AliT0hit", 405);
288 AliDetector::SetTreeAddress();
289 TTree *treeD = fLoader->TreeD();
291 if (fDigits == 0x0) fDigits = new AliT0digit();
292 TBranch* branch = treeD->GetBranch ("T0");
293 if (branch) branch->SetAddress(&fDigits);
296 TTree *treeR = fLoader->TreeR();
298 if (fRecPoints == 0x0) fRecPoints = new AliT0RecPoint() ;
299 TBranch* branch = treeR->GetBranch ("T0");
300 if (branch) branch->SetAddress(&fRecPoints);
306 //_____________________________________________________________________________
307 void AliT0::MakeBranchInTreeD(TTree *treeD, const char *file)
310 // Create TreeD branches for the FMD
312 const Int_t kBufferSize = 4000;
314 sprintf(branchname,"%s",GetName());
317 MakeBranchInTree(treeD, branchname,&fDigits, kBufferSize, file);
321 //_____________________________________________________________________________
322 AliDigitizer* AliT0::CreateDigitizer(AliRunDigitizer* manager) const
324 return new AliT0Digitizer(manager);
326 //____________________________________________________________________________
327 void AliT0::Digits2Raw()
330 // Starting from the T0 digits, writes the Raw Data objects
332 // AliT0Loader* pStartLoader = (AliT0Loader*)fLoader;
333 fLoader ->LoadDigits("read");
334 TTree* treeD = fLoader->TreeD();
336 AliError("no digits tree");
339 if (fDigits == 0x0) fDigits = new AliT0digit();
341 TBranch *branch = treeD->GetBranch("T0");
343 branch->SetAddress(&fDigits);
345 AliError("Branch T0 DIGIT not found");
348 AliT0RawData rawWriter;
349 rawWriter.SetVerbose(0);
351 AliDebug(2,Form(" Formatting raw data for T0 "));
353 // rawWriter.RawDataT0(treeD->GetBranch("T0"));
354 rawWriter.RawDataT0(fDigits);
357 fLoader->UnloadDigits();
361 //____________________________________________________________________________
362 void AliT0::Raw2Digits(AliRawReader *rawReader,TTree* digitsTree)
365 //T0 raw data-> digits conversion
366 // reconstruct time information from raw data
367 // cout<<" AliT0::Raw2Digits(AliRawReader *rawReader,TTree* digitsTree) "<<
368 // rawReader<<" "<<digitsTree<<endl;
371 // AliT0RawReader myrawreader(rawReader,digitsTree);
372 AliT0RawReader myrawreader(rawReader);
373 if (!myrawreader.Next())
374 AliDebug(1,Form(" no raw data found!! %i", myrawreader.Next()));
375 Int_t allData[110][5];
376 for (Int_t i=0; i<110; i++) {
377 allData[i][0]=myrawreader.GetData(i,0);
381 AliT0digit* fDigits = new AliT0digit();
382 digitsTree->Branch("T0","AliT0digit",&fDigits,405,1);
385 TArrayI *timeLED = new TArrayI(24);
386 TArrayI * timeCFD = new TArrayI(24);
387 TArrayI *chargeQT0 = new TArrayI(24);
388 TArrayI *chargeQT1 = new TArrayI(24);
390 for (Int_t in=0; in<24; in++)
392 timeLED->AddAt(allData[in+1][0],in);
393 timeCFD->AddAt(allData[in+25][0],in);
394 chargeQT0->AddAt(allData[in+55][0],in);
395 chargeQT1->AddAt(allData[in+79][0],in);
396 AliDebug(2, Form(" readed Raw %i %i %i %i %i", in, timeLED->At(in),timeCFD->At(in),chargeQT0->At(in),chargeQT1->At(in)));
399 fDigits->SetTimeCFD(*timeCFD);
400 fDigits->SetQT0(*chargeQT1);
402 fDigits->SetTimeLED(*timeLED);
403 fDigits->SetQT1(*chargeQT1);
405 fDigits->SetMeanTime(allData[49][0]);
406 fDigits->SetDiffTime(allData[50][0]);
407 fDigits->SetTimeBestA(allData[51][0]);
408 fDigits->SetTimeBestC(allData[52][0]);