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