warning added if the method GetITSgeom has to fetch the AliITSgeom pointer from file
[u/mrichter/AliRoot.git] / ITS / AliITSLoader.cxx
CommitLineData
aacedc3e 1#include "AliITSdigit.h"
88cb7938 2#include "AliITSLoader.h"
7d62fb64 3#include "AliRunLoader.h"
13033bec 4#include "AliLog.h"
88cb7938 5
aacedc3e 6///////////////////////////////////////////////////////////////////////////
eeac5f9f 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
aacedc3e 12//////////////////////////////////////////////////////////////////////////
88cb7938 13const TString AliITSLoader::fgkDefaultRawClustersContainerName = "TreeC";
14const TString AliITSLoader::fgkDefaultBackTracksContainerName = "TreeB";
15const TString AliITSLoader::fgkDefaultVerticesContainerName = "Vertex";
566abf75 16const TString AliITSLoader::fgkDefaultV0ContainerName = "V0";
17const TString AliITSLoader::fgkDefaultCascadeContainerName = "Cascade";
88cb7938 18ClassImp(AliITSLoader)
19
aacedc3e 20/**********************************************************************/
eeac5f9f 21 AliITSLoader::AliITSLoader():AliLoader(){
22 // Default constructor
e62c1aea 23 fITSpid = 0;
8e50d897 24 fGeom = 0;
aacedc3e 25}
26/*********************************************************************/
27AliITSLoader::AliITSLoader(const Char_t *name,const Char_t *topfoldername):
28AliLoader(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());
eeac5f9f 43
aacedc3e 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());
e62c1aea 63 fITSpid=0;
8e50d897 64 fGeom = 0;
eeac5f9f 65}
aacedc3e 66/**********************************************************************/
67AliITSLoader::AliITSLoader(const Char_t *name,TFolder *topfolder):
68AliLoader(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());
eeac5f9f 76
aacedc3e 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());
8e50d897 103 fITSpid = 0;
104 fGeom = 0;
88cb7938 105}
e62c1aea 106
107//______________________________________________________________________
108AliITSLoader::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//______________________________________________________________________
115AliITSLoader& 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
aacedc3e 122/**********************************************************************/
123AliITSLoader::~AliITSLoader(){
124 //destructor
125 AliDataLoader* dl = 0;
126 UnloadRawClusters();
127 dl = GetRawClLoader();
128 fDataLoaders->Remove(dl);
88cb7938 129
aacedc3e 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);
e62c1aea 145 if(fITSpid)delete fITSpid;
8e50d897 146 if(fGeom)delete fGeom;
88cb7938 147}
7d62fb64 148/*
aacedc3e 149//----------------------------------------------------------------------
150AliITS* AliITSLoader::GetITS(){
151 // Returns the pointer to the ITS, kept on the file. A short cut metthod
152 // Inputs:
153 // none.
154 // Outputs:
155 // none.
156 // Returns:
157 // Returns a pointer to the ITS, if not found returns 0.
158 AliITS *its;
566abf75 159
aacedc3e 160 if(gAlice){
161 its = dynamic_cast<AliITS*> (gAlice->GetDetector(
162 GetDetectorName().Data()));
163 if(its) return its;
164 } // end if gAlice
165 AliRunLoader *rl=0;
166 rl = GetRunLoader();
167 if(!rl) return 0;
168 AliRun *ar=0;
169 ar = rl->GetAliRun();
170 if(!ar) return 0;
171 its = dynamic_cast<AliITS*> (ar->GetDetector(GetDetectorName().Data()));
172 return its;
88cb7938 173}
aacedc3e 174//----------------------------------------------------------------------
175void AliITSLoader::SetupDigits(AliITS *its){
176 // Sets up to store ITS Digits in side AliITS::fDtype TObjArray
177 // Inputs:
178 // AliITS *its Pointer to the ITS
179 // Outputs:
180 // none.
181 // Return:
182 // none.
88cb7938 183
aacedc3e 184 its->SetTreeAddressD(TreeD());
185}
7d62fb64 186*/
aacedc3e 187//----------------------------------------------------------------------
188void AliITSLoader::SetupDigits(TObjArray *digPerDet,Int_t n,
189 const Char_t **digclass){
190 // Sets up digPerDet to store ITS Digits.
191 // Inputs:
192 // TObjArray *digPerDet A pointer to a TObject Array size>=3.
193 // Int_t n The size of the TObjArray and digclass array
194 // Char_t **digclass Array of digit class names
195 // Outputs:
196 // TObjArray *digPerDet Setup and linked to the tree of digits
197 // Return:
198 // none.
199 Int_t i,m;
200 TClonesArray *cl = 0;
201 TTree *td = 0;
202 TBranch *br = 0;
203 Char_t branch[13];
204 const Char_t *det[3] = {"SPD","SDD","SSD"};
205
206 if(!digPerDet){
207 Error("SetUpDigits","TObject Array digPerDet does not exist");
208 return;
209 } // end if
210 m = digPerDet->GetSize();
211 if(m<n){
212 Error("SetUpDigits","TObject Array digPerDet=%p must have a size"
213 " at least that of n=%d",digPerDet,n);
214 } // end if
215 if(m<3){
216 Error("SetUpDigits","TObject Array digPerDet=%p must have a size >2",
217 digPerDet);
218 return;
219 } // end if
220 td = TreeD();
221 for(i=0;i<n;i++){
222 if(digPerDet->At(i)==0){ // set up TClones Array
223 digPerDet->AddAt(new TClonesArray(digclass[i],1000),i);
224 if(n==3) sprintf(branch,"ITSDigits%s",det[i]);
225 else sprintf(branch,"ITSDigits%d",i+1);
226 br = td->GetBranch(branch);
227 br->SetAddress(&((*digPerDet)[i]));
228 continue; // do next one.
229 } // end if
230 cl = dynamic_cast<TClonesArray*> (digPerDet->At(i));
231 if(!cl && digPerDet->At(i)!=0){ // not a TClonesArray
232 Error("SetUpDigits","TObject Array digPerDet-At(%d)=%p must be "
233 "zeroed or filled with TClonesArrays",i,digPerDet);
234 return;
235 } // end if
236 if(!(cl->GetClass()->GetBaseClass(AliITSdigit::Class()))){
237 Error("SetUPDigits","TClones array at digPerDet[%d}=%p must be"
238 "derived from AliITSdigit",i,digPerDet->At(i));
239 } // end if
240 cl->Clear();
241 if(n==3) sprintf(branch,"ITSDigits%s",det[i]);
242 else sprintf(branch,"ITSDigits%d",i+1);
243 br = td->GetBranch(branch);
244 br->SetAddress(&((*digPerDet)[i]));
245 continue;
246 } // end for i
247}
248//---------------------------------------------------------------------
249AliITSdigit * AliITSLoader::GetDigit(TObjArray *digPerDet,Int_t module,
250 Int_t digit){
251 // Gets the digit for for a specific detector type and module.
252 // To be used in conjustion with Setupdigits(AliITS *its).
253 // Inputs:
254 // TObjArray *digPereDet Pointer to the Array of digits
255 // Int_t module Module number
256 // Int_t digit Digit number
257 // Outputs:
258 // none.
259 // Return:
260 // returns the pointer to the digit. if zero then last digit for that
261 // module.
262
263 if(digPerDet==0){
264 Error("GetDigit","digPerDet=%p, module=%d, digit=%d",
265 digPerDet,module,digit);
266 return 0;
267 } // end if
268 return 0;
269}
7d62fb64 270/*
aacedc3e 271//---------------------------------------------------------------------
272AliITSdigit * AliITSLoader::GetDigit(AliITS *its,Int_t module,Int_t digit){
273 // Gets the digit for for a specific detector type and module.
274 // To be used in conjustion with Setupdigits(AliITS *its).
275 // Inputs:
276 // AliITS *its Pointer to the ITS
277 // Int_t module Module number
278 // Int_t digit Digit number
279 // Outputs:
280 // none.
281 // Return:
282 // returns the pointer to the digit. if zero then last digit for that
283 // module.
284 //AliITSDetType *idtype;
285 AliITSgeom *geom = its->GetITSgeom();
286 Int_t idet = geom->GetModuleType(module);
287 TClonesArray *digits;
288
289 its->ResetDigits();
290 TreeD()->GetEvent(module);
291 digits = its->DigitsAddress(idet);
292 if(digit>-1 && digit<digits->GetEntriesFast()){ // if in range.
293 return (AliITSdigit*) digits->At(digit);
294 } // end if
295 return 0;
296}
7d62fb64 297*/
aacedc3e 298//----------------------------------------------------------------------
88cb7938 299void AliITSLoader::MakeTree(Option_t *opt){
aacedc3e 300 // invokes AliLoader::MakeTree + specific ITS tree(s)
301 // Valid options: H,S,D,R,T and C (C=raw clusters)
302 AliLoader::MakeTree(opt);
303 const char *oC = strstr(opt,"C");
304 if (oC) MakeRawClustersContainer();
305
306 const char *oB = strstr(opt,"B");
307 if (oB) MakeBackTracksContainer();
308
309 const char *oV0 = strstr(opt,"V0");
310 if (oV0) MakeV0Container();
311
312 const char *oX = strstr(opt,"X");
313 if (oX) MakeCascadeContainer();
88cb7938 314}
7d62fb64 315
316//----------------------------------------------------------------------
8e50d897 317AliITSgeom* AliITSLoader::GetITSgeom(Bool_t force) {
7d62fb64 318 // retrieves the ITS geometry from file
8e50d897 319 if(fGeom && !force)return fGeom;
320 if(fGeom && force){
321 delete fGeom;
322 fGeom = 0;
323 }
7d62fb64 324 AliRunLoader *runLoader = GetRunLoader();
8e50d897 325 if (!runLoader->GetAliRun()) runLoader->LoadgAlice();
7d62fb64 326 if (!runLoader->GetAliRun()) {
327 Error("GetITSgeom", "couldn't get AliRun object");
328 return NULL;
329 }
330
8e50d897 331 TDirectory *curdir = gDirectory;
7d62fb64 332 runLoader->CdGAFile();
8e50d897 333 fGeom = (AliITSgeom*)gDirectory->Get("AliITSgeom");
334 curdir->cd();
335 if(!fGeom){
7d62fb64 336 Error("GetITSgeom","no ITS geometry available");
337 return NULL;
338 }
13033bec 339 AliWarning("AliITSgeom object has been fetched from galice.root file");
8e50d897 340 return fGeom;
7d62fb64 341}
342