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