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