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