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