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