]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliModule.cxx
Cleaning of warnings (gcc -W)
[u/mrichter/AliRoot.git] / STEER / AliModule.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 ///////////////////////////////////////////////////////////////////////////////
19 //                                                                           //
20 // Base class for ALICE modules. Both sensitive modules (Modules) and      //
21 // non-sensitive ones are described by this base class. This class           //
22 // supports the hit and digit trees produced by the simulation and also      //
23 // the objects produced by the reconstruction.                               //
24 //                                                                           //
25 // This class is also responsible for building the geometry of the           //
26 // Modules.                                                                //
27 //                                                                           //
28 //Begin_Html
29 /*
30 <img src="picts/AliModuleClass.gif">
31 */
32 //End_Html
33 //                                                                           //
34 ///////////////////////////////////////////////////////////////////////////////
35
36 #include <TNode.h>
37 #include <TObjArray.h>
38 #include <TClonesArray.h>
39 #include <TTree.h>
40 #include <TSystem.h>
41 #include <TDirectory.h>
42
43 #include "AliConfig.h"
44 #include "AliLoader.h"
45 #include "AliMagF.h"
46 #include "AliModule.h"
47 #include "AliRun.h"
48 #include "AliTrackReference.h"
49
50 ClassImp(AliModule)
51  
52 //_______________________________________________________________________
53 AliModule::AliModule():
54   fEuclidMaterial(""),
55   fEuclidGeometry(""),
56   fIdtmed(0),
57   fIdmate(0),
58   fLoMedium(0),
59   fHiMedium(0),
60   fActive(0),
61   fHistograms(0),
62   fNodes(0),
63   fDebug(0),
64   fEnable(1),
65   fTrackReferences(0),
66   fMaxIterTrackRef(0),
67   fCurrentIterTrackRef(0)
68 {
69   //
70   // Default constructor for the AliModule class
71   //
72 }
73  
74 //_______________________________________________________________________
75 AliModule::AliModule(const char* name,const char *title):
76   TNamed(name,title),
77   fEuclidMaterial(""),
78   fEuclidGeometry(""),
79   fIdtmed(new TArrayI(100)),
80   fIdmate(new TArrayI(100)),
81   fLoMedium(65536),
82   fHiMedium(0),
83   fActive(0),
84   fHistograms(new TList()),
85   fNodes(new TList()),
86   fDebug(0),
87   fEnable(1),
88   fTrackReferences(new TClonesArray("AliTrackReference", 100)),
89   fMaxIterTrackRef(0),
90   fCurrentIterTrackRef(0)
91 {
92   //
93   // Normal constructor invoked by all Modules.
94   // Create the list for Module specific histograms
95   // Add this Module to the global list of Modules in Run.
96   //
97   // Get the Module numeric ID
98   Int_t id = gAlice->GetModuleID(name);
99   if (id>=0) {
100     // Module already added !
101      Warning("Ctor","Module: %s already present at %d\n",name,id);
102      return;
103   }
104   //
105   // Add this Module to the list of Modules
106
107   gAlice->AddModule(this);
108
109   SetMarkerColor(3);
110   //
111   // Clear space for tracking media and material indexes
112
113   for(Int_t i=0;i<100;i++) (*fIdmate)[i]=(*fIdtmed)[i]=0;
114
115     
116   SetDebug(gAlice->GetDebug());
117 }
118  
119 //_______________________________________________________________________
120 AliModule::AliModule(const AliModule &mod):
121   TNamed(mod),
122   TAttLine(mod),
123   TAttMarker(mod),
124   AliRndm(mod),
125   fEuclidMaterial(""),
126   fEuclidGeometry(""),
127   fIdtmed(0),
128   fIdmate(0),
129   fLoMedium(0),
130   fHiMedium(0),
131   fActive(0),
132   fHistograms(0),
133   fNodes(0),
134   fDebug(0),
135   fEnable(0),
136   fTrackReferences(0),
137   fMaxIterTrackRef(0),
138   fCurrentIterTrackRef(0)
139 {
140   //
141   // Copy constructor
142   //
143   mod.Copy(*this);
144 }
145
146 //_______________________________________________________________________
147 AliModule::~AliModule()
148 {
149   //
150   // Destructor
151   //
152
153   // Remove this Module from the list of Modules
154   if (gAlice) {
155     TObjArray * modules = gAlice->Modules();
156     if (modules) modules->Remove(this);
157   }
158   // Delete ROOT geometry
159   if(fNodes) {
160     fNodes->Clear();
161     delete fNodes;
162     fNodes = 0;
163   }
164   // Delete histograms
165   if(fHistograms) {
166     fHistograms->Clear();
167     delete fHistograms;
168     fHistograms = 0;
169   }
170   // Delete track references
171   if (fTrackReferences) {
172     fTrackReferences->Delete();
173     delete fTrackReferences;
174     fTrackReferences     = 0;
175   }
176   // Delete TArray objects
177   delete fIdtmed;
178   delete fIdmate;
179
180 }
181  
182 //_______________________________________________________________________
183 void AliModule::Copy(AliModule & /* mod */) const
184 {
185   //
186   // Copy *this onto mod, not implemented for AliModule
187   //
188   Fatal("Copy","Not implemented!\n");
189 }
190
191 //_______________________________________________________________________
192 void AliModule::Disable()
193 {
194   //
195   // Disable Module on viewer
196   //
197   fActive = kFALSE;
198   TIter next(fNodes);
199   TNode *node;
200   //
201   // Loop through geometry to disable all
202   // nodes for this Module
203   while((node = dynamic_cast<TNode*>(next()))) {
204     node->SetVisibility(-1);
205   }   
206 }
207
208 //_______________________________________________________________________
209 Int_t AliModule::DistancetoPrimitive(Int_t, Int_t) const
210 {
211   //
212   // Return distance from mouse pointer to object
213   // Dummy routine for the moment
214   //
215   return 9999;
216 }
217
218 //_______________________________________________________________________
219 void AliModule::Enable()
220 {
221   //
222   // Enable Module on the viewver
223   //
224   fActive = kTRUE;
225   TIter next(fNodes);
226   TNode *node;
227   //
228   // Loop through geometry to enable all
229   // nodes for this Module
230   while((node = dynamic_cast<TNode*>(next()))) {
231     node->SetVisibility(3);
232   }   
233 }
234
235 //_______________________________________________________________________
236 void AliModule::AliMaterial(Int_t imat, const char* name, Float_t a, 
237                             Float_t z, Float_t dens, Float_t radl,
238                             Float_t absl, Float_t *buf, Int_t nwbuf) const
239 {
240   //
241   // Store the parameters for a material
242   //
243   // imat        the material index will be stored in (*fIdmate)[imat]
244   // name        material name
245   // a           atomic mass
246   // z           atomic number
247   // dens        density
248   // radl        radiation length
249   // absl        absorbtion length
250   // buf         adress of an array user words
251   // nwbuf       number of user words
252   //
253   Int_t kmat;
254   gMC->Material(kmat, name, a, z, dens, radl, absl, buf, nwbuf);
255   (*fIdmate)[imat]=kmat;
256 }
257   
258 //_______________________________________________________________________
259 void AliModule::AliGetMaterial(Int_t imat, char* name, Float_t &a, 
260                                Float_t &z, Float_t &dens, Float_t &radl,
261                                Float_t &absl) const
262 {
263   //
264   // Store the parameters for a material
265   //
266   // imat        the material index will be stored in (*fIdmate)[imat]
267   // name        material name
268   // a           atomic mass
269   // z           atomic number
270   // dens        density
271   // radl        radiation length
272   // absl        absorbtion length
273   // buf         adress of an array user words
274   // nwbuf       number of user words
275   //
276
277   Float_t buf[10];
278   Int_t nwbuf, kmat;
279   kmat=(*fIdmate)[imat];
280   gMC->Gfmate(kmat, name, a, z, dens, radl, absl, buf, nwbuf);
281 }
282   
283
284 //_______________________________________________________________________
285 void AliModule::AliMixture(Int_t imat, const char *name, Float_t *a,
286                            Float_t *z, Float_t dens, Int_t nlmat,
287                            Float_t *wmat) const
288
289   //
290   // Defines mixture or compound imat as composed by 
291   // nlmat materials defined by arrays a, z and wmat
292   // 
293   // If nlmat > 0 wmat contains the proportion by
294   // weights of each basic material in the mixture  
295   // 
296   // If nlmat < 0 wmat contains the number of atoms 
297   // of eack kind in the molecule of the compound
298   // In this case, wmat is changed on output to the relative weigths.
299   //
300   // imat        the material index will be stored in (*fIdmate)[imat]
301   // name        material name
302   // a           array of atomic masses
303   // z           array of atomic numbers
304   // dens        density
305   // nlmat       number of components
306   // wmat        array of concentrations
307   //
308   Int_t kmat;
309   gMC->Mixture(kmat, name, a, z, dens, nlmat, wmat);
310   (*fIdmate)[imat]=kmat;
311
312  
313 //_______________________________________________________________________
314 void AliModule::AliMedium(Int_t numed, const char *name, Int_t nmat,
315                           Int_t isvol, Int_t ifield, Float_t fieldm,
316                           Float_t tmaxfd, Float_t stemax, Float_t deemax,
317                           Float_t epsil, Float_t stmin, Float_t *ubuf,
318                           Int_t nbuf) const
319
320   //
321   // Store the parameters of a tracking medium
322   //
323   // numed       the medium number is stored into (*fIdtmed)[numed]
324   // name        medium name
325   // nmat        the material number is stored into (*fIdmate)[nmat]
326   // isvol       sensitive volume if isvol!=0
327   // ifield      magnetic field flag (see below)
328   // fieldm      maximum magnetic field
329   // tmaxfd      maximum deflection angle due to magnetic field
330   // stemax      maximum step allowed
331   // deemax      maximum fractional energy loss in one step
332   // epsil       tracking precision in cm
333   // stmin       minimum step due to continuous processes
334   //
335   // ifield =  0       no magnetic field
336   //        = -1       user decision in guswim
337   //        =  1       tracking performed with Runge Kutta
338   //        =  2       tracking performed with helix
339   //        =  3       constant magnetic field along z
340   //  
341   Int_t kmed;
342   gMC->Medium(kmed,name, (*fIdmate)[nmat], isvol, ifield, fieldm,
343                          tmaxfd, stemax, deemax, epsil, stmin, ubuf, nbuf); 
344   (*fIdtmed)[numed]=kmed;
345
346  
347 //_______________________________________________________________________
348 void AliModule::AliMatrix(Int_t &nmat, Float_t theta1, Float_t phi1,
349                           Float_t theta2, Float_t phi2, Float_t theta3,
350                           Float_t phi3) const
351 {
352   // 
353   // Define a rotation matrix. Angles are in degrees.
354   //
355   // nmat        on output contains the number assigned to the rotation matrix
356   // theta1      polar angle for axis I
357   // phi1        azimuthal angle for axis I
358   // theta2      polar angle for axis II
359   // phi2        azimuthal angle for axis II
360   // theta3      polar angle for axis III
361   // phi3        azimuthal angle for axis III
362   //
363   gMC->Matrix(nmat, theta1, phi1, theta2, phi2, theta3, phi3); 
364
365
366 //_______________________________________________________________________
367 Float_t AliModule::ZMin() const
368 {
369   return -500;
370 }
371
372 //_______________________________________________________________________
373 Float_t AliModule::ZMax() const
374 {
375   return 500;
376 }
377
378 //_______________________________________________________________________
379 void AliModule::SetEuclidFile(char* material, char* geometry)
380 {
381   //
382   // Sets the name of the Euclid file
383   //
384   fEuclidMaterial=material;
385   if(geometry) {
386     fEuclidGeometry=geometry;
387   } else {
388     char* name = new char[strlen(material)];
389     strcpy(name,material);
390     strcpy(&name[strlen(name)-4],".euc");
391     fEuclidGeometry=name;
392     delete [] name;
393   }
394 }
395  
396 //_______________________________________________________________________
397 void AliModule::ReadEuclid(const char* filnam, char* topvol)
398 {
399   //                                                                     
400   //       read in the geometry of the detector in euclid file format    
401   //                                                                     
402   //        id_det : the detector identification (2=its,...)            
403   //        topvol : return parameter describing the name of the top    
404   //        volume of geometry.                                          
405   //                                                                     
406   //            author : m. maire                                        
407   //                                                                     
408   //     28.07.98
409   //     several changes have been made by miroslav helbich
410   //     subroutine is rewrited to follow the new established way of memory
411   //     booking for tracking medias and rotation matrices.
412   //     all used tracking media have to be defined first, for this you can use
413   //     subroutine  greutmed.
414   //     top volume is searched as only volume not positioned into another 
415   //
416
417   Int_t i, nvol, iret, itmed, irot, numed, npar, ndiv, iaxe;
418   Int_t ndvmx, nr, flag;
419   char key[5], card[77], natmed[21];
420   char name[5], mother[5], shape[5], konly[5], volst[7000][5];
421   char *filtmp;
422   Float_t par[100];
423   Float_t teta1, phi1, teta2, phi2, teta3, phi3, orig, step;
424   Float_t xo, yo, zo;
425   const Int_t kMaxRot=5000;
426   Int_t idrot[kMaxRot],istop[7000];
427   FILE *lun;
428   //
429   // *** The input filnam name will be with extension '.euc'
430   filtmp=gSystem->ExpandPathName(filnam);
431   lun=fopen(filtmp,"r");
432   delete [] filtmp;
433   if(!lun) {
434     Error("ReadEuclid","Could not open file %s\n",filnam);
435     return;
436   }
437   //* --- definition of rotation matrix 0 ---  
438   TArrayI &idtmed = *fIdtmed;
439   for(i=1; i<kMaxRot; ++i) idrot[i]=-99;
440   idrot[0]=0;
441   nvol=0;
442  L10:
443   for(i=0;i<77;i++) card[i]=0;
444   iret=fscanf(lun,"%77[^\n]",card);
445   if(iret<=0) goto L20;
446   fscanf(lun,"%*c");
447   //*
448   strncpy(key,card,4);
449   key[4]='\0';
450   if (!strcmp(key,"TMED")) {
451     sscanf(&card[5],"%d '%[^']'",&itmed,natmed);
452     if( itmed<0 || itmed>=100 ) {
453       Error("ReadEuclid","TMED illegal medium number %d for %s\n",itmed,natmed);
454       exit(1);
455     }
456     //Pad the string with blanks
457     i=-1;
458     while(natmed[++i]);
459     while(i<20) natmed[i++]=' ';
460     natmed[i]='\0';
461     //
462     if( idtmed[itmed]<=0 ) {
463       Error("ReadEuclid","TMED undefined medium number %d for %s\n",itmed,natmed);
464       exit(1);
465     }
466     gMC->Gckmat(idtmed[itmed],natmed);
467     //*
468   } else if (!strcmp(key,"ROTM")) {
469     sscanf(&card[4],"%d %f %f %f %f %f %f",&irot,&teta1,&phi1,&teta2,&phi2,&teta3,&phi3);
470     if( irot<=0 || irot>=kMaxRot ) {
471       Error("ReadEuclid","ROTM rotation matrix number %d illegal\n",irot);
472       exit(1);
473     }
474     AliMatrix(idrot[irot],teta1,phi1,teta2,phi2,teta3,phi3);
475     //*
476   } else if (!strcmp(key,"VOLU")) {
477     sscanf(&card[5],"'%[^']' '%[^']' %d %d", name, shape, &numed, &npar);
478     if (npar>0) {
479       for(i=0;i<npar;i++) fscanf(lun,"%f",&par[i]);
480       fscanf(lun,"%*c");
481     }
482     gMC->Gsvolu( name, shape, idtmed[numed], par, npar);
483     //*     save the defined volumes
484     strcpy(volst[++nvol],name);
485     istop[nvol]=1;
486     //*
487   } else if (!strcmp(key,"DIVN")) {
488     sscanf(&card[5],"'%[^']' '%[^']' %d %d", name, mother, &ndiv, &iaxe);
489     gMC->Gsdvn  ( name, mother, ndiv, iaxe );
490     //*
491   } else if (!strcmp(key,"DVN2")) {
492     sscanf(&card[5],"'%[^']' '%[^']' %d %d %f %d",name, mother, &ndiv, &iaxe, &orig, &numed);
493     gMC->Gsdvn2( name, mother, ndiv, iaxe, orig,idtmed[numed]);
494     //*
495   } else if (!strcmp(key,"DIVT")) {
496     sscanf(&card[5],"'%[^']' '%[^']' %f %d %d %d", name, mother, &step, &iaxe, &numed, &ndvmx);
497     gMC->Gsdvt ( name, mother, step, iaxe, idtmed[numed], ndvmx);
498     //*
499   } else if (!strcmp(key,"DVT2")) {
500     sscanf(&card[5],"'%[^']' '%[^']' %f %d %f %d %d", name, mother, &step, &iaxe, &orig, &numed, &ndvmx);
501     gMC->Gsdvt2 ( name, mother, step, iaxe, orig, idtmed[numed], ndvmx );
502     //*
503   } else if (!strcmp(key,"POSI")) {
504     sscanf(&card[5],"'%[^']' %d '%[^']' %f %f %f %d '%[^']'", name, &nr, mother, &xo, &yo, &zo, &irot, konly);
505     if( irot<0 || irot>=kMaxRot ) {
506       Error("ReadEuclid","POSI %s#%d rotation matrix number %d illegal\n",name,nr,irot);
507       exit(1);
508     }
509     if( idrot[irot] == -99) {
510       Error("ReadEuclid","POSI %s#%d undefined matrix number %d\n",name,nr,irot);
511       exit(1);
512     }
513     //*** volume name cannot be the top volume
514     for(i=1;i<=nvol;i++) {
515       if (!strcmp(volst[i],name)) istop[i]=0;
516     }
517     //*
518     gMC->Gspos  ( name, nr, mother, xo, yo, zo, idrot[irot], konly );
519     //*
520   } else if (!strcmp(key,"POSP")) {
521     sscanf(&card[5],"'%[^']' %d '%[^']' %f %f %f %d '%[^']' %d", name, &nr, mother, &xo, &yo, &zo, &irot, konly, &npar);
522     if( irot<0 || irot>=kMaxRot ) {
523       Error("ReadEuclid","POSP %s#%d rotation matrix number %d illegal\n",name,nr,irot);
524       exit(1);
525     }
526     if( idrot[irot] == -99) {
527       Error("ReadEuclid","POSP %s#%d undefined matrix number %d\n",name,nr,irot);
528       exit(1);
529     }
530     if (npar > 0) {
531       for(i=0;i<npar;i++) fscanf(lun,"%f",&par[i]);
532       fscanf(lun,"%*c");
533     }
534     //*** volume name cannot be the top volume
535     for(i=1;i<=nvol;i++) {
536       if (!strcmp(volst[i],name)) istop[i]=0;
537     }
538     //*
539     gMC->Gsposp ( name, nr, mother, xo,yo,zo, idrot[irot], konly, par, npar);
540   }
541   //*
542   if (strcmp(key,"END")) goto L10;
543   //* find top volume in the geometry
544   flag=0;
545   for(i=1;i<=nvol;i++) {
546     if (istop[i] && flag) {
547       Warning("ReadEuclid"," %s is another possible top volume\n",volst[i]);
548     }
549     if (istop[i] && !flag) {
550       strcpy(topvol,volst[i]);
551       if(fDebug) printf("%s::ReadEuclid: volume %s taken as a top volume\n",ClassName(),topvol);
552       flag=1;
553     }
554   }
555   if (!flag) {
556     Warning("ReadEuclid","top volume not found\n");
557   }
558   fclose (lun);
559   //*
560   //*     commented out only for the not cernlib version
561   if(fDebug) printf("%s::ReadEuclid: file: %s is now read in\n",ClassName(),filnam);
562   //
563   return;
564   //*
565   L20:
566   Error("ReadEuclid","reading error or premature end of file\n");
567 }
568
569 //_______________________________________________________________________
570 void AliModule::ReadEuclidMedia(const char* filnam)
571 {
572   //                                                                     
573   //       read in the materials and tracking media for the detector     
574   //                   in euclid file format                             
575   //                                                                     
576   //       filnam: name of the input file                                
577   //       id_det: id_det is the detector identification (2=its,...)     
578   //                                                                     
579   //            author : miroslav helbich                                
580   //
581   Float_t sxmgmx = gAlice->Field()->Max();
582   Int_t   isxfld = gAlice->Field()->Integ();
583   Int_t end, i, iret, itmed;
584   char key[5], card[130], natmed[21], namate[21];
585   Float_t ubuf[50];
586   char* filtmp;
587   FILE *lun;
588   Int_t imate;
589   Int_t nwbuf, isvol, ifield, nmat;
590   Float_t a, z, dens, radl, absl, fieldm, tmaxfd, stemax, deemax, epsil, stmin;
591   //
592   end=strlen(filnam);
593   for(i=0;i<end;i++) if(filnam[i]=='.') {
594     end=i;
595     break;
596   }
597   //
598   // *** The input filnam name will be with extension '.euc'
599   if(fDebug) printf("%s::ReadEuclid: The file name is %s\n",ClassName(),filnam); //Debug
600   filtmp=gSystem->ExpandPathName(filnam);
601   lun=fopen(filtmp,"r");
602   delete [] filtmp;
603   if(!lun) {
604     Warning("ReadEuclidMedia","Could not open file %s\n",filnam);
605     return;
606   }
607   //
608   // Retrieve Mag Field parameters
609   Int_t globField=gAlice->Field()->Integ();
610   Float_t globMaxField=gAlice->Field()->Max();
611   //  TArrayI &idtmed = *fIdtmed;
612   //
613  L10:
614   for(i=0;i<130;i++) card[i]=0;
615   iret=fscanf(lun,"%4s %[^\n]",key,card);
616   if(iret<=0) goto L20;
617   fscanf(lun,"%*c");
618   //*
619   //* read material
620   if (!strcmp(key,"MATE")) {
621     sscanf(card,"%d '%[^']' %f %f %f %f %f %d",&imate,namate,&a,&z,&dens,&radl,&absl,&nwbuf);
622     if (nwbuf>0) for(i=0;i<nwbuf;i++) fscanf(lun,"%f",&ubuf[i]);
623     //Pad the string with blanks
624     i=-1;
625     while(namate[++i]);
626     while(i<20) namate[i++]=' ';
627     namate[i]='\0';
628     //
629     AliMaterial(imate,namate,a,z,dens,radl,absl,ubuf,nwbuf);
630     //* read tracking medium
631   } else if (!strcmp(key,"TMED")) {
632     sscanf(card,"%d '%[^']' %d %d %d %f %f %f %f %f %f %d",
633            &itmed,natmed,&nmat,&isvol,&ifield,&fieldm,&tmaxfd,
634            &stemax,&deemax,&epsil,&stmin,&nwbuf);
635     if (nwbuf>0) for(i=0;i<nwbuf;i++) fscanf(lun,"%f",&ubuf[i]);
636     if (ifield<0) ifield=isxfld;
637     if (fieldm<0) fieldm=sxmgmx;
638     //Pad the string with blanks
639     i=-1;
640     while(natmed[++i]);
641     while(i<20) natmed[i++]=' ';
642     natmed[i]='\0';
643     //
644     AliMedium(itmed,natmed,nmat,isvol,globField,globMaxField,tmaxfd,
645                    stemax,deemax,epsil,stmin,ubuf,nwbuf);
646     //    (*fImedia)[idtmed[itmed]-1]=id_det;
647     //*
648   }
649   //*
650   if (strcmp(key,"END")) goto L10;
651   fclose (lun);
652   //*
653   //*     commented out only for the not cernlib version
654   if(fDebug) printf("%s::ReadEuclidMedia: file %s is now read in\n",
655         ClassName(),filnam);
656   //*
657   return;
658   //*
659  L20:
660   Warning("ReadEuclidMedia","reading error or premature end of file\n");
661
662
663 //_______________________________________________________________________
664 void AliModule::RemapTrackReferencesIDs(Int_t *map)
665 {
666   // 
667   // Remapping track reference
668   // Called at finish primary
669   //
670   if (!fTrackReferences) return;
671   for (Int_t i=0;i<fTrackReferences->GetEntries();i++){
672     AliTrackReference * ref = dynamic_cast<AliTrackReference*>(fTrackReferences->UncheckedAt(i));
673     if (ref) {
674       Int_t newID = map[ref->GetTrack()];
675       if (newID>=0) ref->SetTrack(newID);
676       else ref->SetTrack(-1);
677       
678     }
679   }
680 }
681
682
683 //_______________________________________________________________________
684 AliTrackReference* AliModule::FirstTrackReference(Int_t track)
685 {
686   //
687   // Initialise the hit iterator
688   // Return the address of the first hit for track
689   // If track>=0 the track is read from disk
690   // while if track<0 the first hit of the current
691   // track is returned
692   // 
693   if(track>=0) 
694    {
695      AliRunLoader* rl = AliRunLoader::GetRunLoader();
696
697      rl->GetAliRun()->ResetTrackReferences();
698      rl->TreeTR()->GetEvent(track);
699      if (rl == 0x0)
700        Fatal("FirstTrackReference","AliRunLoader not initialized. Can not proceed");
701    }
702   //
703   fMaxIterTrackRef     = fTrackReferences->GetEntriesFast();
704   fCurrentIterTrackRef = 0;
705   if(fMaxIterTrackRef) return dynamic_cast<AliTrackReference*>(fTrackReferences->UncheckedAt(0));
706   else            return 0;
707 }
708
709 //_______________________________________________________________________
710 AliTrackReference* AliModule::NextTrackReference()
711 {
712   //
713   // Return the next hit for the current track
714   //
715   if(fMaxIterTrackRef) {
716     if(++fCurrentIterTrackRef<fMaxIterTrackRef) 
717       return dynamic_cast<AliTrackReference*>(fTrackReferences->UncheckedAt(fCurrentIterTrackRef));
718     else        
719       return 0;
720   } else {
721     printf("* AliModule::NextTrackReference * TrackReference  Iterator called without calling FistTrackReference before\n");
722     return 0;
723   }
724 }
725
726
727 //_______________________________________________________________________
728 void AliModule::ResetTrackReferences()
729 {
730   //
731   // Reset number of hits and the hits array
732   //
733   fMaxIterTrackRef   = 0;
734   if (fTrackReferences)   fTrackReferences->Clear();
735 }
736  
737 //_____________________________________________________________________________
738
739 AliLoader*  AliModule::MakeLoader(const char* /*topfoldername*/) 
740  {
741    return 0x0;
742  }//skowron   
743  
744 //PH Merged with v3-09-08 |
745 //                        V
746 //_____________________________________________________________________________
747
748 void AliModule::SetTreeAddress()
749 {
750   //
751   // Set branch address for track reference Tree
752   //
753
754   TBranch *branch;
755
756   // Branch address for track reference tree
757   TTree *treeTR = TreeTR();
758
759   if (treeTR && fTrackReferences) {
760      branch = treeTR->GetBranch(GetName());
761     if (branch) 
762      {
763        if(GetDebug()) 
764          Info("SetTreeAddress","(%s) Setting for TrackRefs",GetName());
765        branch->SetAddress(&fTrackReferences);
766      }
767     else
768      { 
769      //can be called before MakeBranch and than does not make sense to issue the warning
770        if(GetDebug()) 
771          Warning("SetTreeAddress",
772                  "(%s) Failed for Track References. Can not find branch in tree.",
773                  GetName());
774      }
775   }
776 }
777
778 //_____________________________________________________________________________
779 void  AliModule::AddTrackReference(Int_t label){
780   //
781   // add a trackrefernce to the list
782   if (!fTrackReferences) {
783     cerr<<"Container trackrefernce not active\n";
784     return;
785   }
786   Int_t nref = fTrackReferences->GetEntriesFast();
787   TClonesArray &lref = *fTrackReferences;
788   new(lref[nref]) AliTrackReference(label);
789 }
790
791
792 //_____________________________________________________________________________
793 void AliModule::MakeBranchTR(Option_t */*option*/)
794
795     //
796     // Makes branch in treeTR
797     //  
798   if(GetDebug()) Info("MakeBranchTR","Making Track Refs. Branch for %s",GetName());
799   TTree * tree = TreeTR();
800   if (fTrackReferences && tree) 
801    {
802       TBranch *branch = tree->GetBranch(GetName());
803      if (branch) 
804        {  
805          if(GetDebug()) Info("MakeBranch","Branch %s is already in tree.",GetName());
806          return;
807        }
808   
809      branch = tree->Branch(GetName(),&fTrackReferences);
810    }
811   else
812     {
813       if(GetDebug()) 
814         Info("MakeBranchTR","FAILED for %s: tree=%#x fTrackReferences=%#x",
815              GetName(),tree,fTrackReferences);
816     }
817 }
818
819 //_____________________________________________________________________________
820 TTree* AliModule::TreeTR()
821 {
822   AliRunLoader* rl = AliRunLoader::GetRunLoader();
823
824   if ( rl == 0x0)
825    {
826      Error("TreeTR","Can not get the run loader");
827      return 0x0;
828    }
829
830   TTree* tree = rl->TreeTR();
831   return tree;
832 }