]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSLoader.cxx
Changes to obey coding conventions
[u/mrichter/AliRoot.git] / ITS / AliITSLoader.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 #include <TClonesArray.h>
19 #include <TClass.h>
20 #include <TGeoManager.h>
21
22 #include "AliITSdigit.h"
23 #include "AliITSLoader.h"
24 #include "AliRunLoader.h"
25 #include "AliITSInitGeometry.h"
26 #include "AliLog.h"
27
28 ///////////////////////////////////////////////////////////////////////////
29 // Loader for ITS
30 // it manages the I/O for:
31 // raw clusters, primary vertices
32 // V0 and cascade
33 // and tracks propagated to the origin
34 //////////////////////////////////////////////////////////////////////////
35 const TString AliITSLoader::fgkDefaultRawClustersContainerName = "TreeC";
36 const TString AliITSLoader::fgkDefaultBackTracksContainerName = "TreeB";
37 const TString AliITSLoader::fgkDefaultVerticesContainerName = "Vertex";
38 const TString AliITSLoader::fgkDefaultV0ContainerName = "V0";
39 const TString AliITSLoader::fgkDefaultCascadeContainerName = "Cascade";
40 ClassImp(AliITSLoader)
41
42 /**********************************************************************/
43   AliITSLoader::AliITSLoader():AliLoader(),
44 fITSpid(0),
45 fGeom(0){
46   // Default constructor
47 }
48 /*********************************************************************/
49 AliITSLoader::AliITSLoader(const Char_t *name,const Char_t *topfoldername):
50 AliLoader(name,topfoldername),
51 fITSpid(0),
52 fGeom(0){
53   //Constructor   
54     AliDataLoader* rawClustersDataLoader = new AliDataLoader(
55         fDetectorName + ".RawCl.root",fgkDefaultRawClustersContainerName,
56         "Raw Clusters");
57     fDataLoaders->Add(rawClustersDataLoader);
58     rawClustersDataLoader->SetEventFolder(fEventFolder);
59     rawClustersDataLoader->SetFolder(GetDetectorDataFolder());
60
61     AliDataLoader* backTracksDataLoader =  new AliDataLoader(
62         fDetectorName + ".BackTracks.root",fgkDefaultBackTracksContainerName,
63         "Back Propagated Tracks");
64     fDataLoaders->Add(backTracksDataLoader);
65     backTracksDataLoader->SetEventFolder(fEventFolder);
66     backTracksDataLoader->SetFolder(GetDetectorDataFolder());
67
68     AliDataLoader* vertexDataLoader = new AliDataLoader(
69         fDetectorName + ".Vertex.root",fgkDefaultVerticesContainerName,
70         "Primary Vertices","O");
71     fDataLoaders->Add(vertexDataLoader);
72     vertexDataLoader->SetEventFolder(fEventFolder);
73     vertexDataLoader->SetFolder(GetDetectorDataFolder());
74
75     AliDataLoader* v0DataLoader = new AliDataLoader(
76         fDetectorName + ".V0s.root",fgkDefaultV0ContainerName,"V0 Vertices");
77     fDataLoaders->Add(v0DataLoader);
78     v0DataLoader->SetEventFolder(fEventFolder);
79     v0DataLoader->SetFolder(GetDetectorDataFolder());
80
81     AliDataLoader* cascadeDataLoader = new AliDataLoader(
82         fDetectorName + ".Cascades.root",fgkDefaultCascadeContainerName,
83         "Cascades");
84     fDataLoaders->Add(cascadeDataLoader);
85     cascadeDataLoader->SetEventFolder(fEventFolder);
86     cascadeDataLoader->SetFolder(GetDetectorDataFolder());
87 }
88 /**********************************************************************/
89 AliITSLoader::AliITSLoader(const Char_t *name,TFolder *topfolder): 
90   AliLoader(name,topfolder),
91 fITSpid(0),
92 fGeom(0){
93   //ctor  
94     AliDataLoader*  rawClustersDataLoader = new AliDataLoader(
95         fDetectorName + ".RawCl.root",fgkDefaultRawClustersContainerName,
96         "Raw Clusters"); 
97     fDataLoaders->Add(rawClustersDataLoader);
98     rawClustersDataLoader->SetEventFolder(fEventFolder);
99     rawClustersDataLoader->SetFolder(GetDetectorDataFolder());
100
101     AliDataLoader*  backTracksDataLoader =  new AliDataLoader(
102         fDetectorName + ".BackTracks.root",fgkDefaultBackTracksContainerName,
103         "Back Propagated Tracks");
104     fDataLoaders->Add(backTracksDataLoader);
105     backTracksDataLoader->SetEventFolder(fEventFolder);
106     backTracksDataLoader->SetFolder(GetDetectorDataFolder());
107
108     AliDataLoader* vertexDataLoader = new AliDataLoader(
109         fDetectorName + ".Vertex.root",fgkDefaultVerticesContainerName,
110         "Primary Vertices","O");
111     fDataLoaders->Add(vertexDataLoader);
112     vertexDataLoader->SetEventFolder(fEventFolder);
113     vertexDataLoader->SetFolder(GetDetectorDataFolder());
114
115     AliDataLoader* v0DataLoader = new AliDataLoader(
116         fDetectorName + ".V0.root",fgkDefaultV0ContainerName,"V0 Vertices");
117     fDataLoaders->Add(v0DataLoader);
118     v0DataLoader->SetEventFolder(fEventFolder);
119     v0DataLoader->SetFolder(GetDetectorDataFolder());
120
121     AliDataLoader* cascadeDataLoader = new AliDataLoader(
122         fDetectorName + ".Cascade.root",fgkDefaultCascadeContainerName,
123         "Cascades");
124     fDataLoaders->Add(cascadeDataLoader);
125     cascadeDataLoader->SetEventFolder(fEventFolder);
126     cascadeDataLoader->SetFolder(GetDetectorDataFolder());
127 }
128
129
130 /**********************************************************************/
131 AliITSLoader::~AliITSLoader(){
132     //destructor
133     AliDataLoader* dl = 0;
134     UnloadRawClusters();
135     dl = GetRawClLoader();
136     fDataLoaders->Remove(dl);
137
138     UnloadBackTracks();
139     dl = GetBackTracksDataLoader();
140     fDataLoaders->Remove(dl);
141
142     UnloadVertices();
143     dl = GetVertexDataLoader();
144     fDataLoaders->Remove(dl);
145
146     UnloadV0s();
147     dl = GetV0DataLoader();
148     fDataLoaders->Remove(dl);
149
150     UnloadCascades();
151     dl = GetCascadeDataLoader();
152     fDataLoaders->Remove(dl);
153   
154     if(fGeom)delete fGeom;
155     fGeom = 0;
156 }
157 /*
158 //----------------------------------------------------------------------
159 AliITS* AliITSLoader::GetITS(){
160     // Returns the pointer to the ITS, kept on the file. A short cut metthod
161     // Inputs:
162     //    none.
163     // Outputs:
164     //    none.
165     // Returns:
166     //    Returns a pointer to the ITS, if not found returns 0.
167     AliITS *its;
168
169     if(gAlice){
170         its = dynamic_cast<AliITS*> (gAlice->GetDetector(
171             GetDetectorName().Data()));
172         if(its) return its;
173     } // end if gAlice
174     AliRunLoader *rl=0;
175     rl = GetRunLoader();
176     if(!rl) return 0;
177     AliRun *ar=0;
178     ar = rl->GetAliRun();
179     if(!ar) return 0;
180     its = dynamic_cast<AliITS*> (ar->GetDetector(GetDetectorName().Data()));
181     return its;
182 }
183 //----------------------------------------------------------------------
184 void AliITSLoader::SetupDigits(AliITS *its){
185     // Sets up to store ITS Digits in side AliITS::fDtype TObjArray
186     // Inputs:
187     //    AliITS *its  Pointer to the ITS
188     // Outputs:
189     //    none.
190     // Return:
191     //    none.
192
193     its->SetTreeAddressD(TreeD());
194 }
195 */
196 //----------------------------------------------------------------------
197 void AliITSLoader::SetupDigits(TObjArray *digPerDet,Int_t n,
198                                const Char_t **digclass){
199     // Sets up digPerDet to store ITS Digits.
200     // Inputs:
201     //    TObjArray *digPerDet   A pointer to a TObject Array size>=3.
202     //    Int_t      n           The size of the TObjArray and digclass array
203     //    Char_t     **digclass  Array of digit class names
204     // Outputs:
205     //    TObjArray *digPerDet   Setup and linked to the tree of digits
206     // Return:
207     //    none.
208     Int_t i,m;
209     TClonesArray *cl = 0;
210     TTree *td = 0;
211     TBranch *br = 0;
212     Char_t branch[13];
213     const Char_t *det[3] = {"SPD","SDD","SSD"};
214
215     if(!digPerDet){
216         Error("SetUpDigits","TObject Array digPerDet does not exist");
217         return;
218     } // end if
219     m = digPerDet->GetSize();
220     if(m<n){
221         Error("SetUpDigits","TObject Array digPerDet=%p must have a size"
222               " at least that of n=%d",digPerDet,n);
223     } // end if
224     if(m<3){
225         Error("SetUpDigits","TObject Array digPerDet=%p must have a size >2",
226               digPerDet);
227         return;
228     } // end if
229     td = TreeD();
230     for(i=0;i<n;i++){
231         if(digPerDet->At(i)==0){ // set up TClones Array
232             digPerDet->AddAt(new TClonesArray(digclass[i],1000),i);
233             if(n==3) sprintf(branch,"ITSDigits%s",det[i]);
234             else     sprintf(branch,"ITSDigits%d",i+1);
235             br = td->GetBranch(branch);
236             br->SetAddress(&((*digPerDet)[i]));
237             continue; // do next one.
238         } // end if
239         cl =  dynamic_cast<TClonesArray*> (digPerDet->At(i));
240         if(!cl && digPerDet->At(i)!=0){  // not a TClonesArray
241             Error("SetUpDigits","TObject Array digPerDet-At(%d)=%p must be "
242                   "zeroed or filled with TClonesArrays",i,digPerDet);
243             return;
244         } // end if
245         if(!(cl->GetClass()->GetBaseClass(AliITSdigit::Class()))){
246             Error("SetUPDigits","TClones array at digPerDet[%d}=%p must be"
247                   "derived from AliITSdigit",i,digPerDet->At(i));
248         } // end if
249         cl->Clear();
250         if(n==3) sprintf(branch,"ITSDigits%s",det[i]);
251         else     sprintf(branch,"ITSDigits%d",i+1);
252         br = td->GetBranch(branch);
253         br->SetAddress(&((*digPerDet)[i]));
254         continue;
255     } // end for i
256 }
257 //---------------------------------------------------------------------
258 AliITSdigit * AliITSLoader::GetDigit(TObjArray *digPerDet,Int_t module,
259                                      Int_t digit){
260     // Gets the digit for for a specific detector type and module.
261     // To be used in conjustion with Setupdigits(AliITS *its).
262     // Inputs:
263     //   TObjArray *digPereDet    Pointer to the Array of digits
264     //   Int_t      module        Module number
265     //   Int_t      digit         Digit number
266     // Outputs:
267     //   none.
268     // Return:
269     //   returns the pointer to the digit. if zero then last digit for that
270     //   module.
271
272     if(digPerDet==0){
273         Error("GetDigit","digPerDet=%p, module=%d, digit=%d",
274               digPerDet,module,digit);
275         return 0;
276     } // end if
277     return 0;
278 }
279 /*
280 //---------------------------------------------------------------------
281 AliITSdigit * AliITSLoader::GetDigit(AliITS *its,Int_t module,Int_t digit){
282     // Gets the digit for for a specific detector type and module.
283     // To be used in conjustion with Setupdigits(AliITS *its).
284     // Inputs:
285     //   AliITS *its    Pointer to the ITS
286     //   Int_t  module  Module number
287     //   Int_t digit    Digit number
288     // Outputs:
289     //   none.
290     // Return:
291     //   returns the pointer to the digit. if zero then last digit for that
292     //   module.
293     //AliITSDetType *idtype;
294     AliITSgeom *geom = its->GetITSgeom();
295     Int_t idet = geom->GetModuleType(module);
296     TClonesArray *digits;
297  
298     its->ResetDigits();
299     TreeD()->GetEvent(module);
300     digits = its->DigitsAddress(idet);
301     if(digit>-1 && digit<digits->GetEntriesFast()){ // if in range.
302         return (AliITSdigit*) digits->At(digit);
303     } // end if
304     return 0;
305 }
306 */
307 //----------------------------------------------------------------------
308 void AliITSLoader::MakeTree(Option_t *opt){
309     // invokes AliLoader::MakeTree + specific ITS tree(s)
310     // Valid options: H,S,D,R,T and C (C=raw clusters)
311     AliLoader::MakeTree(opt);
312     const char *oC = strstr(opt,"C");
313     if (oC) MakeRawClustersContainer();
314
315     const char *oB = strstr(opt,"B");
316     if (oB) MakeBackTracksContainer();
317
318     const char *oV0 = strstr(opt,"V0");
319     if (oV0) MakeV0Container();
320
321     const char *oX = strstr(opt,"X");
322     if (oX) MakeCascadeContainer();
323 }
324
325 //----------------------------------------------------------------------
326 AliITSgeom* AliITSLoader::GetITSgeom(Bool_t force) {
327   // retrieves the ITS geometry from file
328   if(fGeom && !force)return fGeom;
329   if(fGeom && force){
330     delete fGeom;
331     fGeom = 0;
332   }
333   if(!gGeoManager){
334     AliError("gGeoManager is a null pointer - ITS geometry not built");
335     return fGeom;
336   }
337   AliITSInitGeometry initgeom;
338   fGeom = initgeom.CreateAliITSgeom();
339   AliDebug(1,"AliITSgeom object has been initialized from TGeo\n");
340   AliInfo(Form("Geometry name: %s",(initgeom.GetGeometryName()).Data()));
341   return fGeom;
342 }
343 //______________________________________________________________________
344 void AliITSLoader::SetITSgeom(AliITSgeom *geom){
345     // Replaces the AliITSgeom object read from file with the one
346     // given.
347     // Inputs:
348     //   AliITSgeom *geom   The AliITSgeom object to replace the one
349     //                      read from the file
350     // Outputs:
351     //   none.
352     // Return:
353     //   none.
354
355     if(fGeom==geom) return; // Same do nothing
356     if(fGeom) {
357         delete fGeom;
358         fGeom=0;
359     }// end if
360     fGeom=geom;
361 }
362