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