]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TOF/AliTOFMerger.cxx
ec789c67f65c148c88fd8faf4160fe277ae6cb07
[u/mrichter/AliRoot.git] / TOF / AliTOFMerger.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-2000, 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 #include <TTree.h> 
17 #include <TVector.h>
18 #include <TObjArray.h>
19 #include <TFile.h>
20 #include <TDirectory.h>
21
22
23 #include "AliTOFMerger.h"
24 #include "AliTOF.h"
25 #include "AliTOFSDigitizer.h"
26 #include "AliTOFhit.h"
27 #include "AliTOFdigit.h"
28
29 #include "AliRun.h"
30 #include "AliPDG.h"
31
32 #include <stdlib.h>
33 #include <iostream.h>
34 #include <fstream.h>
35
36 ClassImp(AliTOFMerger)
37
38 //___________________________________________
39   AliTOFMerger::AliTOFMerger() 
40 {
41 // Default ctor    
42     fNDigits = 0;
43     fEvNrSig = 0;
44     fEvNrBgr = 0;
45     fMerge =kDigitize;
46     fFnBgr   = 0;
47 }
48
49 //------------------------------------------------------------------------
50 AliTOFMerger::~AliTOFMerger()
51 {
52 // Dtor
53   if(fSDigits)  {
54     fSDigits->Delete();
55     delete fSDigits ;
56     fSDigits = 0;
57   }
58 }
59
60
61 //------------------------------------------------------------------------
62 void AliTOFMerger::Init()
63 {
64 // Initialisation
65     if (fMerge) fBgrFile = InitBgr();
66     
67 }
68
69
70
71 //------------------------------------------------------------------------
72 TFile* AliTOFMerger::InitBgr()
73 {
74 // Initialise background event
75     TFile *file = new TFile(fFnBgr);
76 // add error checking later
77     printf("\n AliTOFMerger has opened %s file with background event \n", fFnBgr);
78     return file;
79 }
80
81 //------------------------------------------------------------------------
82 void AliTOFMerger::Digitise()
83 {
84 // as in FMD
85 // keep galice.root for signal and name differently the file for 
86 // background when add! otherwise the track info for signal will be lost !
87
88
89
90 #ifdef DEBUG
91   cout<<"ALiTOFMerger::>SDigits2Digits start...\n";
92 #endif
93
94   AliTOF* TOF = (AliTOF *) gAlice->GetDetector("TOF") ;
95
96
97   TFile *f1 =0;
98   TTree *TK = gAlice->TreeK();
99   if (TK) f1 = TK->GetCurrentFile();
100
101   gAlice->GetEvent(fEvNrSig) ;
102   
103   if(gAlice->TreeD() == 0)      
104     gAlice->MakeTree("D") ;
105   gAlice->TreeD()->Reset();
106
107   // read and write digits for signal
108    ReadWriteDigit(fEvNrSig);
109
110    if(fMerge){ 
111      // bgr file
112     fBgrFile->cd();
113     // gAlice->TreeS()->Reset();
114     gAlice = (AliRun*)fBgrFile->Get("gAlice");
115     ReadWriteDigit(fEvNrBgr);
116    } //if merge
117
118
119   f1->cd();
120    
121   //Make branch for digits
122   TOF->MakeBranch("D");
123
124   gAlice->TreeD()->Reset();
125   gAlice->TreeD()->Fill();
126   
127   fDigits   = TOF->Digits();
128   
129   gAlice->TreeD()->Write(0,TObject::kOverwrite) ;
130   
131   gAlice->ResetDigits();
132
133 }
134
135 //---------------------------------------------------------------------
136
137 void AliTOFMerger::ReadWriteDigit(Int_t iEvNum)
138 {
139 //
140 // Read Sdigits from the current file and write them in the TreeD
141 //
142   AliTOFdigit* tofsdigit;
143   
144   AliTOF * tofinfile = (AliTOF *) gAlice->GetDetector("TOF") ;
145   
146   gAlice->GetEvent(iEvNum) ;
147   if(gAlice->TreeS()==0) {
148     cout<<" TreeS==0 -> return"<<gAlice->TreeS()<<endl; 
149     return ;}
150   
151   Int_t ndig, k;
152   Int_t    tracks[3];    // track info
153   Int_t    vol[5];       // location for a digit
154   Float_t  digit[2];     // TOF digit variables
155
156   gAlice->ResetDigits();
157   gAlice->TreeS()->GetEvent(iEvNum);
158   TClonesArray * TOFdigits   = tofinfile->SDigits();
159   
160   ndig=TOFdigits->GetEntries();
161
162   for (k=0; k<ndig; k++) {
163     tofsdigit= (AliTOFdigit*) TOFdigits->UncheckedAt(k);
164
165         tracks[0] = tofsdigit->GetTrack(0);
166         tracks[1] = tofsdigit->GetTrack(1);
167         tracks[2] = tofsdigit->GetTrack(2);
168
169         vol[0] = tofsdigit->GetSector();
170         vol[1] = tofsdigit->GetPlate();
171         vol[2] = tofsdigit->GetPadx();
172         vol[3] = tofsdigit->GetPadz();
173         vol[4] = tofsdigit->GetStrip();
174
175         digit[0] = tofsdigit->GetTdc();
176         digit[1] = tofsdigit->GetAdc();
177
178         new ((*fDigits)[fNDigits++]) AliTOFdigit(tracks, vol, digit);
179   } // end loop on sdigits in the current file
180 }
181
182
183