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