Take absolute value of daughter label in MatchToMC, to keep fakes in PbPb.
[u/mrichter/AliRoot.git] / ITS / AliITSLoader.cxx
CommitLineData
9edefa04 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
7ca4655f 18#include <TClonesArray.h>
9edefa04 19#include <TClass.h>
6f5308d9 20#include <TGeoManager.h>
9edefa04 21
aacedc3e 22#include "AliITSdigit.h"
88cb7938 23#include "AliITSLoader.h"
7d62fb64 24#include "AliRunLoader.h"
ad7f2bfa 25#include "AliObjectLoader.h"
6def2bd2 26#include "AliITSInitGeometry.h"
13033bec 27#include "AliLog.h"
88cb7938 28
aacedc3e 29///////////////////////////////////////////////////////////////////////////
eeac5f9f 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
aacedc3e 35//////////////////////////////////////////////////////////////////////////
88cb7938 36const TString AliITSLoader::fgkDefaultRawClustersContainerName = "TreeC";
37const TString AliITSLoader::fgkDefaultBackTracksContainerName = "TreeB";
38const TString AliITSLoader::fgkDefaultVerticesContainerName = "Vertex";
566abf75 39const TString AliITSLoader::fgkDefaultV0ContainerName = "V0";
40const TString AliITSLoader::fgkDefaultCascadeContainerName = "Cascade";
88cb7938 41ClassImp(AliITSLoader)
42
aacedc3e 43/**********************************************************************/
e56160b8 44 AliITSLoader::AliITSLoader():AliLoader(),
e56160b8 45fGeom(0){
eeac5f9f 46 // Default constructor
aacedc3e 47}
48/*********************************************************************/
49AliITSLoader::AliITSLoader(const Char_t *name,const Char_t *topfoldername):
e56160b8 50AliLoader(name,topfoldername),
e56160b8 51fGeom(0){
52 //Constructor
aacedc3e 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());
eeac5f9f 66
aacedc3e 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());
eeac5f9f 86}
aacedc3e 87/**********************************************************************/
88AliITSLoader::AliITSLoader(const Char_t *name,TFolder *topfolder):
e56160b8 89 AliLoader(name,topfolder),
e56160b8 90fGeom(0){
aacedc3e 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());
eeac5f9f 98
aacedc3e 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());
88cb7938 125}
e62c1aea 126
e62c1aea 127
aacedc3e 128/**********************************************************************/
129AliITSLoader::~AliITSLoader(){
130 //destructor
131 AliDataLoader* dl = 0;
132 UnloadRawClusters();
133 dl = GetRawClLoader();
134 fDataLoaders->Remove(dl);
88cb7938 135
aacedc3e 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);
e56160b8 151
8e50d897 152 if(fGeom)delete fGeom;
023ae34b 153 fGeom = 0;
88cb7938 154}
7d62fb64 155/*
aacedc3e 156//----------------------------------------------------------------------
157AliITS* 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;
566abf75 166
aacedc3e 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;
88cb7938 180}
aacedc3e 181//----------------------------------------------------------------------
182void 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.
88cb7938 190
aacedc3e 191 its->SetTreeAddressD(TreeD());
192}
7d62fb64 193*/
aacedc3e 194//----------------------------------------------------------------------
195void 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;
ce189d7c 210 Char_t branch[14];
aacedc3e 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);
ce189d7c 231 if(n==3) snprintf(branch,13,"ITSDigits%s",det[i]);
232 else snprintf(branch,13,"ITSDigits%d",i+1);
aacedc3e 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//---------------------------------------------------------------------
256AliITSdigit * 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}
7d62fb64 277/*
aacedc3e 278//---------------------------------------------------------------------
279AliITSdigit * 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}
7d62fb64 304*/
aacedc3e 305//----------------------------------------------------------------------
88cb7938 306void AliITSLoader::MakeTree(Option_t *opt){
aacedc3e 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();
88cb7938 321}
7d62fb64 322
323//----------------------------------------------------------------------
8e50d897 324AliITSgeom* AliITSLoader::GetITSgeom(Bool_t force) {
7d62fb64 325 // retrieves the ITS geometry from file
8e50d897 326 if(fGeom && !force)return fGeom;
327 if(fGeom && force){
328 delete fGeom;
329 fGeom = 0;
330 }
6f5308d9 331 if(!gGeoManager){
332 AliError("gGeoManager is a null pointer - ITS geometry not built");
333 return fGeom;
334 }
108bd0fe 335 AliITSInitGeometry initgeom;
6def2bd2 336 fGeom = initgeom.CreateAliITSgeom();
337 AliDebug(1,"AliITSgeom object has been initialized from TGeo\n");
15e6a32c 338 AliDebug(1,Form("Geometry name: %s",(initgeom.GetGeometryName()).Data()));
8e50d897 339 return fGeom;
7d62fb64 340}
023ae34b 341//______________________________________________________________________
342void 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}