]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TOF/AliTOFMerger.cxx
b92f7bf7e80f38b18719e30f29bddc595d1ee578
[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 //Piotr.Skowronski@cern.ch :
16 //Corrections applied in order to compile (only) with new I/O and folder structure
17 //To be implemented correctly by responsible
18
19 #include "AliRunLoader.h"
20 #include "AliLoader.h"
21
22 #include <TTree.h> 
23 #include <TVector.h>
24 #include <TObjArray.h>
25 #include <TFile.h>
26 #include <TDirectory.h>
27
28
29 #include "AliTOFMerger.h"
30 #include "AliTOF.h"
31 #include "AliTOFSDigitizer.h"
32 #include "AliTOFhit.h"
33 #include "AliTOFdigit.h"
34
35 #include "AliRun.h"
36 #include "AliPDG.h"
37
38 #include <stdlib.h>
39 #include <Riostream.h>
40 #include <Riostream.h>
41
42 ClassImp(AliTOFMerger)
43
44 //___________________________________________
45   AliTOFMerger::AliTOFMerger() 
46 {
47 // Default ctor    
48     fNDigits = 0;
49     fEvNrSig = 0;
50     fEvNrBgr = 0;
51     fMerge =kDigitize;
52     fDigits = 0;
53     fSDigits =0;
54     fFnBgr = 0;
55     fFnSig = 0;
56     fBgrFile = 0;
57     fRunLoader     = 0 ;
58 }
59
60 //------------------------------------------------------------------------
61 AliTOFMerger::~AliTOFMerger()
62 {
63 // Dtor
64   if(fSDigits)  {
65     fSDigits->Delete();
66     delete fSDigits ;
67     fSDigits = 0;
68   }
69   delete fBgrFile;
70   fBgrFile = 0;
71   if(fFnBgr) {
72     delete[] fFnBgr;
73     fFnBgr = 0;
74   }
75   if(fFnSig) {
76     delete[] fFnSig;
77     fFnSig = 0;
78   }
79   delete fRunLoader;
80 }
81
82
83 //------------------------------------------------------------------------
84 void AliTOFMerger::Init()
85 {
86 // Initialisation
87     if (fMerge) fBgrFile = InitBgr();
88     
89 }
90
91
92
93 //------------------------------------------------------------------------
94 TFile* AliTOFMerger::InitBgr()
95 {
96 // Initialise background event
97    fRunLoader = AliRunLoader::Open(fFnBgr);//open session and mount on default event folder
98    
99     TFile *file = new TFile(fFnBgr);
100 // add error checking later
101     printf("\n AliTOFMerger has opened %s file with background event \n", fFnBgr);
102     return file;
103 }
104
105 //------------------------------------------------------------------------
106 void AliTOFMerger::Digitise()
107 {
108 // as in FMD
109 // keep galice.root for signal and name differently the file for 
110 // background when add! otherwise the track info for signal will be lost !
111
112 #ifdef DEBUG
113   cout<<"ALiTOFMerger::>SDigits2Digits start...\n";
114 #endif
115   Int_t retval;
116
117   if (fRunLoader == 0x0)
118    {
119      Error("Exec","Event is not loaded. Exiting");
120      return;
121    }
122   retval = fRunLoader->LoadgAlice();
123   if (retval)
124    {
125      Error("Exec","Error occured while loading gAlice. Exiting");
126      return;
127    }
128   retval = fRunLoader->LoadHeader();
129   if (retval)
130    {
131      Error("Exec","Error occured while loading header. Exiting");
132      return;
133    }
134
135   retval = fRunLoader->LoadKinematics("READ");
136   if (retval)
137    {
138      Error("Exec","Error occured while loading kinematics. Exiting");
139      return;
140    }
141
142   AliLoader* gime = fRunLoader->GetLoader("TOFLoader");
143   if (gime == 0x0)
144    {
145      Error("Exec","Can not find TOF loader in event. Exiting.");
146      return;
147    }
148   gAlice = fRunLoader->GetAliRun();
149   
150   AliTOF* TOF = (AliTOF *) gAlice->GetDetector("TOF") ;
151
152
153   TFile *f1 =0;
154   TTree *TK = fRunLoader->TreeK();
155   if (TK) f1 = TK->GetCurrentFile();
156
157   fRunLoader->GetEvent(fEvNrSig);
158   
159   if(gime->TreeD() == 0)        
160     gime->MakeTree("D") ;
161   
162   gime->TreeD()->Reset();
163
164   // read and write digits for signal
165    ReadWriteDigit(fEvNrSig);
166
167    if(fMerge)
168     { 
169       // bgr file
170       fBgrFile->cd();
171       // gAlice->TreeS()->Reset();
172       gAlice = (AliRun*)fBgrFile->Get("gAlice");
173       ReadWriteDigit(fEvNrBgr);
174     } //if merge
175
176
177   f1->cd();
178    
179   //Make branch for digits
180   TOF->MakeBranch("D");
181
182   gime->TreeD()->Reset();
183   gime->TreeD()->Fill();
184   
185   fDigits   = TOF->Digits();
186   
187   gime->WriteDigits("OVERWRITE");
188   
189   gAlice->ResetDigits();
190
191 }
192
193 //---------------------------------------------------------------------
194
195 void AliTOFMerger::ReadWriteDigit(Int_t iEvNum)
196 {
197 //
198 // Read Sdigits from the current file and write them in the TreeD
199 //
200   AliTOFdigit* tofsdigit;
201   
202   AliTOF * tofinfile = (AliTOF *) gAlice->GetDetector("TOF") ;
203   
204   Int_t retval = fRunLoader->GetEvent(iEvNum);
205   if (retval)
206    {
207      Error("ReadWriteDigit","Error while getting event %d",iEvNum);
208      return;
209    }
210
211   AliLoader* gime = fRunLoader->GetLoader("TOFLoader");
212   if (gime == 0x0)
213    {
214      Error("Exec","Can not find TOF loader in event. Exiting.");
215      return;
216    }
217   
218   
219   
220   if(gime->TreeS()==0) 
221    {
222     cout<<" TreeS==0 -> return"<<gime->TreeS()<<endl; 
223     return ;
224    }
225   
226   Int_t ndig, k;
227   Int_t    tracks[3];    // track info
228   Int_t    vol[5];       // location for a digit
229   Float_t  digit[2];     // TOF digit variables
230
231   gAlice->ResetDigits();
232   gime->TreeS()->GetEvent(iEvNum);
233   TClonesArray * TOFdigits   = tofinfile->SDigits();
234   
235   ndig=TOFdigits->GetEntries();
236
237   for (k=0; k<ndig; k++) {
238     tofsdigit= (AliTOFdigit*) TOFdigits->UncheckedAt(k);
239
240         tracks[0] = tofsdigit->GetTrack(0);
241         tracks[1] = tofsdigit->GetTrack(1);
242         tracks[2] = tofsdigit->GetTrack(2);
243
244         vol[0] = tofsdigit->GetSector();
245         vol[1] = tofsdigit->GetPlate();
246         vol[2] = tofsdigit->GetStrip();
247         vol[3] = tofsdigit->GetPadx();
248         vol[4] = tofsdigit->GetPadz();
249
250         digit[0] = tofsdigit->GetTdc();
251         digit[1] = tofsdigit->GetAdc();
252
253         new ((*fDigits)[fNDigits++]) AliTOFdigit(tracks, vol, digit);
254   } // end loop on sdigits in the current file
255 }
256
257
258