]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/AliTPC.cxx
TTree names are explicitly set via SetName(name) and then Write() is called
[u/mrichter/AliRoot.git] / TPC / AliTPC.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.43  2001/07/28 12:02:54  hristov
19 Branch split level set to 99
20
21 Revision 1.42  2001/07/28 11:38:52  hristov
22 Loop variable declared once
23
24 Revision 1.41  2001/07/28 10:53:50  hristov
25 Digitisation done according to the general scheme (M.Ivanov)
26
27 Revision 1.40  2001/07/27 13:03:14  hristov
28 Default Branch split level set to 99
29
30 Revision 1.39  2001/07/26 09:09:34  kowal2
31 Hits2Reco method added
32
33 Revision 1.38  2001/07/20 14:32:43  kowal2
34 Processing of many events possible now
35
36 Revision 1.37  2001/06/12 07:17:18  kowal2
37 Hits2SDigits method implemented (summable digits)
38
39 Revision 1.36  2001/05/16 14:57:25  alibrary
40 New files for folders and Stack
41
42 Revision 1.35  2001/05/08 16:02:22  kowal2
43 Updated material specifications
44
45 Revision 1.34  2001/05/08 15:00:15  hristov
46 Corrections for tracking in arbitrary magnenetic field. Changes towards a concept of global Alice track. Back propagation of reconstructed tracks (Yu.Belikov)
47
48 Revision 1.33  2001/04/03 12:40:43  kowal2
49 Removed printouts
50
51 Revision 1.32  2001/03/12 17:47:36  hristov
52 Changes needed on Sun with CC 5.0
53
54 Revision 1.31  2001/03/12 08:21:50  kowal2
55 Corrected C++ bug in the material definitions
56
57 Revision 1.30  2001/03/01 17:34:47  kowal2
58 Correction due to the accuracy problem
59
60 Revision 1.29  2001/02/28 16:34:40  kowal2
61 Protection against nonphysical values of the avalanche size,
62 10**6 is the maximum
63
64 Revision 1.28  2001/01/26 19:57:19  hristov
65 Major upgrade of AliRoot code
66
67 Revision 1.27  2001/01/13 17:29:33  kowal2
68 Sun compiler correction
69
70 Revision 1.26  2001/01/10 07:59:43  kowal2
71 Corrections to load points from the noncompressed hits.
72
73 Revision 1.25  2000/11/02 07:25:31  kowal2
74 Changes due to the new hit structure.
75 Memory leak removed.
76
77 Revision 1.24  2000/10/05 16:06:09  kowal2
78 Forward declarations. Changes due to a new class AliComplexCluster.
79
80 Revision 1.23  2000/10/02 21:28:18  fca
81 Removal of useless dependecies via forward declarations
82
83 Revision 1.22  2000/07/10 20:57:39  hristov
84 Update of TPC code and macros by M.Kowalski
85
86 Revision 1.19.2.4  2000/06/26 07:39:42  kowal2
87 Changes to obey the coding rules
88
89 Revision 1.19.2.3  2000/06/25 08:38:41  kowal2
90 Splitted from AliTPCtracking
91
92 Revision 1.19.2.2  2000/06/16 12:59:28  kowal2
93 Changed parameter settings
94
95 Revision 1.19.2.1  2000/06/09 07:15:07  kowal2
96
97 Defaults loaded automatically (hard-wired)
98 Optional parameters can be set via macro called in the constructor
99
100 Revision 1.19  2000/04/18 19:00:59  fca
101 Small bug fixes to TPC files
102
103 Revision 1.18  2000/04/17 09:37:33  kowal2
104 removed obsolete AliTPCDigitsDisplay.C
105
106 Revision 1.17.2.2  2000/04/10 08:15:12  kowal2
107
108 New, experimental data structure from M. Ivanov
109 New tracking algorithm
110 Different pad geometry for different sectors
111 Digitization rewritten
112
113 Revision 1.17.2.1  2000/04/10 07:56:53  kowal2
114 Not used anymore - removed
115
116 Revision 1.17  2000/01/19 17:17:30  fca
117 Introducing a list of lists of hits -- more hits allowed for detector now
118
119 Revision 1.16  1999/11/05 09:29:23  fca
120 Accept only signals > 0
121
122 Revision 1.15  1999/10/08 06:26:53  fca
123 Removed ClustersIndex - not used anymore
124
125 Revision 1.14  1999/09/29 09:24:33  fca
126 Introduction of the Copyright and cvs Log
127
128 */
129
130 ///////////////////////////////////////////////////////////////////////////////
131 //                                                                           //
132 //  Time Projection Chamber                                                  //
133 //  This class contains the basic functions for the Time Projection Chamber  //
134 //  detector. Functions specific to one particular geometry are              //
135 //  contained in the derived classes                                         //
136 //                                                                           //
137 //Begin_Html
138 /*
139 <img src="picts/AliTPCClass.gif">
140 */
141 //End_Html
142 //                                                                           //
143 //                                                                          //
144 ///////////////////////////////////////////////////////////////////////////////
145
146 //
147
148 #include <TMath.h>
149 #include <TRandom.h>
150 #include <TVector.h>
151 #include <TMatrix.h>
152 #include <TGeometry.h>
153 #include <TNode.h>
154 #include <TTUBS.h>
155 #include <TObjectTable.h>
156 #include "TParticle.h"
157 #include "AliTPC.h"
158 #include <TFile.h>  
159 #include <TROOT.h>
160 #include <TSystem.h>     
161 #include "AliRun.h"
162 #include <iostream.h>
163 #include <stdlib.h>
164 #include <fstream.h>
165 #include "AliMC.h"
166 #include "AliMagF.h"
167
168
169 #include "AliTPCParamSR.h"
170 #include "AliTPCPRF2D.h"
171 #include "AliTPCRF1D.h"
172 #include "AliDigits.h"
173 #include "AliSimDigits.h"
174 #include "AliTPCTrackHits.h"
175 #include "AliPoints.h"
176 #include "AliArrayBranch.h"
177
178
179 #include "AliTPCDigitsArray.h"
180 #include "AliComplexCluster.h"
181 #include "AliClusters.h"
182 #include "AliTPCClustersRow.h"
183 #include "AliTPCClustersArray.h"
184
185 #include "AliTPCcluster.h"
186 #include "AliTPCclusterer.h"
187 #include "AliTPCtracker.h"
188
189 #include <TInterpreter.h>
190 #include <TTree.h>
191
192
193
194 ClassImp(AliTPC) 
195
196 //_____________________________________________________________________________
197 AliTPC::AliTPC()
198 {
199   //
200   // Default constructor
201   //
202   fIshunt   = 0;
203   fHits     = 0;
204   fDigits   = 0;
205   fNsectors = 0;
206   //MI changes
207   fDigitsArray = 0;
208   fClustersArray = 0;
209   fDefaults = 0;
210   fTrackHits = 0;  
211   fHitType = 2;  
212   fTPCParam = 0; 
213 }
214  
215 //_____________________________________________________________________________
216 AliTPC::AliTPC(const char *name, const char *title)
217       : AliDetector(name,title)
218 {
219   //
220   // Standard constructor
221   //
222
223   //
224   // Initialise arrays of hits and digits 
225   fHits     = new TClonesArray("AliTPChit",  176);
226   gAlice->AddHitList(fHits);
227   //MI change  
228   fDigitsArray = 0;
229   fClustersArray= 0;
230   fDefaults = 0;
231   //
232   fTrackHits = new AliTPCTrackHits;  //MI - 13.09.2000
233   fTrackHits->SetHitPrecision(0.002);
234   fTrackHits->SetStepPrecision(0.003);  
235   fTrackHits->SetMaxDistance(100); 
236
237   fHitType = 2;
238   //
239   // Initialise counters
240   fNsectors = 0;
241
242   //
243   fIshunt     =  0;
244   //
245   // Initialise color attributes
246   SetMarkerColor(kYellow);
247
248   //
249   //  Set TPC parameters
250   //
251
252
253   if (!strcmp(title,"Default")) {       
254     fTPCParam = new AliTPCParamSR;
255   } else {
256     cerr<<"AliTPC warning: in Config.C you must set non-default parameters\n";
257     fTPCParam=0;
258   }
259
260 }
261
262 //_____________________________________________________________________________
263 AliTPC::~AliTPC()
264 {
265   //
266   // TPC destructor
267   //
268
269   fIshunt   = 0;
270   delete fHits;
271   delete fDigits;
272   delete fTPCParam;
273   delete fTrackHits; //MI 15.09.2000
274 }
275
276 //_____________________________________________________________________________
277 void AliTPC::AddHit(Int_t track, Int_t *vol, Float_t *hits)
278 {
279   //
280   // Add a hit to the list
281   //
282   //  TClonesArray &lhits = *fHits;
283   //  new(lhits[fNhits++]) AliTPChit(fIshunt,track,vol,hits);
284   if (fHitType&1){
285     TClonesArray &lhits = *fHits;
286     new(lhits[fNhits++]) AliTPChit(fIshunt,track,vol,hits);
287   }
288   if (fHitType&2)
289    AddHit2(track,vol,hits);
290 }
291  
292 //_____________________________________________________________________________
293 void AliTPC::BuildGeometry()
294 {
295
296   //
297   // Build TPC ROOT TNode geometry for the event display
298   //
299   TNode *nNode, *nTop;
300   TTUBS *tubs;
301   Int_t i;
302   const int kColorTPC=19;
303   char name[5], title[25];
304   const Double_t kDegrad=TMath::Pi()/180;
305   const Double_t kRaddeg=180./TMath::Pi();
306
307
308   Float_t innerOpenAngle = fTPCParam->GetInnerAngle();
309   Float_t outerOpenAngle = fTPCParam->GetOuterAngle();
310
311   Float_t innerAngleShift = fTPCParam->GetInnerAngleShift();
312   Float_t outerAngleShift = fTPCParam->GetOuterAngleShift();
313
314   Int_t nLo = fTPCParam->GetNInnerSector()/2;
315   Int_t nHi = fTPCParam->GetNOuterSector()/2;  
316
317   const Double_t kloAng = (Double_t)TMath::Nint(innerOpenAngle*kRaddeg);
318   const Double_t khiAng = (Double_t)TMath::Nint(outerOpenAngle*kRaddeg);
319   const Double_t kloAngSh = (Double_t)TMath::Nint(innerAngleShift*kRaddeg);
320   const Double_t khiAngSh = (Double_t)TMath::Nint(outerAngleShift*kRaddeg);  
321
322
323   const Double_t kloCorr = 1/TMath::Cos(0.5*kloAng*kDegrad);
324   const Double_t khiCorr = 1/TMath::Cos(0.5*khiAng*kDegrad);
325
326   Double_t rl,ru;
327   
328
329   //
330   // Get ALICE top node
331   //
332
333   nTop=gAlice->GetGeometry()->GetNode("alice");
334
335   //  inner sectors
336
337   rl = fTPCParam->GetInnerRadiusLow();
338   ru = fTPCParam->GetInnerRadiusUp();
339  
340
341   for(i=0;i<nLo;i++) {
342     sprintf(name,"LS%2.2d",i);
343     name[4]='\0';
344     sprintf(title,"TPC low sector %3d",i);
345     title[24]='\0';
346     
347     tubs = new TTUBS(name,title,"void",rl*kloCorr,ru*kloCorr,250.,
348                      kloAng*(i-0.5)+kloAngSh,kloAng*(i+0.5)+kloAngSh);
349     tubs->SetNumberOfDivisions(1);
350     nTop->cd();
351     nNode = new TNode(name,title,name,0,0,0,"");
352     nNode->SetLineColor(kColorTPC);
353     fNodes->Add(nNode);
354   }
355
356   // Outer sectors
357
358   rl = fTPCParam->GetOuterRadiusLow();
359   ru = fTPCParam->GetOuterRadiusUp();
360
361   for(i=0;i<nHi;i++) {
362     sprintf(name,"US%2.2d",i);
363     name[4]='\0';
364     sprintf(title,"TPC upper sector %d",i);
365     title[24]='\0';
366     tubs = new TTUBS(name,title,"void",rl*khiCorr,ru*khiCorr,250,
367                      khiAng*(i-0.5)+khiAngSh,khiAng*(i+0.5)+khiAngSh);
368     tubs->SetNumberOfDivisions(1);
369     nTop->cd();
370     nNode = new TNode(name,title,name,0,0,0,"");
371     nNode->SetLineColor(kColorTPC);
372     fNodes->Add(nNode);
373   }
374
375 }    
376
377 //_____________________________________________________________________________
378 Int_t AliTPC::DistancetoPrimitive(Int_t , Int_t )
379 {
380   //
381   // Calculate distance from TPC to mouse on the display
382   // Dummy procedure
383   //
384   return 9999;
385 }
386
387 void AliTPC::Clusters2Tracks(TFile *of) {
388   //-----------------------------------------------------------------
389   // This is a track finder.
390   //-----------------------------------------------------------------
391   AliTPCtracker tracker(fTPCParam);
392   tracker.Clusters2Tracks(gFile,of);
393 }
394
395 //_____________________________________________________________________________
396 void AliTPC::CreateMaterials()
397 {
398   //-----------------------------------------------
399   // Create Materials for for TPC simulations
400   //-----------------------------------------------
401
402   //-----------------------------------------------------------------
403   // Origin: Marek Kowalski  IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
404   //-----------------------------------------------------------------
405
406   Int_t iSXFLD=gAlice->Field()->Integ();
407   Float_t sXMGMX=gAlice->Field()->Max();
408
409   Float_t amat[5]; // atomic numbers
410   Float_t zmat[5]; // z
411   Float_t wmat[5]; // proportions
412
413   Float_t density;
414   Float_t apure[2];
415
416
417   //***************** Gases *************************
418   
419   //-------------------------------------------------
420   // pure gases
421   //-------------------------------------------------
422
423   // Neon
424
425
426   amat[0]= 20.18;
427   zmat[0]= 10.;  
428   density = 0.0009;
429  
430   apure[0]=amat[0];
431
432   AliMaterial(20,"Ne",amat[0],zmat[0],density,999.,999.);
433
434   // Argon
435
436   amat[0]= 39.948;
437   zmat[0]= 18.;  
438   density = 0.001782;  
439
440   apure[1]=amat[0];
441
442   AliMaterial(21,"Ar",amat[0],zmat[0],density,999.,999.);
443  
444
445   //--------------------------------------------------------------
446   // gases - compounds
447   //--------------------------------------------------------------
448
449   Float_t amol[3];
450
451   // CO2
452
453   amat[0]=12.011;
454   amat[1]=15.9994;
455
456   zmat[0]=6.;
457   zmat[1]=8.;
458
459   wmat[0]=1.;
460   wmat[1]=2.;
461
462   density=0.001977;
463
464   amol[0] = amat[0]*wmat[0]+amat[1]*wmat[1];
465
466   AliMixture(10,"CO2",amat,zmat,density,-2,wmat);
467   
468   // CF4
469
470   amat[0]=12.011;
471   amat[1]=18.998;
472
473   zmat[0]=6.;
474   zmat[1]=9.;
475  
476   wmat[0]=1.;
477   wmat[1]=4.;
478  
479   density=0.003034;
480
481   amol[1] = amat[0]*wmat[0]+amat[1]*wmat[1];
482
483   AliMixture(11,"CF4",amat,zmat,density,-2,wmat); 
484
485
486   // CH4
487
488   amat[0]=12.011;
489   amat[1]=1.;
490
491   zmat[0]=6.;
492   zmat[1]=1.;
493
494   wmat[0]=1.;
495   wmat[1]=4.;
496
497   density=0.000717;
498
499   amol[2] = amat[0]*wmat[0]+amat[1]*wmat[1];
500
501   AliMixture(12,"CH4",amat,zmat,density,-2,wmat);
502
503   //----------------------------------------------------------------
504   // gases - mixtures, ID >= 20 pure gases, <= 10 ID < 20 -compounds
505   //----------------------------------------------------------------
506
507   char namate[21]; 
508   density = 0.;
509   Float_t am=0;
510   Int_t nc;
511   Float_t rho,absl,X0,buf[1];
512   Int_t nbuf;
513   Float_t a,z;
514
515   for(nc = 0;nc<fNoComp;nc++)
516     {
517     
518       // retrive material constants
519       
520       gMC->Gfmate((*fIdmate)[fMixtComp[nc]],namate,a,z,rho,X0,absl,buf,nbuf);
521
522       amat[nc] = a;
523       zmat[nc] = z;
524
525       Int_t nnc = (fMixtComp[nc]>=20) ? fMixtComp[nc]%20 : fMixtComp[nc]%10;
526  
527       am += fMixtProp[nc]*((fMixtComp[nc]>=20) ? apure[nnc] : amol[nnc]); 
528       density += fMixtProp[nc]*rho;  // density of the mixture
529       
530     }
531
532   // mixture proportions by weight!
533
534   for(nc = 0;nc<fNoComp;nc++)
535     {
536
537       Int_t nnc = (fMixtComp[nc]>=20) ? fMixtComp[nc]%20 : fMixtComp[nc]%10;
538
539       wmat[nc] = fMixtProp[nc]*((fMixtComp[nc]>=20) ? 
540                  apure[nnc] : amol[nnc])/am;
541
542     } 
543
544   // Drift gases 1 - nonsensitive, 2 - sensitive
545
546   AliMixture(31,"Drift gas 1",amat,zmat,density,fNoComp,wmat);
547   AliMixture(32,"Drift gas 2",amat,zmat,density,fNoComp,wmat);
548
549
550   // Air
551
552   amat[0] = 14.61;
553   zmat[0] = 7.3;
554   density = 0.001205;
555
556   AliMaterial(24,"Air",amat[0],zmat[0],density,999.,999.); 
557
558
559   //----------------------------------------------------------------------
560   //               solid materials
561   //----------------------------------------------------------------------
562
563
564   // Kevlar C14H22O2N2
565
566   amat[0] = 12.011;
567   amat[1] = 1.;
568   amat[2] = 15.999;
569   amat[3] = 14.006;
570
571   zmat[0] = 6.;
572   zmat[1] = 1.;
573   zmat[2] = 8.;
574   zmat[3] = 7.;
575
576   wmat[0] = 14.;
577   wmat[1] = 22.;
578   wmat[2] = 2.;
579   wmat[3] = 2.;
580
581   density = 1.45;
582
583   AliMixture(34,"Kevlar",amat,zmat,density,-4,wmat);  
584
585   // NOMEX
586
587   amat[0] = 12.011;
588   amat[1] = 1.;
589   amat[2] = 15.999;
590   amat[3] = 14.006;
591
592   zmat[0] = 6.;
593   zmat[1] = 1.;
594   zmat[2] = 8.;
595   zmat[3] = 7.;
596
597   wmat[0] = 14.;
598   wmat[1] = 22.;
599   wmat[2] = 2.;
600   wmat[3] = 2.;
601
602   density = 0.03;
603
604   
605   AliMixture(35,"NOMEX",amat,zmat,density,-4,wmat);
606
607   // Makrolon C16H18O3
608
609   amat[0] = 12.011;
610   amat[1] = 1.;
611   amat[2] = 15.999;
612
613   zmat[0] = 6.;
614   zmat[1] = 1.;
615   zmat[2] = 8.;
616
617   wmat[0] = 16.;
618   wmat[1] = 18.;
619   wmat[2] = 3.;
620   
621   density = 1.2;
622
623   AliMixture(36,"Makrolon",amat,zmat,density,-3,wmat);
624   
625   // Mylar C5H4O2
626
627   amat[0]=12.011;
628   amat[1]=1.;
629   amat[2]=15.9994;
630
631   zmat[0]=6.;
632   zmat[1]=1.;
633   zmat[2]=8.;
634
635   wmat[0]=5.;
636   wmat[1]=4.;
637   wmat[2]=2.; 
638
639   density = 1.39;
640   
641   AliMixture(37, "Mylar",amat,zmat,density,-3,wmat); 
642
643   // SiO2 - used later for the glass fiber
644
645   amat[0]=28.086;
646   amat[1]=15.9994;
647
648   zmat[0]=14.;
649   zmat[1]=8.;
650
651   wmat[0]=1.;
652   wmat[1]=2.;
653
654
655   AliMixture(38,"SiO2",amat,zmat,2.2,-2,wmat); //SiO2 - quartz (rho=2.2)
656
657   // Al
658
659   amat[0] = 26.98;
660   zmat[0] = 13.;
661
662   density = 2.7;
663
664   AliMaterial(40,"Al",amat[0],zmat[0],density,999.,999.);
665
666   // Si
667
668   amat[0] = 28.086;
669   zmat[0] = 14.;
670
671   density = 2.33;
672
673   AliMaterial(41,"Si",amat[0],zmat[0],density,999.,999.);
674
675   // Cu
676
677   amat[0] = 63.546;
678   zmat[0] = 29.;
679
680   density = 8.96;
681
682   AliMaterial(42,"Cu",amat[0],zmat[0],density,999.,999.);
683
684   // Tedlar C2H3F
685
686   amat[0] = 12.011;
687   amat[1] = 1.;
688   amat[2] = 18.998;
689
690   zmat[0] = 6.;
691   zmat[1] = 1.;
692   zmat[2] = 9.;
693
694   wmat[0] = 2.;
695   wmat[1] = 3.; 
696   wmat[2] = 1.;
697
698   density = 1.71;
699
700   AliMixture(43, "Tedlar",amat,zmat,density,-3,wmat);  
701
702
703   // Plexiglas  C5H8O2
704
705   amat[0]=12.011;
706   amat[1]=1.;
707   amat[2]=15.9994;
708
709   zmat[0]=6.;
710   zmat[1]=1.;
711   zmat[2]=8.;
712
713   wmat[0]=5.;
714   wmat[1]=8.;
715   wmat[2]=2.;
716
717   density=1.18;
718
719   AliMixture(44,"Plexiglas",amat,zmat,density,-3,wmat);
720
721   // Epoxy - C14 H20 O3
722
723   
724   amat[0]=12.011;
725   amat[1]=1.;
726   amat[2]=15.9994;
727
728   zmat[0]=6.;
729   zmat[1]=1.;
730   zmat[2]=8.;
731
732   wmat[0]=14.;
733   wmat[1]=20.;
734   wmat[2]=3.;
735
736   density=1.25;
737
738   AliMixture(45,"Epoxy",amat,zmat,density,-3,wmat);
739
740   // Carbon
741
742   amat[0]=12.011;
743   zmat[0]=6.;
744   density= 2.265;
745
746   AliMaterial(46,"C",amat[0],zmat[0],density,999.,999.);
747
748   // get epoxy
749
750   gMC->Gfmate((*fIdmate)[45],namate,amat[1],zmat[1],rho,X0,absl,buf,nbuf);
751
752   // Carbon fiber
753
754   wmat[0]=0.644; // by weight!
755   wmat[1]=0.356;
756
757   density=0.5*(1.25+2.265);
758
759   AliMixture(47,"Cfiber",amat,zmat,density,2,wmat);
760
761   // get SiO2
762
763   gMC->Gfmate((*fIdmate)[38],namate,amat[0],zmat[0],rho,X0,absl,buf,nbuf); 
764
765   wmat[0]=0.725; // by weight!
766   wmat[1]=0.275;
767
768   density=1.7;
769
770   AliMixture(39,"G10",amat,zmat,density,2,wmat);
771
772  
773
774
775   //----------------------------------------------------------
776   // tracking media for gases
777   //----------------------------------------------------------
778
779   AliMedium(0, "Air", 24, 0, iSXFLD, sXMGMX, 10., 999., .1, .01, .1);
780   AliMedium(1, "Drift gas 1", 31, 0, iSXFLD, sXMGMX, 10., 999.,.1,.001, .001);
781   AliMedium(2, "Drift gas 2", 32, 1, iSXFLD, sXMGMX, 10., 999.,.1,.001, .001);
782   AliMedium(3,"CO2",10,0, iSXFLD, sXMGMX, 10., 999.,.1, .001, .001); 
783
784   //-----------------------------------------------------------  
785   // tracking media for solids
786   //-----------------------------------------------------------
787   
788   AliMedium(4,"Al",40,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
789   AliMedium(5,"Kevlar",34,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
790   AliMedium(6,"Nomex",35,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
791   AliMedium(7,"Makrolon",36,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
792   AliMedium(8,"Mylar",37,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
793   AliMedium(9,"Tedlar",43,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
794   AliMedium(10,"Cu",42,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
795   AliMedium(11,"Si",41,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
796   AliMedium(12,"G10",39,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
797   AliMedium(13,"Plexiglas",44,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
798   AliMedium(14,"Epoxy",45,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
799   AliMedium(15,"Cfiber",47,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
800     
801 }
802
803
804 void AliTPC::Digits2Clusters(TFile *of, Int_t eventnumber)
805 {
806   //-----------------------------------------------------------------
807   // This is a simple cluster finder.
808   //-----------------------------------------------------------------
809   AliTPCclusterer::Digits2Clusters(fTPCParam,of,eventnumber);
810 }
811
812 extern Double_t SigmaY2(Double_t, Double_t, Double_t);
813 extern Double_t SigmaZ2(Double_t, Double_t);
814 //_____________________________________________________________________________
815 void AliTPC::Hits2Clusters(TFile *of, Int_t eventn)
816 {
817   //--------------------------------------------------------
818   // TPC simple cluster generator from hits
819   // obtained from the TPC Fast Simulator
820   // The point errors are taken from the parametrization
821   //--------------------------------------------------------
822
823   //-----------------------------------------------------------------
824   // Origin: Marek Kowalski  IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
825   //-----------------------------------------------------------------
826   // Adopted to Marian's cluster data structure by I.Belikov, CERN,
827   // Jouri.Belikov@cern.ch
828   //----------------------------------------------------------------
829   
830   /////////////////////////////////////////////////////////////////////////////
831   //
832   //---------------------------------------------------------------------
833   //   ALICE TPC Cluster Parameters
834   //--------------------------------------------------------------------
835        
836   
837
838   // Cluster width in rphi
839   const Float_t kACrphi=0.18322;
840   const Float_t kBCrphi=0.59551e-3;
841   const Float_t kCCrphi=0.60952e-1;
842   // Cluster width in z
843   const Float_t kACz=0.19081;
844   const Float_t kBCz=0.55938e-3;
845   const Float_t kCCz=0.30428;
846
847   TDirectory *savedir=gDirectory; 
848
849   if (!of->IsOpen()) {
850      cerr<<"AliTPC::Hits2Clusters(): output file not open !\n";
851      return;
852   }
853
854   //if(fDefaults == 0) SetDefaults();
855
856   Float_t sigmaRphi,sigmaZ,clRphi,clZ;
857   //
858   TParticle *particle; // pointer to a given particle
859   AliTPChit *tpcHit; // pointer to a sigle TPC hit
860   Int_t sector;
861   Int_t ipart;
862   Float_t xyz[5];
863   Float_t pl,pt,tanth,rpad,ratio;
864   Float_t cph,sph;
865   
866   //---------------------------------------------------------------
867   //  Get the access to the tracks 
868   //---------------------------------------------------------------
869   
870   TTree *tH = gAlice->TreeH();
871   Stat_t ntracks = tH->GetEntries();
872
873   //Switch to the output file
874   of->cd();
875
876   char   cname[100];
877
878   sprintf(cname,"TreeC_TPC_%d",eventn);
879
880   fTPCParam->Write(fTPCParam->GetTitle());
881   AliTPCClustersArray carray;
882   carray.Setup(fTPCParam);
883   carray.SetClusterType("AliTPCcluster");
884   carray.MakeTree();
885
886   Int_t nclusters=0; //cluster counter
887   
888   //------------------------------------------------------------
889   // Loop over all sectors (72 sectors for 20 deg
890   // segmentation for both lower and upper sectors)
891   // Sectors 0-35 are lower sectors, 0-17 z>0, 17-35 z<0
892   // Sectors 36-71 are upper sectors, 36-53 z>0, 54-71 z<0
893   //
894   // First cluster for sector 0 starts at "0"
895   //------------------------------------------------------------
896    
897   for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++){
898     //MI change
899     fTPCParam->AdjustCosSin(isec,cph,sph);
900     
901     //------------------------------------------------------------
902     // Loop over tracks
903     //------------------------------------------------------------
904     
905     for(Int_t track=0;track<ntracks;track++){
906       ResetHits();
907       tH->GetEvent(track);
908       //
909       //  Get number of the TPC hits
910       //
911       // nhits=fHits->GetEntriesFast();
912       //
913      
914        tpcHit = (AliTPChit*)FirstHit(-1);
915
916       // Loop over hits
917       //
918        //   for(Int_t hit=0;hit<nhits;hit++){
919        //tpcHit=(AliTPChit*)fHits->UncheckedAt(hit);
920
921        while(tpcHit){
922  
923          if (tpcHit->fQ == 0.) {
924            tpcHit = (AliTPChit*) NextHit();
925            continue; //information about track (I.Belikov)
926          }
927         sector=tpcHit->fSector; // sector number
928
929
930         //      if(sector != isec) continue; //terminate iteration
931
932        if(sector != isec){
933          tpcHit = (AliTPChit*) NextHit();
934          continue; 
935        }
936         ipart=tpcHit->Track();
937         particle=gAlice->Particle(ipart);
938         pl=particle->Pz();
939         pt=particle->Pt();
940         if(pt < 1.e-9) pt=1.e-9;
941         tanth=pl/pt;
942         tanth = TMath::Abs(tanth);
943         rpad=TMath::Sqrt(tpcHit->X()*tpcHit->X() + tpcHit->Y()*tpcHit->Y());
944         ratio=0.001*rpad/pt; // pt must be in MeV/c - historical reason
945
946         //   space-point resolutions
947         
948         sigmaRphi=SigmaY2(rpad,tanth,pt);
949         sigmaZ   =SigmaZ2(rpad,tanth   );
950         
951         //   cluster widths
952         
953         clRphi=kACrphi-kBCrphi*rpad*tanth+kCCrphi*ratio*ratio;
954         clZ=kACz-kBCz*rpad*tanth+kCCz*tanth*tanth;
955         
956         // temporary protection
957         
958         if(sigmaRphi < 0.) sigmaRphi=0.4e-3;
959         if(sigmaZ < 0.) sigmaZ=0.4e-3;
960         if(clRphi < 0.) clRphi=2.5e-3;
961         if(clZ < 0.) clZ=2.5e-5;
962         
963         //
964         
965         //
966         // smearing --> rotate to the 1 (13) or to the 25 (49) sector,
967         // then the inaccuracy in a X-Y plane is only along Y (pad row)!
968         //
969         Float_t xprim= tpcHit->X()*cph + tpcHit->Y()*sph;
970         Float_t yprim=-tpcHit->X()*sph + tpcHit->Y()*cph;
971         xyz[0]=gRandom->Gaus(yprim,TMath::Sqrt(sigmaRphi));   // y
972           Float_t alpha=(isec < fTPCParam->GetNInnerSector()) ?
973           fTPCParam->GetInnerAngle() : fTPCParam->GetOuterAngle();
974           Float_t ymax=xprim*TMath::Tan(0.5*alpha);
975           if (TMath::Abs(xyz[0])>ymax) xyz[0]=yprim; 
976         xyz[1]=gRandom->Gaus(tpcHit->Z(),TMath::Sqrt(sigmaZ)); // z
977           if (TMath::Abs(xyz[1])>fTPCParam->GetZLength()) xyz[1]=tpcHit->Z(); 
978         xyz[2]=sigmaRphi;                                     // fSigmaY2
979         xyz[3]=sigmaZ;                                        // fSigmaZ2
980         xyz[4]=tpcHit->fQ;                                    // q
981
982         AliTPCClustersRow *clrow=carray.GetRow(sector,tpcHit->fPadRow);
983         if (!clrow) clrow=carray.CreateRow(sector,tpcHit->fPadRow);     
984
985         Int_t tracks[3]={tpcHit->Track(), -1, -1};
986         AliTPCcluster cluster(tracks,xyz);
987
988         clrow->InsertCluster(&cluster); nclusters++;
989
990         tpcHit = (AliTPChit*)NextHit();
991         
992
993       } // end of loop over hits
994
995     }   // end of loop over tracks
996
997     Int_t nrows=fTPCParam->GetNRow(isec);
998     for (Int_t irow=0; irow<nrows; irow++) {
999         AliTPCClustersRow *clrow=carray.GetRow(isec,irow);
1000         if (!clrow) continue;
1001         carray.StoreRow(isec,irow);
1002         carray.ClearRow(isec,irow);
1003     }
1004
1005   } // end of loop over sectors  
1006
1007   cerr<<"Number of made clusters : "<<nclusters<<"                        \n";
1008
1009   carray.GetTree()->SetName(cname);
1010   carray.GetTree()->Write();
1011
1012   savedir->cd(); //switch back to the input file
1013   
1014 } // end of function
1015
1016 //_________________________________________________________________
1017 void AliTPC::Hits2ExactClustersSector(Int_t isec)
1018 {
1019   //--------------------------------------------------------
1020   //calculate exact cross point of track and given pad row
1021   //resulting values are expressed in "digit" coordinata
1022   //--------------------------------------------------------
1023
1024   //-----------------------------------------------------------------
1025   // Origin: Marian Ivanov  GSI Darmstadt, m.ivanov@gsi.de
1026   //-----------------------------------------------------------------
1027   //
1028   if (fClustersArray==0){    
1029     return;
1030   }
1031   //
1032   TParticle *particle; // pointer to a given particle
1033   AliTPChit *tpcHit; // pointer to a sigle TPC hit
1034   Int_t sector,nhits;
1035   Int_t ipart;
1036   const Int_t kcmaxhits=30000;
1037   TVector * xxxx = new TVector(kcmaxhits*4);
1038   TVector & xxx = *xxxx;
1039   Int_t maxhits = kcmaxhits;
1040   //construct array for each padrow
1041   for (Int_t i=0; i<fTPCParam->GetNRow(isec);i++) 
1042     fClustersArray->CreateRow(isec,i);
1043   
1044   //---------------------------------------------------------------
1045   //  Get the access to the tracks 
1046   //---------------------------------------------------------------
1047   
1048   TTree *tH = gAlice->TreeH();
1049   Stat_t ntracks = tH->GetEntries();
1050   Int_t npart = gAlice->GetNtrack();
1051     
1052   //------------------------------------------------------------
1053   // Loop over tracks
1054   //------------------------------------------------------------
1055   
1056   for(Int_t track=0;track<ntracks;track++){
1057     ResetHits();
1058     tH->GetEvent(track);
1059     //
1060     //  Get number of the TPC hits and a pointer
1061     //  to the particles
1062     //
1063     nhits=fHits->GetEntriesFast();
1064     //
1065     // Loop over hits
1066     //
1067     Int_t currentIndex=0;
1068     Int_t lastrow=-1;  //last writen row
1069     for(Int_t hit=0;hit<nhits;hit++){
1070       tpcHit=(AliTPChit*)fHits->UncheckedAt(hit);
1071       if (tpcHit==0) continue;
1072       sector=tpcHit->fSector; // sector number
1073       if(sector != isec) continue; 
1074       ipart=tpcHit->Track();
1075       if (ipart<npart) particle=gAlice->Particle(ipart);
1076       
1077       //find row number
1078
1079       Float_t  x[3]={tpcHit->X(),tpcHit->Y(),tpcHit->Z()};
1080       Int_t    index[3]={1,isec,0};
1081       Int_t    currentrow = fTPCParam->GetPadRow(x,index) ;     
1082       if (currentrow<0) continue;
1083       if (lastrow<0) lastrow=currentrow;
1084       if (currentrow==lastrow){
1085         if ( currentIndex>=maxhits){
1086           maxhits+=kcmaxhits;
1087           xxx.ResizeTo(4*maxhits);
1088         }     
1089         xxx(currentIndex*4)=x[0];
1090         xxx(currentIndex*4+1)=x[1];
1091         xxx(currentIndex*4+2)=x[2];     
1092         xxx(currentIndex*4+3)=tpcHit->fQ;
1093         currentIndex++; 
1094       }
1095       else 
1096         if (currentIndex>2){
1097           Float_t sumx=0;
1098           Float_t sumx2=0;
1099           Float_t sumx3=0;
1100           Float_t sumx4=0;
1101           Float_t sumy=0;
1102           Float_t sumxy=0;
1103           Float_t sumx2y=0;
1104           Float_t sumz=0;
1105           Float_t sumxz=0;
1106           Float_t sumx2z=0;
1107           Float_t sumq=0;
1108           for (Int_t index=0;index<currentIndex;index++){
1109             Float_t x,x2,x3,x4;
1110             x=x2=x3=x4=xxx(index*4);
1111             x2*=x;
1112             x3*=x2;
1113             x4*=x3;
1114             sumx+=x;
1115             sumx2+=x2;
1116             sumx3+=x3;
1117             sumx4+=x4;
1118             sumy+=xxx(index*4+1);
1119             sumxy+=xxx(index*4+1)*x;
1120             sumx2y+=xxx(index*4+1)*x2;
1121             sumz+=xxx(index*4+2);
1122             sumxz+=xxx(index*4+2)*x;
1123             sumx2z+=xxx(index*4+2)*x2;   
1124             sumq+=xxx(index*4+3);
1125           }
1126           Float_t centralPad = (fTPCParam->GetNPads(isec,lastrow)-1)/2;
1127           Float_t det=currentIndex*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumx*sumx4-sumx2*sumx3)+
1128             sumx2*(sumx*sumx3-sumx2*sumx2);
1129           
1130           Float_t detay=sumy*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumxy*sumx4-sumx2y*sumx3)+
1131             sumx2*(sumxy*sumx3-sumx2y*sumx2);
1132           Float_t detaz=sumz*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumxz*sumx4-sumx2z*sumx3)+
1133             sumx2*(sumxz*sumx3-sumx2z*sumx2);
1134           
1135           Float_t detby=currentIndex*(sumxy*sumx4-sumx2y*sumx3)-sumy*(sumx*sumx4-sumx2*sumx3)+
1136             sumx2*(sumx*sumx2y-sumx2*sumxy);
1137           Float_t detbz=currentIndex*(sumxz*sumx4-sumx2z*sumx3)-sumz*(sumx*sumx4-sumx2*sumx3)+
1138             sumx2*(sumx*sumx2z-sumx2*sumxz);
1139           
1140           Float_t y=detay/det+centralPad;
1141           Float_t z=detaz/det;  
1142           Float_t by=detby/det; //y angle
1143           Float_t bz=detbz/det; //z angle
1144           sumy/=Float_t(currentIndex);
1145           sumz/=Float_t(currentIndex);
1146           AliComplexCluster cl;
1147           cl.fX=z;
1148           cl.fY=y;
1149           cl.fQ=sumq;
1150           cl.fSigmaX2=bz;
1151           cl.fSigmaY2=by;
1152           cl.fTracks[0]=ipart;
1153           
1154           AliTPCClustersRow * row = (fClustersArray->GetRow(isec,lastrow));
1155           if (row!=0) row->InsertCluster(&cl);
1156           currentIndex=0;
1157           lastrow=currentrow;
1158         } //end of calculating cluster for given row
1159         
1160         
1161         
1162     } // end of loop over hits
1163   }   // end of loop over tracks 
1164   //write padrows to tree 
1165   for (Int_t ii=0; ii<fTPCParam->GetNRow(isec);ii++) {
1166     fClustersArray->StoreRow(isec,ii);    
1167     fClustersArray->ClearRow(isec,ii);        
1168   }
1169   xxxx->Delete();
1170  
1171 }
1172
1173
1174
1175 //__
1176 void AliTPC::SDigits2Digits2(Int_t eventnumber)  
1177 {
1178   //create digits from summable digits
1179
1180   char  sname[100];
1181   char  dname[100];
1182   sprintf(sname,"TreeS_%s_%d",fTPCParam->GetTitle(),eventnumber);
1183   sprintf(dname,"TreeD_%s_%d",fTPCParam->GetTitle(),eventnumber);
1184
1185   //conect tree with sSDigits
1186   TTree *t = (TTree *)gDirectory->Get(sname); 
1187   AliSimDigits digarr, *dummy=&digarr;
1188   t->GetBranch("Segment")->SetAddress(&dummy);
1189   Stat_t nentries = t->GetEntries();
1190
1191   //make tree with digits   
1192   AliTPCDigitsArray *arr = new AliTPCDigitsArray; 
1193   arr->SetClass("AliSimDigits");
1194   arr->Setup(fTPCParam);
1195   arr->MakeTree(fDigitsFile);
1196   
1197   AliTPCParam * par =fTPCParam;
1198   //Loop over segments of the TPC
1199   for (Int_t n=0; n<nentries; n++) {
1200     t->GetEvent(n);
1201     Int_t sec, row;
1202     if (!par->AdjustSectorRow(digarr.GetID(),sec,row)) {
1203       cerr<<"AliTPC warning: invalid segment ID ! "<<digarr.GetID()<<endl;
1204       continue;
1205     }
1206     AliSimDigits * digrow =(AliSimDigits*) arr->CreateRow(sec,row);
1207     Int_t nrows = digrow->GetNRows();
1208     Int_t ncols = digrow->GetNCols();
1209
1210     digrow->ExpandBuffer();
1211     digarr.ExpandBuffer();
1212     digrow->ExpandTrackBuffer();
1213     digarr.ExpandTrackBuffer();
1214
1215     for (row=0;row<nrows; row++)
1216       for (Int_t col=0;col<ncols; col++){
1217         Float_t  q  = digarr.GetDigitFast(row,col);
1218         q/=16;  //konversion faktor
1219         //add noise
1220         q = gRandom->Gaus(q,fTPCParam->GetNoise()*fTPCParam->GetNoiseNormFac()); 
1221         if(q > fTPCParam->GetADCSat()) q = fTPCParam->GetADCSat();
1222         if (q>3){
1223           digrow->SetDigitFast((Short_t)q,row,col);  
1224           for (Int_t tr=0;tr<3;tr++)    
1225             ((AliSimDigits*)digrow)->SetTrackIDFast(digarr.GetTrackIDFast(row,col,tr),row,col,tr);
1226         }
1227       }
1228       
1229
1230  
1231     
1232     arr->StoreRow(sec,row);
1233     //    printf("*** Sector, row, compressed digits %d %d %d ***\n",sec,row,ndig); 
1234     arr->ClearRow(sec,row);  
1235
1236    
1237   }
1238
1239
1240   cerr<<"Digitizing TPC...\n";   
1241
1242   //Hits2Digits(eventnumber);
1243    
1244     
1245   //write results
1246
1247   //  char treeName[100];
1248
1249   //  sprintf(treeName,"TreeD_%s_%d",fTPCParam->GetTitle(),eventnumber);
1250   
1251   arr->GetTree()->SetName(dname);  
1252   arr->GetTree()->Write();  
1253   delete arr;
1254 }
1255
1256
1257 /*_________________________________________
1258 void AliTPC::SDigits2Digits(Int_t eventnumber)
1259 {
1260
1261
1262   cerr<<"Digitizing TPC...\n";
1263
1264   Hits2Digits(eventnumber);
1265    
1266     
1267   //write results
1268
1269   //  char treeName[100];
1270
1271   //  sprintf(treeName,"TreeD_%s_%d",fTPCParam->GetTitle(),eventnumber);
1272   
1273   //  GetDigitsArray()->GetTree()->Write(treeName);  
1274 }
1275 */
1276 //__________________________________________________________________
1277 void AliTPC::SetDefaults(){
1278
1279    
1280    cerr<<"Setting default parameters...\n";
1281
1282   // Set response functions
1283
1284   AliTPCParamSR *param=(AliTPCParamSR*)gDirectory->Get("75x40_100x60");
1285   AliTPCPRF2D    * prfinner   = new AliTPCPRF2D;
1286   AliTPCPRF2D    * prfouter   = new AliTPCPRF2D;
1287   AliTPCRF1D     * rf    = new AliTPCRF1D(kTRUE);
1288   rf->SetGauss(param->GetZSigma(),param->GetZWidth(),1.);
1289   rf->SetOffset(3*param->GetZSigma());
1290   rf->Update();
1291   
1292   TDirectory *savedir=gDirectory;
1293   TFile *f=TFile::Open("$ALICE_ROOT/TPC/AliTPCprf2d.root");
1294   if (!f->IsOpen()) { 
1295     cerr<<"Can't open $ALICE_ROOT/TPC/AliTPCprf2d.root !\n" ;
1296      exit(3);
1297   }
1298   prfinner->Read("prf_07504_Gati_056068_d02");
1299   prfouter->Read("prf_10006_Gati_047051_d03");
1300   f->Close();
1301   savedir->cd();
1302
1303   param->SetInnerPRF(prfinner);
1304   param->SetOuterPRF(prfouter); 
1305   param->SetTimeRF(rf);
1306
1307   // set fTPCParam
1308
1309   SetParam(param);
1310
1311
1312   fDefaults = 1;
1313
1314 }
1315 //__________________________________________________________________  
1316 void AliTPC::Hits2Digits(Int_t eventnumber)  
1317
1318  //----------------------------------------------------
1319  // Loop over all sectors for a single event
1320  //----------------------------------------------------
1321
1322
1323   if(fDefaults == 0) SetDefaults();  // check if the parameters are set
1324
1325   //setup TPCDigitsArray 
1326
1327   if(GetDigitsArray()) delete GetDigitsArray();
1328
1329   AliTPCDigitsArray *arr = new AliTPCDigitsArray; 
1330   arr->SetClass("AliSimDigits");
1331   arr->Setup(fTPCParam);
1332   arr->MakeTree(fDigitsFile);
1333   SetDigitsArray(arr);
1334
1335   fDigitsSwitch=0; // standard digits
1336
1337   cerr<<"Digitizing TPC...\n";
1338
1339  for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++) Hits2DigitsSector(isec);
1340
1341   // write results
1342
1343   char treeName[100];
1344
1345   sprintf(treeName,"TreeD_%s_%d",fTPCParam->GetTitle(),eventnumber);
1346   
1347   GetDigitsArray()->GetTree()->SetName(treeName);  
1348   GetDigitsArray()->GetTree()->Write();  
1349
1350
1351 }
1352
1353
1354
1355 //__________________________________________________________________
1356 void AliTPC::Hits2SDigits2(Int_t eventnumber)  
1357
1358
1359   //-----------------------------------------------------------
1360   //   summable digits - 16 bit "ADC", no noise, no saturation
1361   //-----------------------------------------------------------
1362
1363  //----------------------------------------------------
1364  // Loop over all sectors for a single event
1365  //----------------------------------------------------
1366
1367
1368   if(fDefaults == 0) SetDefaults();
1369
1370   //setup TPCDigitsArray 
1371
1372   if(GetDigitsArray()) delete GetDigitsArray();
1373
1374   AliTPCDigitsArray *arr = new AliTPCDigitsArray; 
1375   arr->SetClass("AliSimDigits");
1376   arr->Setup(fTPCParam);
1377   arr->MakeTree(fDigitsFile);
1378   SetDigitsArray(arr);
1379
1380   cerr<<"Digitizing TPC...\n"; 
1381
1382   fDigitsSwitch=1; // summable digits
1383
1384  for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++) Hits2DigitsSector(isec);
1385
1386
1387   // write results
1388
1389   char treeName[100];
1390
1391   sprintf(treeName,"TreeS_%s_%d",fTPCParam->GetTitle(),eventnumber);
1392   
1393   GetDigitsArray()->GetTree()->SetName(treeName); 
1394   GetDigitsArray()->GetTree()->Write(); 
1395
1396 }
1397
1398
1399
1400 //__________________________________________________________________
1401 void AliTPC::Hits2SDigits()  
1402
1403
1404   //-----------------------------------------------------------
1405   //   summable digits - 16 bit "ADC", no noise, no saturation
1406   //-----------------------------------------------------------
1407
1408  //----------------------------------------------------
1409  // Loop over all sectors for a single event
1410  //----------------------------------------------------
1411   //MI change - for pp run
1412   Int_t eventnumber = gAlice->GetEvNumber();
1413
1414   if(fDefaults == 0) SetDefaults();
1415
1416   //setup TPCDigitsArray 
1417
1418   if(GetDigitsArray()) delete GetDigitsArray();
1419
1420   AliTPCDigitsArray *arr = new AliTPCDigitsArray; 
1421   arr->SetClass("AliSimDigits");
1422   arr->Setup(fTPCParam);
1423   arr->MakeTree(fDigitsFile);
1424   SetDigitsArray(arr);
1425
1426   cerr<<"Digitizing TPC...\n"; 
1427
1428   //  fDigitsSwitch=1; // summable digits  -for the moment direct
1429
1430  for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++) Hits2DigitsSector(isec);
1431
1432
1433   // write results
1434   char treeName[100];
1435
1436   sprintf(treeName,"TreeD_%s_%d",fTPCParam->GetTitle(),eventnumber);
1437   
1438   GetDigitsArray()->GetTree()->SetName(treeName); 
1439   GetDigitsArray()->GetTree()->Write(); 
1440
1441 }
1442
1443
1444 //_____________________________________________________________________________
1445 void AliTPC::Hits2DigitsSector(Int_t isec)
1446 {
1447   //-------------------------------------------------------------------
1448   // TPC conversion from hits to digits.
1449   //------------------------------------------------------------------- 
1450
1451   //-----------------------------------------------------------------
1452   // Origin: Marek Kowalski  IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1453   //-----------------------------------------------------------------
1454
1455   //-------------------------------------------------------
1456   //  Get the access to the track hits
1457   //-------------------------------------------------------
1458
1459   // check if the parameters are set - important if one calls this method
1460   // directly, not from the Hits2Digits
1461
1462   if(fDefaults == 0) SetDefaults();
1463
1464   TTree *tH = gAlice->TreeH(); // pointer to the hits tree
1465   Stat_t ntracks = tH->GetEntries();
1466
1467   if( ntracks > 0){
1468
1469   //------------------------------------------- 
1470   //  Only if there are any tracks...
1471   //-------------------------------------------
1472
1473     TObjArray **row;
1474     
1475     //printf("*** Processing sector number %d ***\n",isec);
1476
1477       Int_t nrows =fTPCParam->GetNRow(isec);
1478
1479       row= new TObjArray* [nrows];
1480     
1481       MakeSector(isec,nrows,tH,ntracks,row);
1482
1483       //--------------------------------------------------------
1484       //   Digitize this sector, row by row
1485       //   row[i] is the pointer to the TObjArray of TVectors,
1486       //   each one containing electrons accepted on this
1487       //   row, assigned into tracks
1488       //--------------------------------------------------------
1489
1490       Int_t i;
1491
1492       if (fDigitsArray->GetTree()==0) fDigitsArray->MakeTree(fDigitsFile);
1493
1494       for (i=0;i<nrows;i++){
1495
1496         AliDigits * dig = fDigitsArray->CreateRow(isec,i); 
1497
1498         DigitizeRow(i,isec,row);
1499
1500         fDigitsArray->StoreRow(isec,i);
1501
1502                 Int_t ndig = dig->GetDigitSize(); 
1503         
1504  
1505        //printf("*** Sector, row, compressed digits %d %d %d ***\n",isec,i,ndig);
1506         
1507         fDigitsArray->ClearRow(isec,i);  
1508
1509    
1510        } // end of the sector digitization
1511
1512       for(i=0;i<nrows;i++){
1513         row[i]->Delete();  
1514         delete row[i];   
1515       }
1516       
1517        delete [] row; // delete the array of pointers to TObjArray-s
1518         
1519   } // ntracks >0
1520
1521 } // end of Hits2DigitsSector
1522
1523
1524 //_____________________________________________________________________________
1525 void AliTPC::DigitizeRow(Int_t irow,Int_t isec,TObjArray **rows)
1526 {
1527   //-----------------------------------------------------------
1528   // Single row digitization, coupling from the neighbouring
1529   // rows taken into account
1530   //-----------------------------------------------------------
1531
1532   //-----------------------------------------------------------------
1533   // Origin: Marek Kowalski  IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1534   // Modified: Marian Ivanov GSI Darmstadt, m.ivanov@gsi.de
1535   //-----------------------------------------------------------------
1536  
1537
1538   Float_t zerosup = fTPCParam->GetZeroSup();
1539   Int_t nrows =fTPCParam->GetNRow(isec);
1540   fCurrentIndex[1]= isec;
1541   
1542
1543   Int_t nofPads = fTPCParam->GetNPads(isec,irow);
1544   Int_t nofTbins = fTPCParam->GetMaxTBin();
1545   Int_t indexRange[4];
1546   //
1547   //  Integrated signal for this row
1548   //  and a single track signal
1549   //    
1550   TMatrix *m1   = new TMatrix(0,nofPads,0,nofTbins); // integrated
1551   TMatrix *m2   = new TMatrix(0,nofPads,0,nofTbins); // single
1552   //
1553   TMatrix &total  = *m1;
1554
1555   //  Array of pointers to the label-signal list
1556
1557   Int_t nofDigits = nofPads*nofTbins; // number of digits for this row
1558   Float_t  **pList = new Float_t* [nofDigits]; 
1559
1560   Int_t lp;
1561   Int_t i1;   
1562   for(lp=0;lp<nofDigits;lp++)pList[lp]=0; // set all pointers to NULL
1563   //
1564   //calculate signal 
1565   //
1566   Int_t row1 = TMath::Max(irow-fTPCParam->GetNCrossRows(),0);
1567   Int_t row2 = TMath::Min(irow+fTPCParam->GetNCrossRows(),nrows-1);
1568   for (Int_t row= row1;row<=row2;row++){
1569     Int_t nTracks= rows[row]->GetEntries();
1570     for (i1=0;i1<nTracks;i1++){
1571       fCurrentIndex[2]= row;
1572       fCurrentIndex[3]=irow;
1573       if (row==irow){
1574         m2->Zero();  // clear single track signal matrix
1575         Float_t trackLabel = GetSignal(rows[row],i1,m2,m1,indexRange); 
1576         GetList(trackLabel,nofPads,m2,indexRange,pList);
1577       }
1578       else   GetSignal(rows[row],i1,0,m1,indexRange);
1579     }
1580   }
1581          
1582   Int_t tracks[3];
1583
1584   AliDigits *dig = fDigitsArray->GetRow(isec,irow);
1585   for(Int_t ip=0;ip<nofPads;ip++){
1586     for(Int_t it=0;it<nofTbins;it++){
1587
1588       Float_t q = total(ip,it);
1589
1590       Int_t gi =it*nofPads+ip; // global index
1591
1592       if(fDigitsSwitch == 0){
1593
1594         q = gRandom->Gaus(q,fTPCParam->GetNoise()*fTPCParam->GetNoiseNormFac()); 
1595
1596         q = (Int_t)q;
1597
1598         if(q <=zerosup) continue; // do not fill zeros
1599         if(q > fTPCParam->GetADCSat()) q = fTPCParam->GetADCSat();  // saturation
1600
1601       }
1602
1603       else {
1604        q *= 16.;
1605        q = (Int_t)q;
1606       }
1607
1608       //
1609       //  "real" signal or electronic noise (list = -1)?
1610       //    
1611
1612       for(Int_t j1=0;j1<3;j1++){
1613         tracks[j1] = (pList[gi]) ?(Int_t)(*(pList[gi]+j1)) : -1;
1614       }
1615
1616 //Begin_Html
1617 /*
1618   <A NAME="AliDigits"></A>
1619   using of AliDigits object
1620 */
1621 //End_Html
1622       dig->SetDigitFast((Short_t)q,it,ip);
1623       if (fDigitsArray->IsSimulated())
1624         {
1625          ((AliSimDigits*)dig)->SetTrackIDFast(tracks[0],it,ip,0);
1626          ((AliSimDigits*)dig)->SetTrackIDFast(tracks[1],it,ip,1);
1627          ((AliSimDigits*)dig)->SetTrackIDFast(tracks[2],it,ip,2);
1628         }
1629      
1630     
1631     } // end of loop over time buckets
1632   }  // end of lop over pads 
1633
1634   //
1635   //  This row has been digitized, delete nonused stuff
1636   //
1637
1638   for(lp=0;lp<nofDigits;lp++){
1639     if(pList[lp]) delete [] pList[lp];
1640   }
1641   
1642   delete [] pList;
1643
1644   delete m1;
1645   delete m2;
1646   //  delete m3;
1647
1648 } // end of DigitizeRow
1649
1650 //_____________________________________________________________________________
1651
1652 Float_t AliTPC::GetSignal(TObjArray *p1, Int_t ntr, TMatrix *m1, TMatrix *m2,
1653                           Int_t *indexRange)
1654 {
1655
1656   //---------------------------------------------------------------
1657   //  Calculates 2-D signal (pad,time) for a single track,
1658   //  returns a pointer to the signal matrix and the track label 
1659   //  No digitization is performed at this level!!!
1660   //---------------------------------------------------------------
1661
1662   //-----------------------------------------------------------------
1663   // Origin: Marek Kowalski  IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1664   // Modified: Marian Ivanov 
1665   //-----------------------------------------------------------------
1666
1667   TVector *tv;
1668  
1669   tv = (TVector*)p1->At(ntr); // pointer to a track
1670   TVector &v = *tv;
1671   
1672   Float_t label = v(0);
1673   Int_t centralPad = (fTPCParam->GetNPads(fCurrentIndex[1],fCurrentIndex[3])-1)/2;
1674
1675   Int_t nElectrons = (tv->GetNrows()-1)/4;
1676   indexRange[0]=9999; // min pad
1677   indexRange[1]=-1; // max pad
1678   indexRange[2]=9999; //min time
1679   indexRange[3]=-1; // max time
1680
1681   //  Float_t IneffFactor = 0.5; // inefficiency in the gain close to the edge, as above
1682
1683   TMatrix &signal = *m1;
1684   TMatrix &total = *m2;
1685   //
1686   //  Loop over all electrons
1687   //
1688   for(Int_t nel=0; nel<nElectrons; nel++){
1689     Int_t idx=nel*4;
1690     Float_t aval =  v(idx+4);
1691     Float_t eltoadcfac=aval*fTPCParam->GetTotalNormFac(); 
1692     Float_t xyz[3]={v(idx+1),v(idx+2),v(idx+3)};
1693     Int_t n = fTPCParam->CalcResponse(xyz,fCurrentIndex,fCurrentIndex[3]);
1694     
1695     if (n>0) for (Int_t i =0; i<n; i++){
1696        Int_t *index = fTPCParam->GetResBin(i);        
1697        Int_t pad=index[1]+centralPad;  //in digit coordinates central pad has coordinate 0
1698        if ( ( pad<(fTPCParam->GetNPads(fCurrentIndex[1],fCurrentIndex[3]))) && (pad>0)) {
1699          Int_t time=index[2];    
1700          Float_t weight = fTPCParam->GetResWeight(i); //we normalise response to ADC channel
1701          weight *= eltoadcfac;
1702          
1703          if (m1!=0) signal(pad,time)+=weight; 
1704          total(pad,time)+=weight;
1705          indexRange[0]=TMath::Min(indexRange[0],pad);
1706          indexRange[1]=TMath::Max(indexRange[1],pad);
1707          indexRange[2]=TMath::Min(indexRange[2],time);
1708          indexRange[3]=TMath::Max(indexRange[3],time); 
1709        }         
1710     }
1711   } // end of loop over electrons
1712   
1713   return label; // returns track label when finished
1714 }
1715
1716 //_____________________________________________________________________________
1717 void AliTPC::GetList(Float_t label,Int_t np,TMatrix *m,Int_t *indexRange,
1718                      Float_t **pList)
1719 {
1720   //----------------------------------------------------------------------
1721   //  Updates the list of tracks contributing to digits for a given row
1722   //----------------------------------------------------------------------
1723
1724   //-----------------------------------------------------------------
1725   // Origin: Marek Kowalski  IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1726   //-----------------------------------------------------------------
1727
1728   TMatrix &signal = *m;
1729
1730   // lop over nonzero digits
1731
1732   for(Int_t it=indexRange[2];it<indexRange[3]+1;it++){
1733     for(Int_t ip=indexRange[0];ip<indexRange[1]+1;ip++){
1734
1735
1736         // accept only the contribution larger than 500 electrons (1/2 s_noise)
1737
1738         if(signal(ip,it)<0.5) continue; 
1739
1740
1741         Int_t globalIndex = it*np+ip; // globalIndex starts from 0!
1742         
1743         if(!pList[globalIndex]){
1744         
1745           // 
1746           // Create new list (6 elements - 3 signals and 3 labels),
1747           //
1748
1749           pList[globalIndex] = new Float_t [6];
1750
1751           // set list to -1 
1752
1753           *pList[globalIndex] = -1.;
1754           *(pList[globalIndex]+1) = -1.;
1755           *(pList[globalIndex]+2) = -1.;
1756           *(pList[globalIndex]+3) = -1.;
1757           *(pList[globalIndex]+4) = -1.;
1758           *(pList[globalIndex]+5) = -1.;
1759
1760
1761           *pList[globalIndex] = label;
1762           *(pList[globalIndex]+3) = signal(ip,it);
1763         }
1764         else{
1765
1766           // check the signal magnitude
1767
1768           Float_t highest = *(pList[globalIndex]+3);
1769           Float_t middle = *(pList[globalIndex]+4);
1770           Float_t lowest = *(pList[globalIndex]+5);
1771
1772           //
1773           //  compare the new signal with already existing list
1774           //
1775
1776           if(signal(ip,it)<lowest) continue; // neglect this track
1777
1778           //
1779
1780           if (signal(ip,it)>highest){
1781             *(pList[globalIndex]+5) = middle;
1782             *(pList[globalIndex]+4) = highest;
1783             *(pList[globalIndex]+3) = signal(ip,it);
1784
1785             *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
1786             *(pList[globalIndex]+1) = *pList[globalIndex];
1787             *pList[globalIndex] = label;
1788           }
1789           else if (signal(ip,it)>middle){
1790             *(pList[globalIndex]+5) = middle;
1791             *(pList[globalIndex]+4) = signal(ip,it);
1792
1793             *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
1794             *(pList[globalIndex]+1) = label;
1795           }
1796           else{
1797             *(pList[globalIndex]+5) = signal(ip,it);
1798             *(pList[globalIndex]+2) = label;
1799           }
1800         }
1801
1802     } // end of loop over pads
1803   } // end of loop over time bins
1804
1805
1806
1807 }//end of GetList
1808 //___________________________________________________________________
1809 void AliTPC::MakeSector(Int_t isec,Int_t nrows,TTree *TH,
1810                         Stat_t ntracks,TObjArray **row)
1811 {
1812
1813   //-----------------------------------------------------------------
1814   // Prepares the sector digitization, creates the vectors of
1815   // tracks for each row of this sector. The track vector
1816   // contains the track label and the position of electrons.
1817   //-----------------------------------------------------------------
1818
1819   //-----------------------------------------------------------------
1820   // Origin: Marek Kowalski  IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1821   //-----------------------------------------------------------------
1822
1823   Float_t gasgain = fTPCParam->GetGasGain();
1824   Int_t i;
1825   Float_t xyz[4]; 
1826
1827   AliTPChit *tpcHit; // pointer to a sigle TPC hit    
1828   //MI change
1829   TBranch * branch=0;
1830   if (fHitType&2) branch = TH->GetBranch("TPC2");
1831   else branch = TH->GetBranch("TPC");
1832
1833  
1834   //----------------------------------------------
1835   // Create TObjArray-s, one for each row,
1836   // each TObjArray will store the TVectors
1837   // of electrons, one TVector per each track.
1838   //---------------------------------------------- 
1839     
1840   Int_t *nofElectrons = new Int_t [nrows]; // electron counter for each row
1841   TVector **tracks = new TVector* [nrows]; //pointers to the track vectors
1842   for(i=0; i<nrows; i++){
1843     row[i] = new TObjArray;
1844     nofElectrons[i]=0;
1845     tracks[i]=0;
1846   }
1847
1848  
1849
1850   //--------------------------------------------------------------------
1851   //  Loop over tracks, the "track" contains the full history
1852   //--------------------------------------------------------------------
1853
1854   Int_t previousTrack,currentTrack;
1855   previousTrack = -1; // nothing to store so far!
1856
1857   for(Int_t track=0;track<ntracks;track++){
1858     Bool_t isInSector=kTRUE;
1859     ResetHits();
1860
1861     if (fHitType&2) {
1862       isInSector=kFALSE;
1863       TBranch * br = TH->GetBranch("fTrackHitsInfo");
1864       br->GetEvent(track);
1865       AliObjectArray * ar = fTrackHits->fTrackHitsInfo;
1866       for (UInt_t j=0;j<ar->GetSize();j++){
1867         if (  ((AliTrackHitsInfo*)ar->At(j))->fVolumeID==isec) isInSector=kTRUE;
1868       }
1869     }
1870     if (!isInSector) continue;
1871     //MI change
1872     branch->GetEntry(track); // get next track
1873
1874     //M.I. changes
1875
1876     tpcHit = (AliTPChit*)FirstHit(-1);
1877
1878     //--------------------------------------------------------------
1879     //  Loop over hits
1880     //--------------------------------------------------------------
1881
1882
1883     while(tpcHit){
1884       
1885       Int_t sector=tpcHit->fSector; // sector number
1886       //      if(sector != isec) continue; 
1887       if(sector != isec){
1888         tpcHit = (AliTPChit*) NextHit();
1889         continue; 
1890       }
1891
1892         currentTrack = tpcHit->Track(); // track number
1893
1894
1895         if(currentTrack != previousTrack){
1896                           
1897            // store already filled fTrack
1898               
1899            for(i=0;i<nrows;i++){
1900              if(previousTrack != -1){
1901                if(nofElectrons[i]>0){
1902                  TVector &v = *tracks[i];
1903                  v(0) = previousTrack;
1904                  tracks[i]->ResizeTo(4*nofElectrons[i]+1); // shrink if necessary
1905                  row[i]->Add(tracks[i]);                     
1906                }
1907                else{
1908                  delete tracks[i]; // delete empty TVector
1909                  tracks[i]=0;
1910                }
1911              }
1912
1913              nofElectrons[i]=0;
1914              tracks[i] = new TVector(481); // TVectors for the next fTrack
1915
1916            } // end of loop over rows
1917                
1918            previousTrack=currentTrack; // update track label 
1919         }
1920            
1921         Int_t qI = (Int_t) (tpcHit->fQ); // energy loss (number of electrons)
1922
1923        //---------------------------------------------------
1924        //  Calculate the electron attachment probability
1925        //---------------------------------------------------
1926
1927
1928         Float_t time = 1.e6*(fTPCParam->GetZLength()-TMath::Abs(tpcHit->Z()))
1929                                                         /fTPCParam->GetDriftV(); 
1930         // in microseconds!     
1931         Float_t attProb = fTPCParam->GetAttCoef()*
1932           fTPCParam->GetOxyCont()*time; //  fraction! 
1933    
1934         //-----------------------------------------------
1935         //  Loop over electrons
1936         //-----------------------------------------------
1937         Int_t index[3];
1938         index[1]=isec;
1939         for(Int_t nel=0;nel<qI;nel++){
1940           // skip if electron lost due to the attachment
1941           if((gRandom->Rndm(0)) < attProb) continue; // electron lost!
1942           xyz[0]=tpcHit->X();
1943           xyz[1]=tpcHit->Y();
1944           xyz[2]=tpcHit->Z();   
1945           //
1946           // protection for the nonphysical avalanche size (10**6 maximum)
1947           //  
1948           Double_t rn=TMath::Max(gRandom->Rndm(0),1.93e-22);
1949           xyz[3]= (Float_t) (-gasgain*TMath::Log(rn)); 
1950           index[0]=1;
1951           
1952           TransportElectron(xyz,index); //MI change -august       
1953           Int_t rowNumber;
1954           fTPCParam->GetPadRow(xyz,index); //MI change august
1955           rowNumber = index[2];
1956           //transform position to local digit coordinates
1957           //relative to nearest pad row 
1958           if ((rowNumber<0)||rowNumber>=fTPCParam->GetNRow(isec)) continue;       
1959           nofElectrons[rowNumber]++;      
1960           //----------------------------------
1961           // Expand vector if necessary
1962           //----------------------------------
1963           if(nofElectrons[rowNumber]>120){
1964             Int_t range = tracks[rowNumber]->GetNrows();
1965             if((nofElectrons[rowNumber])>(range-1)/4){
1966         
1967               tracks[rowNumber]->ResizeTo(range+400); // Add 100 electrons
1968             }
1969           }
1970           
1971           TVector &v = *tracks[rowNumber];
1972           Int_t idx = 4*nofElectrons[rowNumber]-3;
1973
1974           v(idx)=  xyz[0];   // X - pad row coordinate
1975           v(idx+1)=xyz[1];   // Y - pad coordinate (along the pad-row)
1976           v(idx+2)=xyz[2];   // Z - time bin coordinate
1977           v(idx+3)=xyz[3];   // avalanche size  
1978         } // end of loop over electrons
1979
1980         tpcHit = (AliTPChit*)NextHit();
1981         
1982       } // end of loop over hits
1983     } // end of loop over tracks
1984
1985     //
1986     //   store remaining track (the last one) if not empty
1987     //
1988
1989      for(i=0;i<nrows;i++){
1990        if(nofElectrons[i]>0){
1991           TVector &v = *tracks[i];
1992           v(0) = previousTrack;
1993           tracks[i]->ResizeTo(4*nofElectrons[i]+1); // shrink if necessary
1994           row[i]->Add(tracks[i]);  
1995         }
1996         else{
1997           delete tracks[i];
1998           tracks[i]=0;
1999         }  
2000       }  
2001
2002           delete [] tracks;
2003           delete [] nofElectrons;
2004  
2005
2006 } // end of MakeSector
2007
2008
2009 //_____________________________________________________________________________
2010 void AliTPC::Init()
2011 {
2012   //
2013   // Initialise TPC detector after definition of geometry
2014   //
2015   Int_t i;
2016   //
2017   if(fDebug) {
2018     printf("\n%s: ",ClassName());
2019     for(i=0;i<35;i++) printf("*");
2020     printf(" TPC_INIT ");
2021     for(i=0;i<35;i++) printf("*");
2022     printf("\n%s: ",ClassName());
2023     //
2024     for(i=0;i<80;i++) printf("*");
2025     printf("\n");
2026   }
2027 }
2028
2029 //_____________________________________________________________________________
2030 void AliTPC::MakeBranch(Option_t* option, const char *file)
2031 {
2032   //
2033   // Create Tree branches for the TPC.
2034   //
2035   Int_t buffersize = 4000;
2036   char branchname[10];
2037   sprintf(branchname,"%s",GetName());
2038
2039   AliDetector::MakeBranch(option,file);
2040
2041   const char *d = strstr(option,"D");
2042
2043   if (fDigits   && gAlice->TreeD() && d) {
2044       MakeBranchInTree(gAlice->TreeD(), 
2045                        branchname, &fDigits, buffersize, file);
2046   }     
2047
2048   if (fHitType&2) MakeBranch2(option,file); // MI change 14.09.2000
2049 }
2050  
2051 //_____________________________________________________________________________
2052 void AliTPC::ResetDigits()
2053 {
2054   //
2055   // Reset number of digits and the digits array for this detector
2056   //
2057   fNdigits   = 0;
2058   if (fDigits)   fDigits->Clear();
2059 }
2060
2061 //_____________________________________________________________________________
2062 void AliTPC::SetSecAL(Int_t sec)
2063 {
2064   //---------------------------------------------------
2065   // Activate/deactivate selection for lower sectors
2066   //---------------------------------------------------
2067
2068   //-----------------------------------------------------------------
2069   // Origin: Marek Kowalski  IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2070   //-----------------------------------------------------------------
2071
2072   fSecAL = sec;
2073 }
2074
2075 //_____________________________________________________________________________
2076 void AliTPC::SetSecAU(Int_t sec)
2077 {
2078   //----------------------------------------------------
2079   // Activate/deactivate selection for upper sectors
2080   //---------------------------------------------------
2081
2082   //-----------------------------------------------------------------
2083   // Origin: Marek Kowalski  IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2084   //-----------------------------------------------------------------
2085
2086   fSecAU = sec;
2087 }
2088
2089 //_____________________________________________________________________________
2090 void AliTPC::SetSecLows(Int_t s1,Int_t s2,Int_t s3,Int_t s4,Int_t s5, Int_t s6)
2091 {
2092   //----------------------------------------
2093   // Select active lower sectors
2094   //----------------------------------------
2095
2096   //-----------------------------------------------------------------
2097   // Origin: Marek Kowalski  IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2098   //-----------------------------------------------------------------
2099
2100   fSecLows[0] = s1;
2101   fSecLows[1] = s2;
2102   fSecLows[2] = s3;
2103   fSecLows[3] = s4;
2104   fSecLows[4] = s5;
2105   fSecLows[5] = s6;
2106 }
2107
2108 //_____________________________________________________________________________
2109 void AliTPC::SetSecUps(Int_t s1,Int_t s2,Int_t s3,Int_t s4,Int_t s5, Int_t s6,
2110                        Int_t s7, Int_t s8 ,Int_t s9 ,Int_t s10, 
2111                        Int_t s11 , Int_t s12)
2112 {
2113   //--------------------------------
2114   // Select active upper sectors
2115   //--------------------------------
2116
2117   //-----------------------------------------------------------------
2118   // Origin: Marek Kowalski  IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2119   //-----------------------------------------------------------------
2120
2121   fSecUps[0] = s1;
2122   fSecUps[1] = s2;
2123   fSecUps[2] = s3;
2124   fSecUps[3] = s4;
2125   fSecUps[4] = s5;
2126   fSecUps[5] = s6;
2127   fSecUps[6] = s7;
2128   fSecUps[7] = s8;
2129   fSecUps[8] = s9;
2130   fSecUps[9] = s10;
2131   fSecUps[10] = s11;
2132   fSecUps[11] = s12;
2133 }
2134
2135 //_____________________________________________________________________________
2136 void AliTPC::SetSens(Int_t sens)
2137 {
2138
2139   //-------------------------------------------------------------
2140   // Activates/deactivates the sensitive strips at the center of
2141   // the pad row -- this is for the space-point resolution calculations
2142   //-------------------------------------------------------------
2143
2144   //-----------------------------------------------------------------
2145   // Origin: Marek Kowalski  IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2146   //-----------------------------------------------------------------
2147
2148   fSens = sens;
2149 }
2150
2151  
2152 void AliTPC::SetSide(Float_t side=0.)
2153 {
2154   // choice of the TPC side
2155
2156   fSide = side;
2157  
2158 }
2159 //____________________________________________________________________________
2160 void AliTPC::SetGasMixt(Int_t nc,Int_t c1,Int_t c2,Int_t c3,Float_t p1,
2161                            Float_t p2,Float_t p3)
2162 {
2163
2164   // gax mixture definition
2165
2166  fNoComp = nc;
2167  
2168  fMixtComp[0]=c1;
2169  fMixtComp[1]=c2;
2170  fMixtComp[2]=c3;
2171
2172  fMixtProp[0]=p1;
2173  fMixtProp[1]=p2;
2174  fMixtProp[2]=p3; 
2175  
2176  
2177 }
2178 //_____________________________________________________________________________
2179
2180 void AliTPC::TransportElectron(Float_t *xyz, Int_t *index)
2181 {
2182   //
2183   // electron transport taking into account:
2184   // 1. diffusion, 
2185   // 2.ExB at the wires
2186   // 3. nonisochronity
2187   //
2188   // xyz and index must be already transformed to system 1
2189   //
2190
2191   fTPCParam->Transform1to2(xyz,index);
2192   
2193   //add diffusion
2194   Float_t driftl=xyz[2];
2195   if(driftl<0.01) driftl=0.01;
2196   driftl=TMath::Sqrt(driftl);
2197   Float_t sigT = driftl*(fTPCParam->GetDiffT());
2198   Float_t sigL = driftl*(fTPCParam->GetDiffL());
2199   xyz[0]=gRandom->Gaus(xyz[0],sigT);
2200   xyz[1]=gRandom->Gaus(xyz[1],sigT);
2201   xyz[2]=gRandom->Gaus(xyz[2],sigL);
2202
2203   // ExB
2204   
2205   if (fTPCParam->GetMWPCReadout()==kTRUE){
2206     Float_t x1=xyz[0];
2207     fTPCParam->Transform2to2NearestWire(xyz,index);
2208     Float_t dx=xyz[0]-x1;
2209     xyz[1]+=dx*(fTPCParam->GetOmegaTau());
2210   }
2211   //add nonisochronity (not implemented yet)
2212   
2213 }
2214   
2215 ClassImp(AliTPCdigit)
2216  
2217 //_____________________________________________________________________________
2218 AliTPCdigit::AliTPCdigit(Int_t *tracks, Int_t *digits):
2219   AliDigit(tracks)
2220 {
2221   //
2222   // Creates a TPC digit object
2223   //
2224   fSector     = digits[0];
2225   fPadRow     = digits[1];
2226   fPad        = digits[2];
2227   fTime       = digits[3];
2228   fSignal     = digits[4];
2229 }
2230
2231  
2232 ClassImp(AliTPChit)
2233  
2234 //_____________________________________________________________________________
2235 AliTPChit::AliTPChit(Int_t shunt, Int_t track, Int_t *vol, Float_t *hits):
2236 AliHit(shunt,track)
2237 {
2238   //
2239   // Creates a TPC hit object
2240   //
2241   fSector     = vol[0];
2242   fPadRow     = vol[1];
2243   fX          = hits[0];
2244   fY          = hits[1];
2245   fZ          = hits[2];
2246   fQ          = hits[3];
2247 }
2248  
2249
2250 //________________________________________________________________________
2251 // Additional code because of the AliTPCTrackHits
2252
2253 void AliTPC::MakeBranch2(Option_t *option,const char *file)
2254 {
2255   //
2256   // Create a new branch in the current Root Tree
2257   // The branch of fHits is automatically split
2258   // MI change 14.09.2000
2259   if (fHitType&2==0) return;
2260   char branchname[10];
2261   sprintf(branchname,"%s2",GetName());  
2262   //
2263   // Get the pointer to the header
2264   const char *cH = strstr(option,"H");
2265   //
2266   if (fTrackHits   && gAlice->TreeH() && cH) {    
2267     AliObjectBranch * branch = new AliObjectBranch(branchname,"AliTPCTrackHits",&fTrackHits, 
2268                                                    gAlice->TreeH(),fBufferSize,99);
2269     gAlice->TreeH()->GetListOfBranches()->Add(branch);
2270     if (GetDebug()>1) 
2271       printf("* AliDetector::MakeBranch * Making Branch %s for trackhits\n",branchname);
2272     const char folder [] = "RunMC/Event/Data";
2273     if (GetDebug())
2274       printf("%15s: Publishing %s to %s\n",ClassName(),branchname,folder);
2275     Publish(folder,&fTrackHits,branchname);
2276     if (file) {
2277         TBranch *b = gAlice->TreeH()->GetBranch(branchname);
2278         TDirectory *wd = gDirectory;
2279         b->SetFile(file);
2280         TIter next( b->GetListOfBranches());
2281         while ((b=(TBranch*)next())) {
2282           b->SetFile(file);
2283         }
2284         wd->cd(); 
2285         if (GetDebug()>1) 
2286               cout << "Diverting branch " << branchname << " to file " << file << endl;  
2287     }
2288   }     
2289 }
2290
2291 void AliTPC::SetTreeAddress()
2292 {
2293   if (fHitType&1) AliDetector::SetTreeAddress();
2294   if (fHitType&2) SetTreeAddress2();
2295 }
2296
2297 void AliTPC::SetTreeAddress2()
2298 {
2299   //
2300   // Set branch address for the TrackHits Tree
2301   // 
2302   TBranch *branch;
2303   char branchname[20];
2304   sprintf(branchname,"%s2",GetName());
2305   //
2306   // Branch address for hit tree
2307   TTree *treeH = gAlice->TreeH();
2308   if (treeH) {
2309     branch = treeH->GetBranch(branchname);
2310     if (branch) branch->SetAddress(&fTrackHits);
2311   }
2312 }
2313
2314 void AliTPC::FinishPrimary()
2315 {
2316   if (fTrackHits) fTrackHits->FlushHitStack();  
2317 }
2318
2319
2320 void AliTPC::AddHit2(Int_t track, Int_t *vol, Float_t *hits)
2321
2322   //
2323   // add hit to the list  
2324   Int_t rtrack;
2325   if (fIshunt) {
2326     int primary = gAlice->GetPrimary(track);
2327     gAlice->Particle(primary)->SetBit(kKeepBit);
2328     rtrack=primary;
2329   } else {
2330     rtrack=track;
2331     gAlice->FlagTrack(track);
2332   }  
2333   //AliTPChit *hit = (AliTPChit*)fHits->UncheckedAt(fNhits-1);
2334   //if (hit->fTrack!=rtrack)
2335   //  cout<<"bad track number\n";
2336   if (fTrackHits) 
2337     fTrackHits->AddHitKartez(vol[0],rtrack, hits[0],
2338                              hits[1],hits[2],(Int_t)hits[3]);
2339 }
2340
2341 void AliTPC::ResetHits()
2342 {
2343   if (fHitType&1) AliDetector::ResetHits();
2344   if (fHitType&2) ResetHits2();
2345 }
2346
2347 void AliTPC::ResetHits2()
2348 {
2349   //
2350   //reset hits
2351   if (fTrackHits) fTrackHits->Clear();
2352 }   
2353
2354 AliHit* AliTPC::FirstHit(Int_t track)
2355 {
2356   if (fHitType&2) return FirstHit2(track);
2357   return AliDetector::FirstHit(track);
2358 }
2359 AliHit* AliTPC::NextHit()
2360 {
2361   if (fHitType&2) return NextHit2();
2362   return AliDetector::NextHit();
2363 }
2364
2365 AliHit* AliTPC::FirstHit2(Int_t track)
2366 {
2367   //
2368   // Initialise the hit iterator
2369   // Return the address of the first hit for track
2370   // If track>=0 the track is read from disk
2371   // while if track<0 the first hit of the current
2372   // track is returned
2373   // 
2374   if(track>=0) {
2375     gAlice->ResetHits();
2376     gAlice->TreeH()->GetEvent(track);
2377   }
2378   //
2379   if (fTrackHits) {
2380     fTrackHits->First();
2381     return fTrackHits->GetHit();
2382   }
2383   else return 0;
2384 }
2385
2386 AliHit* AliTPC::NextHit2()
2387 {
2388   //
2389   //Return the next hit for the current track
2390
2391   if (fTrackHits) {
2392     fTrackHits->Next();
2393     return fTrackHits->GetHit();
2394   }
2395   else 
2396     return 0;
2397 }
2398
2399 void AliTPC::LoadPoints(Int_t)
2400 {
2401   //
2402   Int_t a = 0;
2403   /*  if(fHitType==1) return AliDetector::LoadPoints(a);
2404   LoadPoints2(a);
2405   */
2406   if(fHitType==1) AliDetector::LoadPoints(a);
2407   else LoadPoints2(a);
2408    
2409   // LoadPoints3(a);
2410
2411 }
2412
2413
2414 void AliTPC::RemapTrackHitIDs(Int_t *map)
2415 {
2416   if (!fTrackHits) return;
2417   AliObjectArray * arr = fTrackHits->fTrackHitsInfo;
2418   for (UInt_t i=0;i<arr->GetSize();i++){
2419     AliTrackHitsInfo * info = (AliTrackHitsInfo *)(arr->At(i));
2420     info->fTrackID = map[info->fTrackID];
2421   }
2422   
2423 }
2424
2425
2426 //_____________________________________________________________________________
2427 void AliTPC::LoadPoints2(Int_t)
2428 {
2429   //
2430   // Store x, y, z of all hits in memory
2431   //
2432   if (fTrackHits == 0) return;
2433   //
2434   Int_t nhits = fTrackHits->GetEntriesFast();
2435   if (nhits == 0) return;
2436   Int_t tracks = gAlice->GetNtrack();
2437   if (fPoints == 0) fPoints = new TObjArray(tracks);
2438   AliHit *ahit;
2439   //
2440   Int_t *ntrk=new Int_t[tracks];
2441   Int_t *limi=new Int_t[tracks];
2442   Float_t **coor=new Float_t*[tracks];
2443   for(Int_t i=0;i<tracks;i++) {
2444     ntrk[i]=0;
2445     coor[i]=0;
2446     limi[i]=0;
2447   }
2448   //
2449   AliPoints *points = 0;
2450   Float_t *fp=0;
2451   Int_t trk;
2452   Int_t chunk=nhits/4+1;
2453   //
2454   // Loop over all the hits and store their position
2455   //
2456   ahit = FirstHit2(-1);
2457   //for (Int_t hit=0;hit<nhits;hit++) {
2458   while (ahit){
2459     //    ahit = (AliHit*)fHits->UncheckedAt(hit);
2460     trk=ahit->GetTrack();
2461     if(ntrk[trk]==limi[trk]) {
2462       //
2463       // Initialise a new track
2464       fp=new Float_t[3*(limi[trk]+chunk)];
2465       if(coor[trk]) {
2466         memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
2467         delete [] coor[trk];
2468       }
2469       limi[trk]+=chunk;
2470       coor[trk] = fp;
2471     } else {
2472       fp = coor[trk];
2473     }
2474     fp[3*ntrk[trk]  ] = ahit->X();
2475     fp[3*ntrk[trk]+1] = ahit->Y();
2476     fp[3*ntrk[trk]+2] = ahit->Z();
2477     ntrk[trk]++;
2478     ahit = NextHit2();
2479   }
2480   //
2481   for(trk=0; trk<tracks; ++trk) {
2482     if(ntrk[trk]) {
2483       points = new AliPoints();
2484       points->SetMarkerColor(GetMarkerColor());
2485       points->SetMarkerSize(GetMarkerSize());
2486       points->SetDetector(this);
2487       points->SetParticle(trk);
2488       points->SetPolyMarker(ntrk[trk],coor[trk],GetMarkerStyle());
2489       fPoints->AddAt(points,trk);
2490       delete [] coor[trk];
2491       coor[trk]=0;
2492     }
2493   }
2494   delete [] coor;
2495   delete [] ntrk;
2496   delete [] limi;
2497 }
2498
2499
2500 //_____________________________________________________________________________
2501 void AliTPC::LoadPoints3(Int_t)
2502 {
2503   //
2504   // Store x, y, z of all hits in memory
2505   // - only intersection point with pad row
2506   if (fTrackHits == 0) return;
2507   //
2508   Int_t nhits = fTrackHits->GetEntriesFast();
2509   if (nhits == 0) return;
2510   Int_t tracks = gAlice->GetNtrack();
2511   if (fPoints == 0) fPoints = new TObjArray(2*tracks);
2512   fPoints->Expand(2*tracks);
2513   AliHit *ahit;
2514   //
2515   Int_t *ntrk=new Int_t[tracks];
2516   Int_t *limi=new Int_t[tracks];
2517   Float_t **coor=new Float_t*[tracks];
2518   for(Int_t i=0;i<tracks;i++) {
2519     ntrk[i]=0;
2520     coor[i]=0;
2521     limi[i]=0;
2522   }
2523   //
2524   AliPoints *points = 0;
2525   Float_t *fp=0;
2526   Int_t trk;
2527   Int_t chunk=nhits/4+1;
2528   //
2529   // Loop over all the hits and store their position
2530   //
2531   ahit = FirstHit2(-1);
2532   //for (Int_t hit=0;hit<nhits;hit++) {
2533
2534   Int_t lastrow = -1;
2535   while (ahit){
2536     //    ahit = (AliHit*)fHits->UncheckedAt(hit);
2537     trk=ahit->GetTrack(); 
2538     Float_t  x[3]={ahit->X(),ahit->Y(),ahit->Z()};
2539     Int_t    index[3]={1,((AliTPChit*)ahit)->fSector,0};
2540     Int_t    currentrow = fTPCParam->GetPadRow(x,index) ;
2541     if (currentrow!=lastrow){
2542       lastrow = currentrow;
2543       //later calculate intersection point           
2544       if(ntrk[trk]==limi[trk]) {
2545         //
2546         // Initialise a new track
2547         fp=new Float_t[3*(limi[trk]+chunk)];
2548         if(coor[trk]) {
2549           memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
2550           delete [] coor[trk];
2551         }
2552         limi[trk]+=chunk;
2553         coor[trk] = fp;
2554       } else {
2555         fp = coor[trk];
2556       }
2557       fp[3*ntrk[trk]  ] = ahit->X();
2558       fp[3*ntrk[trk]+1] = ahit->Y();
2559       fp[3*ntrk[trk]+2] = ahit->Z();
2560       ntrk[trk]++;
2561     }
2562     ahit = NextHit2();
2563   }
2564   
2565   //
2566   for(trk=0; trk<tracks; ++trk) {
2567     if(ntrk[trk]) {
2568       points = new AliPoints();
2569       points->SetMarkerColor(GetMarkerColor()+1);
2570       points->SetMarkerStyle(5);
2571       points->SetMarkerSize(0.2);
2572       points->SetDetector(this);
2573       points->SetParticle(trk);
2574       //      points->SetPolyMarker(ntrk[trk],coor[trk],GetMarkerStyle()20);
2575       points->SetPolyMarker(ntrk[trk],coor[trk],30);
2576       fPoints->AddAt(points,tracks+trk);
2577       delete [] coor[trk];
2578       coor[trk]=0;
2579     }
2580   }
2581   delete [] coor;
2582   delete [] ntrk;
2583   delete [] limi;
2584 }
2585
2586
2587
2588 void AliTPC::FindTrackHitsIntersection(TClonesArray * arr)
2589 {
2590
2591   //
2592   //fill clones array with intersection of current point with the
2593   //middle of the row
2594   Int_t sector;
2595   Int_t ipart;
2596   
2597   const Int_t kcmaxhits=30000;
2598   TVector * xxxx = new TVector(kcmaxhits*4);
2599   TVector & xxx = *xxxx;
2600   Int_t maxhits = kcmaxhits;
2601       
2602   //
2603   AliTPChit * tpcHit=0;
2604   tpcHit = (AliTPChit*)FirstHit2(-1);
2605   Int_t currentIndex=0;
2606   Int_t lastrow=-1;  //last writen row
2607
2608   while (tpcHit){
2609     if (tpcHit==0) continue;
2610     sector=tpcHit->fSector; // sector number
2611     ipart=tpcHit->Track();
2612     
2613     //find row number
2614     
2615     Float_t  x[3]={tpcHit->X(),tpcHit->Y(),tpcHit->Z()};
2616     Int_t    index[3]={1,sector,0};
2617     Int_t    currentrow = fTPCParam->GetPadRow(x,index) ;       
2618     if (currentrow<0) continue;
2619     if (lastrow<0) lastrow=currentrow;
2620     if (currentrow==lastrow){
2621       if ( currentIndex>=maxhits){
2622         maxhits+=kcmaxhits;
2623         xxx.ResizeTo(4*maxhits);
2624       }     
2625       xxx(currentIndex*4)=x[0];
2626       xxx(currentIndex*4+1)=x[1];
2627       xxx(currentIndex*4+2)=x[2];       
2628       xxx(currentIndex*4+3)=tpcHit->fQ;
2629       currentIndex++;   
2630     }
2631     else 
2632       if (currentIndex>2){
2633         Float_t sumx=0;
2634         Float_t sumx2=0;
2635         Float_t sumx3=0;
2636         Float_t sumx4=0;
2637         Float_t sumy=0;
2638         Float_t sumxy=0;
2639         Float_t sumx2y=0;
2640         Float_t sumz=0;
2641         Float_t sumxz=0;
2642         Float_t sumx2z=0;
2643         Float_t sumq=0;
2644         for (Int_t index=0;index<currentIndex;index++){
2645           Float_t x,x2,x3,x4;
2646           x=x2=x3=x4=xxx(index*4);
2647           x2*=x;
2648           x3*=x2;
2649           x4*=x3;
2650           sumx+=x;
2651           sumx2+=x2;
2652           sumx3+=x3;
2653           sumx4+=x4;
2654           sumy+=xxx(index*4+1);
2655           sumxy+=xxx(index*4+1)*x;
2656           sumx2y+=xxx(index*4+1)*x2;
2657           sumz+=xxx(index*4+2);
2658           sumxz+=xxx(index*4+2)*x;
2659           sumx2z+=xxx(index*4+2)*x2;     
2660           sumq+=xxx(index*4+3);
2661         }
2662         Float_t centralPad = (fTPCParam->GetNPads(sector,lastrow)-1)/2;
2663         Float_t det=currentIndex*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumx*sumx4-sumx2*sumx3)+
2664           sumx2*(sumx*sumx3-sumx2*sumx2);
2665         
2666         Float_t detay=sumy*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumxy*sumx4-sumx2y*sumx3)+
2667           sumx2*(sumxy*sumx3-sumx2y*sumx2);
2668         Float_t detaz=sumz*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumxz*sumx4-sumx2z*sumx3)+
2669           sumx2*(sumxz*sumx3-sumx2z*sumx2);
2670         
2671         Float_t detby=currentIndex*(sumxy*sumx4-sumx2y*sumx3)-sumy*(sumx*sumx4-sumx2*sumx3)+
2672           sumx2*(sumx*sumx2y-sumx2*sumxy);
2673         Float_t detbz=currentIndex*(sumxz*sumx4-sumx2z*sumx3)-sumz*(sumx*sumx4-sumx2*sumx3)+
2674           sumx2*(sumx*sumx2z-sumx2*sumxz);
2675         
2676         Float_t y=detay/det+centralPad;
2677         Float_t z=detaz/det;    
2678         Float_t by=detby/det; //y angle
2679         Float_t bz=detbz/det; //z angle
2680         sumy/=Float_t(currentIndex);
2681         sumz/=Float_t(currentIndex);
2682         
2683         AliComplexCluster cl;
2684         cl.fX=z;
2685         cl.fY=y;
2686         cl.fQ=sumq;
2687         cl.fSigmaX2=bz;
2688         cl.fSigmaY2=by;
2689         cl.fTracks[0]=ipart;
2690         
2691         AliTPCClustersRow * row = (fClustersArray->GetRow(sector,lastrow));
2692         if (row!=0) row->InsertCluster(&cl);
2693         currentIndex=0;
2694         lastrow=currentrow;
2695       } //end of calculating cluster for given row
2696                 
2697   } // end of loop over hits
2698   xxxx->Delete();
2699
2700 }
2701 //_______________________________________________________________________________
2702 void AliTPC::Digits2Reco(Int_t firstevent,Int_t lastevent)
2703 {
2704   // produces rec points from digits and writes them on the root file
2705   // AliTPCclusters.root
2706
2707   TDirectory *cwd = gDirectory;
2708
2709
2710   AliTPCParam *dig=(AliTPCParam *)gDirectory->Get("75x40_100x60");
2711   SetParam(dig);
2712   cout<<"AliTPC::Digits2Reco: TPC parameteres have been set"<<endl; 
2713   TFile *out;
2714   if(!gSystem->Getenv("CONFIG_FILE")){
2715     out=TFile::Open("AliTPCclusters.root","recreate");
2716   }
2717   else {
2718     const char *tmp1;
2719     const char *tmp2;
2720     char tmp3[80];
2721     tmp1=gSystem->Getenv("CONFIG_FILE_PREFIX");
2722     tmp2=gSystem->Getenv("CONFIG_OUTDIR");
2723     sprintf(tmp3,"%s%s/AliTPCclusters.root",tmp1,tmp2);
2724     out=TFile::Open(tmp3,"recreate");
2725   }
2726
2727   TStopwatch timer;
2728   cout<<"AliTPC::Digits2Reco - determination of rec points begins"<<endl;
2729   timer.Start();
2730   cwd->cd();
2731   for(Int_t iev=firstevent;iev<lastevent+1;iev++){
2732
2733     printf("Processing event %d\n",iev);
2734     Digits2Clusters(out,iev);
2735   }
2736   cout<<"AliTPC::Digits2Reco - determination of rec points ended"<<endl;
2737   timer.Stop();
2738   timer.Print();
2739   out->Close();
2740   cwd->cd(); 
2741
2742
2743 }