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