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