]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITS.cxx
Remove/commented a number of cout<< statements. and made change needed by
[u/mrichter/AliRoot.git] / ITS / AliITS.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /*
17 $Log$
18 Revision 1.44  2001/04/26 22:44:01  nilsen
19 Removed dependence on layer 5/6 in AliITS::HitsToDigits. This will be
20 done properly in AliITSv???.cxx via SetDefaults.
21
22 Revision 1.43  2001/04/26 13:22:52  barbera
23 TMatrix and TVector elimininated to speed up the code
24
25 Revision 1.42  2001/04/25 21:55:12  barbera
26 Updated version to be compatible with actual verion of STEER and TPC
27
28 Revision 1.41  2001/04/21 15:16:51  barbera
29 Updated with the new SSD reconstruction code
30
31 Revision 1.40  2001/03/17 15:07:06  mariana
32 Update SDD response parameters
33
34 Revision 1.39  2001/03/12 17:45:32  hristov
35 Changes needed on Sun with CC 5.0
36
37 Revision 1.38  2001/03/07 14:04:51  barbera
38 Some vector dimensions increased to cope with full events
39
40 Revision 1.37  2001/03/07 12:36:35  barbera
41 A change added in the tracking part to manage delta rays
42
43 Revision 1.36  2001/03/02 19:44:11  barbera
44  modified to taking into account new version tracking v1
45
46 Revision 1.35  2001/02/28 18:16:46  mariana
47 Make the code compatible with the new AliRun
48
49 Revision 1.34  2001/02/11 15:51:39  mariana
50 Set protection in MakeBranch
51
52 Revision 1.33  2001/02/10 22:26:39  mariana
53 Move the initialization of the containers for raw clusters in MakeTreeC()
54
55 Revision 1.32  2001/02/08 23:55:31  nilsen
56 Removed fMajor/MinorVersion variables in favor of variables in derived classes.
57 Set arrays char *det[3] = {"SPD","SDD","SSD"} as const.
58
59 Revision 1.31  2001/02/02 23:57:28  nilsen
60 Added include file that are no londer included in AliITSgeom.h
61
62 Revision 1.30  2001/01/30 09:23:13  hristov
63 Streamers removed (R.Brun)
64
65 Revision 1.29  2001/01/26 20:01:09  hristov
66 Major upgrade of AliRoot code
67
68 Revision 1.28  2000/12/18 14:02:00  barbera
69 new version of the ITS tracking to take into account the new TPC track parametrization
70
71 Revision 1.27  2000/12/08 13:49:27  barbera
72 Hidden declaration in a for loop removed to be compliant with HP-UX compiler
73
74 Revision 1.26  2000/11/27 13:12:13  barbera
75 New version containing the files for tracking
76
77 Revision 1.25  2000/11/12 22:38:05  barbera
78 Added header file for the SPD Bari model
79
80 Revision 1.24  2000/10/09 22:18:12  barbera
81 Bug fixes from MAriana to le AliITStest.C run correctly
82
83 Revision 1.23  2000/10/05 20:47:42  nilsen
84 fixed dependencies of include files. Tryed but failed to get a root automaticly
85 generates streamer function to work. Modified SetDefaults.
86
87 Revision 1.9.2.15  2000/10/04 16:56:40  nilsen
88 Needed to include stdlib.h
89
90 =======
91 Revision 1.22  2000/10/04 19:45:52  barbera
92 Corrected by F. Carminati for v3.04
93
94 Revision 1.21  2000/10/02 21:28:08  fca
95 Removal of useless dependecies via forward declarations
96
97 Revision 1.20  2000/10/02 16:31:39  barbera
98 General code clean-up
99
100 Revision 1.9.2.14  2000/10/02 15:43:51  barbera
101 General code clean-up (e.g., printf -> cout)
102
103 Revision 1.19  2000/09/22 12:13:25  nilsen
104 Patches and updates for fixes to this and other routines.
105
106 Revision 1.18  2000/07/12 05:32:20  fca
107 Correcting several syntax problem with static members
108
109 Revision 1.17  2000/07/10 16:07:18  fca
110 Release version of ITS code
111
112 Revision 1.9.2.3  2000/02/02 13:42:09  barbera
113 fixed AliITS.cxx for new AliRun structure. Added ITS hits list to list of hits which will have their track numbers updated
114
115 Revision 1.9.2.2  2000/01/23 03:03:13  nilsen
116 //fixed FillModule. Removed fi(fabs(xl)<dx....
117
118 Revision 1.9.2.1  2000/01/12 19:03:32  nilsen
119 This is the version of the files after the merging done in December 1999.
120 See the ReadMe110100.txt file for details
121
122 Revision 1.9  1999/11/14 14:33:25  fca
123 Correct problems with distructors and pointers, thanks to I.Hrivnacova
124
125 Revision 1.8  1999/09/29 09:24:19  fca
126 Introduction of the Copyright and cvs Log
127
128 */
129
130 ///////////////////////////////////////////////////////////////////////////////
131 //
132 //      An overview of the basic philosophy of the ITS code development
133 // and analysis is show in the figure below.
134 //Begin_Html
135 /*
136 <img src="picts/ITS/ITS_Analysis_schema.gif">
137 </pre>
138 <br clear=left>
139 <font size=+2 color=red>
140 <p>Roberto Barbera is in charge of the ITS Offline code (1999).
141 <a href="mailto:roberto.barbera@ct.infn.it">Roberto Barbera</a>.
142 </font>
143 <pre>
144 */
145 //End_Html
146 //
147 //  AliITS. Inner Traking System base class.
148 //  This class contains the base procedures for the Inner Tracking System
149 //
150 //Begin_Html
151 /*
152 <img src="picts/ITS/AliITS_Class_Diagram.gif">
153 </pre>
154 <br clear=left>
155 <font size=+2 color=red>
156 <p>This show the class diagram of the different elements that are part of
157 the AliITS class.
158 </font>
159 <pre>
160 */
161 //End_Html
162 //
163 // Version: 0
164 // Written by Rene Brun, Federico Carminati, and Roberto Barbera
165 //
166 // Version: 1
167 // Modified and documented by Bjorn S. Nilsen
168 // July 11 1999
169 //
170 // Version: 2
171 // Modified and documented by A. Bologna
172 // October 18 1999
173 //
174 // AliITS is the general base class for the ITS. Also see AliDetector for
175 // futher information.
176 //
177 ///////////////////////////////////////////////////////////////////////////////
178 #include <iostream.h>
179 #include <iomanip.h>
180 #include <fstream.h>
181 #include <stdlib.h>
182 #include <TMath.h>
183 #include <TRandom.h>
184 #include <TBranch.h>
185 #include <TVector.h>
186 #include <TClonesArray.h>
187 #include <TROOT.h>
188 #include <TObjectTable.h>
189 #include <TFile.h>
190 #include <TTree.h>
191 #include <TString.h>
192 #include <TParticle.h>
193
194
195 #include "AliRun.h"
196 #include "AliITS.h"
197 #include "AliITSMap.h"
198 #include "AliITSDetType.h"
199 #include "AliITSClusterFinder.h"
200 //#include "AliITSsimulation.h"
201 #include "AliITSsimulationSPD.h"
202 #include "AliITSsimulationSDD.h"
203 #include "AliITSsimulationSSD.h"
204 #include "AliITSresponse.h"
205 #include "AliITSsegmentationSPD.h"
206 #include "AliITSresponseSPD.h"
207 #include "AliITSresponseSPDbari.h"
208 #include "AliITSsegmentationSDD.h"
209 #include "AliITSresponseSDD.h"
210 #include "AliITSsegmentationSSD.h"
211 #include "AliITSresponseSSD.h"
212 #include "AliITShit.h"
213 #include "AliITSgeom.h"
214 #include "AliITSdigit.h"
215 #include "AliITSmodule.h"
216 #include "AliITSRecPoint.h"
217 #include "AliITSRawCluster.h"
218 #include "AliMC.h"
219 #include "stdlib.h"
220 #include "AliKalmanTrack.h" 
221 #include "AliMagF.h"
222
223 #include "AliITStrack.h"
224 #include "AliITSiotrack.h"
225 #include "AliITStracking.h"
226 #include "AliITSRad.h"   
227 #include "../TPC/AliTPC.h"
228 #include "../TPC/AliTPCParam.h"
229
230
231 ClassImp(AliITS)
232  
233 //_____________________________________________________________________________
234 AliITS::AliITS() : AliDetector() {
235   //
236   // Default initialiser for ITS
237   //     The default constructor of the AliITS class. In addition to
238   // creating the AliITS class it zeros the variables fIshunt (a member
239   // of AliDetector class), fEuclidOut, and fIdN, and zeros the pointers
240   // fITSpoints, fIdSens, and fIdName. The AliDetector default constructor
241   // is also called.
242   //
243
244
245   fIshunt     = 0;
246   fEuclidOut  = 0;
247
248   fNDetTypes = kNTYPES;
249   fIdN        = 0;
250   fIdName     = 0;
251   fIdSens     = 0;
252   fITSmodules = 0;
253   //
254   fDetTypes   = 0;
255   //
256   fDtype  = 0;
257   fNdtype = 0;
258   fCtype  = 0;
259   fNctype = 0;
260   fRecPoints = 0;
261   fNRecPoints = 0;
262   fTreeC = 0;
263   //
264   fITSgeom=0;
265 }
266
267 //_____________________________________________________________________________
268 AliITS::AliITS(const char *name, const char *title):AliDetector(name,title){
269   //
270   // Default initialiser for ITS
271   //     The constructor of the AliITS class. In addition to creating the
272   // AliITS class, it allocates memory for the TClonesArrays fHits and
273   // fDigits, and for the TObjArray fITSpoints. It also zeros the variables
274   // fIshunt (a member of AliDetector class), fEuclidOut, and fIdN, and zeros
275   // the pointers fIdSens and fIdName. To help in displaying hits via the ROOT
276   // macro display.C AliITS also sets the marker color to red. The variables
277   // passes with this constructor, const char *name and *title, are used by
278   // the constructor of AliDetector class. See AliDetector class for a
279   // description of these parameters and its constructor functions.
280   //
281
282
283   fHits       = new TClonesArray("AliITShit", 1560);
284   gAlice->AddHitList(fHits);
285
286   fNDetTypes = kNTYPES;
287
288   fNdtype = new Int_t[kNTYPES];
289   fDtype = new TObjArray(kNTYPES);
290
291   fNctype = new Int_t[kNTYPES];
292   fCtype = new TObjArray(kNTYPES);
293
294
295   fRecPoints = 0;
296   fNRecPoints = 0;
297
298   fTreeC = 0;
299
300   fITSmodules = 0; 
301
302   fIshunt     = 0;
303   fEuclidOut  = 0;
304   fIdN        = 0;
305   fIdName     = 0;
306   fIdSens     = 0;
307  
308   fDetTypes = new TObjArray(kNTYPES);  
309
310   Int_t i;
311   for(i=0;i<kNTYPES;i++) {
312     (*fDetTypes)[i]=new AliITSDetType(); 
313     fNdtype[i]=0;
314     fNctype[i]=0;
315    }
316   //
317
318   SetMarkerColor(kRed);
319
320   fITSgeom=0;
321 }
322 //___________________________________________________________________________
323 AliITS::AliITS(AliITS &source){
324   // copy constructor
325   if(this==&source) return;
326   Error("AliITS::Copy constructor",
327         "You are not allowed to make a copy of the AliITS");
328   exit(1);
329 }
330 //____________________________________________________________________________
331 AliITS& AliITS::operator=(AliITS &source){
332   // assignment operator
333   if(this==&source) return *this;
334   Error("AliITS::operator=",
335         "You are not allowed to make a copy of the AliITS");
336   exit(1);
337   return *this; //fake return
338 }
339 //____________________________________________________________________________
340 void AliITS::ClearModules(){
341   //clear the modules TObjArray
342
343   if(fITSmodules) fITSmodules->Delete();
344
345 }
346 //_____________________________________________________________________________
347 AliITS::~AliITS(){
348   //
349   // Default distructor for ITS
350   //     The default destructor of the AliITS class. In addition to deleting
351   // the AliITS class it deletes the memory pointed to by the fHits, fDigits,
352   // fIdSens, fIdName, and fITSpoints.
353   //
354
355
356   delete fHits;
357   delete fDigits;
358   delete fRecPoints;
359 //  delete fIdName;        // TObjArray of TObjStrings
360   if(fIdName!=0) delete[] fIdName;  // Array of TStrings
361   if(fIdSens!=0) delete[] fIdSens;
362   if(fITSmodules!=0) {
363       this->ClearModules();
364       delete fITSmodules;
365   }// end if fITSmodules!=0
366
367   //
368   if(fDtype) {
369     fDtype->Delete();
370     delete fDtype;
371   }
372   delete [] fNdtype;
373   if (fCtype) {
374     fCtype->Delete();
375     delete fCtype;
376   }
377   delete [] fNctype;
378   //
379
380   if (fDetTypes) {
381     fDetTypes->Delete();
382     delete fDetTypes;
383   }
384
385   if (fTreeC) delete fTreeC;
386
387   if (fITSgeom) delete fITSgeom;
388
389 }
390
391 //___________________________________________
392 AliITSDetType* AliITS::DetType(Int_t id)
393 {
394   //return pointer to id detector type
395     return ((AliITSDetType*) (*fDetTypes)[id]);
396
397 }
398 //___________________________________________
399 void AliITS::SetClasses(Int_t id, const char *digit, const char *cluster)
400 {
401   //set the digit and cluster classes to be used for the id detector type
402     ((AliITSDetType*) (*fDetTypes)[id])->ClassNames(digit,cluster);
403
404 }
405 //___________________________________________
406 void AliITS::SetResponseModel(Int_t id, AliITSresponse *response)
407 {
408   //set the response model for the id detector type
409
410     ((AliITSDetType*) (*fDetTypes)[id])->ResponseModel(response);
411
412 }
413
414 //___________________________________________
415 void AliITS::SetSegmentationModel(Int_t id, AliITSsegmentation *seg)
416 {
417   //set the segmentation model for the id detector type
418
419     ((AliITSDetType*) (*fDetTypes)[id])->SegmentationModel(seg);
420
421 }
422
423 //___________________________________________
424 void AliITS::SetSimulationModel(Int_t id, AliITSsimulation *sim)
425 {
426   //set the simulation model for the id detector type
427
428    ((AliITSDetType*) (*fDetTypes)[id])->SimulationModel(sim);
429
430 }
431 //___________________________________________
432 void AliITS::SetReconstructionModel(Int_t id, AliITSClusterFinder *reconst)
433 {
434   //set the cluster finder model for the id detector type
435
436    ((AliITSDetType*) (*fDetTypes)[id])->ReconstructionModel(reconst);
437
438 }
439
440 //_____________________________________________________________________________
441 void AliITS::AddHit(Int_t track, Int_t *vol, Float_t *hits){
442   //
443   // Add an ITS hit
444   //     The function to add information to the AliITShit class. See the
445   // AliITShit class for a full description. This function allocates the
446   // necessary new space for the hit information and passes the variable
447   // track, and the pointers *vol and *hits to the AliITShit constructor
448   // function.
449   //
450   TClonesArray &lhits = *fHits;
451   new(lhits[fNhits++]) AliITShit(fIshunt,track,vol,hits);
452 }
453 //_____________________________________________________________________________
454 void AliITS::AddRealDigit(Int_t id, Int_t *digits) 
455 {
456   // add a real digit - as coming from data
457
458   TClonesArray &ldigits = *((TClonesArray*)(*fDtype)[id]);
459   new(ldigits[fNdtype[id]++]) AliITSdigit(digits);
460
461 }
462 //_____________________________________________________________________________
463 void AliITS::AddSimDigit(Int_t id, AliITSdigit *d) 
464 {
465
466   // add a simulated digit
467
468   TClonesArray &ldigits = *((TClonesArray*)(*fDtype)[id]);
469
470   switch(id)
471   {
472   case 0:
473      new(ldigits[fNdtype[id]++]) AliITSdigitSPD(*((AliITSdigitSPD*)d));
474      break;
475   case 1:
476      new(ldigits[fNdtype[id]++]) AliITSdigitSDD(*((AliITSdigitSDD*)d));
477      break;
478   case 2:
479      new(ldigits[fNdtype[id]++]) AliITSdigitSSD(*((AliITSdigitSSD*)d));
480      break;
481   }
482
483 }
484
485 //_____________________________________________________________________________
486 void AliITS::AddSimDigit(Int_t id,Float_t phys,Int_t *digits,Int_t *tracks,Int_t *hits,Float_t *charges){
487
488   // add a simulated digit to the list
489
490   TClonesArray &ldigits = *((TClonesArray*)(*fDtype)[id]);
491   switch(id)
492   {
493   case 0:
494      new(ldigits[fNdtype[id]++]) AliITSdigitSPD(digits,tracks,hits);
495      break;
496   case 1:
497      new(ldigits[fNdtype[id]++]) AliITSdigitSDD(phys,digits,tracks,hits,charges);
498      break;
499   case 2:
500      new(ldigits[fNdtype[id]++]) AliITSdigitSSD(digits,tracks,hits);
501      break;
502   }
503  
504 }
505
506 //_____________________________________________________________________________
507 void AliITS::AddCluster(Int_t id, AliITSRawCluster *c) 
508 {
509
510   // add a cluster to the list
511
512   TClonesArray &lcl = *((TClonesArray*)(*fCtype)[id]);
513
514   switch(id)
515   {
516   case 0:
517      new(lcl[fNctype[id]++]) AliITSRawClusterSPD(*((AliITSRawClusterSPD*)c));
518      break;
519   case 1:
520      new(lcl[fNctype[id]++]) AliITSRawClusterSDD(*((AliITSRawClusterSDD*)c));
521      break;
522   case 2:
523      new(lcl[fNctype[id]++]) AliITSRawClusterSSD(*((AliITSRawClusterSSD*)c));
524      break;
525   }
526
527 }
528
529
530 //_____________________________________________________________________________
531 void AliITS::AddRecPoint(const AliITSRecPoint &r)
532 {
533   //
534   // Add a reconstructed space point to the list
535   //
536   TClonesArray &lrecp = *fRecPoints;
537   new(lrecp[fNRecPoints++]) AliITSRecPoint(r);
538 }
539  
540
541 //____________________________________________
542 void AliITS::ResetDigits()
543 {
544     //
545     // Reset number of digits and the digits array for the ITS detector
546     //
547
548     if (!fDtype) return;
549
550     Int_t i;
551     for (i=0;i<kNTYPES;i++ ) {
552         if ((*fDtype)[i])    ((TClonesArray*)(*fDtype)[i])->Clear();
553         if (fNdtype)  fNdtype[i]=0;
554     }
555 }
556
557 //____________________________________________
558 void AliITS::ResetDigits(Int_t i)
559 {
560     //
561     // Reset number of digits and the digits array for this branch
562     //
563   if ((*fDtype)[i])    ((TClonesArray*)(*fDtype)[i])->Clear();
564   if (fNdtype)  fNdtype[i]=0;
565 }
566
567
568 //____________________________________________
569 void AliITS::ResetClusters()
570 {
571     //
572     // Reset number of clusters and the clusters array for ITS
573     //
574
575     Int_t i;
576     for (i=0;i<kNTYPES;i++ ) {
577         if ((*fCtype)[i])    ((TClonesArray*)(*fCtype)[i])->Clear();
578         if (fNctype)  fNctype[i]=0;
579     }
580
581 }
582
583 //____________________________________________
584 void AliITS::ResetClusters(Int_t i)
585 {
586     //
587     // Reset number of clusters and the clusters array for this branch
588     //
589         if ((*fCtype)[i])    ((TClonesArray*)(*fCtype)[i])->Clear();
590         if (fNctype)  fNctype[i]=0;
591
592 }
593
594
595 //____________________________________________
596 void AliITS::ResetRecPoints()
597 {
598     //
599     // Reset number of rec points and the rec points array 
600     //
601     if (fRecPoints) fRecPoints->Clear();
602     fNRecPoints = 0;
603
604 }
605
606 //_____________________________________________________________________________
607 Int_t AliITS::DistancetoPrimitive(Int_t , Int_t ){
608   //
609   // Distance from mouse to ITS on the screen. Dummy routine
610   //     A dummy routine used by the ROOT macro display.C to allow for the
611   // use of the mouse (pointing device) in the macro. In general this should
612   // never be called. If it is it returns the number 9999 for any value of
613   // x and y.
614   //
615   return 9999;
616 }
617
618 //_____________________________________________________________________________
619 void AliITS::Init(){
620   //
621   // Initialise ITS after it has been built
622   //     This routine initializes the AliITS class. It is intended to be called
623   // from the Init function in AliITSv?. Besides displaying a banner
624   // indicating that it has been called it initializes the array fIdSens
625   // and sets the default segmentation, response, digit and raw cluster classes
626   // Therefore it should be called after a call to CreateGeometry.
627   //
628   Int_t i;
629
630 //
631   SetDefaults();
632 // Array of TStrings
633   for(i=0;i<fIdN;i++) fIdSens[i] = gMC->VolId(fIdName[i]);
634 //
635 }
636
637 //_____________________________________________________________________________
638 void AliITS::SetDefaults()
639 {
640   // sets the default segmentation, response, digit and raw cluster classes
641
642   printf("SetDefaults\n");
643
644   AliITSDetType *iDetType;
645
646
647   //SPD 
648
649   iDetType=DetType(0); 
650   if (!iDetType->GetSegmentationModel()) {
651     AliITSsegmentationSPD *seg0=new AliITSsegmentationSPD(fITSgeom);
652     SetSegmentationModel(0,seg0); 
653   }
654   if (!iDetType->GetResponseModel()) {
655      SetResponseModel(0,new AliITSresponseSPD()); 
656   }
657   // set digit and raw cluster classes to be used
658   
659   const char *kData0=(iDetType->GetResponseModel())->DataType();
660   if (strstr(kData0,"real")) {
661       iDetType->ClassNames("AliITSdigit","AliITSRawClusterSPD");
662   } else iDetType->ClassNames("AliITSdigitSPD","AliITSRawClusterSPD");
663
664   // SDD                                          //
665   iDetType=DetType(1); 
666   if (!iDetType->GetResponseModel()) {
667     SetResponseModel(1,new AliITSresponseSDD()); 
668   }
669   AliITSresponse *resp1=iDetType->GetResponseModel();
670   if (!iDetType->GetSegmentationModel()) {
671     AliITSsegmentationSDD *seg1=new AliITSsegmentationSDD(fITSgeom,resp1);
672     SetSegmentationModel(1,seg1); 
673   }
674   const char *kData1=(iDetType->GetResponseModel())->DataType();
675   const char *kopt=iDetType->GetResponseModel()->ZeroSuppOption();
676   if ((!strstr(kopt,"2D")) && (!strstr(kopt,"1D")) || strstr(kData1,"real") ) {
677       iDetType->ClassNames("AliITSdigit","AliITSRawClusterSDD");
678   } else iDetType->ClassNames("AliITSdigitSDD","AliITSRawClusterSDD");
679
680   // SSD
681   iDetType=DetType(2); 
682   if (!iDetType->GetSegmentationModel()) {
683     AliITSsegmentationSSD *seg2=new AliITSsegmentationSSD(fITSgeom);
684     SetSegmentationModel(2,seg2); 
685   }
686   if (!iDetType->GetResponseModel()) {
687     SetResponseModel(2,new AliITSresponseSSD()); 
688   }
689   const char *kData2=(iDetType->GetResponseModel())->DataType();
690   if (strstr(kData2,"real")) {
691       iDetType->ClassNames("AliITSdigit","AliITSRawClusterSSD");
692   } else iDetType->ClassNames("AliITSdigitSSD","AliITSRawClusterSSD");
693
694   if (kNTYPES>3) {
695     Warning("SetDefaults","Only the three basic detector types are initialised!");
696   } 
697
698 }
699
700
701
702 //_____________________________________________________________________________
703 void AliITS::SetDefaultSimulation()
704 {
705   // to be written
706
707 }
708 //_____________________________________________________________________________
709 void AliITS::SetDefaultClusterFinders()
710 {
711   // to be written
712
713 }
714 //_____________________________________________________________________________
715
716 void AliITS::MakeTreeC(Option_t *option)
717 {
718   // create a separate tree to store the clusters
719
720 //  cout << "AliITS::MakeTreeC" << endl;
721
722      const char *optC = strstr(option,"C");
723      if (optC && !fTreeC) fTreeC = new TTree("TC","Clusters in ITS");
724      else return;
725
726      Int_t buffersize = 4000;
727      char branchname[30];
728
729      const char *det[3] = {"SPD","SDD","SSD"};
730
731      char digclass[40];
732      char clclass[40];
733
734      // one branch for Clusters per type of detector
735      Int_t i;
736      for (i=0; i<kNTYPES ;i++) {
737        AliITSDetType *iDetType=DetType(i); 
738        iDetType->GetClassNames(digclass,clclass);
739        // clusters
740        (*fCtype)[i] = new TClonesArray(clclass,10000); 
741         if (kNTYPES==3) sprintf(branchname,"%sClusters%s",GetName(),det[i]);
742         else  sprintf(branchname,"%sClusters%d",GetName(),i+1);
743         if (fCtype   && fTreeC) {
744            TreeC()->Branch(branchname,&((*fCtype)[i]), buffersize);
745 //         cout << "Making Branch " << branchname;
746 //         cout << " for Clusters of detector type " << i+1 << endl;
747         }       
748      }
749
750 }
751
752 //_____________________________________________________________________________
753 void AliITS::GetTreeC(Int_t event)
754 {
755
756 //  cout << "AliITS::GetTreeC" << endl;
757
758   // get the clusters tree for this event and set the branch address
759     char treeName[20];
760     char branchname[30];
761
762     const char *det[3] = {"SPD","SDD","SSD"};
763
764     ResetClusters();
765     if (fTreeC) {
766           delete fTreeC;
767     }
768
769     sprintf(treeName,"TreeC%d",event);
770     fTreeC = (TTree*)gDirectory->Get(treeName);
771
772     TBranch *branch;
773     if (fTreeC) {
774         Int_t i;
775         for (i=0; i<kNTYPES; i++) {
776            if (kNTYPES==3) sprintf(branchname,"%sClusters%s",GetName(),det[i]);
777            else  sprintf(branchname,"%sClusters%d",GetName(),i+1);
778            if (fCtype) {
779                 branch = fTreeC->GetBranch(branchname);
780                 if (branch) branch->SetAddress(&((*fCtype)[i]));
781             }
782         }
783     } else {
784         Error("AliITS::GetTreeC",
785                 "cannot find Clusters Tree for event:%d\n",event);
786     }
787
788 }
789 //_____________________________________________________________________________
790 void AliITS::MakeBranch(Option_t* option, char *file)
791 {
792   //
793   // Creates Tree branches for the ITS.
794   //
795   //
796   Int_t buffersize = 4000;
797   char branchname[30];
798   sprintf(branchname,"%s",GetName());
799
800   AliDetector::MakeBranch(option,file);
801
802   const char *cD = strstr(option,"D");
803   const char *cR = strstr(option,"R");
804
805   if (cD) {
806   //
807   // one branch for digits per type of detector
808   //
809    const char *det[3] = {"SPD","SDD","SSD"};
810
811    char digclass[40];
812    char clclass[40];
813
814    Int_t i;
815    for (i=0; i<kNTYPES ;i++) {
816        AliITSDetType *iDetType=DetType(i); 
817        iDetType->GetClassNames(digclass,clclass);
818        // digits
819        if(!((*fDtype)[i])) (*fDtype)[i] = new TClonesArray(digclass,10000);
820        else ResetDigits(i);
821    }
822
823    for (i=0; i<kNTYPES ;i++) {
824       if (kNTYPES==3) sprintf(branchname,"%sDigits%s",GetName(),det[i]);
825       else  sprintf(branchname,"%sDigits%d",GetName(),i+1);      
826       if (fDtype && gAlice->TreeD()) {
827         gAlice->MakeBranchInTree(gAlice->TreeD(), 
828                          branchname, &((*fDtype)[i]), buffersize, file);
829 //          cout << "Making Branch " << branchname;
830 //          cout << " for digits of type "<< i+1 << endl;
831       } 
832     }
833   }
834
835   if (cR) {
836   //
837   // only one branch for rec points for all detector types
838   //
839     sprintf(branchname,"%sRecPoints",GetName());
840  
841     if(!fRecPoints) fRecPoints=new TClonesArray("AliITSRecPoint",10000);
842
843     if (fRecPoints && gAlice->TreeR()) {
844       gAlice->MakeBranchInTree(gAlice->TreeR(), 
845                                branchname, &fRecPoints, buffersize, file) ;
846 //      cout << "Making Branch " << branchname;
847 //      cout << " for reconstructed space points" << endl;
848     }
849   }     
850 }
851
852 //___________________________________________
853 void AliITS::SetTreeAddress()
854 {
855
856   // Set branch address for the Trees.
857
858   char branchname[30];
859   AliDetector::SetTreeAddress();
860
861   const char *det[3] = {"SPD","SDD","SSD"};
862
863   TBranch *branch;
864   TTree *treeD = gAlice->TreeD();
865   TTree *treeR = gAlice->TreeR();
866
867   Int_t i;
868   if (treeD) {
869       for (i=0; i<kNTYPES; i++) {
870           if (kNTYPES==3) sprintf(branchname,"%sDigits%s",GetName(),det[i]);
871           else  sprintf(branchname,"%sDigits%d",GetName(),i+1);
872           if (fDtype) {
873               branch = treeD->GetBranch(branchname);
874               if (branch) branch->SetAddress(&((*fDtype)[i]));
875           }
876       }
877   }
878
879  
880   if (treeR) {
881     sprintf(branchname,"%sRecPoints",GetName());
882       branch = treeR->GetBranch(branchname);
883       if (branch) branch->SetAddress(&fRecPoints);
884   }
885   
886
887 }
888
889 //____________________________________________________________________________
890 void AliITS::InitModules(Int_t size,Int_t &nmodules){
891
892   //initialize the modules array
893
894   if(fITSmodules){ 
895       fITSmodules->Delete();
896       delete fITSmodules;
897   }
898
899     Int_t nl,indexMAX,index;
900
901     if(size<=0){ // default to using data stored in AliITSgeom
902         if(fITSgeom==0) {
903             Error("AliITS::InitModules",
904                 "in AliITS::InitModule fITSgeom not defined\n");
905             return;
906         } // end if fITSgeom==0
907         nl = fITSgeom->GetNlayers();
908         indexMAX = fITSgeom->GetModuleIndex(nl,fITSgeom->GetNladders(nl),
909                                             fITSgeom->GetNdetectors(nl))+1;
910         nmodules = indexMAX;
911         fITSmodules = new TObjArray(indexMAX);
912         for(index=0;index<indexMAX;index++){
913                 fITSmodules->AddAt( new AliITSmodule(index),index);
914         } // end for index
915     }else{
916         fITSmodules = new TObjArray(size);
917         for(index=0;index<size;index++) {
918             fITSmodules->AddAt( new AliITSmodule(index),index);
919         }
920
921         nmodules = size;
922     } // end i size<=0
923 }
924
925 //____________________________________________________________________________
926 void AliITS::FillModules(Int_t evnt,Int_t bgrev,Int_t nmodules,Option_t *option,Text_t *filename){
927
928   // fill the modules with the sorted by module hits; add hits from background
929   // if option=Add
930
931
932     static TTree *trH1;                 //Tree with background hits
933     static TClonesArray *fHits2;        //List of hits for one track only
934
935     static Bool_t first=kTRUE;
936     static TFile *file;
937     const char *addBgr = strstr(option,"Add");
938
939
940     if (addBgr ) {
941         if(first) {
942 //          cout<<"filename "<<filename<<endl;
943             file=new TFile(filename);
944 //          cout<<"I have opened "<<filename<<" file "<<endl;
945             fHits2     = new TClonesArray("AliITShit",1000  );
946         }           
947         first=kFALSE;
948         file->cd();
949         file->ls();
950         // Get Hits Tree header from file
951         if(fHits2) fHits2->Clear();
952         if(trH1) delete trH1;
953         trH1=0;
954         
955         char treeName[20];
956         sprintf(treeName,"TreeH%d",bgrev);
957         trH1 = (TTree*)gDirectory->Get(treeName);
958         //printf("TrH1 %p of treename %s for event %d \n",trH1,treeName,bgrev);
959         
960         if (!trH1) {
961             Error("AliITS::FillModules",
962             "cannot find Hits Tree for event:%d\n",bgrev);
963         }
964         // Set branch addresses
965         TBranch *branch;
966         char branchname[20];
967         sprintf(branchname,"%s",GetName());
968         if (trH1 && fHits2) {
969             branch = trH1->GetBranch(branchname);
970             if (branch) branch->SetAddress(&fHits2);
971         }
972
973         // test
974         //Int_t ntracks1 =(Int_t)TrH1->GetEntries();
975         //printf("background - ntracks1 - %d\n",ntracks1);
976    }
977
978     //Int_t npart = gAlice->GetEvent(evnt);
979     //if(npart<=0) return;
980     TClonesArray *itsHits = this->Hits();
981     Int_t lay,lad,det,index;
982     AliITShit *itsHit=0;
983     AliITSmodule *mod=0;
984
985     TTree *iTH = gAlice->TreeH();
986     Int_t ntracks =(Int_t) iTH->GetEntries();
987
988     Int_t t,h;
989     for(t=0; t<ntracks; t++){
990         gAlice->ResetHits();
991         iTH->GetEvent(t);
992         Int_t nhits = itsHits->GetEntriesFast();
993         //printf("nhits %d\n",nhits);
994         if (!nhits) continue;
995         for(h=0; h<nhits; h++){
996             itsHit = (AliITShit *)itsHits->UncheckedAt(h);
997             itsHit->GetDetectorID(lay,lad,det);
998             // temporarily index=det-1 !!!
999             if(fITSgeom) index = fITSgeom->GetModuleIndex(lay,lad,det);
1000             else index=det-1;
1001             //
1002             mod = this->GetModule(index);
1003             mod->AddHit(itsHit,t,h);
1004         } // end loop over hits 
1005     } // end loop over tracks
1006
1007     // open the file with background
1008     
1009     if (addBgr ) {
1010           Int_t track,i;
1011           ntracks =(Int_t)trH1->GetEntries();
1012             //printf("background - ntracks1 %d\n",ntracks);
1013             //printf("background - Start loop over tracks \n");     
1014             //   Loop over tracks
1015
1016             for (track=0; track<ntracks; track++) {
1017
1018                 if (fHits2)       fHits2->Clear();
1019                 trH1->GetEvent(track);
1020                 //   Loop over hits
1021                 for(i=0;i<fHits2->GetEntriesFast();++i) {
1022
1023                     itsHit=(AliITShit*) (*fHits2)[i];
1024                     itsHit->GetDetectorID(lay,lad,det);
1025                     // temporarily index=det-1 !!!
1026                     if(fITSgeom) index = fITSgeom->GetModuleIndex(lay,lad,det);
1027                     else index=det-1;
1028                     //
1029                     mod = this->GetModule(index);
1030                     mod->AddHit(itsHit,track,i);
1031                }  // end loop over hits
1032             } // end loop over tracks
1033
1034             TTree *fAli=gAlice->TreeK();
1035             TFile *fileAli=0;
1036             
1037             if (fAli) fileAli =fAli->GetCurrentFile();
1038             fileAli->cd();
1039
1040     } // end if add
1041
1042     //gObjectTable->Print();
1043
1044 }
1045
1046 //____________________________________________________________________________
1047
1048 void AliITS::SDigits2Digits()
1049 {
1050   
1051   AliITSgeom *geom = GetITSgeom();
1052   
1053   // SPD
1054   AliITSDetType *iDetType;
1055   iDetType=DetType(0);
1056   AliITSsegmentationSPD *seg0=(AliITSsegmentationSPD*)iDetType->GetSegmentationModel();
1057   AliITSresponseSPD *res0 = (AliITSresponseSPD*)iDetType->GetResponseModel();
1058   AliITSsimulationSPD *sim0=new AliITSsimulationSPD(seg0,res0);
1059   SetSimulationModel(0,sim0);
1060   // test
1061   // printf("SPD dimensions %f %f \n",seg0->Dx(),seg0->Dz());
1062   // printf("SPD npixels %d %d \n",seg0->Npz(),seg0->Npx());
1063   // printf("SPD pitches %d %d \n",seg0->Dpz(0),seg0->Dpx(0));
1064   // end test
1065   // 
1066   // SDD
1067   //Set response functions
1068   // SDD compression param: 2 fDecrease, 2fTmin, 2fTmax or disable, 2 fTolerance
1069
1070   iDetType=DetType(1);
1071   AliITSresponseSDD *res1 = (AliITSresponseSDD*)iDetType->GetResponseModel();
1072   if (!res1) {
1073     res1=new AliITSresponseSDD();
1074     SetResponseModel(1,res1);
1075   }
1076   Float_t noise, baseline;
1077   res1->GetNoiseParam(noise,baseline);
1078   Float_t noise_after_el =  res1->GetNoiseAfterElectronics();
1079   Float_t fCutAmp = baseline + 2.*noise_after_el;
1080   Int_t cp[8]={0,0,(int)fCutAmp,(int)fCutAmp,0,0,0,0}; //1D
1081   res1->SetCompressParam(cp);
1082   AliITSsegmentationSDD *seg1=(AliITSsegmentationSDD*)iDetType->GetSegmentationModel();
1083   if (!seg1) {
1084     seg1 = new AliITSsegmentationSDD(geom,res1);
1085     SetSegmentationModel(1,seg1);
1086   }
1087   AliITSsimulationSDD *sim1=new AliITSsimulationSDD(seg1,res1);
1088   SetSimulationModel(1,sim1);
1089
1090   // SSD
1091   iDetType=DetType(2);
1092   AliITSsegmentationSSD *seg2=(AliITSsegmentationSSD*)iDetType->GetSegmentationModel();
1093   AliITSresponseSSD *res2 = (AliITSresponseSSD*)iDetType->GetResponseModel();
1094   res2->SetSigmaSpread(3.,2.);
1095   AliITSsimulationSSD *sim2=new AliITSsimulationSSD(seg2,res2);
1096   SetSimulationModel(2,sim2);
1097  
1098   cerr<<"Digitizing ITS...\n";
1099  
1100   TStopwatch timer;
1101   timer.Start();
1102   HitsToDigits(0,0,-1," ","All"," ");
1103   timer.Stop(); timer.Print();
1104
1105   delete sim0;
1106   delete sim1;
1107   delete sim2;
1108 }
1109
1110
1111 //____________________________________________________________________________
1112 void AliITS::HitsToDigits(Int_t evNumber,Int_t bgrev,Int_t size, Option_t *option, Option_t *opt,Text_t *filename)
1113 {
1114     // keep galice.root for signal and name differently the file for 
1115     // background when add! otherwise the track info for signal will be lost !
1116   
1117    // the condition below will disappear when the geom class will be
1118    // initialised for all versions - for the moment it is only for v5 !
1119    // 7 is the SDD beam test version  
1120    Int_t ver = this->IsVersion(); 
1121    if(ver!=5 && ver!=7) return; 
1122
1123    const char *all = strstr(opt,"All");
1124    const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),strstr(opt,"SSD")};
1125 //   cout<<" 1 AliITS "<<endl;
1126    Int_t nmodules;
1127    InitModules(size,nmodules); 
1128 //   cout<<" 2 AliITS "<<endl;
1129    FillModules(evNumber,bgrev,nmodules,option,filename);
1130 //   cout<<" 3 AliITS "<<endl;
1131
1132    //TBranch *branch;
1133    AliITSsimulation* sim;
1134    //TObjArray *branches=gAlice->TreeD()->GetListOfBranches();
1135    AliITSgeom *geom = GetITSgeom();
1136
1137    Int_t id,module;
1138 //   Int_t lay, lad, detect;
1139    Int_t first,last;
1140    for (id=0;id<kNTYPES;id++) {
1141         if (!all && !det[id]) continue;
1142         //branch = (TBranch*)branches->UncheckedAt(id);
1143         AliITSDetType *iDetType=DetType(id); 
1144         sim = (AliITSsimulation*)iDetType->GetSimulationModel();
1145
1146         if (!sim) {
1147            Error("HitsToDigits","The simulation class was not instantiated!");
1148            exit(1);
1149            // or SetDefaultSimulation();
1150         }
1151
1152         if(geom) {
1153           first = geom->GetStartDet(id);
1154           last = geom->GetLastDet(id);
1155         } else first=last=0;
1156 //      cout << "det type " << id << " first, last "<< first << last << endl;
1157         for(module=first;module<=last;module++) {
1158             AliITSmodule *mod = (AliITSmodule *)fITSmodules->At(module);
1159 /*
1160             geom->GetModuleId(module,lay, lad, detect);
1161             if ( lay == 6 )
1162               ((AliITSsegmentationSSD*)(((AliITSsimulationSSD*)sim)->GetSegmentation()))->SetLayer(6);
1163             if ( lay == 5 )
1164               ((AliITSsegmentationSSD*)(((AliITSsimulationSSD*)sim)->GetSegmentation()))->SetLayer(5);
1165 */
1166             sim->DigitiseModule(mod,module,evNumber);
1167             // fills all branches - wasted disk space
1168             gAlice->TreeD()->Fill(); 
1169             ResetDigits();
1170             // try and fill only the branch 
1171             //branch->Fill();
1172             //ResetDigits(id);
1173         } // loop over modules
1174    } // loop over detector types
1175
1176    ClearModules();
1177
1178 //   Int_t nentries=(Int_t)
1179    gAlice->TreeD()->GetEntries();
1180 //   cout << "nentries in TreeD" << nentries << endl;
1181
1182    char hname[30];
1183    sprintf(hname,"TreeD%d",evNumber);
1184    gAlice->TreeD()->Write(hname,TObject::kOverwrite);
1185    // reset tree
1186    gAlice->TreeD()->Reset();
1187
1188 }
1189
1190
1191 //____________________________________________________________________________
1192 void AliITS::DigitsToRecPoints(Int_t evNumber,Int_t lastentry,Option_t *opt)
1193 {
1194   // cluster finding and reconstruction of space points
1195   
1196    // the condition below will disappear when the geom class will be
1197    // initialised for all versions - for the moment it is only for v5 !
1198    // 7 is the SDD beam test version  
1199    Int_t ver = this->IsVersion(); 
1200    if(ver!=5) return; 
1201
1202    const char *all = strstr(opt,"All");
1203    const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),strstr(opt,"SSD")};
1204
1205    static Bool_t first=kTRUE;
1206    if (!TreeC() && first) {
1207        MakeTreeC("C");
1208        first=kFALSE;
1209    }
1210
1211    TTree *treeC=TreeC();
1212  
1213
1214    //TBranch *branch;
1215    AliITSClusterFinder* rec;
1216
1217    //TObjArray *branches=gAlice->TreeR()->GetListOfBranches();
1218    AliITSgeom *geom = GetITSgeom();
1219
1220    Int_t id,module;
1221    for (id=0;id<kNTYPES;id++) {
1222         if (!all && !det[id]) continue;
1223         //branch = (TBranch*)branches->UncheckedAt(id);
1224         AliITSDetType *iDetType=DetType(id); 
1225         rec = (AliITSClusterFinder*)iDetType->GetReconstructionModel();
1226         if (!rec) {
1227            Error("DigitsToRecPoints","The cluster finder class was not instantiated!");
1228            exit(1);
1229            // or SetDefaultClusterFinders();
1230         }
1231         TClonesArray *itsDigits  = this->DigitsAddress(id);
1232
1233         Int_t first,last;
1234         if(geom) {
1235           first = geom->GetStartDet(id);
1236           last = geom->GetLastDet(id);
1237         } else first=last=0;
1238         //printf("first last %d %d\n",first,last);
1239         for(module=first;module<=last;module++) {
1240               this->ResetDigits();
1241               if (all) gAlice->TreeD()->GetEvent(lastentry+module);
1242               else gAlice->TreeD()->GetEvent(lastentry+(module-first));
1243               Int_t ndigits = itsDigits->GetEntriesFast();
1244               if (ndigits) rec->FindRawClusters(module);
1245               gAlice->TreeR()->Fill(); 
1246               ResetRecPoints();
1247               treeC->Fill();
1248               ResetClusters();
1249               // try and fill only the branch 
1250               //branch->Fill();
1251               //ResetRecPoints(id);
1252         } // loop over modules
1253    } // loop over detector types
1254
1255
1256 //   Int_t nentries=(Int_t)
1257    gAlice->TreeR()->GetEntries();
1258 //   Int_t ncentries=(Int_t)
1259    treeC->GetEntries();
1260 //   cout << " nentries ncentries " << nentries << ncentries <<  endl;
1261
1262    char hname[30];
1263    sprintf(hname,"TreeR%d",evNumber);
1264    gAlice->TreeR()->Write(hname,TObject::kOverwrite);
1265    // reset tree
1266    gAlice->TreeR()->Reset();
1267
1268    sprintf(hname,"TreeC%d",evNumber);
1269    treeC->Write(hname,TObject::kOverwrite);
1270    treeC->Reset();
1271 }
1272
1273
1274 //____________________________________________________________________________
1275 void AliITS::HitsToFastRecPoints(Int_t evNumber,Int_t bgrev,Int_t size,
1276 Option_t *option,Option_t *opt,Text_t *filename)
1277 {
1278     // keep galice.root for signal and name differently the file for 
1279     // background when add! otherwise the track info for signal will be lost !
1280   
1281
1282    // the condition below will disappear when the geom class will be
1283    // initialised for all versions - for the moment it is only for v5 !  
1284    Int_t ver = this->IsVersion(); 
1285    if(ver!=5) return; 
1286
1287    const char *all = strstr(opt,"All");
1288    const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),strstr(opt,"SSD")};
1289
1290    Int_t nmodules;
1291    InitModules(size,nmodules);
1292    FillModules(evNumber,bgrev,nmodules,option,filename);
1293
1294
1295    AliITSsimulation* sim;
1296    AliITSgeom *geom = GetITSgeom();
1297
1298    TRandom *random=new TRandom[9];
1299    random[0].SetSeed(111);
1300    random[1].SetSeed(222);
1301    random[2].SetSeed(333);              
1302    random[3].SetSeed(444);
1303    random[4].SetSeed(555);
1304    random[5].SetSeed(666);              
1305    random[6].SetSeed(777);
1306    random[7].SetSeed(888);
1307    random[8].SetSeed(999);              
1308
1309
1310    Int_t id,module;
1311    for (id=0;id<kNTYPES;id++) {
1312         if (!all && !det[id]) continue;
1313         AliITSDetType *iDetType=DetType(id); 
1314         sim = (AliITSsimulation*)iDetType->GetSimulationModel();
1315         if (!sim) {
1316            Error("HitsToFastPoints","The simulation class was not instantiated!");
1317            exit(1);
1318            // or SetDefaultSimulation();
1319         }
1320         Int_t first = geom->GetStartDet(id);
1321         Int_t last = geom->GetLastDet(id);
1322         for(module=first;module<=last;module++) {
1323             AliITSmodule *mod = (AliITSmodule *)fITSmodules->At(module);
1324             sim->CreateFastRecPoints(mod,module,random);
1325             gAlice->TreeR()->Fill(); 
1326             ResetRecPoints();
1327         } // loop over modules
1328    } // loop over detector types
1329
1330
1331    ClearModules();
1332
1333    //Int_t nentries=(Int_t)gAlice->TreeR()->GetEntries();
1334
1335    char hname[30];
1336    sprintf(hname,"TreeR%d",evNumber);
1337    gAlice->TreeR()->Write(hname,TObject::kOverwrite);
1338    // reset tree
1339    gAlice->TreeR()->Reset();
1340
1341    delete [] random;
1342
1343 }
1344
1345 //________________________________________________________________
1346 AliITStrack  AliITS::Tracking(AliITStrack &track, AliITStrack *reference,TObjArray *fastpoints, Int_t
1347 **vettid, Bool_t flagvert,  AliITSRad *rl  ) { 
1348                                                                                 
1349 //Origin  A. Badala' and G.S. Pappalardo:  e-mail Angela.Badala@ct.infn.it, Giuseppe.S.Pappalardo@ct.infn.it 
1350
1351                                                                                     
1352   TList *list= new TList();   
1353
1354   AliITStrack tr(track);
1355   
1356   list->AddLast(&tr);
1357   
1358   Double_t Pt=(tr).GetPt();
1359 //  cout << "\n Pt = " << Pt <<"\n";  //stampa
1360
1361   AliITStracking obj(list, reference, this, fastpoints,TMath::Abs(Pt),vettid, flagvert, rl);
1362   list->Delete();
1363   delete list;
1364
1365   Int_t itot=-1;
1366   TVector VecTotLabref(18);
1367   Int_t lay, k;
1368   for(lay=5; lay>=0; lay--) {
1369     TVector VecLabref(3); 
1370     VecLabref=(*reference).GetLabTrack(lay);
1371     Float_t ClustZ=(*reference).GetZclusterTrack( lay);   //aggiunta il 5-3-2001
1372     for(k=0; k<3; k++){ //{itot++; VecTotLabref(itot)=VecLabref(k);} //cambiata il 5-3-2001 
1373                 Int_t lpp=(Int_t)VecLabref(k);
1374                 if(lpp>=0) {
1375                   TParticle *p=(TParticle*) gAlice->Particle(lpp);
1376                   Int_t pcode=p->GetPdgCode();
1377                   if(pcode==11) VecLabref(k)=p->GetFirstMother();
1378                 }    
1379     itot++; VecTotLabref(itot)=VecLabref(k);
1380     if(VecLabref(k)==0. && ClustZ == 0.) VecTotLabref(itot) =-3.; }  
1381   }
1382   Long_t labref;
1383   Int_t freq;  
1384   (*reference).Search(VecTotLabref, labref, freq);
1385     
1386   //if(freq < 4) labref=-labref;
1387   //if(freq < 6) labref=-labref;        // cinque - sei
1388   if(freq < 5) labref=-labref;        // cinque - sei   
1389   (*reference).SetLabel(labref);
1390
1391   return *reference; 
1392
1393 }
1394
1395
1396
1397 //________________________________________________________________
1398
1399
1400
1401 void AliITS::DoTracking(Int_t evNumber, Int_t min_t, Int_t max_t, TFile *file, Bool_t flagvert) {
1402
1403 //   ex macro for tracking ITS
1404
1405   printf("begin DoTracking - file %p\n",file);
1406
1407   //const char *pname="75x40_100x60";
1408   
1409  Int_t imax=200,jmax=450;
1410   AliITSRad *rl = new AliITSRad(imax,jmax);
1411   //cout<<" dopo costruttore AliITSRad\n"; getchar();
1412     
1413   struct GoodTrack {
1414     Int_t lab,code;
1415     Float_t px,py,pz,x,y,z,pxg,pyg,pzg,ptg;
1416     Bool_t flag;
1417   };
1418   
1419
1420   gAlice->GetEvent(0);
1421  
1422   AliKalmanTrack *kkprov;
1423   kkprov->SetConvConst(100/0.299792458/0.2/gAlice->Field()->Factor());  
1424
1425   /*  //modificato il 26-4-2001
1426   AliTPC *TPC=(AliTPC*)gAlice->GetDetector("TPC");
1427   AliTPCParam *digp = (AliTPCParam*)file->Get(pname);
1428   if (digp!=0) TPC->SetParam(digp);
1429   */
1430   TFile *cf=TFile::Open("AliTPCclusters.root");  
1431   AliTPCParam *digp= (AliTPCParam*)cf->Get("75x40_100x60");
1432   if (!digp) { cerr<<"TPC parameters have not been found !\n"; getchar();}
1433      
1434   
1435   GoodTrack gt[15000];
1436   Int_t ngood=0;
1437   ifstream in("itsgood_tracks");
1438
1439   cerr<<"Reading itsgood tracks...\n";
1440   while (in>>gt[ngood].lab>>gt[ngood].code
1441           >>gt[ngood].px >>gt[ngood].py>>gt[ngood].pz
1442           >>gt[ngood].x  >>gt[ngood].y >>gt[ngood].z
1443           >>gt[ngood].pxg  >>gt[ngood].pyg >>gt[ngood].pzg
1444           >>gt[ngood].ptg >>gt[ngood].flag) {
1445     ngood++;
1446     cerr<<ngood<<'\r';
1447     if (ngood==15000) {
1448       cerr<<"Too many good tracks !\n";
1449       break;
1450     }
1451   }
1452   if (!in.eof()) cerr<<"Read error (itsgood_tracks) !\n";
1453   
1454   
1455 // Load tracks
1456  // TFile *tf=TFile::Open("tpctracks.root"); //commentato 26-4-2001 
1457   TFile *tf=TFile::Open("AliTPCtracks.root"); 
1458   if (!tf->IsOpen()) {cerr<<"Can't open AliTPCtracks.root !\n"; return ;}
1459   TObjArray tracks(200000);
1460   TTree *tracktree=(TTree*)tf->Get("TreeT");
1461   TBranch *tbranch=tracktree->GetBranch("tracks");
1462   Int_t nentr=(Int_t)tracktree->GetEntries();
1463   Int_t kk;
1464   /*  commentato il 26-4-2001
1465   for (kk=0; kk<nentr; kk++) {
1466     AliTPCtrack *iotrack=new AliTPCtrack;
1467     tbranch->SetAddress(&iotrack);
1468     tracktree->GetEvent(kk);
1469     tracks.AddLast(iotrack);
1470   } 
1471   */
1472    AliTPCtrack *iotracktpc=0;    
1473   for (kk=0; kk<nentr; kk++) {
1474     iotracktpc=new AliTPCtrack; 
1475     tbranch->SetAddress(&iotracktpc);
1476     tracktree->GetEvent(kk);
1477     tracks.AddLast(iotracktpc);    
1478   }      
1479   tf->Close();
1480
1481
1482   Int_t nt = tracks.GetEntriesFast();
1483   cerr<<"Number of found tracks "<<nt<<endl;
1484   
1485   TVector DataOut(9);
1486   Int_t kkk=0;
1487   
1488   Double_t ptg=0.,pxg=0.,pyg=0.,pzg=0.;
1489
1490   //////////////////////////////  good tracks definition in TPC  ////////////////////////////////
1491       
1492   ofstream out1 ("AliITSTrag.out");
1493   Int_t i;
1494   for (i=0; i<ngood; i++) out1 << gt[i].ptg << "\n";
1495   out1.close();
1496
1497
1498   TVector vec(5);
1499   TTree *TR=gAlice->TreeR();
1500   Int_t nent=(Int_t)TR->GetEntries();
1501   TClonesArray  *recPoints = RecPoints();
1502   Int_t numbpoints;
1503   Int_t totalpoints=0;
1504   Int_t *np = new Int_t[nent];
1505   Int_t **vettid = new Int_t* [nent];
1506   Int_t mod;
1507   for (mod=0; mod<nent; mod++) {
1508     vettid[mod]=0;
1509     this->ResetRecPoints();
1510     //gAlice->TreeR()->GetEvent(mod+1); //first entry in TreeR is empty
1511     gAlice->TreeR()->GetEvent(mod); //first entry in TreeR is empty
1512     numbpoints = recPoints->GetEntries();
1513     totalpoints+=numbpoints;
1514     np[mod] = numbpoints;
1515   //cout<<" mod = "<<mod<<"   numbpoints = "<<numbpoints<<"\n"; getchar();
1516     vettid[mod] = new Int_t[numbpoints];
1517     Int_t ii;
1518     for (ii=0;ii<numbpoints; ii++) *(vettid[mod]+ii)=0;
1519   }
1520
1521   AliTPCtrack *track=0;
1522
1523      
1524   if(min_t < 0) {min_t = 0; max_t = nt-1;}   
1525
1526 /*
1527   ///////////////////////////////// Definition of vertex end its error ////////////////////////////
1528   ////////////////////////// In the future it will be given by a method ///////////////////////////
1529   Double_t Vx=0.;
1530   Double_t Vy=0.;
1531   Double_t Vz=0.;
1532   
1533   Float_t sigmavx=0.0050;      // 50  microns
1534   Float_t sigmavy=0.0050;      // 50  microns
1535   Float_t sigmavz=0.010;       // 100 microns
1536
1537   //Vx+=gRandom->Gaus(0,sigmavx);  Vy+=gRandom->Gaus(0,sigmavy);  Vz+=gRandom->Gaus(0,sigmavz);
1538   TVector vertex(3), ervertex(3)
1539   vertex(0)=Vx; vertex(1)=Vy; vertex(2)=Vz;
1540   ervertex(0)=sigmavx;  ervertex(1)=sigmavy;  ervertex(2)=sigmavz;
1541   /////////////////////////////////////////////////////////////////////////////////////////////////
1542 */      
1543  
1544
1545   TTree tracktree1("TreeT","Tree with ITS tracks");
1546   AliITSiotrack *iotrack=0;
1547   tracktree1.Branch("ITStracks","AliITSiotrack",&iotrack,32000,0);
1548
1549   ofstream out ("AliITSTra.out");
1550   //ofstream outprova ("AliITSprova.out"); //commentato il 26-4-2001 
1551   
1552   Int_t j;       
1553   for (j=min_t; j<=max_t; j++) {     
1554     track=(AliTPCtrack*)tracks.UncheckedAt(j);
1555     Int_t flaglab=0;
1556     if (!track) continue;
1557     ////// elimination of not good tracks ////////////   
1558     Int_t ilab=TMath::Abs(track->GetLabel());
1559     Int_t iii;
1560     for (iii=0;iii<ngood;iii++) {
1561          //cout<<" ilab, gt[iii].lab = "<<ilab<<" "<<gt[iii].lab<<"\n"; getchar();
1562       if (ilab==gt[iii].lab) { 
1563         flaglab=1;
1564         ptg=gt[iii].ptg; 
1565         pxg=gt[iii].pxg;
1566         pyg=gt[iii].pyg;
1567         pzg=gt[iii].pzg;        
1568         break;
1569       }
1570     }
1571          //cout<<" j flaglab =  " <<j<<" "<<flaglab<<"\n";  getchar();
1572     if (!flaglab) continue;  
1573          //cout<<" j =  " <<j<<"\n";  getchar();
1574   /*            
1575     ////// old propagation to the end of TPC //////////////       
1576     Double_t xk=76.;
1577     track->PropagateTo(xk);
1578     xk-=0.11;
1579     track->PropagateTo(xk,42.7,2.27); //C
1580     xk-=2.6;
1581     track->PropagateTo(xk,36.2,1.98e-3); //C02
1582     xk-=0.051;
1583     track->PropagateTo(xk,42.7,2.27); //C 
1584     /////////////////////////////////////////////////// 
1585          */
1586                  
1587          ////// new propagation to the end of TPC //////////////
1588     Double_t xk=77.415;
1589     track->PropagateTo(xk, 28.94, 1.204e-3);     //Ne
1590          xk -=0.01;
1591     track->PropagateTo(xk, 44.77, 1.71);         //Tedlar
1592          xk -=0.04;
1593     track->PropagateTo(xk, 44.86, 1.45);         //Kevlar
1594          xk -=2.0;
1595     track->PropagateTo(xk, 41.28, 0.029);        //Nomex         
1596     xk-=16;
1597     track->PropagateTo(xk,36.2,1.98e-3); //C02
1598          xk -=0.01;
1599     track->PropagateTo(xk, 24.01, 2.7);  //Al    
1600          xk -=0.01;
1601     track->PropagateTo(xk, 44.77, 1.71);         //Tedlar
1602          xk -=0.04;
1603     track->PropagateTo(xk, 44.86, 1.45);         //Kevlar
1604          xk -=0.5;
1605     track->PropagateTo(xk, 41.28, 0.029);        //Nomex                                                 
1606                      
1607        ///////////////////////////////////////////////////////////////                   
1608   
1609    ///////////////////////////////////////////////////////////////
1610     AliITStrack trackITS(*track);
1611     AliITStrack result(*track);
1612     AliITStrack primarytrack(*track); 
1613     
1614 ///////////////////////////////////////////////////////////////////////////////////////////////
1615          TVector Vgeant(3);
1616          Vgeant=result.GetVertex(); 
1617                           
1618   // Definition of Dv and Zv for vertex constraint      
1619      Double_t sigmaDv=0.0050;  Double_t sigmaZv=0.010;  
1620     //Double_t sigmaDv=0.0015;  Double_t sigmaZv=0.0015;                                  
1621         Double_t uniform= gRandom->Uniform();
1622         Double_t signdv;
1623         if(uniform<=0.5) signdv=-1.;
1624            else
1625                  signdv=1.;
1626          
1627         Double_t Vr=TMath::Sqrt(Vgeant(0)*Vgeant(0)+ Vgeant(1)*Vgeant(1));
1628           Double_t Dv=gRandom->Gaus(signdv*Vr,(Float_t)sigmaDv); 
1629     Double_t Zv=gRandom->Gaus(Vgeant(2),(Float_t)sigmaZv);
1630                                 
1631   //cout<<" Dv e Zv = "<<Dv<<" "<<Zv<<"\n";                             
1632     trackITS.SetDv(Dv);  trackITS.SetZv(Zv);
1633     trackITS.SetsigmaDv(sigmaDv); trackITS.SetsigmaZv(sigmaZv); 
1634     result.SetDv(Dv);  result.SetZv(Zv);
1635     result.SetsigmaDv(sigmaDv); result.SetsigmaZv(sigmaZv);
1636     primarytrack.SetDv(Dv);  primarytrack.SetZv(Zv);
1637     primarytrack.SetsigmaDv(sigmaDv); primarytrack.SetsigmaZv(sigmaZv);                                                                 
1638
1639 /////////////////////////////////////////////////////////////////////////////////////////////////        
1640                 
1641     primarytrack.PrimaryTrack(rl);
1642     TVector  d2=primarytrack.Getd2();
1643     TVector  tgl2=primarytrack.Gettgl2();
1644     TVector  dtgl=primarytrack.Getdtgl();
1645     trackITS.Setd2(d2); trackITS.Settgl2(tgl2);  trackITS.Setdtgl(dtgl); 
1646     result.Setd2(d2); result.Settgl2(tgl2);  result.Setdtgl(dtgl);         
1647          /*                      
1648     trackITS.SetVertex(vertex); trackITS.SetErrorVertex(ervertex);
1649     result.SetVertex(vertex);   result.SetErrorVertex(ervertex);   
1650     */
1651                          
1652     Tracking(trackITS,&result,recPoints,vettid, flagvert,rl);  
1653              
1654     // cout<<" progressive track number = "<<j<<"\r";
1655    // cout<<j<<"\r";
1656     Int_t NumofCluster=result.GetNumClust();  
1657 //    cout<<" progressive track number = "<<j<<"\n";    // stampa
1658     Long_t labITS=result.GetLabel();
1659 //    cout << " ITS track label = " << labITS << "\n";  // stampa           
1660     int lab=track->GetLabel();              
1661 //    cout << " TPC track label = " << lab <<"\n";      // stampa
1662          
1663              
1664 //propagation to vertex
1665         
1666     Double_t rbeam=3.;
1667      
1668     result.Propagation(rbeam);
1669          
1670          Double_t C00,C10,C11,C20,C21,C22,C30,C31,C32,C33,C40,C41,C42,C43,C44;
1671          result.GetCElements(C00,C10,C11,C20,C21,C22,C30,C31,C32,C33,C40,C41,C42,C43,C44);
1672                  
1673     Double_t pt=TMath::Abs(result.GetPt());
1674     Double_t Dr=result.GetD();
1675     Double_t Z=result.GetZ();
1676     Double_t tgl=result.GetTgl();
1677     Double_t C=result.GetC();
1678     Double_t Cy=C/2.;
1679     Double_t Dz=Z-(tgl/Cy)*TMath::ASin(result.arga(rbeam));
1680          Dz-=Vgeant(2);
1681           
1682          // cout<<" Dr e dz alla fine = "<<Dr<<" "<<Dz<<"\n"; getchar();
1683     Double_t phi=result.Getphi();
1684     Double_t phivertex = phi - TMath::ASin(result.argA(rbeam));
1685     Double_t duepi=2.*TMath::Pi();       
1686     if(phivertex>duepi) phivertex-=duepi;
1687     if(phivertex<0.) phivertex+=duepi;
1688     Double_t Dtot=TMath::Sqrt(Dr*Dr+Dz*Dz);
1689          
1690 //////////////////////////////////////////////////////////////////////////////////////////      
1691   
1692     Int_t idmodule,idpoint;
1693          if(NumofCluster >=5)  {            // cinque - sei
1694          //if(NumofCluster ==6)  {            // cinque - sei 
1695
1696
1697       AliITSiotrack outtrack;
1698
1699       iotrack=&outtrack;
1700
1701       iotrack->SetStatePhi(phi);
1702       iotrack->SetStateZ(Z);
1703       iotrack->SetStateD(Dr);
1704       iotrack->SetStateTgl(tgl);
1705       iotrack->SetStateC(C);
1706                 Double_t radius=result.Getrtrack();
1707                 iotrack->SetRadius(radius);
1708                 Int_t charge;
1709                 if(C>0.) charge=-1;  else charge=1;
1710                 iotrack->SetCharge(charge);
1711                 
1712
1713
1714       iotrack->SetCovMatrix(C00,C10,C11,C20,C21,C22,C30,C31,C32,C33,C40,C41,C42,C43,C44);  
1715
1716       Double_t px=pt*TMath::Cos(phivertex);
1717       Double_t py=pt*TMath::Sin(phivertex);
1718       Double_t pz=pt*tgl;
1719                 
1720       Double_t xtrack=Dr*TMath::Sin(phivertex);
1721       Double_t ytrack=Dr*TMath::Cos(phivertex);
1722       Double_t ztrack=Dz+Vgeant(2);
1723
1724
1725       iotrack->SetPx(px);
1726       iotrack->SetPy(py);
1727       iotrack->SetPz(pz);
1728       iotrack->SetX(xtrack);
1729       iotrack->SetY(ytrack);
1730       iotrack->SetZ(ztrack);
1731       iotrack->SetLabel(labITS);
1732                 
1733       Int_t il;         
1734                 for(il=0;il<6; il++){
1735                   iotrack->SetIdPoint(il,result.GetIdPoint(il));
1736                   iotrack->SetIdModule(il,result.GetIdModule(il));              
1737                 }
1738       tracktree1.Fill();
1739
1740    //cout<<" labITS = "<<labITS<<"\n";
1741         //cout<<" phi z Dr tgl C = "<<phi<<" "<<Z<<" "<<Dr<<" "<<tgl<<" "<<C<<"\n";  getchar();    
1742
1743      DataOut(kkk) = ptg; kkk++; DataOut(kkk)=labITS; kkk++; DataOut(kkk)=lab; kkk++;            
1744
1745       for (il=0;il<6;il++) {
1746         idpoint=result.GetIdPoint(il);
1747         idmodule=result.GetIdModule(il);
1748         *(vettid[idmodule]+idpoint)=1; 
1749         iotrack->SetIdPoint(il,idpoint);
1750         iotrack->SetIdModule(il,idmodule);
1751       }
1752       
1753     //  cout<<"  +++++++++++++  pt e ptg = "<<pt<<" "<<ptg<<"  ++++++++++\n";
1754       Double_t difpt= (pt-ptg)/ptg*100.;                                        
1755       DataOut(kkk)=difpt; kkk++;                                             
1756       Double_t lambdag=TMath::ATan(pzg/ptg);
1757       Double_t   lam=TMath::ATan(tgl);      
1758       Double_t diflam = (lam - lambdag)*1000.;
1759       DataOut(kkk) = diflam; kkk++;                                         
1760       Double_t phig=TMath::ATan2(pyg,pxg);  if(phig<0) phig=2.*TMath::Pi()+phig;       
1761       Double_t phi=phivertex;
1762         
1763       Double_t difphi = (phi - phig)*1000.;
1764       DataOut(kkk)=difphi; kkk++;
1765       DataOut(kkk)=Dtot*1.e4; kkk++;
1766       DataOut(kkk)=Dr*1.e4; kkk++;
1767       DataOut(kkk)=Dz*1.e4; kkk++; 
1768       Int_t r;
1769       for (r=0; r<9; r++) { out<<DataOut(r)<<" ";}
1770       out<<"\n";
1771       kkk=0;  
1772                 
1773             
1774     } // end if on NumofCluster
1775   //gObjectTable->Print();    // stampa memoria     
1776   }  //  end for (int j=min_t; j<=max_t; j++)
1777   
1778   out.close();  
1779   //outprova.close();   
1780  
1781   static Bool_t first=kTRUE;
1782   static TFile *tfile;
1783
1784         if(first) {
1785             tfile=new TFile("itstracks.root","RECREATE");
1786             //cout<<"I have opened itstracks.root file "<<endl;
1787         }           
1788         first=kFALSE;
1789         tfile->cd();
1790         tfile->ls();
1791
1792    char hname[30];
1793    sprintf(hname,"TreeT%d",evNumber);
1794
1795   tracktree1.Write(hname);
1796
1797
1798   
1799             TTree *fAli=gAlice->TreeK();
1800             TFile *fileAli=0;
1801             
1802             if (fAli) fileAli =fAli->GetCurrentFile();
1803             fileAli->cd();
1804      
1805   ////////////////////////////////////////////////////////////////////////////////////////////////
1806
1807   printf("delete vectors\n");
1808   if(np) delete [] np;
1809   if(vettid) delete [] vettid;
1810   
1811 }
1812