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