]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITS.cxx
Update of documentation to reflect changes in AliITSdigitS?D classes.
[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.72  2002/06/10 17:28:55  nilsen
19 Added new FillModules routine and cleaned up the old one.
20
21 Revision 1.71  2002/05/13 14:27:56  hristov
22 TreeC created once per event (M.Masera)
23
24 Revision 1.70  2002/05/10 22:28:30  nilsen
25 Changes by Massimo Masera to allow the TTree of clusters to be written to a
26 file otherthan the one with digits in it.
27
28 Revision 1.69  2002/05/05 21:06:55  nilsen
29 Added GetSimulationMoel, and fixed up SetDefaultSimulation to do the
30 proper initilization when a simulation has already been defined.
31
32 Revision 1.68  2002/05/02 18:51:53  nilsen
33 AliITS.h
34    Method MakeBranchR has now a second argument, with a default value:
35        Option_t *opt=" ". Opt="Fast" is to create a separate branch
36        for fast points in TreeR
37    New method MakeBranchRF: it a separate branch in TreeR for Fast Points
38
39 AliITS.cxx
40 1) TTree->Write() replaced with TTree->AutoSave for TreeS, TreeD and
41    TreeR
42 2) Changes in MakeBranchR to allow the creation of a special branch
43    for fast points
44
45 Revision 1.67  2002/03/15 17:22:51  nilsen
46 Intoduced SDigits2Digits and SDigitsToDigits functions.
47
48 Revision 1.66  2001/11/28 01:35:45  nilsen
49 Using standard constructors instead of default constructors for Clusterfinder,
50 Response, and FastSimulator.
51
52 Revision 1.65  2001/11/27 16:27:28  nilsen
53 Adding AliITSDigitizer class to do merging and digitization . Based on the
54 TTask method. AliITSDigitizer class added to the Makefile and ITSLinkDef.h
55 file. The following files required minor changes. AliITS, added functions
56 SetHitsAddressBranch, MakeBranchInTreeD and modified MakeBranchD.
57 AliITSsimulationSDD.cxx needed a Tree indepenent way of returning back to
58 the original Root Directory in function Compress1D. Now it uses gDirectory.
59
60 Revision 1.64  2001/11/19 16:17:02  nilsen
61 Applyed fixes to bugs found by Rene Brun. With many thanks. Some additonal
62 bugs found by Rene require more work to fix. Will be fixed soon.
63
64 Revision 1.63  2001/10/24 21:16:34  nilsen
65 Removed some dead code and improved comments/documntation.
66
67 Revision 1.62  2001/10/21 19:23:21  nilsen
68 Added function to allow to limit which detectors to digitize and reconstruct.
69 The default is All. This change makes no changes to any root file.
70
71 Revision 1.61  2001/10/11 15:26:07  mariana
72 Correct HitsToFastRecPoints
73
74 Revision 1.60  2001/10/04 22:38:10  nilsen
75 Changes made to support PreDigits (SDigits) plus other helpful changes.
76
77 Revision 1.59  2001/08/30 09:56:18  hristov
78 The operator[] is replaced by At() or AddAt() in case of TObjArray.
79
80 Revision 1.58  2001/07/26 15:05:29  hristov
81 Use global gRandom generator (M.Ivanov)
82
83 Revision 1.57  2001/07/24 14:26:11  mariana
84 Introduce the function Digits2Reco() and write the defaults for simulation and reconstruction
85
86 Revision 1.56  2001/07/05 12:49:49  mariana
87 Temporary patches required by root.v3.01.05
88
89 Revision 1.55  2001/06/14 14:59:00  barbera
90 Tracking V1 decoupled from AliITS
91
92 Revision 1.54  2001/05/31 20:37:56  barbera
93 Bari/Salerno model set as defaault SPD simulation
94
95 Revision 1.53  2001/05/31 18:52:24 barbera 
96 Bari model becomes the default
97
98 Revision 1.53  2001/05/30 07:52:24  hristov
99 TPC and CONTAINERS included in the search path
100
101 Revision 1.52  2001/05/30 06:04:58  hristov
102 Changes made to be consitant with changes in TPC tracking classes (B.Nilsen)
103
104 Revision 1.51  2001/05/16 14:57:15  alibrary
105 New files for folders and Stack
106
107 Revision 1.50  2001/05/11 09:15:21  barbera
108 Corrected to make fast point creation working with PPR geometry
109
110 Revision 1.49  2001/05/11 07:37:49  hristov
111 Legacy lines commented
112
113 Revision 1.48  2001/05/10 18:14:25  barbera
114 A typo corrected
115
116 Revision 1.47  2001/05/10 17:55:59  barbera
117 Modified to create rec points also for PPR geometries
118
119 Revision 1.46  2001/05/10 00:05:28  nilsen
120 Allowed for HitsToDigits function to work with versions 5, 7, 8, and 9. This
121 should probably be cleaned up to only check to make sure that fITSgeom has
122 been properly defined.
123
124 Revision 1.45  2001/05/01 22:35:48  nilsen
125 Remove/commented a number of cout<< statements. and made change needed by
126 SSD code.
127
128 Revision 1.44  2001/04/26 22:44:01  nilsen
129 Removed dependence on layer 5/6 in AliITS::HitsToDigits. This will be
130 done properly in AliITSv???.cxx via SetDefaults.
131
132 Revision 1.43  2001/04/26 13:22:52  barbera
133 TMatrix and TVector elimininated to speed up the code
134
135 Revision 1.42  2001/04/25 21:55:12  barbera
136 Updated version to be compatible with actual verion of STEER and TPC
137
138 Revision 1.41  2001/04/21 15:16:51  barbera
139 Updated with the new SSD reconstruction code
140
141 Revision 1.40  2001/03/17 15:07:06  mariana
142 Update SDD response parameters
143
144 Revision 1.39  2001/03/12 17:45:32  hristov
145 Changes needed on Sun with CC 5.0
146
147 Revision 1.38  2001/03/07 14:04:51  barbera
148 Some vector dimensions increased to cope with full events
149
150 Revision 1.37  2001/03/07 12:36:35  barbera
151 A change added in the tracking part to manage delta rays
152
153 Revision 1.36  2001/03/02 19:44:11  barbera
154  modified to taking into account new version tracking v1
155
156 Revision 1.35  2001/02/28 18:16:46  mariana
157 Make the code compatible with the new AliRun
158
159 Revision 1.34  2001/02/11 15:51:39  mariana
160 Set protection in MakeBranch
161
162 Revision 1.33  2001/02/10 22:26:39  mariana
163 Move the initialization of the containers for raw clusters in MakeTreeC()
164
165 Revision 1.32  2001/02/08 23:55:31  nilsen
166 Removed fMajor/MinorVersion variables in favor of variables in derived classes.
167 Set arrays char *det[3] = {"SPD","SDD","SSD"} as const.
168
169 Revision 1.31  2001/02/02 23:57:28  nilsen
170 Added include file that are no londer included in AliITSgeom.h
171
172 Revision 1.30  2001/01/30 09:23:13  hristov
173 Streamers removed (R.Brun)
174
175 Revision 1.29  2001/01/26 20:01:09  hristov
176 Major upgrade of AliRoot code
177
178 Revision 1.28  2000/12/18 14:02:00  barbera
179 new version of the ITS tracking to take into account the new TPC track parametrization
180
181 Revision 1.27  2000/12/08 13:49:27  barbera
182 Hidden declaration in a for loop removed to be compliant with HP-UX compiler
183
184 Revision 1.26  2000/11/27 13:12:13  barbera
185 New version containing the files for tracking
186
187 Revision 1.25  2000/11/12 22:38:05  barbera
188 Added header file for the SPD Bari model
189
190 Revision 1.24  2000/10/09 22:18:12  barbera
191 Bug fixes from MAriana to le AliITStest.C run correctly
192
193 Revision 1.23  2000/10/05 20:47:42  nilsen
194 fixed dependencies of include files. Tryed but failed to get a root automaticly
195 generates streamer function to work. Modified SetDefaults.
196
197 Revision 1.9.2.15  2000/10/04 16:56:40  nilsen
198 Needed to include stdlib.h
199
200 =======
201 Revision 1.22  2000/10/04 19:45:52  barbera
202 Corrected by F. Carminati for v3.04
203
204 Revision 1.21  2000/10/02 21:28:08  fca
205 Removal of useless dependecies via forward declarations
206
207 Revision 1.20  2000/10/02 16:31:39  barbera
208 General code clean-up
209
210 Revision 1.9.2.14  2000/10/02 15:43:51  barbera
211 General code clean-up (e.g., printf -> cout)
212
213 Revision 1.19  2000/09/22 12:13:25  nilsen
214 Patches and updates for fixes to this and other routines.
215
216 Revision 1.18  2000/07/12 05:32:20  fca
217 Correcting several syntax problem with static members
218
219 Revision 1.17  2000/07/10 16:07:18  fca
220 Release version of ITS code
221
222 Revision 1.9.2.3  2000/02/02 13:42:09  barbera
223 fixed AliITS.cxx for new AliRun structure. Added ITS hits list to list of hits which will have their track numbers updated
224
225 Revision 1.9.2.2  2000/01/23 03:03:13  nilsen
226 //fixed FillModule. Removed fi(fabs(xl)<dx....
227
228 Revision 1.9.2.1  2000/01/12 19:03:32  nilsen
229 This is the version of the files after the merging done in December 1999.
230 See the ReadMe110100.txt file for details
231
232 Revision 1.9  1999/11/14 14:33:25  fca
233 Correct problems with distructors and pointers, thanks to I.Hrivnacova
234
235 Revision 1.8  1999/09/29 09:24:19  fca
236 Introduction of the Copyright and cvs Log
237
238 */
239
240 ///////////////////////////////////////////////////////////////////////////////
241 //
242 //      An overview of the basic philosophy of the ITS code development
243 // and analysis is show in the figure below.
244 //Begin_Html
245 /*
246 <img src="picts/ITS/ITS_Analysis_schema.gif">
247 </pre>
248 <br clear=left>
249 <font size=+2 color=red>
250 <p>Roberto Barbera is in charge of the ITS Offline code (1999).
251 <a href="mailto:roberto.barbera@ct.infn.it">Roberto Barbera</a>.
252 </font>
253 <pre>
254 */
255 //End_Html
256 //
257 //  AliITS. Inner Traking System base class.
258 //  This class contains the base procedures for the Inner Tracking System
259 //
260 //Begin_Html
261 /*
262 <img src="picts/ITS/AliITS_Class_Diagram.gif">
263 </pre>
264 <br clear=left>
265 <font size=+2 color=red>
266 <p>This show the class diagram of the different elements that are part of
267 the AliITS class.
268 </font>
269 <pre>
270 */
271 //End_Html
272 //
273 // Version: 0
274 // Written by Rene Brun, Federico Carminati, and Roberto Barbera
275 //
276 // Version: 1
277 // Modified and documented by Bjorn S. Nilsen
278 // July 11 1999
279 //
280 // Version: 2
281 // Modified and documented by A. Bologna
282 // October 18 1999
283 //
284 // AliITS is the general base class for the ITS. Also see AliDetector for
285 // futher information.
286 //
287 ///////////////////////////////////////////////////////////////////////////////
288 #include <iostream.h>
289 #include <iomanip.h>
290 #include <fstream.h>
291 #include <stdlib.h>
292 #include <TMath.h>
293 #include <TRandom.h>
294 #include <TBranch.h>
295 #include <TVector.h>
296 #include <TClonesArray.h>
297 #include <TROOT.h>
298 #include <TObjectTable.h>
299 #include <TFile.h>
300 #include <TTree.h>
301 #include <TString.h>
302
303 #include "AliMC.h"
304 #include "AliHeader.h"
305
306 #include "AliITS.h"
307 #include "AliITSDetType.h"
308 #include "AliITSresponseSPD.h"
309 #include "AliITSresponseSDD.h"
310 #include "AliITSresponseSSD.h"
311 #include "AliITSsegmentationSPD.h"
312 #include "AliITSsegmentationSDD.h"
313 #include "AliITSsegmentationSSD.h"
314 #include "AliITSsimulationSPD.h"
315 #include "AliITSsimulationSDD.h"
316 #include "AliITSsimulationSSD.h"
317 #include "AliITSClusterFinderSPD.h"
318 #include "AliITSClusterFinderSDD.h"
319 #include "AliITSClusterFinderSSD.h"
320 #include "AliITShit.h"
321 #include "AliITSgeom.h"
322 #include "AliITSpList.h"
323 #include "AliITSdigit.h"
324 #include "AliITSmodule.h"
325 #include "AliITSRecPoint.h"
326 #include "AliITSRawCluster.h"
327
328 ClassImp(AliITS)
329
330 //______________________________________________________________________
331 AliITS::AliITS() : AliDetector() {
332     // Default initializer for ITS
333     //      The default constructor of the AliITS class. In addition to
334     // creating the AliITS class it zeros the variables fIshunt (a member
335     // of AliDetector class), fEuclidOut, and fIdN, and zeros the pointers
336     // fITSpoints, fIdSens, and fIdName. The AliDetector default constructor
337     // is also called.
338     // Inputs:
339     //      none.
340     // Outputs:
341     //      none.
342     // Return:
343     //      Blank ITS class.
344
345     fIshunt     = 0;   // not zeroed in AliDetector.
346
347     // AliITS variables.
348     fEuclidOut  = 0;
349     fITSgeom    = 0;
350     fITSmodules = 0;
351     fOpt        = "All";
352 //    SetDetectors(); // default to fOpt="All". This variable not written out.
353
354     fIdN        = 0;
355     fIdName     = 0;
356     fIdSens     = 0;
357
358     fNDetTypes  = kNTYPES;
359     fDetTypes   = 0;
360
361     fSDigits    = 0;
362     fNSDigits   = 0;
363
364     fNdtype     = 0;
365     fDtype      = 0;
366
367     fCtype      = 0;
368     fNctype     = 0;
369     fTreeC      = 0;
370
371     fRecPoints  = 0;
372     fNRecPoints = 0;
373
374     SetMarkerColor(kRed);
375 }
376 //______________________________________________________________________
377 AliITS::AliITS(const char *name, const char *title):AliDetector(name,title){
378     //     The standard Constructor for the ITS class. In addition to 
379     // creating the AliITS class, it allocates memory for the TClonesArrays 
380     // fHits, fSDigits, fDigits, fITSpoints, and the TObjArray of fCtype 
381     // (clusters). It also zeros the variables
382     // fIshunt (a member of AliDetector class), fEuclidOut, and fIdN, and zeros
383     // the pointers fIdSens and fIdName. To help in displaying hits via the
384     // ROOT macro display.C AliITS also sets the marker color to red. The
385     // variables passes with this constructor, const char *name and *title,
386     // are used by the constructor of AliDetector class. See AliDetector
387     // class for a description of these parameters and its constructor
388     // functions.
389     // Inputs:
390     //      const char *name      Detector name. Should always be "ITS"
391     //      const char *title     Detector title.
392     // Outputs:
393     //      none.
394     // Return:
395     //      An ITS class.
396
397     fIshunt     = 0;  // not zeroed in AliDetector
398     fHits       = new TClonesArray("AliITShit", 1560);//not done in AliDetector
399     gAlice->AddHitList(fHits);  // Not done in AliDetector.
400
401     fEuclidOut  = 0;
402     fITSgeom    = 0;
403     fITSmodules = 0;
404     SetDetectors(); // default to fOpt="All". This variable not written out.
405
406     fIdN        = 0;
407     fIdName     = 0;
408     fIdSens     = 0;
409
410     fNDetTypes  = kNTYPES;
411     fDetTypes   = new TObjArray(fNDetTypes);
412
413     fSDigits    = new TClonesArray("AliITSpListItem",1000);
414     fNSDigits   = 0;
415
416     fNdtype     = new Int_t[fNDetTypes];
417     fDtype      = new TObjArray(fNDetTypes);
418
419     fCtype      = new TObjArray(fNDetTypes);
420     fNctype     = new Int_t[fNDetTypes];
421     fTreeC      = 0;
422
423     fRecPoints  = new TClonesArray("AliITSRecPoint",1000);
424     fNRecPoints = 0;
425
426     Int_t i;
427     for(i=0;i<fNDetTypes;i++) {
428         fDetTypes->AddAt(new AliITSDetType(),i); 
429         fNdtype[i] = 0;
430         fNctype[i] = 0;
431     } // end for i
432
433     SetMarkerColor(kRed);
434 }
435 //______________________________________________________________________
436 AliITS::~AliITS(){
437     // Default destructor for ITS.
438     //     The default destructor of the AliITS class. In addition to deleting
439     // the AliITS class it deletes the memory pointed to by the fHits, fDigits,
440     // fSDigits, fCtype, fITSmodules, fITSgeom, fRecPoints, fIdSens, fIdName, 
441     // fITSpoints, fDetType and it's contents.
442     // Inputs:
443     //      none.
444     // Outputs:
445     //      none.
446     // Return:
447     //      none.
448
449     delete fHits; fHits=0;
450     delete fSDigits; fSDigits=0;
451 //    delete fDigits; fDigits=0;
452     delete fRecPoints; fRecPoints=0;
453     if(fIdName!=0) delete[] fIdName;  // Array of TStrings
454     if(fIdSens!=0) delete[] fIdSens;
455     if(fITSmodules!=0) {
456         this->ClearModules();
457         delete fITSmodules;
458     }// end if fITSmodules!=0
459
460     if(fDtype) {
461         fDtype->Delete();
462         delete fDtype;
463     } // end if fDtype
464     delete [] fNdtype;
465     if (fCtype) {
466         fCtype->Delete();
467         delete fCtype;
468     } // end if fCtype
469     delete [] fNctype;
470
471     if (fDetTypes) {
472         fDetTypes->Delete();
473         delete fDetTypes;
474     } // end if fDetTypes
475
476     if (fTreeC) delete fTreeC;
477
478     if (fITSgeom) delete fITSgeom;
479 }
480 //______________________________________________________________________
481 AliITS::AliITS(AliITS &source){
482     // Copy constructor. This is a function which is not allowed to be
483     // done to the ITS. It exits with an error.
484     // Inputs:
485     //      AliITS &source  An AliITS class.
486     // Outputs:
487     //      none.
488     // Return:
489     //      none.
490
491     if(this==&source) return;
492     Error("Copy constructor",
493           "You are not allowed to make a copy of the AliITS");
494     exit(1);
495 }
496 //______________________________________________________________________
497 AliITS& AliITS::operator=(AliITS &source){
498     // Assignment operator. This is a function which is not allowed to be
499     // done to the ITS. It exits with an error.
500     // Inputs:
501     //      AliITS &source  An AliITS class.
502     // Outputs:
503     //      none.
504     // Return:
505     //      none.
506
507     if(this==&source) return *this;
508     Error("operator=","You are not allowed to make a copy of the AliITS");
509     exit(1);
510     return *this; //fake return
511 }
512 //______________________________________________________________________
513 Int_t AliITS::DistancetoPrimitive(Int_t,Int_t){
514     // Distance from mouse to ITS on the screen. Dummy routine
515     //     A dummy routine used by the ROOT macro display.C to allow for the
516     // use of the mouse (pointing device) in the macro. In general this should
517     // never be called. If it is it returns the number 9999 for any value of
518     // x and y.
519     // Inputs:
520     //      Int_t     Dummy screen coordinate.
521     //      Int_t     Dummy screen coordinate.
522     // Outputs:
523     //      none.
524     // Return:
525     //      Int_t     Dummy = 9999 distance to ITS.
526
527     return 9999;
528 }
529 //______________________________________________________________________
530 void AliITS::Init(){
531     // Initializer ITS after it has been built
532     //     This routine initializes the AliITS class. It is intended to be
533     // called from the Init function in AliITSv?. Besides displaying a banner
534     // indicating that it has been called it initializes the array fIdSens
535     // and sets the default segmentation, response, digit and raw cluster
536     // classes therefore it should be called after a call to CreateGeometry.
537     // Inputs:
538     //      none.
539     // Outputs:
540     //      none.
541     // Return:
542     //      none.
543     Int_t i;
544
545     SetDefaults();
546     // Array of TStrings
547     for(i=0;i<fIdN;i++) fIdSens[i] = gMC->VolId(fIdName[i]);
548 }
549 //______________________________________________________________________
550 void AliITS::SetDefaults(){
551     // sets the default segmentation, response, digit and raw cluster classes.
552     // Inputs:
553     //      none.
554     // Outputs:
555     //      none.
556     // Return:
557     //      none.
558
559     if(fDebug) printf("%s: SetDefaults\n",ClassName());
560
561     AliITSDetType *iDetType;
562
563     //SPD
564     iDetType=DetType(0); 
565     if (!iDetType->GetSegmentationModel()) {
566         AliITSsegmentationSPD *seg0=new AliITSsegmentationSPD(fITSgeom);
567         SetSegmentationModel(0,seg0); 
568     } // end if
569     if (!iDetType->GetResponseModel()) {
570         SetResponseModel(0,new AliITSresponseSPD()); 
571     } // end if
572     // set digit and raw cluster classes to be used
573
574     const char *kData0=(iDetType->GetResponseModel())->DataType();
575     if (strstr(kData0,"real")) {
576         iDetType->ClassNames("AliITSdigit","AliITSRawClusterSPD");
577     } else iDetType->ClassNames("AliITSdigitSPD","AliITSRawClusterSPD");
578
579     // SDD
580     iDetType=DetType(1); 
581     if (!iDetType->GetResponseModel()) {
582         SetResponseModel(1,new AliITSresponseSDD("simulated")); 
583     } // end if
584     AliITSresponse *resp1=iDetType->GetResponseModel();
585     if (!iDetType->GetSegmentationModel()) {
586         AliITSsegmentationSDD *seg1=new AliITSsegmentationSDD(fITSgeom,resp1);
587         SetSegmentationModel(1,seg1); 
588     } // end if
589     const char *kData1=(iDetType->GetResponseModel())->DataType();
590     const char *kopt=iDetType->GetResponseModel()->ZeroSuppOption();
591     if((!strstr(kopt,"2D"))&&(!strstr(kopt,"1D")) || strstr(kData1,"real") ){
592         iDetType->ClassNames("AliITSdigit","AliITSRawClusterSDD");
593     } else iDetType->ClassNames("AliITSdigitSDD","AliITSRawClusterSDD");
594
595     // SSD
596     iDetType=DetType(2); 
597     if (!iDetType->GetSegmentationModel()) {
598         AliITSsegmentationSSD *seg2=new AliITSsegmentationSSD(fITSgeom);
599         SetSegmentationModel(2,seg2); 
600     } // end if
601     if (!iDetType->GetResponseModel()) {
602         SetResponseModel(2,new AliITSresponseSSD("simulated"));
603     } // end if
604     const char *kData2=(iDetType->GetResponseModel())->DataType();
605     if (strstr(kData2,"real")) {
606         iDetType->ClassNames("AliITSdigit","AliITSRawClusterSSD");
607     } else iDetType->ClassNames("AliITSdigitSSD","AliITSRawClusterSSD");
608
609     if (kNTYPES>3) {
610         Warning("SetDefaults",
611                 "Only the three basic detector types are initialized!");
612     }  // end if
613 }
614 //______________________________________________________________________
615 void AliITS::SetDefaultSimulation(){
616     // sets the default simulation.
617     // Inputs:
618     //      none.
619     // Outputs:
620     //      none.
621     // Return:
622     //      none.
623
624     AliITSDetType *iDetType;
625     AliITSsimulation *sim;
626     iDetType=DetType(0);
627     sim = iDetType->GetSimulationModel();
628     if (!sim) {
629         AliITSsegmentation *seg0=
630             (AliITSsegmentation*)iDetType->GetSegmentationModel();
631         AliITSresponse *res0 = (AliITSresponse*)iDetType->GetResponseModel();
632         AliITSsimulationSPD *sim0=new AliITSsimulationSPD(seg0,res0);
633         SetSimulationModel(0,sim0);
634     }else{ // simulation exists, make sure it is set up properly.
635         ((AliITSsimulationSPD*)sim)->Init(
636             (AliITSsegmentationSPD*) iDetType->GetSegmentationModel(),
637             (AliITSresponseSPD*) iDetType->GetResponseModel());
638 //      if(sim->GetResponseModel()==0) sim->SetResponseModel(
639 //          (AliITSresponse*)iDetType->GetResponseModel());
640 //      if(sim->GetSegmentationModel()==0) sim->SetSegmentationModel(
641 //          (AliITSsegmentation*)iDetType->GetSegmentationModel());
642     } // end if
643     iDetType=DetType(1);
644     sim = iDetType->GetSimulationModel();
645     if (!sim) {
646         AliITSsegmentation *seg1=
647             (AliITSsegmentation*)iDetType->GetSegmentationModel();
648         AliITSresponse *res1 = (AliITSresponse*)iDetType->GetResponseModel();
649         AliITSsimulationSDD *sim1=new AliITSsimulationSDD(seg1,res1);
650         SetSimulationModel(1,sim1);
651     }else{ // simulation exists, make sure it is set up properly.
652         ((AliITSsimulationSDD*)sim)->Init(
653             (AliITSsegmentationSDD*) iDetType->GetSegmentationModel(),
654             (AliITSresponseSDD*) iDetType->GetResponseModel());
655 //      if(sim->GetResponseModel()==0) sim->SetResponseModel(
656 //          (AliITSresponse*)iDetType->GetResponseModel());
657 //      if(sim->GetSegmentationModel()==0) sim->SetSegmentationModel(
658 //          (AliITSsegmentation*)iDetType->GetSegmentationModel());
659     } //end if
660     iDetType=DetType(2);
661     sim = iDetType->GetSimulationModel();
662     if (!sim) {
663         AliITSsegmentation *seg2=
664             (AliITSsegmentation*)iDetType->GetSegmentationModel();
665         AliITSresponse *res2 = (AliITSresponse*)iDetType->GetResponseModel();
666         AliITSsimulationSSD *sim2=new AliITSsimulationSSD(seg2,res2);
667         SetSimulationModel(2,sim2);
668     }else{ // simulation exists, make sure it is set up properly.
669         ((AliITSsimulationSSD*)sim)->Init(
670             (AliITSsegmentationSSD*) iDetType->GetSegmentationModel(),
671             (AliITSresponseSSD*) iDetType->GetResponseModel());
672 //      if(sim->GetResponseModel()==0) sim->SetResponseModel(
673 //          (AliITSresponse*)iDetType->GetResponseModel());
674 //      if(sim->GetSegmentationModel()==0) sim->SetSegmentationModel(
675 //          (AliITSsegmentation*)iDetType->GetSegmentationModel());
676     } // end if
677 }
678 //______________________________________________________________________
679 void AliITS::SetDefaultClusterFinders(){
680     // Sets the default cluster finders. Used in finding RecPoints.
681     // Inputs:
682     //      none.
683     // Outputs:
684     //      none.
685     // Return:
686     //      none.
687
688     MakeTreeC();
689     AliITSDetType *iDetType;
690
691     // SPD
692     iDetType=DetType(0);
693     if (!iDetType->GetReconstructionModel()) {
694         AliITSsegmentation *seg0 =
695             (AliITSsegmentation*)iDetType->GetSegmentationModel();
696         TClonesArray *dig0=DigitsAddress(0);
697         TClonesArray *recp0=ClustersAddress(0);
698         AliITSClusterFinderSPD *rec0 = new AliITSClusterFinderSPD(seg0,dig0,
699                                                                   recp0);
700         SetReconstructionModel(0,rec0);
701     } // end if
702
703     // SDD
704     iDetType=DetType(1);
705     if (!iDetType->GetReconstructionModel()) {
706         AliITSsegmentation *seg1 =
707             (AliITSsegmentation*)iDetType->GetSegmentationModel();
708         AliITSresponse *res1 = (AliITSresponse*)iDetType->GetResponseModel();
709         TClonesArray *dig1=DigitsAddress(1);
710         TClonesArray *recp1=ClustersAddress(1);
711         AliITSClusterFinderSDD *rec1 =
712             new AliITSClusterFinderSDD(seg1,res1,dig1,recp1);
713       SetReconstructionModel(1,rec1);
714     } // end if
715
716     // SSD
717     iDetType=DetType(2);
718     if (!iDetType->GetReconstructionModel()) {
719         AliITSsegmentation *seg2=
720             (AliITSsegmentation*)iDetType->GetSegmentationModel();
721         TClonesArray *dig2=DigitsAddress(2);
722         AliITSClusterFinderSSD *rec2= new AliITSClusterFinderSSD(seg2,dig2);
723         SetReconstructionModel(2,rec2);
724     } // end if
725 }
726 //______________________________________________________________________
727 void AliITS::MakeBranch(Option_t* option, const char *file){
728     // Creates Tree branches for the ITS.
729     // Inputs:
730     //      Option_t *option    String of Tree types S,D, and/or R.
731     //      const char *file    String of the file name where these branches
732     //                          are to be stored. If blank then these branches
733     //                          are written to the same tree as the Hits were
734     //                          read from.
735     // Outputs:
736     //      none.
737     // Return:
738     //      none.
739     Bool_t cS = (strstr(option,"S")!=0);
740     Bool_t cD = (strstr(option,"D")!=0);
741     Bool_t cR = (strstr(option,"R")!=0);
742     Bool_t cRF = (strstr(option,"RF")!=0);
743     if(cRF)cR = kFALSE;
744
745     AliDetector::MakeBranch(option,file);
746
747     if(cS) MakeBranchS(file);
748     if(cD) MakeBranchD(file);
749     if(cR) MakeBranchR(file);
750     if(cRF) MakeBranchRF(file);
751 }
752 //______________________________________________________________________
753 void AliITS::SetTreeAddress(){
754     // Set branch address for the Trees.
755     // Inputs:
756     //      none.
757     // Outputs:
758     //      none.
759     // Return:
760     //      none.
761     TTree *treeS = gAlice->TreeS();
762     TTree *treeD = gAlice->TreeD();
763     TTree *treeR = gAlice->TreeR();
764
765     AliDetector::SetTreeAddress();
766
767     SetTreeAddressS(treeS);
768     SetTreeAddressD(treeD);
769     SetTreeAddressR(treeR);
770 }
771 //______________________________________________________________________
772 AliITSDetType* AliITS::DetType(Int_t id){
773     // Return pointer to id detector type.
774     // Inputs:
775     //      Int_t id   detector id number.
776     // Outputs:
777     //      none.
778     // Return:
779     //      returned, a pointer to a AliITSDetType.
780
781     return ((AliITSDetType*) fDetTypes->At(id));
782 }
783 //______________________________________________________________________
784 void AliITS::SetResponseModel(Int_t id, AliITSresponse *response){
785     // Set the response model for the id detector type.
786     // Inputs:
787     //      Int_t id        detector id number.
788     //      AliITSresponse* a pointer containing an instance of AliITSresponse
789     //                      to be stored/owned b y AliITSDetType.
790     // Outputs:
791     //      none.
792     // Return:
793     //      none.
794
795     ((AliITSDetType*) fDetTypes->At(id))->ResponseModel(response);
796 }
797 //______________________________________________________________________
798 void AliITS::SetSegmentationModel(Int_t id, AliITSsegmentation *seg){
799     // Set the segmentation model for the id detector type.
800     // Inputs:
801     //      Int_t id            detector id number.
802     //      AliITSsegmentation* a pointer containing an instance of 
803     //                          AliITSsegmentation to be stored/owned b y 
804     //                          AliITSDetType.
805     // Outputs:
806     //      none.
807     // Return:
808     //      none.
809
810     ((AliITSDetType*) fDetTypes->At(id))->SegmentationModel(seg);
811 }
812 //______________________________________________________________________
813 void AliITS::SetSimulationModel(Int_t id, AliITSsimulation *sim){
814     // Set the simulation model for the id detector type.
815     // Inputs:
816     //      Int_t id        detector id number.
817     //      AliITSresponse* a pointer containing an instance of AliITSresponse
818     //                      to be stored/owned b y AliITSDetType.
819     // Outputs:
820     //      none.
821     // Return:
822     //      none.
823
824    ((AliITSDetType*) fDetTypes->At(id))->SimulationModel(sim);
825
826 }
827 //______________________________________________________________________
828 void AliITS::SetReconstructionModel(Int_t id, AliITSClusterFinder *reconst){
829     // Set the cluster finder model for the id detector type.
830     // Inputs:
831     //      Int_t id             detector id number.
832     //      AliITSClusterFinder* a pointer containing an instance of 
833     //                           AliITSClusterFinder to be stored/owned b y 
834     //                           AliITSDetType.
835     // Outputs:
836     //      none.
837     // Return:
838     //      none.
839
840     ((AliITSDetType*) fDetTypes->At(id))->ReconstructionModel(reconst);
841 }
842 //______________________________________________________________________
843 void AliITS::SetClasses(Int_t id, const char *digit, const char *cluster){
844     // Set the digit and cluster classes name to be used for the id detector
845     // type.
846     // Inputs:
847     //      Int_t id            detector id number.
848     //      const char *digit   Digit class name for detector id.
849     //      const char *cluster Cluster class name for detector id.
850     // Outputs:
851     //      none.
852     // Return:
853     //      none.
854
855     ((AliITSDetType*) fDetTypes->At(id))->ClassNames(digit,cluster);
856 }
857 //______________________________________________________________________
858 void AliITS::AddHit(Int_t track, Int_t *vol, Float_t *hits){
859     // Add an ITS hit
860     //     The function to add information to the AliITShit class. See the
861     // AliITShit class for a full description. This function allocates the
862     // necessary new space for the hit information and passes the variable
863     // track, and the pointers *vol and *hits to the AliITShit constructor
864     // function.
865     // Inputs:
866     //      Int_t   track   Track number which produced this hit.
867     //      Int_t   *vol    Array of Integer Hit information. See AliITShit.h
868     //      Float_t *hits   Array of Floating Hit information.  see AliITShit.h
869     // Outputs:
870     //      none.
871     // Return:
872     //      none.
873
874     TClonesArray &lhits = *fHits;
875     new(lhits[fNhits++]) AliITShit(fIshunt,track,vol,hits);
876 }
877 //______________________________________________________________________
878 void AliITS::InitModules(Int_t size,Int_t &nmodules){
879     // Initialize the modules array.
880     // Inputs:
881     //      Int_t size  Size of array of the number of modules to be
882     //                  created. If size <=0 then the number of modules
883     //                  is gotten from AliITSgeom class kept in fITSgeom.
884     // Outputs:
885     //      Int_t &nmodules The number of modules existing.
886     // Return:
887     //      none.
888
889     if(fITSmodules){ 
890         fITSmodules->Delete();
891         delete fITSmodules;
892     } // end fir fITSmoudles
893
894     Int_t nl,indexMAX,index;
895
896     if(size<=0){ // default to using data stored in AliITSgeom
897         if(fITSgeom==0) {
898             Error("InitModules","fITSgeom not defined");
899             return;
900         } // end if fITSgeom==0
901         nl = fITSgeom->GetNlayers();
902         indexMAX = fITSgeom->GetModuleIndex(nl,fITSgeom->GetNladders(nl),
903                                             fITSgeom->GetNdetectors(nl))+1;
904         nmodules = indexMAX;
905         fITSmodules = new TObjArray(indexMAX);
906         for(index=0;index<indexMAX;index++){
907             fITSmodules->AddAt( new AliITSmodule(index),index);
908         } // end for index
909     }else{
910         fITSmodules = new TObjArray(size);
911         for(index=0;index<size;index++) {
912             fITSmodules->AddAt( new AliITSmodule(index),index);
913         } // end for index
914
915         nmodules = size;
916     } // end i size<=0
917 }
918 //______________________________________________________________________
919 void AliITS::FillModules(Int_t evnt,Int_t bgrev,Int_t nmodules,
920                          Option_t *option,Text_t *filename){
921     // fill the modules with the sorted by module hits; add hits from
922     // background if option=Add.
923     // Inputs:
924     //      Int_t evnt       Event to be processed.
925     //      Int_t bgrev      Background Hit tree number.
926     //      Int_t nmodules   Not used.
927     //      Option_t *option String indicating if merging hits or not. To
928     //                       merge hits set equal to "Add". Otherwise no
929     //                       background hits are considered.
930     //      Test_t *filename File name containing the background hits..
931     // Outputs:
932     //      none.
933     // Return:
934     //      none.
935     static TTree *trH1;                 //Tree with background hits
936 //    static TClonesArray *fHits2;        //List of hits for one track only
937     static Bool_t first=kTRUE;
938     static TFile *file;
939     const char *addBgr = strstr(option,"Add");
940
941     if (addBgr ) {
942         if(first) {
943             file=new TFile(filename);
944 //          fHits2     = new TClonesArray("AliITShit",1000  );
945         } // end if first
946         first=kFALSE;
947         file->cd();
948         file->ls();
949         // Get Hits Tree header from file
950 //      if(fHits2) fHits2->Clear();
951         if(trH1) delete trH1;
952         trH1=0;
953
954         char treeName[20];
955         sprintf(treeName,"TreeH%d",bgrev);
956         trH1 = (TTree*)gDirectory->Get(treeName);
957         if (!trH1) {
958             Error("FillModules","cannot find Hits Tree for event:%d",bgrev);
959         } // end if !trH1
960         // Set branch addresses
961 /*
962         TBranch *branch;
963         char branchname[20];
964         sprintf(branchname,"%s",GetName());
965         if (trH1 && fHits2) {
966             branch = trH1->GetBranch(branchname);
967             if (branch) branch->SetAddress(&fHits2);
968         } // end if trH1 && fHits
969 */
970     } // end if addBgr
971
972     FillModules(gAlice->TreeH(),0); // fill from this file's tree.
973 /*
974     TClonesArray *itsHits = this->Hits();
975     Int_t lay,lad,det,index;
976     AliITShit *itsHit=0;
977     AliITSmodule *mod=0;
978     TTree *iTH = gAlice->TreeH();
979     Int_t ntracks =(Int_t) iTH->GetEntries();
980     Int_t t,h;
981     for(t=0; t<ntracks; t++){
982         gAlice->ResetHits();
983         iTH->GetEvent(t);
984         Int_t nhits = itsHits->GetEntriesFast();
985         if (!nhits) continue;
986         for(h=0; h<nhits; h++){
987             itsHit = (AliITShit *)itsHits->UncheckedAt(h);
988             itsHit->GetDetectorID(lay,lad,det);
989             // temporarily index=det-1 !!!
990             if(fITSgeom) index = fITSgeom->GetModuleIndex(lay,lad,det);
991             else index=det-1;
992             //
993             mod = this->GetModule(index);
994             mod->AddHit(itsHit,t,h);
995         } // end loop over hits 
996     } // end loop over tracks
997 */
998     // open the file with background
999     
1000     if (addBgr ) {
1001         FillModules(trH1,10000000); // Default mask 10M.
1002 /*
1003         Int_t track,i;
1004         ntracks =(Int_t)trH1->GetEntries();     
1005         // Loop over tracks
1006         for (track=0; track<ntracks; track++) {
1007             if (fHits2)       fHits2->Clear();
1008             trH1->GetEvent(track);
1009             //   Loop over hits
1010             for(i=0;i<fHits2->GetEntriesFast();++i) {
1011                 itsHit=(AliITShit*) (*fHits2)[i];
1012                 itsHit->GetDetectorID(lay,lad,det);
1013                 // temporarily index=det-1 !!!
1014                 if(fITSgeom) index = fITSgeom->GetModuleIndex(lay,lad,det);
1015                 else index=det-1;
1016                 //
1017                 mod = this->GetModule(index);
1018                 mod->AddHit(itsHit,track,i);
1019             }  // end loop over hits
1020         } // end loop over tracks
1021 */
1022         TTree *fAli=gAlice->TreeK();
1023         TFile *fileAli=0;
1024         if (fAli) fileAli =fAli->GetCurrentFile();
1025         fileAli->cd();
1026     } // end if add
1027 }
1028 //______________________________________________________________________
1029 void AliITS::FillModules(TTree *treeH, Int_t mask) {
1030     // fill the modules with the sorted by module hits; 
1031     // can be called many times to do a merging
1032     // Inputs:
1033     //      TTree *treeH  The tree containing the hits to be copied into
1034     //                    the modules.
1035     //      Int_t mask    The track number mask to indecate which file
1036     //                    this hits came from.
1037     // Outputs:
1038     //      none.
1039     // Return:
1040     //      none.
1041
1042     Int_t lay,lad,det,index;
1043     AliITShit *itsHit=0;
1044     AliITSmodule *mod=0;
1045     char branchname[20];
1046     sprintf(branchname,"%s",GetName());
1047     TBranch *branch = treeH->GetBranch(branchname);
1048     if (!branch) {
1049         Error("FillModules","%s branch in TreeH not found",branchname);
1050         return;
1051     } // end if !branch
1052     branch->SetAddress(&fHits);
1053     Int_t nTracks =(Int_t) treeH->GetEntries();
1054     Int_t iPrimTrack,h;
1055     for(iPrimTrack=0; iPrimTrack<nTracks; iPrimTrack++){
1056         ResetHits();
1057         Int_t nBytes = treeH->GetEvent(iPrimTrack);
1058         if (nBytes <= 0) continue;
1059         Int_t nHits = fHits->GetEntriesFast();
1060         for(h=0; h<nHits; h++){
1061             itsHit = (AliITShit *)fHits->UncheckedAt(h);
1062             itsHit->GetDetectorID(lay,lad,det);
1063             if (fITSgeom) {
1064                 index = fITSgeom->GetModuleIndex(lay,lad,det);
1065             } else {
1066                 index=det-1; // This should not be used.
1067             } // end if [You must have fITSgeom for this to work!]
1068             mod = GetModule(index);
1069             itsHit->SetTrack(itsHit->GetTrack()+mask); // Set track mask.
1070             mod->AddHit(itsHit,iPrimTrack,h);
1071         } // end loop over hits 
1072     } // end loop over tracks
1073 }
1074 //______________________________________________________________________
1075 void AliITS::ClearModules(){
1076     // Clear the modules TObjArray.
1077     // Inputs:
1078     //      none.
1079     // Outputs:
1080     //      none.
1081
1082     if(fITSmodules) fITSmodules->Delete();
1083 }
1084 //______________________________________________________________________
1085 void AliITS::MakeBranchS(const char *fl){
1086     // Creates Tree Branch for the ITS summable digits.
1087     // Inputs:
1088     //      cont char *fl  File name where SDigits branch is to be written
1089     //                     to. If blank it write the SDigits to the same
1090     //                     file in which the Hits were found.
1091     // Outputs:
1092     //      none.
1093     // Return:
1094     //      none.
1095     Int_t buffersize = 4000;
1096     char branchname[30];
1097
1098     // only one branch for SDigits.
1099     sprintf(branchname,"%s",GetName());
1100     if(fSDigits && gAlice->TreeS()){
1101         MakeBranchInTree(gAlice->TreeS(),branchname,&fSDigits,buffersize,fl);
1102     } // end if
1103 }
1104 //______________________________________________________________________
1105 void AliITS::SetTreeAddressS(TTree *treeS){
1106     // Set branch address for the ITS summable digits Trees.
1107     // Inputs:
1108     //      TTree *treeS   Tree containing the SDigits.
1109     // Outputs:
1110     //      none.
1111     // Return:
1112     //      none.
1113     char branchname[30];
1114
1115     if(!treeS) return;
1116     TBranch *branch;
1117     sprintf(branchname,"%s",GetName());
1118     branch = treeS->GetBranch(branchname);
1119     if (branch) branch->SetAddress(&fSDigits);
1120 }
1121 //______________________________________________________________________
1122 void AliITS::MakeBranchInTreeD(TTree *treeD,const char *file){
1123     // Creates Tree branches for the ITS.
1124     // Inputs:
1125     //      TTree     *treeD Pointer to the Digits Tree.
1126     //      cont char *file  File name where Digits branch is to be written
1127     //                       to. If blank it write the SDigits to the same
1128     //                       file in which the Hits were found.
1129     // Outputs:
1130     //      none.
1131     // Return:
1132     //      none.
1133     Int_t buffersize = 4000;
1134     char branchname[30];
1135
1136     sprintf(branchname,"%s",GetName());
1137     // one branch for digits per type of detector
1138     const char *det[3] = {"SPD","SDD","SSD"};
1139     char digclass[40];
1140     char clclass[40];
1141     Int_t i;
1142     for (i=0; i<kNTYPES ;i++) {
1143         DetType(i)->GetClassNames(digclass,clclass);
1144         // digits
1145         if(!(fDtype->At(i))) fDtype->AddAt(new TClonesArray(digclass,1000),i);
1146         else ResetDigits(i);
1147     } // end for i
1148     for (i=0; i<kNTYPES ;i++) {
1149         if (kNTYPES==3) sprintf(branchname,"%sDigits%s",GetName(),det[i]);
1150         else  sprintf(branchname,"%sDigits%d",GetName(),i+1);      
1151         if (fDtype && treeD) {
1152             MakeBranchInTree(treeD, 
1153                              branchname, &((*fDtype)[i]),buffersize,file);
1154         } // end if
1155     } // end for i
1156 }
1157 //______________________________________________________________________
1158 void AliITS::SetTreeAddressD(TTree *treeD){
1159     // Set branch address for the Trees.
1160     // Inputs:
1161     //      TTree *treeD   Tree containing the Digits.
1162     // Outputs:
1163     //      none.
1164     // Return:
1165     //      none.
1166     char branchname[30];
1167     const char *det[3] = {"SPD","SDD","SSD"};
1168     TBranch *branch;
1169     char digclass[40];
1170     char clclass[40];
1171     Int_t i;
1172
1173     if(!treeD) return;
1174     for (i=0; i<kNTYPES; i++) {
1175         DetType(i)->GetClassNames(digclass,clclass);
1176         // digits
1177         if(!(fDtype->At(i))) fDtype->AddAt(new TClonesArray(digclass,1000),i);
1178         else ResetDigits(i);
1179         if (kNTYPES==3) sprintf(branchname,"%sDigits%s",GetName(),det[i]);
1180         else  sprintf(branchname,"%sDigits%d",GetName(),i+1);
1181         if (fDtype) {
1182             branch = treeD->GetBranch(branchname);
1183             if (branch) branch->SetAddress(&((*fDtype)[i]));
1184         } // end if fDtype
1185     } // end for i
1186 }
1187 //______________________________________________________________________
1188 void AliITS::Hits2SDigits(){
1189     // Standard Hits to summable Digits function.
1190     // Inputs:
1191     //      none.
1192     // Outputs:
1193     //      none.
1194
1195 //    return; // Using Hits in place of the larger sDigits.
1196     AliHeader *header=gAlice->GetHeader(); // Get event number from this file.
1197     // Do the Hits to Digits operation. Use Standard input values.
1198     // Event number from file, no background hit merging , use size from
1199     // AliITSgeom class, option="All", input from this file only.
1200     HitsToSDigits(header->GetEvent(),0,-1," ",fOpt," ");
1201 }
1202 //______________________________________________________________________
1203 void AliITS::Hits2PreDigits(){
1204     // Standard Hits to summable Digits function.
1205     // Inputs:
1206     //      none.
1207     // Outputs:
1208     //      none.
1209
1210     AliHeader *header=gAlice->GetHeader(); // Get event number from this file.
1211     // Do the Hits to Digits operation. Use Standard input values.
1212     // Event number from file, no background hit merging , use size from
1213     // AliITSgeom class, option="All", input from this file only.
1214     HitsToPreDigits(header->GetEvent(),0,-1," ",fOpt," ");
1215 }
1216 //______________________________________________________________________
1217 void AliITS::SDigitsToDigits(Option_t *opt){
1218     // Standard Summable digits to Digits function.
1219     // Inputs:
1220     //      none.
1221     // Outputs:
1222     //      none.
1223     char name[20] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
1224
1225     if(!GetITSgeom()) return; // need transformations to do digitization.
1226     AliITSgeom *geom = GetITSgeom();
1227
1228     const char *all = strstr(opt,"All");
1229     const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
1230                           strstr(opt,"SSD")};
1231     if( !det[0] && !det[1] && !det[2] ) all = "All";
1232     else all = 0;
1233     static Bool_t setDef=kTRUE;
1234     if (setDef) SetDefaultSimulation();
1235     setDef=kFALSE;
1236
1237     AliITSsimulation *sim      = 0;
1238     AliITSDetType    *iDetType = 0;
1239     TTree            *trees    = gAlice->TreeS();
1240     if( !(trees && this->GetSDigits()) ){
1241         Error("SDigits2Digits","Error: No trees or SDigits. Returning.");
1242         return;
1243     } // end if
1244     sprintf( name, "%s", this->GetName() );
1245     TBranch *brchSDigits = trees->GetBranch( name );
1246     
1247     Int_t id,module;
1248     for(module=0;module<geom->GetIndexMax();module++){
1249         id       = geom->GetModuleType(module);
1250         if (!all && !det[id]) continue;
1251         iDetType = DetType(id);
1252         sim      = (AliITSsimulation*)iDetType->GetSimulationModel();
1253         if (!sim) {
1254             Error("SDigit2Digits",
1255                   "The simulation class was not instanciated!");
1256             exit(1);
1257         } // end if !sim
1258         sim->InitSimulationModule(module,gAlice->GetEvNumber());
1259 //
1260         // add summable digits to module
1261         this->GetSDigits()->Clear();
1262         brchSDigits->GetEvent(module);
1263         sim->AddSDigitsToModule(GetSDigits(),0);
1264 //
1265         // Digitise current module sum(SDigits)->Digits
1266         sim->FinishSDigitiseModule();
1267
1268         // fills all branches - wasted disk space
1269         gAlice->TreeD()->Fill();
1270         this->ResetDigits();
1271     } // end for module
1272
1273     gAlice->TreeD()->GetEntries();
1274
1275     gAlice->TreeD()->AutoSave();
1276     // reset tree
1277     gAlice->TreeD()->Reset();
1278     
1279 }
1280 //______________________________________________________________________
1281 void AliITS::Hits2Digits(){
1282     // Standard Hits to Digits function.
1283     // Inputs:
1284     //      none.
1285     // Outputs:
1286     //      none.
1287
1288     AliHeader *header=gAlice->GetHeader(); // Get event number from this file.
1289     // Do the Hits to Digits operation. Use Standard input values.
1290     // Event number from file, no background hit merging , use size from
1291     // AliITSgeom class, option="All", input from this file only.
1292     HitsToDigits(header->GetEvent(),0,-1," ",fOpt," ");
1293 }
1294 //______________________________________________________________________
1295 void AliITS::HitsToSDigits(Int_t evNumber,Int_t bgrev,Int_t size,
1296                           Option_t *option, Option_t *opt,Text_t *filename){
1297     // keep galice.root for signal and name differently the file for 
1298     // background when add! otherwise the track info for signal will be lost !
1299     // the condition below will disappear when the geom class will be
1300     // initialized for all versions - for the moment it is only for v5 !
1301     // 7 is the SDD beam test version. Dummy routine. Hits are ITS's Summable
1302     // Digits.
1303     // Inputs:
1304     //      Int_t evnt       Event to be processed.
1305     //      Int_t bgrev      Background Hit tree number.
1306     //      Int_t nmodules   Not used.
1307     //      Option_t *option String indicating if merging hits or not. To
1308     //                       merge hits set equal to "Add". Otherwise no
1309     //                       background hits are considered.
1310     //      Test_t *filename File name containing the background hits..
1311     // Outputs:
1312     //      none.
1313     // Return:
1314     //      none.
1315 //    return; // using Hits instead of the larger sdigits.
1316
1317     HitsToPreDigits(evNumber,bgrev,size,option,opt,filename);
1318 }
1319 //______________________________________________________________________
1320 void AliITS::HitsToPreDigits(Int_t evNumber,Int_t bgrev,Int_t size,
1321                           Option_t *option, Option_t *opt,Text_t *filename){
1322     //   Keep galice.root for signal and name differently the file for 
1323     // background when add! otherwise the track info for signal will be lost !
1324     // the condition below will disappear when the geom class will be
1325     // initialized for all versions - for the moment it is only for v5 !
1326     // 7 is the SDD beam test version.
1327     // Inputs:
1328     //      Int_t evnt       Event to be processed.
1329     //      Int_t bgrev      Background Hit tree number.
1330     //      Int_t nmodules   Not used.
1331     //      Option_t *option String indicating if merging hits or not. To
1332     //                       merge hits set equal to "Add". Otherwise no
1333     //                       background hits are considered.
1334     //      Test_t *filename File name containing the background hits..
1335     // Outputs:
1336     //      none.
1337     // Return:
1338     //      none.
1339
1340     if(!GetITSgeom()) return; // need transformations to do digitization.
1341     AliITSgeom *geom = GetITSgeom();
1342
1343     const char *all = strstr(opt,"All");
1344     const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
1345                           strstr(opt,"SSD")};
1346     static Bool_t setDef=kTRUE;
1347     if (setDef) SetDefaultSimulation();
1348     setDef=kFALSE;
1349
1350     Int_t nmodules;
1351     InitModules(size,nmodules);
1352     FillModules(evNumber,bgrev,nmodules,option,filename);
1353
1354     AliITSsimulation *sim      = 0;
1355     AliITSDetType    *iDetType = 0;
1356     AliITSmodule     *mod      = 0;
1357     Int_t id,module;
1358     for(module=0;module<geom->GetIndexMax();module++){
1359         id       = geom->GetModuleType(module);
1360         if (!all && !det[id]) continue;
1361         iDetType = DetType(id);
1362         sim      = (AliITSsimulation*)iDetType->GetSimulationModel();
1363         if (!sim) {
1364             Error("HitsToSDigits",
1365                   "The simulation class was not instanciated!");
1366             exit(1);
1367         } // end if !sim
1368         mod      = (AliITSmodule *)fITSmodules->At(module);
1369         sim->SDigitiseModule(mod,module,evNumber);
1370         // fills all branches - wasted disk space
1371         gAlice->TreeS()->Fill(); 
1372         ResetSDigits();
1373     } // end for module
1374
1375     ClearModules();
1376
1377     gAlice->TreeS()->GetEntries();
1378     gAlice->TreeS()->AutoSave();
1379     // reset tree
1380     gAlice->TreeS()->Reset();
1381 }
1382 //______________________________________________________________________
1383 void AliITS::HitsToDigits(Int_t evNumber,Int_t bgrev,Int_t size,
1384                           Option_t *option, Option_t *opt,Text_t *filename){
1385     //   Keep galice.root for signal and name differently the file for 
1386     // background when add! otherwise the track info for signal will be lost !
1387     // the condition below will disappear when the geom class will be
1388     // initialized for all versions - for the moment it is only for v5 !
1389     // 7 is the SDD beam test version.
1390     // Inputs:
1391     //      Int_t evnt       Event to be processed.
1392     //      Int_t bgrev      Background Hit tree number.
1393     //      Int_t nmodules   Not used.
1394     //      Option_t *option String indicating if merging hits or not. To
1395     //                       merge hits set equal to "Add". Otherwise no
1396     //                       background hits are considered.
1397     //      Test_t *filename File name containing the background hits..
1398     // Outputs:
1399     //      none.
1400     // Return:
1401     //      none.
1402
1403     if(!GetITSgeom()) return; // need transformations to do digitization.
1404     AliITSgeom *geom = GetITSgeom();
1405
1406     const char *all = strstr(opt,"All");
1407     const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
1408                           strstr(opt,"SSD")};
1409     static Bool_t setDef=kTRUE;
1410     if (setDef) SetDefaultSimulation();
1411     setDef=kFALSE;
1412
1413     Int_t nmodules;
1414     InitModules(size,nmodules);
1415     FillModules(evNumber,bgrev,nmodules,option,filename);
1416
1417     AliITSsimulation *sim      = 0;
1418     AliITSDetType    *iDetType = 0;
1419     AliITSmodule     *mod      = 0;
1420     Int_t id,module;
1421     for(module=0;module<geom->GetIndexMax();module++){
1422         id       = geom->GetModuleType(module);
1423         if (!all && !det[id]) continue;
1424         iDetType = DetType(id);
1425         sim      = (AliITSsimulation*)iDetType->GetSimulationModel();
1426         if (!sim) {
1427             Error("HitsToDigits",
1428                   "The simulation class was not instanciated!");
1429             exit(1);
1430         } // end if !sim
1431         mod      = (AliITSmodule *)fITSmodules->At(module);
1432         sim->DigitiseModule(mod,module,evNumber);
1433         // fills all branches - wasted disk space
1434         gAlice->TreeD()->Fill(); 
1435         ResetDigits();
1436     } // end for module
1437
1438     ClearModules();
1439
1440     gAlice->TreeD()->GetEntries();
1441     gAlice->TreeD()->AutoSave();
1442     // reset tree
1443     gAlice->TreeD()->Reset();
1444 }
1445 //______________________________________________________________________
1446 void AliITS::ResetSDigits(){
1447     // Reset the Summable Digits array.
1448     // Inputs:
1449     //      none.
1450     // Outputs:
1451     //      none.
1452
1453     if (fSDigits) fSDigits->Clear();
1454     fNSDigits = 0;
1455 }
1456 //______________________________________________________________________
1457 void AliITS::ResetDigits(){
1458     // Reset number of digits and the digits array for the ITS detector.
1459     // Inputs:
1460     //      none.
1461     // Outputs:
1462     //      none.
1463
1464     if (!fDtype) return;
1465
1466     Int_t i;
1467     for (i=0;i<kNTYPES;i++ ) {
1468         if (fDtype->At(i))    ((TClonesArray*)fDtype->At(i))->Clear();
1469         if (fNdtype)  fNdtype[i]=0;
1470     } // end for i
1471 }
1472 //______________________________________________________________________
1473 void AliITS::ResetDigits(Int_t i){
1474     // Reset number of digits and the digits array for this branch.
1475     // Inputs:
1476     //      none.
1477     // Outputs:
1478     //      none.
1479
1480     if (fDtype->At(i))    ((TClonesArray*)fDtype->At(i))->Clear();
1481     if (fNdtype)  fNdtype[i]=0;
1482 }
1483 //______________________________________________________________________
1484 void AliITS::AddSumDigit(AliITSpListItem &sdig){
1485     // Adds the a module full of summable digits to the summable digits tree.
1486     // Inputs:
1487     //      AliITSpListItem &sdig   SDigit to be added to SDigits tree.
1488     // Outputs:
1489     //      none.
1490     // Return:
1491     //      none.
1492
1493     TClonesArray &lsdig = *fSDigits;
1494     new(lsdig[fNSDigits++]) AliITSpListItem(sdig);
1495 }
1496 //______________________________________________________________________
1497 void AliITS::AddRealDigit(Int_t id, Int_t *digits){
1498     //   Add a real digit - as coming from data.
1499     // Inputs:
1500     //      Int_t id        Detector type number.
1501     //      Int_t *digits   Integer array containing the digits info. See 
1502     //                      AliITSdigit.h
1503     // Outputs:
1504     //      none.
1505     // Return:
1506     //      none.
1507
1508     TClonesArray &ldigits = *((TClonesArray*)fDtype->At(id));
1509     new(ldigits[fNdtype[id]++]) AliITSdigit(digits);
1510 }
1511 //______________________________________________________________________
1512 void AliITS::AddSimDigit(Int_t id, AliITSdigit *d){
1513     //    Add a simulated digit.
1514     // Inputs:
1515     //      Int_t id        Detector type number.
1516     //      AliITSdigit *d  Digit to be added to the Digits Tree. See 
1517     //                      AliITSdigit.h
1518     // Outputs:
1519     //      none.
1520     // Return:
1521     //      none.
1522
1523     TClonesArray &ldigits = *((TClonesArray*)fDtype->At(id));
1524
1525     switch(id){
1526     case 0:
1527         new(ldigits[fNdtype[id]++]) AliITSdigitSPD(*((AliITSdigitSPD*)d));
1528         break;
1529     case 1:
1530         new(ldigits[fNdtype[id]++]) AliITSdigitSDD(*((AliITSdigitSDD*)d));
1531         break;
1532     case 2:
1533         new(ldigits[fNdtype[id]++]) AliITSdigitSSD(*((AliITSdigitSSD*)d));
1534         break;
1535     } // end switch id
1536 }
1537 //______________________________________________________________________
1538 void AliITS::AddSimDigit(Int_t id,Float_t phys,Int_t *digits,Int_t *tracks,
1539                          Int_t *hits,Float_t *charges){
1540     //   Add a simulated digit to the list.
1541     // Inputs:
1542     //      Int_t id        Detector type number.
1543     //      Float_t phys    Physics indicator. See AliITSdigits.h
1544     //      Int_t *digits   Integer array containing the digits info. See 
1545     //                      AliITSdigit.h
1546     //      Int_t *tracks   Integer array [AliITSdigitS?D::GetNTracks()] 
1547     //                      containing the track numbers that contributed to
1548     //                      this digit.
1549     //      Int_t *hits     Integer array [AliITSdigitS?D::GetNTracks()]
1550     //                      containing the hit numbers, from AliITSmodule, that
1551     //                      contributed to this digit.
1552     //      Float_t *charge Floating point array of the signals contributed
1553     //                      to this digit by each track.
1554     // Outputs:
1555     //      none.
1556     // Return:
1557     //      none.
1558
1559     TClonesArray &ldigits = *((TClonesArray*)fDtype->At(id));
1560     switch(id){
1561     case 0:
1562         new(ldigits[fNdtype[id]++]) AliITSdigitSPD(digits,tracks,hits);
1563         break;
1564     case 1:
1565         new(ldigits[fNdtype[id]++]) AliITSdigitSDD(phys,digits,tracks,
1566                                                    hits,charges);
1567         break;
1568     case 2:
1569         new(ldigits[fNdtype[id]++]) AliITSdigitSSD(digits,tracks,hits);
1570         break;
1571     } // end switch id
1572 }
1573 //______________________________________________________________________
1574 void AliITS::MakeTreeC(Option_t *option){
1575     //   Create a separate tree to store the clusters.
1576     // Inputs:
1577     //      Option_t *option  string which must contain "C" otherwise
1578     //                        no Cluster Tree is created.
1579     // Outputs:
1580     //      none.
1581     // Return:
1582     //      none.
1583   TDirectory *cwd = gDirectory;
1584   TFile *fileRecPoints = gAlice->GetTreeRFile();
1585   if(fileRecPoints)fileRecPoints->cd();
1586     const char *optC = strstr(option,"C");
1587     char hname[30];
1588     Int_t cureve = gAlice->GetEvNumber();
1589     sprintf(hname,"TreeC%d",cureve);
1590     if(fTreeC){
1591       const char *curname = fTreeC->GetName();
1592       char *exists = strstr(hname,curname);
1593       if(!exists){
1594         delete fTreeC; 
1595         fTreeC=0;
1596       }
1597     }
1598     if (optC && !fTreeC) fTreeC = new TTree(hname,"Clusters in ITS");
1599     else return;
1600
1601     Int_t buffersize = 4000;
1602     char branchname[30];
1603     const char *det[3] = {"SPD","SDD","SSD"};
1604     char digclass[40];
1605     char clclass[40];
1606
1607     // one branch for Clusters per type of detector
1608     Int_t i;   
1609     for (i=0; i<kNTYPES ;i++) {
1610         AliITSDetType *iDetType=DetType(i); 
1611         iDetType->GetClassNames(digclass,clclass);
1612         // clusters
1613         if(!ClustersAddress(i)){
1614           fCtype->AddAt(new TClonesArray(clclass,1000),i);
1615         }
1616         if (kNTYPES==3) sprintf(branchname,"%sClusters%s",GetName(),det[i]);
1617         else  sprintf(branchname,"%sClusters%d",GetName(),i+1);
1618         if (fCtype   && fTreeC) {
1619             TreeC()->Branch(branchname,&((*fCtype)[i]), buffersize);
1620         } // end if fCtype && fTreeC
1621     } // end for i
1622     cwd->cd();
1623 }
1624 //______________________________________________________________________
1625 void AliITS::GetTreeC(Int_t event){
1626     //    Get the clusters tree for this event and set the branch address.
1627     // Inputs:
1628     //      Int_t event    Event number for the cluster tree.
1629     // Outputs:
1630     //      none.
1631     // Return:
1632     //      none.
1633     char treeName[20];
1634     char branchname[30];
1635     const char *det[3] = {"SPD","SDD","SSD"};
1636
1637     ResetClusters();
1638     if (fTreeC) {
1639         delete fTreeC;
1640     } // end if fTreeC
1641
1642     sprintf(treeName,"TreeC%d",event);
1643     TFile *fileRecPoints = gAlice->GetTreeRFile();
1644     if(!fileRecPoints){
1645       fTreeC = (TTree*)gDirectory->Get(treeName);
1646     }
1647     else {
1648       fTreeC = (TTree*)fileRecPoints->Get(treeName);
1649     }
1650
1651     TBranch *branch;
1652
1653     if (fTreeC) {
1654         Int_t i;
1655         char digclass[40];
1656         char clclass[40];
1657         for (i=0; i<kNTYPES; i++) {
1658             AliITSDetType *iDetType=DetType(i); 
1659             iDetType->GetClassNames(digclass,clclass);
1660             // clusters
1661             if(!fCtype->At(i)) fCtype->AddAt(new TClonesArray(clclass,1000),i);
1662             if(kNTYPES==3) sprintf(branchname,"%sClusters%s",GetName(),det[i]);
1663             else  sprintf(branchname,"%sClusters%d",GetName(),i+1);
1664             if (fCtype) {
1665                 branch = fTreeC->GetBranch(branchname);
1666                 if (branch) branch->SetAddress(&((*fCtype)[i]));
1667             } // end if fCtype
1668         } // end for i
1669     } else {
1670         Error("GetTreeC","cannot find Clusters Tree for event:%d",event);
1671     } // end if fTreeC
1672 }
1673 //______________________________________________________________________
1674 void AliITS::AddCluster(Int_t id, AliITSRawCluster *c){
1675     //   Add a cluster to the list.
1676     // Inputs:
1677     //      Int_t id             Detector type number.
1678     //      AliITSRawCluster *c  Cluster class to be added to the tree of
1679     //                           clusters.
1680     // Outputs:
1681     //      none.
1682     // Return:
1683     //      none.
1684
1685     TClonesArray &lc = *((TClonesArray*)fCtype->At(id));
1686
1687     switch(id){
1688     case 0:
1689         new(lc[fNctype[id]++]) AliITSRawClusterSPD(*((AliITSRawClusterSPD*)c));
1690         break;
1691     case 1:
1692         new(lc[fNctype[id]++]) AliITSRawClusterSDD(*((AliITSRawClusterSDD*)c));
1693         break;
1694     case 2:
1695         new(lc[fNctype[id]++]) AliITSRawClusterSSD(*((AliITSRawClusterSSD*)c));
1696         break;
1697     } // end switch id
1698 }
1699 //______________________________________________________________________
1700 void AliITS::ResetClusters(){
1701     // Reset number of clusters and the clusters array for ITS.
1702     // Inputs:
1703     //      none.
1704     // Outputs:
1705     //      none.
1706
1707     Int_t i;
1708     for (i=0;i<kNTYPES;i++ ) ResetClusters(i);
1709 }
1710 //______________________________________________________________________
1711 void AliITS::ResetClusters(Int_t i){
1712     //    Reset number of clusters and the clusters array for this branch.
1713     // Inputs:
1714     //      Int_t i        Detector type number.
1715     // Outputs:
1716     //      none.
1717     // Return:
1718     //      none.
1719
1720     if (fCtype->At(i))    ((TClonesArray*)fCtype->At(i))->Clear();
1721     if (fNctype)  fNctype[i]=0;
1722 }
1723 //______________________________________________________________________
1724 void AliITS::MakeBranchR(const char *file, Option_t *opt){
1725     // Creates Tree branches for the ITS Reconstructed points.
1726     // Inputs:
1727     //      cont char *file  File name where RecPoints branch is to be written
1728     //                       to. If blank it write the SDigits to the same
1729     //                       file in which the Hits were found.
1730     // Outputs:
1731     //      none.
1732     // Return:
1733     //      none.
1734     Int_t buffsz = 4000;
1735     char branchname[30];
1736
1737     // only one branch for rec points for all detector types
1738     Bool_t oFast= (strstr(opt,"Fast")!=0);
1739     if(oFast){
1740       sprintf(branchname,"%sRecPointsF",GetName());
1741     } else {
1742       sprintf(branchname,"%sRecPoints",GetName());
1743     }
1744     if (fRecPoints && gAlice->TreeR()) {
1745         MakeBranchInTree(gAlice->TreeR(),branchname,&fRecPoints,buffsz,file);
1746     } // end if
1747 }
1748 //______________________________________________________________________
1749 void AliITS::SetTreeAddressR(TTree *treeR){
1750     // Set branch address for the Reconstructed points Trees.
1751     // Inputs:
1752     //      TTree *treeR   Tree containing the RecPoints.
1753     // Outputs:
1754     //      none.
1755     // Return:
1756     //      none.
1757     char branchname[30];
1758
1759     if(!treeR) return;
1760     TBranch *branch;
1761     sprintf(branchname,"%sRecPoints",GetName());
1762     branch = treeR->GetBranch(branchname);
1763     if (branch) {
1764       branch->SetAddress(&fRecPoints);
1765     }
1766     else {
1767       sprintf(branchname,"%sRecPointsF",GetName());
1768       branch = treeR->GetBranch(branchname);
1769       if (branch) {
1770         branch->SetAddress(&fRecPoints);
1771       }
1772     }
1773 }
1774 //______________________________________________________________________
1775 void AliITS::AddRecPoint(const AliITSRecPoint &r){
1776     // Add a reconstructed space point to the list
1777     // Inputs:
1778     //      const AliITSRecPoint &r RecPoint class to be added to the tree
1779     //                              of reconstructed points TreeR.
1780     // Outputs:
1781     //      none.
1782     // Return:
1783     //      none.
1784
1785     TClonesArray &lrecp = *fRecPoints;
1786     new(lrecp[fNRecPoints++]) AliITSRecPoint(r);
1787 }
1788 //______________________________________________________________________
1789 void AliITS::HitsToFastRecPoints(Int_t evNumber,Int_t bgrev,Int_t size,
1790                                  Option_t *opt0,Option_t *opt1,Text_t *flnm){
1791     // keep galice.root for signal and name differently the file for 
1792     // background when add! otherwise the track info for signal will be lost !
1793     // the condition below will disappear when the geom class will be
1794     // initialized for all versions - for the moment it is only for v5 !
1795     // Inputs:
1796     //      Int_t evnt       Event to be processed.
1797     //      Int_t bgrev      Background Hit tree number.
1798     //      Int_t size       Size used by InitModules. See InitModules.
1799     //      Option_t *opt0   Option passed to FillModules. See FillModules.
1800     //      Option_t *opt1   String indicating if merging hits or not. To
1801     //                       merge hits set equal to "Add". Otherwise no
1802     //                       background hits are considered.
1803     //      Test_t *flnm     File name containing the background hits..
1804     // Outputs:
1805     //      none.
1806     // Return:
1807     //      none.
1808
1809     if(!GetITSgeom()) return;
1810     AliITSgeom *geom = GetITSgeom();
1811
1812     const char *all = strstr(opt1,"All");
1813     const char *det[3] ={strstr(opt1,"SPD"),strstr(opt1,"SDD"),
1814                          strstr(opt1,"SSD")};
1815     Int_t nmodules;
1816     InitModules(size,nmodules);
1817     FillModules(evNumber,bgrev,nmodules,opt0,flnm);
1818
1819     AliITSsimulation *sim      = 0;
1820     AliITSDetType    *iDetType = 0;
1821     AliITSmodule     *mod      = 0;
1822     Int_t id,module;
1823
1824     //m.b. : this change is nothing but a nice way to make sure
1825     //the CPU goes up !
1826     for(module=0;module<geom->GetIndexMax();module++){
1827         id       = geom->GetModuleType(module);
1828         if (!all && !det[id]) continue;
1829         iDetType = DetType(id);
1830         sim      = (AliITSsimulation*)iDetType->GetSimulationModel();
1831         if (!sim) {
1832             Error("HitsToFastPoints",
1833                   "The simulation class was not instanciated!");
1834             exit(1);
1835         } // end if !sim
1836         mod      = (AliITSmodule *)fITSmodules->At(module);
1837         sim->CreateFastRecPoints(mod,module,gRandom);
1838     //  gAlice->TreeR()->Fill(); 
1839     TBranch *br=gAlice->TreeR()->GetBranch("ITSRecPointsF");
1840     br->Fill();
1841         ResetRecPoints();
1842     } // end for module
1843
1844     ClearModules();
1845
1846     gAlice->TreeR()->AutoSave();
1847     // reset tree
1848     gAlice->TreeR()->Reset();
1849 }
1850 //______________________________________________________________________
1851 void AliITS::Digits2Reco(){
1852     // Find clusters and reconstruct space points.
1853     // Inputs:
1854     //      none.
1855     // Outputs:
1856     //      none.
1857
1858     AliHeader *header=gAlice->GetHeader();
1859     // to Digits to RecPoints for event in file, all digits in file, and
1860     // all ITS detectors.
1861     DigitsToRecPoints(header->GetEvent(),0,fOpt);
1862 }
1863 //______________________________________________________________________
1864 void AliITS::DigitsToRecPoints(Int_t evNumber,Int_t lastentry,Option_t *opt){
1865     // cluster finding and reconstruction of space points
1866     // the condition below will disappear when the geom class will be
1867     // initialized for all versions - for the moment it is only for v5 !
1868     // 7 is the SDD beam test version
1869     // Inputs:
1870     //      Int_t evNumber   Event number to be processed.
1871     //      Int_t lastentry  Offset for module when not all of the modules
1872     //                       are processed.
1873     //      Option_t *opt    String indicating which ITS sub-detectors should
1874     //                       be processed. If ="All" then all of the ITS
1875     //                       sub detectors are processed.
1876     // Outputs:
1877     //      none.
1878     // Return:
1879     //      none.
1880
1881     if(!GetITSgeom()) return;
1882     AliITSgeom *geom = GetITSgeom();
1883     
1884     const char *all = strstr(opt,"All");
1885     const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
1886                           strstr(opt,"SSD")};
1887     static Bool_t setRec=kTRUE;
1888     if (setRec) SetDefaultClusterFinders();
1889     setRec=kFALSE;
1890
1891     TTree *treeC=TreeC();
1892     AliITSClusterFinder *rec     = 0;
1893     AliITSDetType      *iDetType = 0;
1894     Int_t id,module,first=0;
1895     for(module=0;module<geom->GetIndexMax();module++){
1896         id       = geom->GetModuleType(module);
1897         if (!all && !det[id]) continue;
1898         if(det[id]) first = geom->GetStartDet(id);
1899         iDetType = DetType(id);
1900         rec = (AliITSClusterFinder*)iDetType->GetReconstructionModel();
1901         TClonesArray *itsDigits  = this->DigitsAddress(id);
1902         if (!rec) {
1903             Error("DigitsToRecPoints",
1904                   "The reconstruction class was not instanciated!");
1905             exit(1);
1906         } // end if !rec
1907         this->ResetDigits();
1908         if (all) gAlice->TreeD()->GetEvent(lastentry+module);
1909         else gAlice->TreeD()->GetEvent(lastentry+(module-first));
1910         Int_t ndigits = itsDigits->GetEntriesFast();
1911         if (ndigits) rec->FindRawClusters(module);
1912     gAlice->TreeR()->Fill(); 
1913         ResetRecPoints();
1914         treeC->Fill();
1915         ResetClusters();
1916     } // end for module
1917
1918     gAlice->TreeR()->GetEntries();
1919     treeC->GetEntries();
1920     gAlice->TreeR()->AutoSave();
1921     // reset tree
1922     gAlice->TreeR()->Reset();
1923
1924     treeC->AutoSave();
1925     treeC->Reset();
1926 }
1927 //______________________________________________________________________
1928 void AliITS::ResetRecPoints(){
1929     // Reset number of rec points and the rec points array.
1930     // Inputs:
1931     //      none.
1932     // Outputs:
1933     //      none.
1934
1935     if (fRecPoints) fRecPoints->Clear();
1936     fNRecPoints = 0;
1937 }