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