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