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