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