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