]> git.uio.no Git - u/mrichter/AliRoot.git/blob - T0/AliT0.cxx
Now uses the simplified interface of RawStreamTracker to loop over raw data
[u/mrichter/AliRoot.git] / T0 / AliT0.cxx
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>
50 #include <AliESD.h>
51
52 #include "AliLog.h"
53 #include "AliMC.h"
54 #include "AliLoader.h"
55 #include "AliRun.h"
56 #include "TClonesArray.h"
57 #include "AliT0.h"
58 #include "AliT0Loader.h"
59 #include "AliT0digit.h"
60 #include "AliT0hit.h"
61 #include "AliT0Digitizer.h"
62 #include "AliT0RawData.h"
63 #include "AliT0RecPoint.h"
64 #include "AliT0Parameters.h"
65 #include "AliLog.h"
66
67 ClassImp(AliT0)
68
69   //static  AliT0digit *digits; 
70
71 //_____________________________________________________________________________
72 AliT0::AliT0()
73   : AliDetector(), fIdSens(0), fDigits(NULL), fRecPoints(NULL)
74 {
75   //
76   // Default constructor for class AliT0
77   //
78   fIshunt   = 1;
79   fHits     = 0;
80   fDigits   = 0;
81   fRecPoints = 0;
82 }
83  
84 //_____________________________________________________________________________
85 AliT0::AliT0(const char *name, const char *title)
86   : AliDetector(name,title), fIdSens(0), fDigits(new AliT0digit()), fRecPoints(new AliT0RecPoint())
87 {
88   //
89   // Standard constructor for T0 Detector
90   //
91
92   
93   //
94   // Initialise Hit array
95   fHits       = new TClonesArray("AliT0hit",  405);
96   gAlice->GetMCApp()->AddHitList(fHits);
97   //  fDigits    = new AliT0digit();
98   //  fRecPoints = new AliT0RecPoint();
99   fIshunt     =  1;
100   //  fIdSens   =  0;
101   //PH  SetMarkerColor(kRed);
102 }
103
104 //_____________________________________________________________________________
105 AliT0::~AliT0() {
106   
107   if (fHits) {
108     fHits->Delete();
109     delete fHits;
110   }
111   /*
112   if (fDigits) {
113     fDigits->Delete();
114     delete fDigits;
115     cout<<" delete fDigits; "<<endl;
116   }
117   if (fRecPoints) {
118    fRecPoints ->Delete();
119     delete fRecPoints;
120     cout<<" delete fRecPoints; "<<endl;
121   }
122   */ 
123 }
124
125 //_____________________________________________________________________________
126 void AliT0::AddHit(Int_t track, Int_t *vol, Float_t *hits)
127 {
128   //
129   // Add a T0 hit
130   //
131   TClonesArray &lhits = *fHits;
132   new(lhits[fNhits++]) AliT0hit(fIshunt,track,vol,hits);
133 }
134
135
136 //_____________________________________________________________________________
137
138 void AliT0::AddDigit(Int_t besttimeright, Int_t besttimeleft, Int_t meantime, 
139                         Int_t timediff, Int_t sumMult,
140                         TArrayI *timeCFD, TArrayI *qt0, TArrayI *timeLED, TArrayI *qt1)
141 {
142   
143   //  Add a T0 digit to the list.
144  //
145   
146   if (!fDigits) {
147     fDigits = new AliT0digit();
148   }
149   fDigits-> SetTimeBestA(besttimeright);
150   fDigits->SetTimeBestC(besttimeleft);
151   fDigits-> SetMeanTime(meantime);
152   fDigits-> SetDiffTime(timediff);
153   fDigits-> SetSumMult(sumMult);
154   fDigits->SetTimeCFD(*timeCFD);
155   fDigits->SetTimeLED(*timeLED);
156   fDigits->SetQT0(*qt0);
157   fDigits->SetQT1(*qt1);
158 }
159
160
161 //_____________________________________________________________________________
162 void 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 //_____________________________________________________________________________
189 Int_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 //-------------------------------------------------------------------------
199 void 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 //---------------------------------------------------------------------------
219 void 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 //_____________________________________________________________________________
263 void AliT0::ResetHits()
264 {
265   AliDetector::ResetHits();
266   
267 }
268 //____________________________________________________________________
269 void 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 //_____________________________________________________________________________
278 void 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 //_____________________________________________________________________________
308 void 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 //_____________________________________________________________________________
323 AliDigitizer* AliT0::CreateDigitizer(AliRunDigitizer* manager) const
324 {
325   return new AliT0Digitizer(manager);
326 }
327 //____________________________________________________________________________
328 void 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 }
361
362 //____________________________________________________________________________
363 void 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   
400    fDigits->SetTimeCFD(*timeCFD);
401    fDigits->SetQT0(*chargeQT1);
402
403    fDigits->SetTimeLED(*timeLED);
404    fDigits->SetQT1(*chargeQT1);
405
406    fDigits->SetMeanTime(allData[49][0]);
407    fDigits->SetDiffTime(allData[50][0]);
408    fDigits->SetTimeBestA(allData[51][0]);
409    fDigits->SetTimeBestC(allData[52][0]);
410    digitsTree->Fill();
411    fDigits->Write();
412  
413    delete timeCFD ;
414    delete chargeQT0;
415    delete timeLED ;
416    delete chargeQT1;
417
418
419 }