]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITS.cxx
Tracking V1 decoupled from AliITS
[u/mrichter/AliRoot.git] / ITS / AliITS.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 /*
17 $Log$
18 Revision 1.54  2001/05/31 20:37:56  barbera
19 Bari/Salerno model set as defaault SPD simulation
20
21 Revision 1.53  2001/05/31 18:52:24 barbera 
22 Bari model becomes the default
23
24 Revision 1.53  2001/05/30 07:52:24  hristov
25 TPC and CONTAINERS included in the search path
26
27 Revision 1.52  2001/05/30 06:04:58  hristov
28 Changes made to be consitant with changes in TPC tracking classes (B.Nilsen)
29
30 Revision 1.51  2001/05/16 14:57:15  alibrary
31 New files for folders and Stack
32
33 Revision 1.50  2001/05/11 09:15:21  barbera
34 Corrected to make fast point creation working with PPR geometry
35
36 Revision 1.49  2001/05/11 07:37:49  hristov
37 Legacy lines commented
38
39 Revision 1.48  2001/05/10 18:14:25  barbera
40 A typo corrected
41
42 Revision 1.47  2001/05/10 17:55:59  barbera
43 Modified to create rec points also for PPR geometries
44
45 Revision 1.46  2001/05/10 00:05:28  nilsen
46 Allowed for HitsToDigits function to work with versions 5, 7, 8, and 9. This
47 should probably be cleaned up to only check to make sure that fITSgeom has
48 been properly defined.
49
50 Revision 1.45  2001/05/01 22:35:48  nilsen
51 Remove/commented a number of cout<< statements. and made change needed by
52 SSD code.
53
54 Revision 1.44  2001/04/26 22:44:01  nilsen
55 Removed dependence on layer 5/6 in AliITS::HitsToDigits. This will be
56 done properly in AliITSv???.cxx via SetDefaults.
57
58 Revision 1.43  2001/04/26 13:22:52  barbera
59 TMatrix and TVector elimininated to speed up the code
60
61 Revision 1.42  2001/04/25 21:55:12  barbera
62 Updated version to be compatible with actual verion of STEER and TPC
63
64 Revision 1.41  2001/04/21 15:16:51  barbera
65 Updated with the new SSD reconstruction code
66
67 Revision 1.40  2001/03/17 15:07:06  mariana
68 Update SDD response parameters
69
70 Revision 1.39  2001/03/12 17:45:32  hristov
71 Changes needed on Sun with CC 5.0
72
73 Revision 1.38  2001/03/07 14:04:51  barbera
74 Some vector dimensions increased to cope with full events
75
76 Revision 1.37  2001/03/07 12:36:35  barbera
77 A change added in the tracking part to manage delta rays
78
79 Revision 1.36  2001/03/02 19:44:11  barbera
80  modified to taking into account new version tracking v1
81
82 Revision 1.35  2001/02/28 18:16:46  mariana
83 Make the code compatible with the new AliRun
84
85 Revision 1.34  2001/02/11 15:51:39  mariana
86 Set protection in MakeBranch
87
88 Revision 1.33  2001/02/10 22:26:39  mariana
89 Move the initialization of the containers for raw clusters in MakeTreeC()
90
91 Revision 1.32  2001/02/08 23:55:31  nilsen
92 Removed fMajor/MinorVersion variables in favor of variables in derived classes.
93 Set arrays char *det[3] = {"SPD","SDD","SSD"} as const.
94
95 Revision 1.31  2001/02/02 23:57:28  nilsen
96 Added include file that are no londer included in AliITSgeom.h
97
98 Revision 1.30  2001/01/30 09:23:13  hristov
99 Streamers removed (R.Brun)
100
101 Revision 1.29  2001/01/26 20:01:09  hristov
102 Major upgrade of AliRoot code
103
104 Revision 1.28  2000/12/18 14:02:00  barbera
105 new version of the ITS tracking to take into account the new TPC track parametrization
106
107 Revision 1.27  2000/12/08 13:49:27  barbera
108 Hidden declaration in a for loop removed to be compliant with HP-UX compiler
109
110 Revision 1.26  2000/11/27 13:12:13  barbera
111 New version containing the files for tracking
112
113 Revision 1.25  2000/11/12 22:38:05  barbera
114 Added header file for the SPD Bari model
115
116 Revision 1.24  2000/10/09 22:18:12  barbera
117 Bug fixes from MAriana to le AliITStest.C run correctly
118
119 Revision 1.23  2000/10/05 20:47:42  nilsen
120 fixed dependencies of include files. Tryed but failed to get a root automaticly
121 generates streamer function to work. Modified SetDefaults.
122
123 Revision 1.9.2.15  2000/10/04 16:56:40  nilsen
124 Needed to include stdlib.h
125
126 =======
127 Revision 1.22  2000/10/04 19:45:52  barbera
128 Corrected by F. Carminati for v3.04
129
130 Revision 1.21  2000/10/02 21:28:08  fca
131 Removal of useless dependecies via forward declarations
132
133 Revision 1.20  2000/10/02 16:31:39  barbera
134 General code clean-up
135
136 Revision 1.9.2.14  2000/10/02 15:43:51  barbera
137 General code clean-up (e.g., printf -> cout)
138
139 Revision 1.19  2000/09/22 12:13:25  nilsen
140 Patches and updates for fixes to this and other routines.
141
142 Revision 1.18  2000/07/12 05:32:20  fca
143 Correcting several syntax problem with static members
144
145 Revision 1.17  2000/07/10 16:07:18  fca
146 Release version of ITS code
147
148 Revision 1.9.2.3  2000/02/02 13:42:09  barbera
149 fixed AliITS.cxx for new AliRun structure. Added ITS hits list to list of hits which will have their track numbers updated
150
151 Revision 1.9.2.2  2000/01/23 03:03:13  nilsen
152 //fixed FillModule. Removed fi(fabs(xl)<dx....
153
154 Revision 1.9.2.1  2000/01/12 19:03:32  nilsen
155 This is the version of the files after the merging done in December 1999.
156 See the ReadMe110100.txt file for details
157
158 Revision 1.9  1999/11/14 14:33:25  fca
159 Correct problems with distructors and pointers, thanks to I.Hrivnacova
160
161 Revision 1.8  1999/09/29 09:24:19  fca
162 Introduction of the Copyright and cvs Log
163
164 */
165
166 ///////////////////////////////////////////////////////////////////////////////
167 //
168 //      An overview of the basic philosophy of the ITS code development
169 // and analysis is show in the figure below.
170 //Begin_Html
171 /*
172 <img src="picts/ITS/ITS_Analysis_schema.gif">
173 </pre>
174 <br clear=left>
175 <font size=+2 color=red>
176 <p>Roberto Barbera is in charge of the ITS Offline code (1999).
177 <a href="mailto:roberto.barbera@ct.infn.it">Roberto Barbera</a>.
178 </font>
179 <pre>
180 */
181 //End_Html
182 //
183 //  AliITS. Inner Traking System base class.
184 //  This class contains the base procedures for the Inner Tracking System
185 //
186 //Begin_Html
187 /*
188 <img src="picts/ITS/AliITS_Class_Diagram.gif">
189 </pre>
190 <br clear=left>
191 <font size=+2 color=red>
192 <p>This show the class diagram of the different elements that are part of
193 the AliITS class.
194 </font>
195 <pre>
196 */
197 //End_Html
198 //
199 // Version: 0
200 // Written by Rene Brun, Federico Carminati, and Roberto Barbera
201 //
202 // Version: 1
203 // Modified and documented by Bjorn S. Nilsen
204 // July 11 1999
205 //
206 // Version: 2
207 // Modified and documented by A. Bologna
208 // October 18 1999
209 //
210 // AliITS is the general base class for the ITS. Also see AliDetector for
211 // futher information.
212 //
213 ///////////////////////////////////////////////////////////////////////////////
214 #include <iostream.h>
215 #include <iomanip.h>
216 #include <fstream.h>
217 #include <stdlib.h>
218 #include <TMath.h>
219 #include <TRandom.h>
220 #include <TBranch.h>
221 #include <TVector.h>
222 #include <TClonesArray.h>
223 #include <TROOT.h>
224 #include <TObjectTable.h>
225 #include <TFile.h>
226 #include <TTree.h>
227 #include <TString.h>
228 //#include <TParticle.h>
229
230
231 #include "AliRun.h"
232 #include "AliITS.h"
233 #include "AliITSMap.h"
234 #include "AliITSDetType.h"
235 #include "AliITSClusterFinder.h"
236 #include "AliITSsimulationSPD.h"
237 #include "AliITSsimulationSDD.h"
238 #include "AliITSsimulationSSD.h"
239 #include "AliITSresponse.h"
240 #include "AliITSsegmentationSPD.h"
241 #include "AliITSresponseSPD.h"
242 #include "AliITSresponseSPDdubna.h"
243 #include "AliITSsegmentationSDD.h"
244 #include "AliITSresponseSDD.h"
245 #include "AliITSsegmentationSSD.h"
246 #include "AliITSresponseSSD.h"
247 #include "AliITShit.h"
248 #include "AliITSgeom.h"
249 #include "AliITSdigit.h"
250 #include "AliITSmodule.h"
251 #include "AliITSRecPoint.h"
252 #include "AliITSRawCluster.h"
253 #include "AliMC.h"
254 #include "stdlib.h"
255
256 //#include "AliKalmanTrack.h" 
257 //#include "AliMagF.h"
258 //#include "AliITStrack.h"
259 //#include "AliITSiotrack.h"
260 //#include "AliITStracking.h"
261 //#include "AliITSRad.h"   
262 //#include "AliTPC.h"
263 //#include "AliTPCParam.h"
264 //#include "AliTPCtracker.h"
265
266 ClassImp(AliITS)
267  
268 //_____________________________________________________________________________
269 AliITS::AliITS() : AliDetector() {
270   //
271   // Default initialiser for ITS
272   //     The default constructor of the AliITS class. In addition to
273   // creating the AliITS class it zeros the variables fIshunt (a member
274   // of AliDetector class), fEuclidOut, and fIdN, and zeros the pointers
275   // fITSpoints, fIdSens, and fIdName. The AliDetector default constructor
276   // is also called.
277   //
278
279
280   fIshunt     = 0;
281   fEuclidOut  = 0;
282
283   fNDetTypes = kNTYPES;
284   fIdN        = 0;
285   fIdName     = 0;
286   fIdSens     = 0;
287   fITSmodules = 0;
288   //
289   fDetTypes   = 0;
290   //
291   fDtype  = 0;
292   fNdtype = 0;
293   fCtype  = 0;
294   fNctype = 0;
295   fRecPoints = 0;
296   fNRecPoints = 0;
297   fTreeC = 0;
298   //
299   fITSgeom=0;
300 }
301
302 //_____________________________________________________________________________
303 AliITS::AliITS(const char *name, const char *title):AliDetector(name,title){
304   //
305   // Default initialiser for ITS
306   //     The constructor of the AliITS class. In addition to creating the
307   // AliITS class, it allocates memory for the TClonesArrays fHits and
308   // fDigits, and for the TObjArray fITSpoints. It also zeros the variables
309   // fIshunt (a member of AliDetector class), fEuclidOut, and fIdN, and zeros
310   // the pointers fIdSens and fIdName. To help in displaying hits via the ROOT
311   // macro display.C AliITS also sets the marker color to red. The variables
312   // passes with this constructor, const char *name and *title, are used by
313   // the constructor of AliDetector class. See AliDetector class for a
314   // description of these parameters and its constructor functions.
315   //
316
317
318   fHits       = new TClonesArray("AliITShit", 1560);
319   gAlice->AddHitList(fHits);
320
321   fNDetTypes = kNTYPES;
322
323   fNdtype = new Int_t[kNTYPES];
324   fDtype = new TObjArray(kNTYPES);
325
326   fNctype = new Int_t[kNTYPES];
327   fCtype = new TObjArray(kNTYPES);
328
329
330   fRecPoints = 0;
331   fNRecPoints = 0;
332
333   fTreeC = 0;
334
335   fITSmodules = 0; 
336
337   fIshunt     = 0;
338   fEuclidOut  = 0;
339   fIdN        = 0;
340   fIdName     = 0;
341   fIdSens     = 0;
342  
343   fDetTypes = new TObjArray(kNTYPES);  
344
345   Int_t i;
346   for(i=0;i<kNTYPES;i++) {
347     fDetTypes->AddAt(new AliITSDetType(),i); 
348     fNdtype[i]=0;
349     fNctype[i]=0;
350    }
351   //
352
353   SetMarkerColor(kRed);
354
355   fITSgeom=0;
356 }
357 //___________________________________________________________________________
358 AliITS::AliITS(AliITS &source){
359   // copy constructor
360   if(this==&source) return;
361   Error("AliITS::Copy constructor",
362         "You are not allowed to make a copy of the AliITS");
363   exit(1);
364 }
365 //____________________________________________________________________________
366 AliITS& AliITS::operator=(AliITS &source){
367   // assignment operator
368   if(this==&source) return *this;
369   Error("AliITS::operator=",
370         "You are not allowed to make a copy of the AliITS");
371   exit(1);
372   return *this; //fake return
373 }
374 //____________________________________________________________________________
375 void AliITS::ClearModules(){
376   //clear the modules TObjArray
377
378   if(fITSmodules) fITSmodules->Delete();
379
380 }
381 //_____________________________________________________________________________
382 AliITS::~AliITS(){
383   //
384   // Default distructor for ITS
385   //     The default destructor of the AliITS class. In addition to deleting
386   // the AliITS class it deletes the memory pointed to by the fHits, fDigits,
387   // fIdSens, fIdName, and fITSpoints.
388   //
389
390
391   delete fHits;
392   delete fDigits;
393   delete fRecPoints;
394 //  delete fIdName;        // TObjArray of TObjStrings
395   if(fIdName!=0) delete[] fIdName;  // Array of TStrings
396   if(fIdSens!=0) delete[] fIdSens;
397   if(fITSmodules!=0) {
398       this->ClearModules();
399       delete fITSmodules;
400   }// end if fITSmodules!=0
401
402   //
403   if(fDtype) {
404     fDtype->Delete();
405     delete fDtype;
406   }
407   delete [] fNdtype;
408   if (fCtype) {
409     fCtype->Delete();
410     delete fCtype;
411   }
412   delete [] fNctype;
413   //
414
415   if (fDetTypes) {
416     fDetTypes->Delete();
417     delete fDetTypes;
418   }
419
420   if (fTreeC) delete fTreeC;
421
422   if (fITSgeom) delete fITSgeom;
423
424 }
425
426 //___________________________________________
427 AliITSDetType* AliITS::DetType(Int_t id)
428 {
429   //return pointer to id detector type
430     return ((AliITSDetType*) (*fDetTypes)[id]);
431
432 }
433 //___________________________________________
434 void AliITS::SetClasses(Int_t id, const char *digit, const char *cluster)
435 {
436   //set the digit and cluster classes to be used for the id detector type
437     ((AliITSDetType*) (*fDetTypes)[id])->ClassNames(digit,cluster);
438
439 }
440 //___________________________________________
441 void AliITS::SetResponseModel(Int_t id, AliITSresponse *response)
442 {
443   //set the response model for the id detector type
444
445     ((AliITSDetType*) (*fDetTypes)[id])->ResponseModel(response);
446
447 }
448
449 //___________________________________________
450 void AliITS::SetSegmentationModel(Int_t id, AliITSsegmentation *seg)
451 {
452   //set the segmentation model for the id detector type
453
454     ((AliITSDetType*) (*fDetTypes)[id])->SegmentationModel(seg);
455
456 }
457
458 //___________________________________________
459 void AliITS::SetSimulationModel(Int_t id, AliITSsimulation *sim)
460 {
461   //set the simulation model for the id detector type
462
463    ((AliITSDetType*) (*fDetTypes)[id])->SimulationModel(sim);
464
465 }
466 //___________________________________________
467 void AliITS::SetReconstructionModel(Int_t id, AliITSClusterFinder *reconst)
468 {
469   //set the cluster finder model for the id detector type
470
471    ((AliITSDetType*) (*fDetTypes)[id])->ReconstructionModel(reconst);
472
473 }
474
475 //_____________________________________________________________________________
476 void AliITS::AddHit(Int_t track, Int_t *vol, Float_t *hits){
477   //
478   // Add an ITS hit
479   //     The function to add information to the AliITShit class. See the
480   // AliITShit class for a full description. This function allocates the
481   // necessary new space for the hit information and passes the variable
482   // track, and the pointers *vol and *hits to the AliITShit constructor
483   // function.
484   //
485   TClonesArray &lhits = *fHits;
486   new(lhits[fNhits++]) AliITShit(fIshunt,track,vol,hits);
487 }
488 //_____________________________________________________________________________
489 void AliITS::AddRealDigit(Int_t id, Int_t *digits) 
490 {
491   // add a real digit - as coming from data
492
493   TClonesArray &ldigits = *((TClonesArray*)(*fDtype)[id]);
494   new(ldigits[fNdtype[id]++]) AliITSdigit(digits);
495
496 }
497 //_____________________________________________________________________________
498 void AliITS::AddSimDigit(Int_t id, AliITSdigit *d) 
499 {
500
501   // add a simulated digit
502
503   TClonesArray &ldigits = *((TClonesArray*)(*fDtype)[id]);
504
505   switch(id)
506   {
507   case 0:
508      new(ldigits[fNdtype[id]++]) AliITSdigitSPD(*((AliITSdigitSPD*)d));
509      break;
510   case 1:
511      new(ldigits[fNdtype[id]++]) AliITSdigitSDD(*((AliITSdigitSDD*)d));
512      break;
513   case 2:
514      new(ldigits[fNdtype[id]++]) AliITSdigitSSD(*((AliITSdigitSSD*)d));
515      break;
516   }
517
518 }
519
520 //_____________________________________________________________________________
521 void AliITS::AddSimDigit(Int_t id,Float_t phys,Int_t *digits,Int_t *tracks,Int_t *hits,Float_t *charges){
522
523   // add a simulated digit to the list
524
525   TClonesArray &ldigits = *((TClonesArray*)(*fDtype)[id]);
526   switch(id)
527   {
528   case 0:
529      new(ldigits[fNdtype[id]++]) AliITSdigitSPD(digits,tracks,hits);
530      break;
531   case 1:
532      new(ldigits[fNdtype[id]++]) AliITSdigitSDD(phys,digits,tracks,hits,charges);
533      break;
534   case 2:
535      new(ldigits[fNdtype[id]++]) AliITSdigitSSD(digits,tracks,hits);
536      break;
537   }
538  
539 }
540
541 //_____________________________________________________________________________
542 void AliITS::AddCluster(Int_t id, AliITSRawCluster *c) 
543 {
544
545   // add a cluster to the list
546
547   TClonesArray &lcl = *((TClonesArray*)(*fCtype)[id]);
548
549   switch(id)
550   {
551   case 0:
552      new(lcl[fNctype[id]++]) AliITSRawClusterSPD(*((AliITSRawClusterSPD*)c));
553      break;
554   case 1:
555      new(lcl[fNctype[id]++]) AliITSRawClusterSDD(*((AliITSRawClusterSDD*)c));
556      break;
557   case 2:
558      new(lcl[fNctype[id]++]) AliITSRawClusterSSD(*((AliITSRawClusterSSD*)c));
559      break;
560   }
561
562 }
563
564
565 //_____________________________________________________________________________
566 void AliITS::AddRecPoint(const AliITSRecPoint &r)
567 {
568   //
569   // Add a reconstructed space point to the list
570   //
571   TClonesArray &lrecp = *fRecPoints;
572   new(lrecp[fNRecPoints++]) AliITSRecPoint(r);
573 }
574  
575
576 //____________________________________________
577 void AliITS::ResetDigits()
578 {
579     //
580     // Reset number of digits and the digits array for the ITS detector
581     //
582
583     if (!fDtype) return;
584
585     Int_t i;
586     for (i=0;i<kNTYPES;i++ ) {
587         if ((*fDtype)[i])    ((TClonesArray*)(*fDtype)[i])->Clear();
588         if (fNdtype)  fNdtype[i]=0;
589     }
590 }
591
592 //____________________________________________
593 void AliITS::ResetDigits(Int_t i)
594 {
595     //
596     // Reset number of digits and the digits array for this branch
597     //
598   if ((*fDtype)[i])    ((TClonesArray*)(*fDtype)[i])->Clear();
599   if (fNdtype)  fNdtype[i]=0;
600 }
601
602
603 //____________________________________________
604 void AliITS::ResetClusters()
605 {
606     //
607     // Reset number of clusters and the clusters array for ITS
608     //
609
610     Int_t i;
611     for (i=0;i<kNTYPES;i++ ) {
612         if ((*fCtype)[i])    ((TClonesArray*)(*fCtype)[i])->Clear();
613         if (fNctype)  fNctype[i]=0;
614     }
615
616 }
617
618 //____________________________________________
619 void AliITS::ResetClusters(Int_t i)
620 {
621     //
622     // Reset number of clusters and the clusters array for this branch
623     //
624         if ((*fCtype)[i])    ((TClonesArray*)(*fCtype)[i])->Clear();
625         if (fNctype)  fNctype[i]=0;
626
627 }
628
629
630 //____________________________________________
631 void AliITS::ResetRecPoints()
632 {
633     //
634     // Reset number of rec points and the rec points array 
635     //
636     if (fRecPoints) fRecPoints->Clear();
637     fNRecPoints = 0;
638
639 }
640
641 //_____________________________________________________________________________
642 Int_t AliITS::DistancetoPrimitive(Int_t , Int_t ){
643   //
644   // Distance from mouse to ITS on the screen. Dummy routine
645   //     A dummy routine used by the ROOT macro display.C to allow for the
646   // use of the mouse (pointing device) in the macro. In general this should
647   // never be called. If it is it returns the number 9999 for any value of
648   // x and y.
649   //
650   return 9999;
651 }
652
653 //_____________________________________________________________________________
654 void AliITS::Init(){
655   //
656   // Initialise ITS after it has been built
657   //     This routine initializes the AliITS class. It is intended to be called
658   // from the Init function in AliITSv?. Besides displaying a banner
659   // indicating that it has been called it initializes the array fIdSens
660   // and sets the default segmentation, response, digit and raw cluster classes
661   // Therefore it should be called after a call to CreateGeometry.
662   //
663   Int_t i;
664
665 //
666   SetDefaults();
667 // Array of TStrings
668   for(i=0;i<fIdN;i++) fIdSens[i] = gMC->VolId(fIdName[i]);
669 //
670 }
671
672 //_____________________________________________________________________________
673 void AliITS::SetDefaults()
674 {
675   // sets the default segmentation, response, digit and raw cluster classes
676
677   if(fDebug) printf("%s: SetDefaults\n",ClassName());
678
679   AliITSDetType *iDetType;
680
681
682   //SPD 
683
684   iDetType=DetType(0); 
685   if (!iDetType->GetSegmentationModel()) {
686     AliITSsegmentationSPD *seg0=new AliITSsegmentationSPD(fITSgeom);
687     SetSegmentationModel(0,seg0); 
688   }
689   if (!iDetType->GetResponseModel()) {
690      SetResponseModel(0,new AliITSresponseSPD()); 
691   }
692   // set digit and raw cluster classes to be used
693   
694   const char *kData0=(iDetType->GetResponseModel())->DataType();
695   if (strstr(kData0,"real")) {
696       iDetType->ClassNames("AliITSdigit","AliITSRawClusterSPD");
697   } else iDetType->ClassNames("AliITSdigitSPD","AliITSRawClusterSPD");
698
699   // SDD                                          //
700   iDetType=DetType(1); 
701   if (!iDetType->GetResponseModel()) {
702     SetResponseModel(1,new AliITSresponseSDD()); 
703   }
704   AliITSresponse *resp1=iDetType->GetResponseModel();
705   if (!iDetType->GetSegmentationModel()) {
706     AliITSsegmentationSDD *seg1=new AliITSsegmentationSDD(fITSgeom,resp1);
707     SetSegmentationModel(1,seg1); 
708   }
709   const char *kData1=(iDetType->GetResponseModel())->DataType();
710   const char *kopt=iDetType->GetResponseModel()->ZeroSuppOption();
711   if ((!strstr(kopt,"2D")) && (!strstr(kopt,"1D")) || strstr(kData1,"real") ) {
712       iDetType->ClassNames("AliITSdigit","AliITSRawClusterSDD");
713   } else iDetType->ClassNames("AliITSdigitSDD","AliITSRawClusterSDD");
714
715   // SSD
716   iDetType=DetType(2); 
717   if (!iDetType->GetSegmentationModel()) {
718     AliITSsegmentationSSD *seg2=new AliITSsegmentationSSD(fITSgeom);
719     SetSegmentationModel(2,seg2); 
720   }
721   if (!iDetType->GetResponseModel()) {
722     SetResponseModel(2,new AliITSresponseSSD()); 
723   }
724   const char *kData2=(iDetType->GetResponseModel())->DataType();
725   if (strstr(kData2,"real")) {
726       iDetType->ClassNames("AliITSdigit","AliITSRawClusterSSD");
727   } else iDetType->ClassNames("AliITSdigitSSD","AliITSRawClusterSSD");
728
729   if (kNTYPES>3) {
730     Warning("SetDefaults","Only the three basic detector types are initialised!");
731   } 
732
733 }
734 //_____________________________________________________________________________
735 void AliITS::SetDefaultSimulation()
736 {
737   // to be written
738
739 }
740 //_____________________________________________________________________________
741 void AliITS::SetDefaultClusterFinders()
742 {
743   // to be written
744
745 }
746 //_____________________________________________________________________________
747
748 void AliITS::MakeTreeC(Option_t *option)
749 {
750   // create a separate tree to store the clusters
751
752 //  cout << "AliITS::MakeTreeC" << endl;
753
754      const char *optC = strstr(option,"C");
755      if (optC && !fTreeC) fTreeC = new TTree("TC","Clusters in ITS");
756      else return;
757
758      Int_t buffersize = 4000;
759      char branchname[30];
760
761      const char *det[3] = {"SPD","SDD","SSD"};
762
763      char digclass[40];
764      char clclass[40];
765
766      // one branch for Clusters per type of detector
767      Int_t i;
768      for (i=0; i<kNTYPES ;i++) {
769        AliITSDetType *iDetType=DetType(i); 
770        iDetType->GetClassNames(digclass,clclass);
771        // clusters
772        (*fCtype)[i] = new TClonesArray(clclass,10000); 
773         if (kNTYPES==3) sprintf(branchname,"%sClusters%s",GetName(),det[i]);
774         else  sprintf(branchname,"%sClusters%d",GetName(),i+1);
775         if (fCtype   && fTreeC) {
776            TreeC()->Branch(branchname,&((*fCtype)[i]), buffersize);
777 //         cout << "Making Branch " << branchname;
778 //         cout << " for Clusters of detector type " << i+1 << endl;
779         }       
780      }
781
782 }
783
784 //_____________________________________________________________________________
785 void AliITS::GetTreeC(Int_t event)
786 {
787
788 //  cout << "AliITS::GetTreeC" << endl;
789
790   // get the clusters tree for this event and set the branch address
791     char treeName[20];
792     char branchname[30];
793
794     const char *det[3] = {"SPD","SDD","SSD"};
795
796     ResetClusters();
797     if (fTreeC) {
798           delete fTreeC;
799     }
800
801     sprintf(treeName,"TreeC%d",event);
802     fTreeC = (TTree*)gDirectory->Get(treeName);
803
804     TBranch *branch;
805     if (fTreeC) {
806         Int_t i;
807         for (i=0; i<kNTYPES; i++) {
808            if (kNTYPES==3) sprintf(branchname,"%sClusters%s",GetName(),det[i]);
809            else  sprintf(branchname,"%sClusters%d",GetName(),i+1);
810            if (fCtype) {
811                 branch = fTreeC->GetBranch(branchname);
812                 if (branch) branch->SetAddress(&((*fCtype)[i]));
813             }
814         }
815     } else {
816         Error("AliITS::GetTreeC",
817                 "cannot find Clusters Tree for event:%d\n",event);
818     }
819
820 }
821 //_____________________________________________________________________________
822 void AliITS::MakeBranch(Option_t* option, const char *file)
823 {
824   //
825   // Creates Tree branches for the ITS.
826   //
827   //
828   Int_t buffersize = 4000;
829   char branchname[30];
830   sprintf(branchname,"%s",GetName());
831
832   AliDetector::MakeBranch(option,file);
833
834   const char *cD = strstr(option,"D");
835   const char *cR = strstr(option,"R");
836
837   if (cD) {
838   //
839   // one branch for digits per type of detector
840   //
841    const char *det[3] = {"SPD","SDD","SSD"};
842
843    char digclass[40];
844    char clclass[40];
845
846    Int_t i;
847    for (i=0; i<kNTYPES ;i++) {
848        AliITSDetType *iDetType=DetType(i); 
849        iDetType->GetClassNames(digclass,clclass);
850        // digits
851        if(!((*fDtype)[i])) (*fDtype)[i] = new TClonesArray(digclass,10000);
852        else ResetDigits(i);
853    }
854
855    for (i=0; i<kNTYPES ;i++) {
856       if (kNTYPES==3) sprintf(branchname,"%sDigits%s",GetName(),det[i]);
857       else  sprintf(branchname,"%sDigits%d",GetName(),i+1);      
858       if (fDtype && gAlice->TreeD()) {
859         MakeBranchInTree(gAlice->TreeD(), 
860                          branchname, &((*fDtype)[i]), buffersize, file);
861 //          cout << "Making Branch " << branchname;
862 //          cout << " for digits of type "<< i+1 << endl;
863       } 
864     }
865   }
866
867   if (cR) {
868   //
869   // only one branch for rec points for all detector types
870   //
871     sprintf(branchname,"%sRecPoints",GetName());
872  
873     if(!fRecPoints) fRecPoints=new TClonesArray("AliITSRecPoint",10000);
874
875     if (fRecPoints && gAlice->TreeR()) {
876       MakeBranchInTree(gAlice->TreeR(), 
877                                branchname, &fRecPoints, buffersize, file) ;
878 //      cout << "Making Branch " << branchname;
879 //      cout << " for reconstructed space points" << endl;
880     }
881   }     
882 }
883
884 //___________________________________________
885 void AliITS::SetTreeAddress()
886 {
887
888   // Set branch address for the Trees.
889
890   char branchname[30];
891   AliDetector::SetTreeAddress();
892
893   const char *det[3] = {"SPD","SDD","SSD"};
894
895   TBranch *branch;
896   TTree *treeD = gAlice->TreeD();
897   TTree *treeR = gAlice->TreeR();
898
899   Int_t i;
900   if (treeD) {
901       for (i=0; i<kNTYPES; i++) {
902           if (kNTYPES==3) sprintf(branchname,"%sDigits%s",GetName(),det[i]);
903           else  sprintf(branchname,"%sDigits%d",GetName(),i+1);
904           if (fDtype) {
905               branch = treeD->GetBranch(branchname);
906               if (branch) branch->SetAddress(&((*fDtype)[i]));
907           }
908       }
909   }
910
911  
912   if (treeR) {
913     sprintf(branchname,"%sRecPoints",GetName());
914       branch = treeR->GetBranch(branchname);
915       if (branch) branch->SetAddress(&fRecPoints);
916   }
917   
918
919 }
920
921 //____________________________________________________________________________
922 void AliITS::InitModules(Int_t size,Int_t &nmodules){
923
924   //initialize the modules array
925
926   if(fITSmodules){ 
927       fITSmodules->Delete();
928       delete fITSmodules;
929   }
930
931     Int_t nl,indexMAX,index;
932
933     if(size<=0){ // default to using data stored in AliITSgeom
934         if(fITSgeom==0) {
935             Error("AliITS::InitModules",
936                 "in AliITS::InitModule fITSgeom not defined\n");
937             return;
938         } // end if fITSgeom==0
939         nl = fITSgeom->GetNlayers();
940         indexMAX = fITSgeom->GetModuleIndex(nl,fITSgeom->GetNladders(nl),
941                                             fITSgeom->GetNdetectors(nl))+1;
942         nmodules = indexMAX;
943         fITSmodules = new TObjArray(indexMAX);
944         for(index=0;index<indexMAX;index++){
945                 fITSmodules->AddAt( new AliITSmodule(index),index);
946         } // end for index
947     }else{
948         fITSmodules = new TObjArray(size);
949         for(index=0;index<size;index++) {
950             fITSmodules->AddAt( new AliITSmodule(index),index);
951         }
952
953         nmodules = size;
954     } // end i size<=0
955 }
956
957 //____________________________________________________________________________
958 void AliITS::FillModules(Int_t evnt,Int_t bgrev,Int_t nmodules,Option_t *option,Text_t *filename){
959
960   // fill the modules with the sorted by module hits; add hits from background
961   // if option=Add
962
963
964     static TTree *trH1;                 //Tree with background hits
965     static TClonesArray *fHits2;        //List of hits for one track only
966
967     static Bool_t first=kTRUE;
968     static TFile *file;
969     const char *addBgr = strstr(option,"Add");
970
971
972     if (addBgr ) {
973         if(first) {
974 //          cout<<"filename "<<filename<<endl;
975             file=new TFile(filename);
976 //          cout<<"I have opened "<<filename<<" file "<<endl;
977             fHits2     = new TClonesArray("AliITShit",1000  );
978         }           
979         first=kFALSE;
980         file->cd();
981         file->ls();
982         // Get Hits Tree header from file
983         if(fHits2) fHits2->Clear();
984         if(trH1) delete trH1;
985         trH1=0;
986         
987         char treeName[20];
988         sprintf(treeName,"TreeH%d",bgrev);
989         trH1 = (TTree*)gDirectory->Get(treeName);
990         //printf("TrH1 %p of treename %s for event %d \n",trH1,treeName,bgrev);
991         
992         if (!trH1) {
993             Error("AliITS::FillModules",
994             "cannot find Hits Tree for event:%d\n",bgrev);
995         }
996         // Set branch addresses
997         TBranch *branch;
998         char branchname[20];
999         sprintf(branchname,"%s",GetName());
1000         if (trH1 && fHits2) {
1001             branch = trH1->GetBranch(branchname);
1002             if (branch) branch->SetAddress(&fHits2);
1003         }
1004
1005         // test
1006         //Int_t ntracks1 =(Int_t)TrH1->GetEntries();
1007         //printf("background - ntracks1 - %d\n",ntracks1);
1008    }
1009
1010     //Int_t npart = gAlice->GetEvent(evnt);
1011     //if(npart<=0) return;
1012     TClonesArray *itsHits = this->Hits();
1013     Int_t lay,lad,det,index;
1014     AliITShit *itsHit=0;
1015     AliITSmodule *mod=0;
1016
1017     TTree *iTH = gAlice->TreeH();
1018     Int_t ntracks =(Int_t) iTH->GetEntries();
1019
1020     Int_t t,h;
1021     for(t=0; t<ntracks; t++){
1022         gAlice->ResetHits();
1023         iTH->GetEvent(t);
1024         Int_t nhits = itsHits->GetEntriesFast();
1025         //printf("nhits %d\n",nhits);
1026         if (!nhits) continue;
1027         for(h=0; h<nhits; h++){
1028             itsHit = (AliITShit *)itsHits->UncheckedAt(h);
1029             itsHit->GetDetectorID(lay,lad,det);
1030             // temporarily index=det-1 !!!
1031             if(fITSgeom) index = fITSgeom->GetModuleIndex(lay,lad,det);
1032             else index=det-1;
1033             //
1034             mod = this->GetModule(index);
1035             mod->AddHit(itsHit,t,h);
1036         } // end loop over hits 
1037     } // end loop over tracks
1038
1039     // open the file with background
1040     
1041     if (addBgr ) {
1042           Int_t track,i;
1043           ntracks =(Int_t)trH1->GetEntries();
1044             //printf("background - ntracks1 %d\n",ntracks);
1045             //printf("background - Start loop over tracks \n");     
1046             //   Loop over tracks
1047
1048             for (track=0; track<ntracks; track++) {
1049
1050                 if (fHits2)       fHits2->Clear();
1051                 trH1->GetEvent(track);
1052                 //   Loop over hits
1053                 for(i=0;i<fHits2->GetEntriesFast();++i) {
1054
1055                     itsHit=(AliITShit*) (*fHits2)[i];
1056                     itsHit->GetDetectorID(lay,lad,det);
1057                     // temporarily index=det-1 !!!
1058                     if(fITSgeom) index = fITSgeom->GetModuleIndex(lay,lad,det);
1059                     else index=det-1;
1060                     //
1061                     mod = this->GetModule(index);
1062                     mod->AddHit(itsHit,track,i);
1063                }  // end loop over hits
1064             } // end loop over tracks
1065
1066             TTree *fAli=gAlice->TreeK();
1067             TFile *fileAli=0;
1068             
1069             if (fAli) fileAli =fAli->GetCurrentFile();
1070             fileAli->cd();
1071
1072     } // end if add
1073
1074     //gObjectTable->Print();
1075
1076 }
1077
1078 //____________________________________________________________________________
1079
1080 void AliITS::SDigits2Digits()
1081 {
1082   
1083   AliITSgeom *geom = GetITSgeom();
1084   
1085   // SPD
1086   AliITSDetType *iDetType;
1087   iDetType=DetType(0);
1088   AliITSsegmentationSPD *seg0=(AliITSsegmentationSPD*)iDetType->GetSegmentationModel();
1089   AliITSresponseSPD *res0 = (AliITSresponseSPD*)iDetType->GetResponseModel();
1090   AliITSsimulationSPD *sim0=new AliITSsimulationSPD(seg0,res0);
1091   SetSimulationModel(0,sim0);
1092   // test
1093   // printf("SPD dimensions %f %f \n",seg0->Dx(),seg0->Dz());
1094   // printf("SPD npixels %d %d \n",seg0->Npz(),seg0->Npx());
1095   // printf("SPD pitches %d %d \n",seg0->Dpz(0),seg0->Dpx(0));
1096   // end test
1097   // 
1098   // SDD
1099   //Set response functions
1100   // SDD compression param: 2 fDecrease, 2fTmin, 2fTmax or disable, 2 fTolerance
1101
1102   iDetType=DetType(1);
1103   AliITSresponseSDD *res1 = (AliITSresponseSDD*)iDetType->GetResponseModel();
1104   if (!res1) {
1105     res1=new AliITSresponseSDD();
1106     SetResponseModel(1,res1);
1107   }
1108   Float_t noise, baseline;
1109   res1->GetNoiseParam(noise,baseline);
1110   Float_t noise_after_el =  res1->GetNoiseAfterElectronics();
1111   Float_t fCutAmp = baseline + 2.*noise_after_el;
1112   Int_t cp[8]={0,0,(int)fCutAmp,(int)fCutAmp,0,0,0,0}; //1D
1113   res1->SetCompressParam(cp);
1114   AliITSsegmentationSDD *seg1=(AliITSsegmentationSDD*)iDetType->GetSegmentationModel();
1115   if (!seg1) {
1116     seg1 = new AliITSsegmentationSDD(geom,res1);
1117     SetSegmentationModel(1,seg1);
1118   }
1119   AliITSsimulationSDD *sim1=new AliITSsimulationSDD(seg1,res1);
1120   SetSimulationModel(1,sim1);
1121
1122   // SSD
1123   iDetType=DetType(2);
1124   AliITSsegmentationSSD *seg2=(AliITSsegmentationSSD*)iDetType->GetSegmentationModel();
1125   AliITSresponseSSD *res2 = (AliITSresponseSSD*)iDetType->GetResponseModel();
1126   res2->SetSigmaSpread(3.,2.);
1127   AliITSsimulationSSD *sim2=new AliITSsimulationSSD(seg2,res2);
1128   SetSimulationModel(2,sim2);
1129  
1130   cerr<<"Digitizing ITS...\n";
1131  
1132   TStopwatch timer;
1133   timer.Start();
1134   HitsToDigits(gAlice->GetEvNumber(),0,-1," ","All"," ");
1135   timer.Stop(); timer.Print();
1136
1137   delete sim0;
1138   delete sim1;
1139   delete sim2;
1140 }
1141
1142
1143 //____________________________________________________________________________
1144 void AliITS::HitsToDigits(Int_t evNumber,Int_t bgrev,Int_t size, Option_t *option, Option_t *opt,Text_t *filename)
1145 {
1146     // keep galice.root for signal and name differently the file for 
1147     // background when add! otherwise the track info for signal will be lost !
1148   
1149    // the condition below will disappear when the geom class will be
1150    // initialised for all versions - for the moment it is only for v5 !
1151    // 7 is the SDD beam test version  
1152    Int_t ver = this->IsVersion(); 
1153    if(ver!=5 && ver!=7 && ver!=8 && ver!=9) return; 
1154
1155    const char *all = strstr(opt,"All");
1156    const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),strstr(opt,"SSD")};
1157 //   cout<<" 1 AliITS "<<endl;
1158    Int_t nmodules;
1159    InitModules(size,nmodules); 
1160 //   cout<<" 2 AliITS "<<endl;
1161    FillModules(evNumber,bgrev,nmodules,option,filename);
1162 //   cout<<" 3 AliITS "<<endl;
1163
1164    //TBranch *branch;
1165    AliITSsimulation* sim;
1166    //TObjArray *branches=gAlice->TreeD()->GetListOfBranches();
1167    AliITSgeom *geom = GetITSgeom();
1168
1169    Int_t id,module;
1170 //   Int_t lay, lad, detect;
1171    Int_t first,last;
1172    for (id=0;id<kNTYPES;id++) {
1173         if (!all && !det[id]) continue;
1174         //branch = (TBranch*)branches->UncheckedAt(id);
1175         AliITSDetType *iDetType=DetType(id); 
1176         sim = (AliITSsimulation*)iDetType->GetSimulationModel();
1177
1178         if (!sim) {
1179            Error("HitsToDigits","The simulation class was not instantiated!");
1180            exit(1);
1181            // or SetDefaultSimulation();
1182         }
1183
1184         if(geom) {
1185           first = geom->GetStartDet(id);
1186           last = geom->GetLastDet(id);
1187         } else first=last=0;
1188 //      cout << "det type " << id << " first, last "<< first << last << endl;
1189         for(module=first;module<=last;module++) {
1190             AliITSmodule *mod = (AliITSmodule *)fITSmodules->At(module);
1191 /*
1192             geom->GetModuleId(module,lay, lad, detect);
1193             if ( lay == 6 )
1194               ((AliITSsegmentationSSD*)(((AliITSsimulationSSD*)sim)->GetSegmentation()))->SetLayer(6);
1195             if ( lay == 5 )
1196               ((AliITSsegmentationSSD*)(((AliITSsimulationSSD*)sim)->GetSegmentation()))->SetLayer(5);
1197 */
1198             sim->DigitiseModule(mod,module,evNumber);
1199             // fills all branches - wasted disk space
1200             gAlice->TreeD()->Fill(); 
1201             ResetDigits();
1202             // try and fill only the branch 
1203             //branch->Fill();
1204             //ResetDigits(id);
1205         } // loop over modules
1206    } // loop over detector types
1207
1208    ClearModules();
1209
1210 //   Int_t nentries=(Int_t)
1211    gAlice->TreeD()->GetEntries();
1212 //   cout << "nentries in TreeD" << nentries << endl;
1213
1214    char hname[30];
1215    sprintf(hname,"TreeD%d",evNumber);
1216    gAlice->TreeD()->Write(hname,TObject::kOverwrite);
1217    // reset tree
1218    gAlice->TreeD()->Reset();
1219
1220 }
1221
1222
1223 //____________________________________________________________________________
1224 void AliITS::DigitsToRecPoints(Int_t evNumber,Int_t lastentry,Option_t *opt)
1225 {
1226   // cluster finding and reconstruction of space points
1227   
1228    // the condition below will disappear when the geom class will be
1229    // initialised for all versions - for the moment it is only for v5 !
1230    // 7 is the SDD beam test version  
1231    Int_t ver = this->IsVersion(); 
1232    if(ver!=5 && ver!=8 && ver!=9) return;
1233
1234    const char *all = strstr(opt,"All");
1235    const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),strstr(opt,"SSD")};
1236
1237    static Bool_t first=kTRUE;
1238    if (!TreeC() && first) {
1239        MakeTreeC("C");
1240        first=kFALSE;
1241    }
1242
1243    TTree *treeC=TreeC();
1244  
1245
1246    //TBranch *branch;
1247    AliITSClusterFinder* rec;
1248
1249    //TObjArray *branches=gAlice->TreeR()->GetListOfBranches();
1250    AliITSgeom *geom = GetITSgeom();
1251
1252    Int_t id,module;
1253    for (id=0;id<kNTYPES;id++) {
1254         if (!all && !det[id]) continue;
1255         //branch = (TBranch*)branches->UncheckedAt(id);
1256         AliITSDetType *iDetType=DetType(id); 
1257         rec = (AliITSClusterFinder*)iDetType->GetReconstructionModel();
1258         if (!rec) {
1259            Error("DigitsToRecPoints","The cluster finder class was not instantiated!");
1260            exit(1);
1261            // or SetDefaultClusterFinders();
1262         }
1263         TClonesArray *itsDigits  = this->DigitsAddress(id);
1264
1265         Int_t first,last;
1266         if(geom) {
1267           first = geom->GetStartDet(id);
1268           last = geom->GetLastDet(id);
1269         } else first=last=0;
1270         printf("first module - last module %d %d\n",first,last);
1271         for(module=first;module<=last;module++) {
1272               this->ResetDigits();
1273               if (all) gAlice->TreeD()->GetEvent(lastentry+module);
1274               else gAlice->TreeD()->GetEvent(lastentry+(module-first));
1275               Int_t ndigits = itsDigits->GetEntriesFast();
1276               if (ndigits) rec->FindRawClusters(module);
1277               gAlice->TreeR()->Fill(); 
1278               ResetRecPoints();
1279               treeC->Fill();
1280               ResetClusters();
1281               // try and fill only the branch 
1282               //branch->Fill();
1283               //ResetRecPoints(id);
1284         } // loop over modules
1285    } // loop over detector types
1286
1287
1288 //   Int_t nentries=(Int_t)
1289    gAlice->TreeR()->GetEntries();
1290 //   Int_t ncentries=(Int_t)
1291    treeC->GetEntries();
1292 //   cout << " nentries ncentries " << nentries << ncentries <<  endl;
1293
1294    char hname[30];
1295    sprintf(hname,"TreeR%d",evNumber);
1296    gAlice->TreeR()->Write(hname,TObject::kOverwrite);
1297    // reset tree
1298    gAlice->TreeR()->Reset();
1299
1300    sprintf(hname,"TreeC%d",evNumber);
1301    treeC->Write(hname,TObject::kOverwrite);
1302    treeC->Reset();
1303 }
1304 //____________________________________________________________________________
1305 void AliITS::HitsToFastRecPoints(Int_t evNumber,Int_t bgrev,Int_t size,
1306 Option_t *option,Option_t *opt,Text_t *filename)
1307 {
1308     // keep galice.root for signal and name differently the file for 
1309     // background when add! otherwise the track info for signal will be lost !
1310   
1311
1312    // the condition below will disappear when the geom class will be
1313    // initialised for all versions - for the moment it is only for v5 !  
1314    Int_t ver = this->IsVersion(); 
1315    if(ver!=5 && ver!=8 && ver!=9) return;
1316    //if(ver!=5) return; 
1317
1318    const char *all = strstr(opt,"All");
1319    const char *det[3] ={strstr(opt,"SPD"),strstr(opt,"SDD"),strstr(opt,"SSD")};
1320
1321    Int_t nmodules;
1322    InitModules(size,nmodules);
1323    FillModules(evNumber,bgrev,nmodules,option,filename);
1324
1325
1326    AliITSsimulation* sim;
1327    AliITSgeom *geom = GetITSgeom();
1328
1329    TRandom *random=new TRandom[9];
1330    random[0].SetSeed(111);
1331    random[1].SetSeed(222);
1332    random[2].SetSeed(333);              
1333    random[3].SetSeed(444);
1334    random[4].SetSeed(555);
1335    random[5].SetSeed(666);              
1336    random[6].SetSeed(777);
1337    random[7].SetSeed(888);
1338    random[8].SetSeed(999);              
1339
1340
1341    Int_t id,module;
1342    for (id=0;id<kNTYPES;id++) {
1343         if (!all && !det[id]) continue;
1344         AliITSDetType *iDetType=DetType(id); 
1345         sim = (AliITSsimulation*)iDetType->GetSimulationModel();
1346         if (!sim) {
1347            Error("HitsToFastPoints",
1348                  "The simulation class was not instantiated!");
1349            exit(1);
1350            // or SetDefaultSimulation();
1351         }
1352
1353         Int_t first,last;
1354         if(geom) {
1355           first = geom->GetStartDet(id);
1356           last = geom->GetLastDet(id);
1357         } else first=last=0;
1358         printf("first module - last module %d %d\n",first,last);
1359         for(module=first;module<=last;module++) {
1360             AliITSmodule *mod = (AliITSmodule *)fITSmodules->At(module);
1361             sim->CreateFastRecPoints(mod,module,random);
1362             gAlice->TreeR()->Fill(); 
1363             ResetRecPoints();
1364         } // loop over modules
1365    } // loop over detector types
1366
1367
1368    ClearModules();
1369
1370    //Int_t nentries=(Int_t)gAlice->TreeR()->GetEntries();
1371
1372    char hname[30];
1373    sprintf(hname,"TreeR%d",evNumber);
1374    gAlice->TreeR()->Write(hname,TObject::kOverwrite);
1375    // reset tree
1376    gAlice->TreeR()->Reset();
1377
1378    delete [] random;
1379
1380 }