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