]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TPC/AliTPC.cxx
PPR version of the JETAN code (M. Lopez Noriega)
[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>
88cb7938 52#include <TVirtualMC.h>
2a336e15 53#include <TString.h>
54#include <TF2.h>
4c57c771 55#include <TStopwatch.h>
cc80f89e 56
cc80f89e 57#include "AliDigits.h"
88cb7938 58#include "AliMagF.h"
59#include "AliPoints.h"
60#include "AliRun.h"
61#include "AliRunLoader.h"
cc80f89e 62#include "AliSimDigits.h"
88cb7938 63#include "AliTPC.h"
64#include "AliTPC.h"
88cb7938 65#include "AliTPCDigitsArray.h"
66#include "AliTPCLoader.h"
67#include "AliTPCPRF2D.h"
68#include "AliTPCParamSR.h"
69#include "AliTPCRF1D.h"
be5ffbfe 70//#include "AliTPCTrackHits.h"
792bb11c 71#include "AliTPCTrackHitsV2.h"
88cb7938 72#include "AliTrackReference.h"
5d12ce38 73#include "AliMC.h"
85a5290f 74#include "AliTPCDigitizer.h"
0421c3d1 75#include "AliTPCBuffer.h"
76#include "AliTPCDDLRawData.h"
8c2b3fd7 77#include "AliLog.h"
39c8eb58 78
79
fe4da5cc 80ClassImp(AliTPC)
fe4da5cc 81//_____________________________________________________________________________
82AliTPC::AliTPC()
83{
84 //
85 // Default constructor
86 //
87 fIshunt = 0;
fe4da5cc 88 fHits = 0;
89 fDigits = 0;
fe4da5cc 90 fNsectors = 0;
cc80f89e 91 fDigitsArray = 0;
afc42102 92 fDefaults = 0;
792bb11c 93 fTrackHits = 0;
be5ffbfe 94 // fTrackHitsOld = 0;
8c2b3fd7 95#if ROOT_VERSION_CODE >= ROOT_VERSION(4,0,1)
96 fHitType = 4; // ROOT containers
97#else
98 fHitType = 2; //default CONTAINERS - based on ROOT structure
99#endif
407ff276 100 fTPCParam = 0;
101 fNoiseTable = 0;
792bb11c 102 fActiveSectors =0;
407ff276 103
fe4da5cc 104}
105
106//_____________________________________________________________________________
107AliTPC::AliTPC(const char *name, const char *title)
108 : AliDetector(name,title)
109{
110 //
111 // Standard constructor
112 //
113
114 //
115 // Initialise arrays of hits and digits
116 fHits = new TClonesArray("AliTPChit", 176);
5d12ce38 117 gAlice->GetMCApp()->AddHitList(fHits);
cc80f89e 118 fDigitsArray = 0;
afc42102 119 fDefaults = 0;
fe4da5cc 120 //
792bb11c 121 fTrackHits = new AliTPCTrackHitsV2;
39c8eb58 122 fTrackHits->SetHitPrecision(0.002);
123 fTrackHits->SetStepPrecision(0.003);
792bb11c 124 fTrackHits->SetMaxDistance(100);
125
be5ffbfe 126 //fTrackHitsOld = new AliTPCTrackHits; //MI - 13.09.2000
127 //fTrackHitsOld->SetHitPrecision(0.002);
128 //fTrackHitsOld->SetStepPrecision(0.003);
129 //fTrackHitsOld->SetMaxDistance(100);
792bb11c 130
407ff276 131 fNoiseTable =0;
39c8eb58 132
8c2b3fd7 133#if ROOT_VERSION_CODE >= ROOT_VERSION(4,0,1)
134 fHitType = 4; // ROOT containers
135#else
da33556f 136 fHitType = 2;
8c2b3fd7 137#endif
792bb11c 138 fActiveSectors = 0;
39c8eb58 139 //
fe4da5cc 140 // Initialise counters
cc80f89e 141 fNsectors = 0;
cc80f89e 142
fe4da5cc 143 //
144 fIshunt = 0;
145 //
146 // Initialise color attributes
147 SetMarkerColor(kYellow);
73042f01 148
149 //
150 // Set TPC parameters
151 //
152
afc42102 153
154 if (!strcmp(title,"Default")) {
155 fTPCParam = new AliTPCParamSR;
73042f01 156 } else {
8c2b3fd7 157 AliWarning("In Config.C you must set non-default parameters.");
73042f01 158 fTPCParam=0;
159 }
160
fe4da5cc 161}
162
163//_____________________________________________________________________________
9bdd974b 164AliTPC::AliTPC(const AliTPC& t):AliDetector(t){
165 //
166 // dummy copy constructor
167 //
168}
fe4da5cc 169AliTPC::~AliTPC()
170{
171 //
172 // TPC destructor
173 //
73042f01 174
fe4da5cc 175 fIshunt = 0;
176 delete fHits;
177 delete fDigits;
73042f01 178 delete fTPCParam;
39c8eb58 179 delete fTrackHits; //MI 15.09.2000
be5ffbfe 180 // delete fTrackHitsOld; //MI 10.12.2001
407ff276 181 if (fNoiseTable) delete [] fNoiseTable;
182
fe4da5cc 183}
184
fe4da5cc 185//_____________________________________________________________________________
186void AliTPC::AddHit(Int_t track, Int_t *vol, Float_t *hits)
187{
188 //
189 // Add a hit to the list
190 //
39c8eb58 191 if (fHitType&1){
192 TClonesArray &lhits = *fHits;
193 new(lhits[fNhits++]) AliTPChit(fIshunt,track,vol,hits);
194 }
792bb11c 195 if (fHitType>1)
8c2b3fd7 196 AddHit2(track,vol,hits);
fe4da5cc 197}
88cb7938 198
fe4da5cc 199//_____________________________________________________________________________
200void AliTPC::BuildGeometry()
201{
cc80f89e 202
fe4da5cc 203 //
204 // Build TPC ROOT TNode geometry for the event display
205 //
73042f01 206 TNode *nNode, *nTop;
fe4da5cc 207 TTUBS *tubs;
208 Int_t i;
209 const int kColorTPC=19;
1283eee5 210 char name[5], title[25];
fe4da5cc 211 const Double_t kDegrad=TMath::Pi()/180;
1283eee5 212 const Double_t kRaddeg=180./TMath::Pi();
213
1283eee5 214
73042f01 215 Float_t innerOpenAngle = fTPCParam->GetInnerAngle();
216 Float_t outerOpenAngle = fTPCParam->GetOuterAngle();
1283eee5 217
73042f01 218 Float_t innerAngleShift = fTPCParam->GetInnerAngleShift();
219 Float_t outerAngleShift = fTPCParam->GetOuterAngleShift();
1283eee5 220
221 Int_t nLo = fTPCParam->GetNInnerSector()/2;
222 Int_t nHi = fTPCParam->GetNOuterSector()/2;
223
73042f01 224 const Double_t kloAng = (Double_t)TMath::Nint(innerOpenAngle*kRaddeg);
225 const Double_t khiAng = (Double_t)TMath::Nint(outerOpenAngle*kRaddeg);
226 const Double_t kloAngSh = (Double_t)TMath::Nint(innerAngleShift*kRaddeg);
227 const Double_t khiAngSh = (Double_t)TMath::Nint(outerAngleShift*kRaddeg);
1283eee5 228
229
73042f01 230 const Double_t kloCorr = 1/TMath::Cos(0.5*kloAng*kDegrad);
231 const Double_t khiCorr = 1/TMath::Cos(0.5*khiAng*kDegrad);
1283eee5 232
233 Double_t rl,ru;
234
235
fe4da5cc 236 //
237 // Get ALICE top node
fe4da5cc 238 //
1283eee5 239
73042f01 240 nTop=gAlice->GetGeometry()->GetNode("alice");
1283eee5 241
242 // inner sectors
243
cc80f89e 244 rl = fTPCParam->GetInnerRadiusLow();
245 ru = fTPCParam->GetInnerRadiusUp();
1283eee5 246
247
fe4da5cc 248 for(i=0;i<nLo;i++) {
249 sprintf(name,"LS%2.2d",i);
1283eee5 250 name[4]='\0';
251 sprintf(title,"TPC low sector %3d",i);
252 title[24]='\0';
253
73042f01 254 tubs = new TTUBS(name,title,"void",rl*kloCorr,ru*kloCorr,250.,
255 kloAng*(i-0.5)+kloAngSh,kloAng*(i+0.5)+kloAngSh);
fe4da5cc 256 tubs->SetNumberOfDivisions(1);
73042f01 257 nTop->cd();
258 nNode = new TNode(name,title,name,0,0,0,"");
259 nNode->SetLineColor(kColorTPC);
260 fNodes->Add(nNode);
fe4da5cc 261 }
1283eee5 262
fe4da5cc 263 // Outer sectors
1283eee5 264
cc80f89e 265 rl = fTPCParam->GetOuterRadiusLow();
266 ru = fTPCParam->GetOuterRadiusUp();
1283eee5 267
fe4da5cc 268 for(i=0;i<nHi;i++) {
269 sprintf(name,"US%2.2d",i);
1283eee5 270 name[4]='\0';
fe4da5cc 271 sprintf(title,"TPC upper sector %d",i);
1283eee5 272 title[24]='\0';
73042f01 273 tubs = new TTUBS(name,title,"void",rl*khiCorr,ru*khiCorr,250,
274 khiAng*(i-0.5)+khiAngSh,khiAng*(i+0.5)+khiAngSh);
fe4da5cc 275 tubs->SetNumberOfDivisions(1);
73042f01 276 nTop->cd();
277 nNode = new TNode(name,title,name,0,0,0,"");
278 nNode->SetLineColor(kColorTPC);
279 fNodes->Add(nNode);
fe4da5cc 280 }
cc80f89e 281
73042f01 282}
1283eee5 283
fe4da5cc 284//_____________________________________________________________________________
285void AliTPC::CreateMaterials()
286{
8c555625 287 //-----------------------------------------------
37831078 288 // Create Materials for for TPC simulations
8c555625 289 //-----------------------------------------------
290
291 //-----------------------------------------------------------------
292 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
293 //-----------------------------------------------------------------
1283eee5 294
73042f01 295 Int_t iSXFLD=gAlice->Field()->Integ();
296 Float_t sXMGMX=gAlice->Field()->Max();
1283eee5 297
298 Float_t amat[5]; // atomic numbers
299 Float_t zmat[5]; // z
300 Float_t wmat[5]; // proportions
301
302 Float_t density;
37831078 303 Float_t apure[2];
1283eee5 304
1283eee5 305
37831078 306 //***************** Gases *************************
307
308 //-------------------------------------------------
1283eee5 309 // pure gases
37831078 310 //-------------------------------------------------
1283eee5 311
37831078 312 // Neon
1283eee5 313
314
37831078 315 amat[0]= 20.18;
316 zmat[0]= 10.;
1283eee5 317 density = 0.0009;
37831078 318
319 apure[0]=amat[0];
1283eee5 320
37831078 321 AliMaterial(20,"Ne",amat[0],zmat[0],density,999.,999.);
1283eee5 322
37831078 323 // Argon
1283eee5 324
37831078 325 amat[0]= 39.948;
326 zmat[0]= 18.;
327 density = 0.001782;
1283eee5 328
37831078 329 apure[1]=amat[0];
1283eee5 330
37831078 331 AliMaterial(21,"Ar",amat[0],zmat[0],density,999.,999.);
332
1283eee5 333
334 //--------------------------------------------------------------
335 // gases - compounds
336 //--------------------------------------------------------------
337
338 Float_t amol[3];
339
37831078 340 // CO2
1283eee5 341
342 amat[0]=12.011;
343 amat[1]=15.9994;
344
345 zmat[0]=6.;
346 zmat[1]=8.;
347
348 wmat[0]=1.;
349 wmat[1]=2.;
350
351 density=0.001977;
352
353 amol[0] = amat[0]*wmat[0]+amat[1]*wmat[1];
354
355 AliMixture(10,"CO2",amat,zmat,density,-2,wmat);
e4e763b9 356
1283eee5 357 // CF4
358
359 amat[0]=12.011;
360 amat[1]=18.998;
361
362 zmat[0]=6.;
363 zmat[1]=9.;
364
365 wmat[0]=1.;
366 wmat[1]=4.;
367
368 density=0.003034;
369
370 amol[1] = amat[0]*wmat[0]+amat[1]*wmat[1];
371
372 AliMixture(11,"CF4",amat,zmat,density,-2,wmat);
373
37831078 374
1283eee5 375 // CH4
376
377 amat[0]=12.011;
378 amat[1]=1.;
379
380 zmat[0]=6.;
381 zmat[1]=1.;
382
383 wmat[0]=1.;
384 wmat[1]=4.;
385
386 density=0.000717;
387
388 amol[2] = amat[0]*wmat[0]+amat[1]*wmat[1];
389
390 AliMixture(12,"CH4",amat,zmat,density,-2,wmat);
391
392 //----------------------------------------------------------------
393 // gases - mixtures, ID >= 20 pure gases, <= 10 ID < 20 -compounds
394 //----------------------------------------------------------------
37831078 395
00d6d986 396 char namate[21]="";
1283eee5 397 density = 0.;
398 Float_t am=0;
399 Int_t nc;
9bdd974b 400 Float_t rho,absl,x0,buf[1];
1283eee5 401 Int_t nbuf;
37831078 402 Float_t a,z;
1283eee5 403
8c2b3fd7 404 for(nc = 0;nc<fNoComp;nc++) {
1283eee5 405
8c2b3fd7 406 // retrive material constants
1283eee5 407
8c2b3fd7 408 gMC->Gfmate((*fIdmate)[fMixtComp[nc]],namate,a,z,rho,x0,absl,buf,nbuf);
1283eee5 409
8c2b3fd7 410 amat[nc] = a;
411 zmat[nc] = z;
412
413 Int_t nnc = (fMixtComp[nc]>=20) ? fMixtComp[nc]%20 : fMixtComp[nc]%10;
414
415 am += fMixtProp[nc]*((fMixtComp[nc]>=20) ? apure[nnc] : amol[nnc]);
416 density += fMixtProp[nc]*rho; // density of the mixture
417
418 }
419
1283eee5 420 // mixture proportions by weight!
8c2b3fd7 421
422 for(nc = 0;nc<fNoComp;nc++) {
1283eee5 423
8c2b3fd7 424 Int_t nnc = (fMixtComp[nc]>=20) ? fMixtComp[nc]%20 : fMixtComp[nc]%10;
1283eee5 425
8c2b3fd7 426 wmat[nc] = fMixtProp[nc]*((fMixtComp[nc]>=20) ?
427 apure[nnc] : amol[nnc])/am;
37831078 428
8c2b3fd7 429 }
37831078 430
431 // Drift gases 1 - nonsensitive, 2 - sensitive
1283eee5 432
e4e763b9 433 // AliMixture(31,"Drift gas 1",amat,zmat,density,fNoComp,wmat);
434 // AliMixture(32,"Drift gas 2",amat,zmat,density,fNoComp,wmat);
435
436 amat[0]= 20.18;
437 amat[1]=12.011;
438 amat[2]=15.9994;
439
440 zmat[0]= 10.;
441 zmat[1]=6.;
442 zmat[2]=8.;
443
444 wmat[2] = wmat[1]*0.728;
445 wmat[1] *= 0.272;
446
447
448
449 AliMixture(31,"Drift gas 1",amat,zmat,density,3,wmat);
450 AliMixture(32,"Drift gas 2",amat,zmat,density,3,wmat);
1283eee5 451
1283eee5 452
37831078 453 // Air
454
e4e763b9 455 /* amat[0] = 14.61;
37831078 456 zmat[0] = 7.3;
457 density = 0.001205;
1283eee5 458
37831078 459 AliMaterial(24,"Air",amat[0],zmat[0],density,999.,999.);
e4e763b9 460 */
461
462
463 // Air (79% N 21% 0)
1283eee5 464
e4e763b9 465
466 amat[0]=15.9994;
467 amat[1]=14.007;
468 zmat[0]=8.;
469 zmat[1]=7.;
470 density = 0.001205;
471
472 wmat[0]=0.233;
473 wmat[1]=0.767;
474
475 AliMixture(24,"Air",amat,zmat,density,2,wmat);
1283eee5 476
477 //----------------------------------------------------------------------
478 // solid materials
479 //----------------------------------------------------------------------
480
1283eee5 481
37831078 482 // Kevlar C14H22O2N2
1283eee5 483
37831078 484 amat[0] = 12.011;
485 amat[1] = 1.;
486 amat[2] = 15.999;
487 amat[3] = 14.006;
1283eee5 488
37831078 489 zmat[0] = 6.;
490 zmat[1] = 1.;
491 zmat[2] = 8.;
492 zmat[3] = 7.;
493
494 wmat[0] = 14.;
495 wmat[1] = 22.;
496 wmat[2] = 2.;
497 wmat[3] = 2.;
498
499 density = 1.45;
500
501 AliMixture(34,"Kevlar",amat,zmat,density,-4,wmat);
502
503 // NOMEX
1283eee5 504
37831078 505 amat[0] = 12.011;
506 amat[1] = 1.;
507 amat[2] = 15.999;
508 amat[3] = 14.006;
509
510 zmat[0] = 6.;
511 zmat[1] = 1.;
512 zmat[2] = 8.;
513 zmat[3] = 7.;
514
515 wmat[0] = 14.;
516 wmat[1] = 22.;
517 wmat[2] = 2.;
518 wmat[3] = 2.;
519
520 density = 0.03;
1283eee5 521
fe4da5cc 522
37831078 523 AliMixture(35,"NOMEX",amat,zmat,density,-4,wmat);
524
525 // Makrolon C16H18O3
526
527 amat[0] = 12.011;
528 amat[1] = 1.;
529 amat[2] = 15.999;
1283eee5 530
37831078 531 zmat[0] = 6.;
532 zmat[1] = 1.;
533 zmat[2] = 8.;
534
535 wmat[0] = 16.;
536 wmat[1] = 18.;
537 wmat[2] = 3.;
538
539 density = 1.2;
540
541 AliMixture(36,"Makrolon",amat,zmat,density,-3,wmat);
542
1283eee5 543 // Mylar C5H4O2
544
545 amat[0]=12.011;
546 amat[1]=1.;
547 amat[2]=15.9994;
548
549 zmat[0]=6.;
550 zmat[1]=1.;
551 zmat[2]=8.;
552
553 wmat[0]=5.;
554 wmat[1]=4.;
555 wmat[2]=2.;
556
557 density = 1.39;
fe4da5cc 558
37831078 559 AliMixture(37, "Mylar",amat,zmat,density,-3,wmat);
1283eee5 560
ba1d05f9 561 // SiO2 - used later for the glass fiber
1283eee5 562
37831078 563 amat[0]=28.086;
564 amat[1]=15.9994;
1283eee5 565
37831078 566 zmat[0]=14.;
567 zmat[1]=8.;
1283eee5 568
37831078 569 wmat[0]=1.;
570 wmat[1]=2.;
1283eee5 571
1283eee5 572
ba1d05f9 573 AliMixture(38,"SiO2",amat,zmat,2.2,-2,wmat); //SiO2 - quartz (rho=2.2)
1283eee5 574
37831078 575 // Al
1283eee5 576
37831078 577 amat[0] = 26.98;
578 zmat[0] = 13.;
1283eee5 579
37831078 580 density = 2.7;
1283eee5 581
37831078 582 AliMaterial(40,"Al",amat[0],zmat[0],density,999.,999.);
1283eee5 583
37831078 584 // Si
1283eee5 585
37831078 586 amat[0] = 28.086;
9a3667bd 587 zmat[0] = 14.;
1283eee5 588
37831078 589 density = 2.33;
1283eee5 590
37831078 591 AliMaterial(41,"Si",amat[0],zmat[0],density,999.,999.);
1283eee5 592
37831078 593 // Cu
1283eee5 594
37831078 595 amat[0] = 63.546;
596 zmat[0] = 29.;
1283eee5 597
37831078 598 density = 8.96;
1283eee5 599
37831078 600 AliMaterial(42,"Cu",amat[0],zmat[0],density,999.,999.);
1283eee5 601
37831078 602 // Tedlar C2H3F
1283eee5 603
37831078 604 amat[0] = 12.011;
605 amat[1] = 1.;
606 amat[2] = 18.998;
1283eee5 607
37831078 608 zmat[0] = 6.;
609 zmat[1] = 1.;
610 zmat[2] = 9.;
1283eee5 611
37831078 612 wmat[0] = 2.;
613 wmat[1] = 3.;
614 wmat[2] = 1.;
1283eee5 615
37831078 616 density = 1.71;
1283eee5 617
37831078 618 AliMixture(43, "Tedlar",amat,zmat,density,-3,wmat);
1283eee5 619
1283eee5 620
37831078 621 // Plexiglas C5H8O2
1283eee5 622
37831078 623 amat[0]=12.011;
624 amat[1]=1.;
625 amat[2]=15.9994;
1283eee5 626
37831078 627 zmat[0]=6.;
628 zmat[1]=1.;
629 zmat[2]=8.;
1283eee5 630
37831078 631 wmat[0]=5.;
632 wmat[1]=8.;
633 wmat[2]=2.;
1283eee5 634
37831078 635 density=1.18;
1283eee5 636
37831078 637 AliMixture(44,"Plexiglas",amat,zmat,density,-3,wmat);
1283eee5 638
ba1d05f9 639 // Epoxy - C14 H20 O3
1283eee5 640
5a28a08f 641
642 amat[0]=12.011;
643 amat[1]=1.;
644 amat[2]=15.9994;
645
646 zmat[0]=6.;
647 zmat[1]=1.;
648 zmat[2]=8.;
649
ba1d05f9 650 wmat[0]=14.;
651 wmat[1]=20.;
5a28a08f 652 wmat[2]=3.;
653
ba1d05f9 654 density=1.25;
5a28a08f 655
656 AliMixture(45,"Epoxy",amat,zmat,density,-3,wmat);
37831078 657
ba1d05f9 658 // Carbon
659
660 amat[0]=12.011;
661 zmat[0]=6.;
662 density= 2.265;
663
664 AliMaterial(46,"C",amat[0],zmat[0],density,999.,999.);
665
666 // get epoxy
667
9bdd974b 668 gMC->Gfmate((*fIdmate)[45],namate,amat[1],zmat[1],rho,x0,absl,buf,nbuf);
ba1d05f9 669
670 // Carbon fiber
671
e4e763b9 672
673
674 amat[1]=12.011;
675 amat[2]=1.;
676 amat[3]=15.9994;
677
678 zmat[1]=6.;
679 zmat[2]=1.;
680 zmat[3]=8.;
681
682 wmat[0]=0.644; // by weight! C
683 wmat[1]=0.356; // epoxy altogether
684
685
686 wmat[3]=wmat[1]*0.203;
687 wmat[2]=wmat[1]*0.085;
688 wmat[1] *= 0.712;
689
ba1d05f9 690
691 density=0.5*(1.25+2.265);
692
e4e763b9 693 AliMixture(47,"Cfiber",amat,zmat,density,4,wmat);
ba1d05f9 694
695 // get SiO2
696
9bdd974b 697 gMC->Gfmate((*fIdmate)[38],namate,amat[0],zmat[0],rho,x0,absl,buf,nbuf);
ba1d05f9 698
e4e763b9 699
700 //
701 amat[0]=28.086;
702 amat[1]=15.9994;
703
704 zmat[0]=14.;
705 zmat[1]=8.;
706
707 //
708
709 amat[2]=12.011;
710 amat[3]=1.;
711 amat[4]=15.9994;
712
713 zmat[2]=6.;
714 zmat[3]=1.;
715 zmat[4]=8.;
716
ba1d05f9 717 wmat[0]=0.725; // by weight!
e4e763b9 718 wmat[1]=wmat[0]*0.533;
719 wmat[0] *=0.467;
720
721 wmat[2]=0.275;
722 wmat[3]=wmat[2]*0.085;
723 wmat[4]=wmat[2]*0.203;
724 wmat[2] *= 0.712;
ba1d05f9 725
726 density=1.7;
727
e4e763b9 728 AliMixture(39,"G10",amat,zmat,density,5,wmat);
ba1d05f9 729
730
731
732
37831078 733 //----------------------------------------------------------
734 // tracking media for gases
735 //----------------------------------------------------------
736
737 AliMedium(0, "Air", 24, 0, iSXFLD, sXMGMX, 10., 999., .1, .01, .1);
738 AliMedium(1, "Drift gas 1", 31, 0, iSXFLD, sXMGMX, 10., 999.,.1,.001, .001);
739 AliMedium(2, "Drift gas 2", 32, 1, iSXFLD, sXMGMX, 10., 999.,.1,.001, .001);
740 AliMedium(3,"CO2",10,0, iSXFLD, sXMGMX, 10., 999.,.1, .001, .001);
741
742 //-----------------------------------------------------------
743 // tracking media for solids
744 //-----------------------------------------------------------
745
746 AliMedium(4,"Al",40,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
747 AliMedium(5,"Kevlar",34,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
748 AliMedium(6,"Nomex",35,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
749 AliMedium(7,"Makrolon",36,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
750 AliMedium(8,"Mylar",37,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
751 AliMedium(9,"Tedlar",43,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
752 AliMedium(10,"Cu",42,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
753 AliMedium(11,"Si",41,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
754 AliMedium(12,"G10",39,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
755 AliMedium(13,"Plexiglas",44,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
5a28a08f 756 AliMedium(14,"Epoxy",45,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
ba1d05f9 757 AliMedium(15,"Cfiber",47,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
1283eee5 758
fe4da5cc 759}
760
407ff276 761void AliTPC::GenerNoise(Int_t tablesize)
762{
763 //
764 //Generate table with noise
765 //
766 if (fTPCParam==0) {
767 // error message
768 fNoiseDepth=0;
769 return;
770 }
771 if (fNoiseTable) delete[] fNoiseTable;
772 fNoiseTable = new Float_t[tablesize];
773 fNoiseDepth = tablesize;
774 fCurrentNoise =0; //!index of the noise in the noise table
775
776 Float_t norm = fTPCParam->GetNoise()*fTPCParam->GetNoiseNormFac();
777 for (Int_t i=0;i<tablesize;i++) fNoiseTable[i]= gRandom->Gaus(0,norm);
778}
779
780Float_t AliTPC::GetNoise()
781{
782 // get noise from table
783 // if ((fCurrentNoise%10)==0)
784 // fCurrentNoise= gRandom->Rndm()*fNoiseDepth;
785 if (fCurrentNoise>=fNoiseDepth) fCurrentNoise=0;
786 return fNoiseTable[fCurrentNoise++];
787 //gRandom->Gaus(0, fTPCParam->GetNoise()*fTPCParam->GetNoiseNormFac());
788}
789
790
9bdd974b 791Bool_t AliTPC::IsSectorActive(Int_t sec) const
792bb11c 792{
793 //
794 // check if the sector is active
795 if (!fActiveSectors) return kTRUE;
796 else return fActiveSectors[sec];
797}
798
799void AliTPC::SetActiveSectors(Int_t * sectors, Int_t n)
800{
801 // activate interesting sectors
88cb7938 802 SetTreeAddress();//just for security
792bb11c 803 if (fActiveSectors) delete [] fActiveSectors;
804 fActiveSectors = new Bool_t[fTPCParam->GetNSector()];
805 for (Int_t i=0;i<fTPCParam->GetNSector();i++) fActiveSectors[i]=kFALSE;
806 for (Int_t i=0;i<n;i++)
807 if ((sectors[i]>=0) && sectors[i]<fTPCParam->GetNSector()) fActiveSectors[sectors[i]]=kTRUE;
808
809}
810
12d8d654 811void AliTPC::SetActiveSectors(Int_t flag)
792bb11c 812{
813 //
814 // activate sectors which were hitted by tracks
815 //loop over tracks
88cb7938 816 SetTreeAddress();//just for security
792bb11c 817 if (fHitType==0) return; // if Clones hit - not short volume ID information
818 if (fActiveSectors) delete [] fActiveSectors;
819 fActiveSectors = new Bool_t[fTPCParam->GetNSector()];
12d8d654 820 if (flag) {
821 for (Int_t i=0;i<fTPCParam->GetNSector();i++) fActiveSectors[i]=kTRUE;
822 return;
823 }
792bb11c 824 for (Int_t i=0;i<fTPCParam->GetNSector();i++) fActiveSectors[i]=kFALSE;
825 TBranch * branch=0;
88cb7938 826 if (TreeH() == 0x0)
827 {
8c2b3fd7 828 AliFatal("Can not find TreeH in folder");
88cb7938 829 return;
830 }
831 if (fHitType>1) branch = TreeH()->GetBranch("TPC2");
832 else branch = TreeH()->GetBranch("TPC");
833 Stat_t ntracks = TreeH()->GetEntries();
792bb11c 834 // loop over all hits
8c2b3fd7 835 AliDebug(1,Form("Got %d tracks",ntracks));
88cb7938 836
8c2b3fd7 837 for(Int_t track=0;track<ntracks;track++) {
792bb11c 838 ResetHits();
839 //
840 if (fTrackHits && fHitType&4) {
88cb7938 841 TBranch * br1 = TreeH()->GetBranch("fVolumes");
842 TBranch * br2 = TreeH()->GetBranch("fNVolumes");
792bb11c 843 br1->GetEvent(track);
844 br2->GetEvent(track);
845 Int_t *volumes = fTrackHits->GetVolumes();
846 for (Int_t j=0;j<fTrackHits->GetNVolumes(); j++)
847 fActiveSectors[volumes[j]]=kTRUE;
848 }
849
850 //
be5ffbfe 851// if (fTrackHitsOld && fHitType&2) {
852// TBranch * br = TreeH()->GetBranch("fTrackHitsInfo");
853// br->GetEvent(track);
854// AliObjectArray * ar = fTrackHitsOld->fTrackHitsInfo;
855// for (UInt_t j=0;j<ar->GetSize();j++){
856// fActiveSectors[((AliTrackHitsInfo*)ar->At(j))->fVolumeID] =kTRUE;
857// }
858// }
792bb11c 859 }
792bb11c 860}
861
862
863
fe4da5cc 864
0421c3d1 865//_____________________________________________________________________________
866void AliTPC::Digits2Raw()
867{
868// convert digits of the current event to raw data
869
870 static const Int_t kThreshold = 0;
871 static const Bool_t kCompress = kTRUE;
872
873 fLoader->LoadDigits();
874 TTree* digits = fLoader->TreeD();
875 if (!digits) {
8c2b3fd7 876 AliError("No digits tree");
0421c3d1 877 return;
878 }
879
880 AliSimDigits digarr;
881 AliSimDigits* digrow = &digarr;
882 digits->GetBranch("Segment")->SetAddress(&digrow);
883
884 const char* fileName = "AliTPCDDL.dat";
885 AliTPCBuffer* buffer = new AliTPCBuffer(fileName);
886 //Verbose level
887 // 0: Silent
888 // 1: cout messages
889 // 2: txt files with digits
890 //BE CAREFUL, verbose level 2 MUST be used only for debugging and
891 //it is highly suggested to use this mode only for debugging digits files
892 //reasonably small, because otherwise the size of the txt files can reach
893 //quickly several MB wasting time and disk space.
894 buffer->SetVerbose(0);
895
896 Int_t nEntries = Int_t(digits->GetEntries());
897 Int_t previousSector = -1;
898 Int_t subSector = 0;
899 for (Int_t i = 0; i < nEntries; i++) {
900 digits->GetEntry(i);
901 Int_t sector, row;
902 fTPCParam->AdjustSectorRow(digarr.GetID(), sector, row);
903 if(previousSector != sector) {
904 subSector = 0;
905 previousSector = sector;
906 }
907
908 if (sector < 36) { //inner sector [0;35]
909 if (row != 30) {
910 //the whole row is written into the output file
911 buffer->WriteRowBinary(kThreshold, digrow, 0, 0, 0,
912 sector, subSector, row);
913 } else {
914 //only the pads in the range [37;48] are written into the output file
915 buffer->WriteRowBinary(kThreshold, digrow, 37, 48, 1,
916 sector, subSector, row);
917 subSector = 1;
918 //only the pads outside the range [37;48] are written into the output file
919 buffer->WriteRowBinary(kThreshold, digrow, 37, 48, 2,
920 sector, subSector, row);
921 }//end else
922
923 } else { //outer sector [36;71]
924 if (row == 54) subSector = 2;
925 if ((row != 27) && (row != 76)) {
926 buffer->WriteRowBinary(kThreshold, digrow, 0, 0, 0,
927 sector, subSector, row);
928 } else if (row == 27) {
8c2b3fd7 929 //only the pads outside the range [43;46] are written into the output file
930 buffer->WriteRowBinary(kThreshold, digrow, 43, 46, 2,
0421c3d1 931 sector, subSector, row);
8c2b3fd7 932 subSector = 1;
933 //only the pads in the range [43;46] are written into the output file
934 buffer->WriteRowBinary(kThreshold, digrow, 43, 46, 1,
0421c3d1 935 sector, subSector, row);
936 } else if (row == 76) {
8c2b3fd7 937 //only the pads outside the range [33;88] are written into the output file
938 buffer->WriteRowBinary(kThreshold, digrow, 33, 88, 2,
939 sector, subSector, row);
940 subSector = 3;
941 //only the pads in the range [33;88] are written into the output file
942 buffer->WriteRowBinary(kThreshold, digrow, 33, 88, 1,
0421c3d1 943 sector, subSector, row);
944 }
945 }//end else
946 }//end for
947
948 delete buffer;
949 fLoader->UnloadDigits();
950
951 AliTPCDDLRawData rawWriter;
952 rawWriter.SetVerbose(0);
953
954 rawWriter.RawData(fileName);
955 gSystem->Unlink(fileName);
956
957 if (kCompress) {
8c2b3fd7 958 AliInfo("Compressing raw data");
0421c3d1 959 rawWriter.RawDataCompDecompress(kTRUE);
960 gSystem->Unlink("Statistics");
961 }
962}
963
964
0a61bf9d 965
85a5290f 966//______________________________________________________________________
9bdd974b 967AliDigitizer* AliTPC::CreateDigitizer(AliRunDigitizer* manager) const
85a5290f 968{
969 return new AliTPCDigitizer(manager);
970}
0a61bf9d 971//__
176aff27 972void AliTPC::SDigits2Digits2(Int_t /*eventnumber*/)
0a61bf9d 973{
974 //create digits from summable digits
407ff276 975 GenerNoise(500000); //create teble with noise
0a61bf9d 976
977 //conect tree with sSDigits
88cb7938 978 TTree *t = fLoader->TreeS();
979
8c2b3fd7 980 if (t == 0x0) {
981 fLoader->LoadSDigits("READ");
982 t = fLoader->TreeS();
983 if (t == 0x0) {
984 AliError("Can not get input TreeS");
985 return;
986 }
987 }
88cb7938 988
989 if (fLoader->TreeD() == 0x0) fLoader->MakeTree("D");
990
0a61bf9d 991 AliSimDigits digarr, *dummy=&digarr;
88cb7938 992 TBranch* sdb = t->GetBranch("Segment");
8c2b3fd7 993 if (sdb == 0x0) {
994 AliError("Can not find branch with segments in TreeS.");
995 return;
996 }
88cb7938 997
998 sdb->SetAddress(&dummy);
999
0a61bf9d 1000 Stat_t nentries = t->GetEntries();
1001
5f16d237 1002 // set zero suppression
1003
1004 fTPCParam->SetZeroSup(2);
1005
1006 // get zero suppression
1007
1008 Int_t zerosup = fTPCParam->GetZeroSup();
1009
1010 //make tree with digits
1011
0a61bf9d 1012 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1013 arr->SetClass("AliSimDigits");
1014 arr->Setup(fTPCParam);
88cb7938 1015 arr->MakeTree(fLoader->TreeD());
0a61bf9d 1016
88cb7938 1017 AliTPCParam * par = fTPCParam;
5f16d237 1018
0a61bf9d 1019 //Loop over segments of the TPC
5f16d237 1020
0a61bf9d 1021 for (Int_t n=0; n<nentries; n++) {
1022 t->GetEvent(n);
1023 Int_t sec, row;
1024 if (!par->AdjustSectorRow(digarr.GetID(),sec,row)) {
8c2b3fd7 1025 AliWarning(Form("Invalid segment ID ! %d",digarr.GetID()));
0a61bf9d 1026 continue;
1027 }
8c2b3fd7 1028 if (!IsSectorActive(sec)) continue;
1029
0a61bf9d 1030 AliSimDigits * digrow =(AliSimDigits*) arr->CreateRow(sec,row);
1031 Int_t nrows = digrow->GetNRows();
1032 Int_t ncols = digrow->GetNCols();
1033
1034 digrow->ExpandBuffer();
1035 digarr.ExpandBuffer();
1036 digrow->ExpandTrackBuffer();
1037 digarr.ExpandTrackBuffer();
1038
5f16d237 1039
407ff276 1040 Short_t * pamp0 = digarr.GetDigits();
1041 Int_t * ptracks0 = digarr.GetTracks();
1042 Short_t * pamp1 = digrow->GetDigits();
1043 Int_t * ptracks1 = digrow->GetTracks();
1044 Int_t nelems =nrows*ncols;
1045 Int_t saturation = fTPCParam->GetADCSat();
1046 //use internal structure of the AliDigits - for speed reason
1047 //if you cahnge implementation
1048 //of the Alidigits - it must be rewriten -
1049 for (Int_t i= 0; i<nelems; i++){
407ff276 1050 Float_t q = TMath::Nint(Float_t(*pamp0)/16.+GetNoise());
1051 if (q>zerosup){
1052 if (q>saturation) q=saturation;
1053 *pamp1=(Short_t)q;
8c2b3fd7 1054
407ff276 1055 ptracks1[0]=ptracks0[0];
1056 ptracks1[nelems]=ptracks0[nelems];
1057 ptracks1[2*nelems]=ptracks0[2*nelems];
1058 }
1059 pamp0++;
1060 pamp1++;
1061 ptracks0++;
1062 ptracks1++;
1063 }
5f16d237 1064
5f16d237 1065 arr->StoreRow(sec,row);
1066 arr->ClearRow(sec,row);
5f16d237 1067 }
0a61bf9d 1068
0a61bf9d 1069
5f16d237 1070 //write results
88cb7938 1071 fLoader->WriteDigits("OVERWRITE");
5f16d237 1072
88cb7938 1073 delete arr;
afc42102 1074}
1075//__________________________________________________________________
1076void AliTPC::SetDefaults(){
9bdd974b 1077 //
1078 // setting the defaults
1079 //
afc42102 1080
afc42102 1081 // Set response functions
1082
88cb7938 1083 //
024a7e64 1084 AliRunLoader* rl = (AliRunLoader*)fLoader->GetEventFolder()->FindObject(AliRunLoader::GetRunLoaderName());
88cb7938 1085 rl->CdGAFile();
2ab0c725 1086 AliTPCParamSR *param=(AliTPCParamSR*)gDirectory->Get("75x40_100x60");
7a09f434 1087 if(param){
8c2b3fd7 1088 AliInfo("You are using 2 pad-length geom hits with 3 pad-lenght geom digits...");
7a09f434 1089 delete param;
1090 param = new AliTPCParamSR();
1091 }
1092 else {
1093 param=(AliTPCParamSR*)gDirectory->Get("75x40_100x60_150x60");
1094 }
1095 if(!param){
8c2b3fd7 1096 AliFatal("No TPC parameters found");
7a09f434 1097 }
1098
1099
2ab0c725 1100 AliTPCPRF2D * prfinner = new AliTPCPRF2D;
f03e3423 1101 AliTPCPRF2D * prfouter1 = new AliTPCPRF2D;
1102 AliTPCPRF2D * prfouter2 = new AliTPCPRF2D;
2ab0c725 1103 AliTPCRF1D * rf = new AliTPCRF1D(kTRUE);
2ab0c725 1104 rf->SetGauss(param->GetZSigma(),param->GetZWidth(),1.);
1105 rf->SetOffset(3*param->GetZSigma());
1106 rf->Update();
afc42102 1107
1108 TDirectory *savedir=gDirectory;
2ab0c725 1109 TFile *f=TFile::Open("$ALICE_ROOT/TPC/AliTPCprf2d.root");
8c2b3fd7 1110 if (!f->IsOpen())
1111 AliFatal("Can't open $ALICE_ROOT/TPC/AliTPCprf2d.root !");
2a336e15 1112
1113 TString s;
2ab0c725 1114 prfinner->Read("prf_07504_Gati_056068_d02");
2a336e15 1115 //PH Set different names
1116 s=prfinner->GetGRF()->GetName();
1117 s+="in";
1118 prfinner->GetGRF()->SetName(s.Data());
1119
f03e3423 1120 prfouter1->Read("prf_10006_Gati_047051_d03");
2a336e15 1121 s=prfouter1->GetGRF()->GetName();
1122 s+="out1";
1123 prfouter1->GetGRF()->SetName(s.Data());
1124
f03e3423 1125 prfouter2->Read("prf_15006_Gati_047051_d03");
2a336e15 1126 s=prfouter2->GetGRF()->GetName();
1127 s+="out2";
1128 prfouter2->GetGRF()->SetName(s.Data());
1129
2ab0c725 1130 f->Close();
afc42102 1131 savedir->cd();
1132
2ab0c725 1133 param->SetInnerPRF(prfinner);
f03e3423 1134 param->SetOuter1PRF(prfouter1);
1135 param->SetOuter2PRF(prfouter2);
2ab0c725 1136 param->SetTimeRF(rf);
1137
afc42102 1138 // set fTPCParam
1139
2ab0c725 1140 SetParam(param);
1141
afc42102 1142
1143 fDefaults = 1;
1144
1145}
1146//__________________________________________________________________
85a5290f 1147void AliTPC::Hits2Digits()
1148{
9bdd974b 1149 //
1150 // creates digits from hits
1151 //
1152
85a5290f 1153 fLoader->LoadHits("read");
1154 fLoader->LoadDigits("recreate");
1155 AliRunLoader* runLoader = fLoader->GetRunLoader();
1156
1157 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
1158 runLoader->GetEvent(iEvent);
1159 SetActiveSectors();
1160 Hits2Digits(iEvent);
1161 }
1162
1163 fLoader->UnloadHits();
1164 fLoader->UnloadDigits();
1165}
1166//__________________________________________________________________
afc42102 1167void AliTPC::Hits2Digits(Int_t eventnumber)
1168{
1169 //----------------------------------------------------
1170 // Loop over all sectors for a single event
1171 //----------------------------------------------------
024a7e64 1172 AliRunLoader* rl = (AliRunLoader*)fLoader->GetEventFolder()->FindObject(AliRunLoader::GetRunLoaderName());
88cb7938 1173 rl->GetEvent(eventnumber);
8c2b3fd7 1174 if (fLoader->TreeH() == 0x0) {
1175 if(fLoader->LoadHits()) {
1176 AliError("Can not load hits.");
1177 }
1178 }
88cb7938 1179 SetTreeAddress();
1180
8c2b3fd7 1181 if (fLoader->TreeD() == 0x0 ) {
1182 fLoader->MakeTree("D");
1183 if (fLoader->TreeD() == 0x0 ) {
1184 AliError("Can not get TreeD");
1185 return;
1186 }
1187 }
afc42102 1188
1189 if(fDefaults == 0) SetDefaults(); // check if the parameters are set
407ff276 1190 GenerNoise(500000); //create teble with noise
2ab0c725 1191
1192 //setup TPCDigitsArray
afc42102 1193
1194 if(GetDigitsArray()) delete GetDigitsArray();
8c2b3fd7 1195
2ab0c725 1196 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1197 arr->SetClass("AliSimDigits");
afc42102 1198 arr->Setup(fTPCParam);
88cb7938 1199
1200 arr->MakeTree(fLoader->TreeD());
2ab0c725 1201 SetDigitsArray(arr);
1202
afc42102 1203 fDigitsSwitch=0; // standard digits
2ab0c725 1204
8c2b3fd7 1205 for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++)
1206 if (IsSectorActive(isec)) {
1207 AliDebug(1,Form("Hits2Digits","Sector %d is active.",isec));
1208 Hits2DigitsSector(isec);
1209 }
1210 else {
1211 AliDebug(1,Form("Hits2Digits","Sector %d is NOT active.",isec));
1212 }
1213
88cb7938 1214 fLoader->WriteDigits("OVERWRITE");
f2a509af 1215
1216//this line prevents the crash in the similar one
1217//on the beginning of this method
1218//destructor attempts to reset the tree, which is deleted by the loader
1219//need to be redesign
8c2b3fd7 1220 if(GetDigitsArray()) delete GetDigitsArray();
1221 SetDigitsArray(0x0);
f2a509af 1222
8c555625 1223}
1224
f8cf550c 1225//__________________________________________________________________
0a61bf9d 1226void AliTPC::Hits2SDigits2(Int_t eventnumber)
f8cf550c 1227{
1228
1229 //-----------------------------------------------------------
1230 // summable digits - 16 bit "ADC", no noise, no saturation
1231 //-----------------------------------------------------------
1232
8c2b3fd7 1233 //----------------------------------------------------
1234 // Loop over all sectors for a single event
1235 //----------------------------------------------------
88cb7938 1236
1237 AliRunLoader* rl = fLoader->GetRunLoader();
1238
1239 rl->GetEvent(eventnumber);
8c2b3fd7 1240 if (fLoader->TreeH() == 0x0) {
1241 if(fLoader->LoadHits()) {
1242 AliError("Can not load hits.");
1243 return;
1244 }
1245 }
88cb7938 1246 SetTreeAddress();
f8cf550c 1247
afc42102 1248
8c2b3fd7 1249 if (fLoader->TreeS() == 0x0 ) {
1250 fLoader->MakeTree("S");
1251 }
88cb7938 1252
afc42102 1253 if(fDefaults == 0) SetDefaults();
88cb7938 1254
407ff276 1255 GenerNoise(500000); //create table with noise
afc42102 1256 //setup TPCDigitsArray
1257
1258 if(GetDigitsArray()) delete GetDigitsArray();
1259
88cb7938 1260
afc42102 1261 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1262 arr->SetClass("AliSimDigits");
1263 arr->Setup(fTPCParam);
88cb7938 1264 arr->MakeTree(fLoader->TreeS());
1265
afc42102 1266 SetDigitsArray(arr);
1267
afc42102 1268 fDigitsSwitch=1; // summable digits
5f16d237 1269
1270 // set zero suppression to "0"
1271
1272 fTPCParam->SetZeroSup(0);
f8cf550c 1273
8c2b3fd7 1274 for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++)
1275 if (IsSectorActive(isec)) {
1276 Hits2DigitsSector(isec);
1277 }
88cb7938 1278
8c2b3fd7 1279 fLoader->WriteSDigits("OVERWRITE");
88cb7938 1280
1281//this line prevents the crash in the similar one
1282//on the beginning of this method
1283//destructor attempts to reset the tree, which is deleted by the loader
1284//need to be redesign
8c2b3fd7 1285 if(GetDigitsArray()) delete GetDigitsArray();
1286 SetDigitsArray(0x0);
f8cf550c 1287}
0a61bf9d 1288//__________________________________________________________________
88cb7938 1289
0a61bf9d 1290void AliTPC::Hits2SDigits()
1291{
1292
1293 //-----------------------------------------------------------
1294 // summable digits - 16 bit "ADC", no noise, no saturation
1295 //-----------------------------------------------------------
1296
85a5290f 1297 fLoader->LoadHits("read");
1298 fLoader->LoadSDigits("recreate");
1299 AliRunLoader* runLoader = fLoader->GetRunLoader();
0a61bf9d 1300
85a5290f 1301 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
1302 runLoader->GetEvent(iEvent);
1303 SetTreeAddress();
1304 SetActiveSectors();
1305 Hits2SDigits2(iEvent);
1306 }
0a61bf9d 1307
85a5290f 1308 fLoader->UnloadHits();
1309 fLoader->UnloadSDigits();
0a61bf9d 1310}
fe4da5cc 1311//_____________________________________________________________________________
88cb7938 1312
8c555625 1313void AliTPC::Hits2DigitsSector(Int_t isec)
fe4da5cc 1314{
8c555625 1315 //-------------------------------------------------------------------
fe4da5cc 1316 // TPC conversion from hits to digits.
8c555625 1317 //-------------------------------------------------------------------
1318
1319 //-----------------------------------------------------------------
1320 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1321 //-----------------------------------------------------------------
1322
fe4da5cc 1323 //-------------------------------------------------------
8c555625 1324 // Get the access to the track hits
fe4da5cc 1325 //-------------------------------------------------------
8c555625 1326
afc42102 1327 // check if the parameters are set - important if one calls this method
1328 // directly, not from the Hits2Digits
1329
1330 if(fDefaults == 0) SetDefaults();
cc80f89e 1331
88cb7938 1332 TTree *tH = TreeH(); // pointer to the hits tree
8c2b3fd7 1333 if (tH == 0x0) {
1334 AliFatal("Can not find TreeH in folder");
1335 return;
1336 }
88cb7938 1337
73042f01 1338 Stat_t ntracks = tH->GetEntries();
8c555625 1339
1340 if( ntracks > 0){
1341
1342 //-------------------------------------------
1343 // Only if there are any tracks...
1344 //-------------------------------------------
1345
8c555625 1346 TObjArray **row;
fe4da5cc 1347
8c2b3fd7 1348 Int_t nrows =fTPCParam->GetNRow(isec);
8c555625 1349
8c2b3fd7 1350 row= new TObjArray* [nrows+2]; // 2 extra rows for cross talk
fe4da5cc 1351
8c2b3fd7 1352 MakeSector(isec,nrows,tH,ntracks,row);
8c555625 1353
8c2b3fd7 1354 //--------------------------------------------------------
1355 // Digitize this sector, row by row
1356 // row[i] is the pointer to the TObjArray of TVectors,
1357 // each one containing electrons accepted on this
1358 // row, assigned into tracks
1359 //--------------------------------------------------------
8c555625 1360
8c2b3fd7 1361 Int_t i;
8c555625 1362
8c2b3fd7 1363 if (fDigitsArray->GetTree()==0) {
1364 AliFatal("Tree not set in fDigitsArray");
1365 }
8c555625 1366
8c2b3fd7 1367 for (i=0;i<nrows;i++){
1368
1369 AliDigits * dig = fDigitsArray->CreateRow(isec,i);
8c555625 1370
8c2b3fd7 1371 DigitizeRow(i,isec,row);
8c555625 1372
8c2b3fd7 1373 fDigitsArray->StoreRow(isec,i);
8c555625 1374
8c2b3fd7 1375 Int_t ndig = dig->GetDigitSize();
88cb7938 1376
8c2b3fd7 1377 AliDebug(10,
1378 Form("*** Sector, row, compressed digits %d %d %d ***\n",
1379 isec,i,ndig));
792bb11c 1380
8c2b3fd7 1381 fDigitsArray->ClearRow(isec,i);
8c555625 1382
cc80f89e 1383
8c2b3fd7 1384 } // end of the sector digitization
8c555625 1385
8c2b3fd7 1386 for(i=0;i<nrows+2;i++){
1387 row[i]->Delete();
1388 delete row[i];
1389 }
cc80f89e 1390
8c2b3fd7 1391 delete [] row; // delete the array of pointers to TObjArray-s
8c555625 1392
1393 } // ntracks >0
8c555625 1394
cc80f89e 1395} // end of Hits2DigitsSector
8c555625 1396
8c555625 1397
8c555625 1398//_____________________________________________________________________________
cc80f89e 1399void AliTPC::DigitizeRow(Int_t irow,Int_t isec,TObjArray **rows)
8c555625 1400{
1401 //-----------------------------------------------------------
1402 // Single row digitization, coupling from the neighbouring
1403 // rows taken into account
1404 //-----------------------------------------------------------
1405
1406 //-----------------------------------------------------------------
1407 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
cc80f89e 1408 // Modified: Marian Ivanov GSI Darmstadt, m.ivanov@gsi.de
8c555625 1409 //-----------------------------------------------------------------
1410
8c555625 1411 Float_t zerosup = fTPCParam->GetZeroSup();
8c2b3fd7 1412
cc80f89e 1413 fCurrentIndex[1]= isec;
8c555625 1414
8c555625 1415
73042f01 1416 Int_t nofPads = fTPCParam->GetNPads(isec,irow);
1417 Int_t nofTbins = fTPCParam->GetMaxTBin();
1418 Int_t indexRange[4];
8c555625 1419 //
1420 // Integrated signal for this row
1421 // and a single track signal
cc80f89e 1422 //
de61d5d5 1423
8c2b3fd7 1424 TMatrix *m1 = new TMatrix(0,nofPads,0,nofTbins); // integrated
1425 TMatrix *m2 = new TMatrix(0,nofPads,0,nofTbins); // single
8c555625 1426 //
8c2b3fd7 1427 TMatrix &total = *m1;
8c555625 1428
1429 // Array of pointers to the label-signal list
1430
73042f01 1431 Int_t nofDigits = nofPads*nofTbins; // number of digits for this row
1432 Float_t **pList = new Float_t* [nofDigits];
8c555625 1433
1434 Int_t lp;
cc80f89e 1435 Int_t i1;
73042f01 1436 for(lp=0;lp<nofDigits;lp++)pList[lp]=0; // set all pointers to NULL
8c555625 1437 //
cc80f89e 1438 //calculate signal
1439 //
b584c7dd 1440 Int_t row1=irow;
1441 Int_t row2=irow+2;
cc80f89e 1442 for (Int_t row= row1;row<=row2;row++){
1443 Int_t nTracks= rows[row]->GetEntries();
1444 for (i1=0;i1<nTracks;i1++){
1445 fCurrentIndex[2]= row;
b584c7dd 1446 fCurrentIndex[3]=irow+1;
1447 if (row==irow+1){
cc80f89e 1448 m2->Zero(); // clear single track signal matrix
73042f01 1449 Float_t trackLabel = GetSignal(rows[row],i1,m2,m1,indexRange);
1450 GetList(trackLabel,nofPads,m2,indexRange,pList);
cc80f89e 1451 }
73042f01 1452 else GetSignal(rows[row],i1,0,m1,indexRange);
cc80f89e 1453 }
8c555625 1454 }
cc80f89e 1455
8c555625 1456 Int_t tracks[3];
8c555625 1457
cc80f89e 1458 AliDigits *dig = fDigitsArray->GetRow(isec,irow);
de61d5d5 1459 Int_t gi=-1;
1460 Float_t fzerosup = zerosup+0.5;
1461 for(Int_t it=0;it<nofTbins;it++){
de61d5d5 1462 for(Int_t ip=0;ip<nofPads;ip++){
1463 gi++;
8c2b3fd7 1464 Float_t q=total(ip,it);
f8cf550c 1465 if(fDigitsSwitch == 0){
407ff276 1466 q+=GetNoise();
de61d5d5 1467 if(q <=fzerosup) continue; // do not fill zeros
68771f83 1468 q = TMath::Nint(q);
f8cf550c 1469 if(q > fTPCParam->GetADCSat()) q = fTPCParam->GetADCSat(); // saturation
cc80f89e 1470
f8cf550c 1471 }
1472
1473 else {
8c2b3fd7 1474 if(q <= 0.) continue; // do not fill zeros
1475 if(q>2000.) q=2000.;
1476 q *= 16.;
1477 q = TMath::Nint(q);
f8cf550c 1478 }
8c555625 1479
1480 //
1481 // "real" signal or electronic noise (list = -1)?
1482 //
1483
1484 for(Int_t j1=0;j1<3;j1++){
407ff276 1485 tracks[j1] = (pList[gi]) ?(Int_t)(*(pList[gi]+j1)) : -2;
8c555625 1486 }
1487
cc80f89e 1488//Begin_Html
1489/*
1490 <A NAME="AliDigits"></A>
1491 using of AliDigits object
1492*/
1493//End_Html
1494 dig->SetDigitFast((Short_t)q,it,ip);
8c2b3fd7 1495 if (fDigitsArray->IsSimulated()) {
1496 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[0],it,ip,0);
1497 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[1],it,ip,1);
1498 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[2],it,ip,2);
1499 }
8c555625 1500
1501 } // end of loop over time buckets
1502 } // end of lop over pads
1503
1504 //
1505 // This row has been digitized, delete nonused stuff
1506 //
1507
73042f01 1508 for(lp=0;lp<nofDigits;lp++){
8c555625 1509 if(pList[lp]) delete [] pList[lp];
1510 }
1511
1512 delete [] pList;
1513
1514 delete m1;
1515 delete m2;
8c555625 1516
1517} // end of DigitizeRow
cc80f89e 1518
8c555625 1519//_____________________________________________________________________________
cc80f89e 1520
de61d5d5 1521Float_t AliTPC::GetSignal(TObjArray *p1, Int_t ntr,
8c2b3fd7 1522 TMatrix *m1, TMatrix *m2,Int_t *indexRange)
8c555625 1523{
1524
1525 //---------------------------------------------------------------
1526 // Calculates 2-D signal (pad,time) for a single track,
1527 // returns a pointer to the signal matrix and the track label
1528 // No digitization is performed at this level!!!
1529 //---------------------------------------------------------------
1530
1531 //-----------------------------------------------------------------
1532 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
cc80f89e 1533 // Modified: Marian Ivanov
8c555625 1534 //-----------------------------------------------------------------
1535
8c2b3fd7 1536 TVector *tv;
de61d5d5 1537
8c2b3fd7 1538 tv = (TVector*)p1->At(ntr); // pointer to a track
1539 TVector &v = *tv;
8c555625 1540
1541 Float_t label = v(0);
b584c7dd 1542 Int_t centralPad = (fTPCParam->GetNPads(fCurrentIndex[1],fCurrentIndex[3]-1)-1)/2;
8c555625 1543
e61fd20d 1544 Int_t nElectrons = (tv->GetNrows()-1)/5;
73042f01 1545 indexRange[0]=9999; // min pad
1546 indexRange[1]=-1; // max pad
1547 indexRange[2]=9999; //min time
1548 indexRange[3]=-1; // max time
8c555625 1549
8c2b3fd7 1550 TMatrix &signal = *m1;
1551 TMatrix &total = *m2;
8c555625 1552 //
1553 // Loop over all electrons
1554 //
8c555625 1555 for(Int_t nel=0; nel<nElectrons; nel++){
e61fd20d 1556 Int_t idx=nel*5;
cc80f89e 1557 Float_t aval = v(idx+4);
1558 Float_t eltoadcfac=aval*fTPCParam->GetTotalNormFac();
e61fd20d 1559 Float_t xyz[4]={v(idx+1),v(idx+2),v(idx+3),v(idx+5)};
de61d5d5 1560 Int_t n = ((AliTPCParamSR*)fTPCParam)->CalcResponseFast(xyz,fCurrentIndex,fCurrentIndex[3]);
1561
1562 Int_t *index = fTPCParam->GetResBin(0);
1563 Float_t *weight = & (fTPCParam->GetResWeight(0));
1564
1565 if (n>0) for (Int_t i =0; i<n; i++){
8c2b3fd7 1566 Int_t pad=index[1]+centralPad; //in digit coordinates central pad has coordinate 0
1567
1568 if (pad>=0){
1569 Int_t time=index[2];
1570 Float_t qweight = *(weight)*eltoadcfac;
1571
1572 if (m1!=0) signal(pad,time)+=qweight;
1573 total(pad,time)+=qweight;
1574 if (indexRange[0]>pad) indexRange[0]=pad;
1575 if (indexRange[1]<pad) indexRange[1]=pad;
1576 if (indexRange[2]>time) indexRange[2]=time;
1577 if (indexRange[3]<time) indexRange[3]=time;
1578
1579 index+=3;
1580 weight++;
1581
1582 }
cc80f89e 1583 }
8c555625 1584 } // end of loop over electrons
cc80f89e 1585
8c555625 1586 return label; // returns track label when finished
1587}
1588
1589//_____________________________________________________________________________
8c2b3fd7 1590void AliTPC::GetList(Float_t label,Int_t np,TMatrix *m,
de61d5d5 1591 Int_t *indexRange, Float_t **pList)
8c555625 1592{
1593 //----------------------------------------------------------------------
1594 // Updates the list of tracks contributing to digits for a given row
1595 //----------------------------------------------------------------------
1596
1597 //-----------------------------------------------------------------
1598 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1599 //-----------------------------------------------------------------
1600
8c2b3fd7 1601 TMatrix &signal = *m;
8c555625 1602
1603 // lop over nonzero digits
1604
73042f01 1605 for(Int_t it=indexRange[2];it<indexRange[3]+1;it++){
1606 for(Int_t ip=indexRange[0];ip<indexRange[1]+1;ip++){
8c555625 1607
1608
8c2b3fd7 1609 // accept only the contribution larger than 500 electrons (1/2 s_noise)
921bf71a 1610
8c2b3fd7 1611 if(signal(ip,it)<0.5) continue;
921bf71a 1612
8c2b3fd7 1613 Int_t globalIndex = it*np+ip; // globalIndex starts from 0!
8c555625 1614
8c2b3fd7 1615 if(!pList[globalIndex]){
8c555625 1616
8c2b3fd7 1617 //
1618 // Create new list (6 elements - 3 signals and 3 labels),
1619 //
8c555625 1620
8c2b3fd7 1621 pList[globalIndex] = new Float_t [6];
8c555625 1622
8c2b3fd7 1623 // set list to -1
1624
1625 *pList[globalIndex] = -1.;
1626 *(pList[globalIndex]+1) = -1.;
1627 *(pList[globalIndex]+2) = -1.;
1628 *(pList[globalIndex]+3) = -1.;
1629 *(pList[globalIndex]+4) = -1.;
1630 *(pList[globalIndex]+5) = -1.;
1631
1632 *pList[globalIndex] = label;
1633 *(pList[globalIndex]+3) = signal(ip,it);
1634 }
1635 else {
8c555625 1636
8c2b3fd7 1637 // check the signal magnitude
8c555625 1638
8c2b3fd7 1639 Float_t highest = *(pList[globalIndex]+3);
1640 Float_t middle = *(pList[globalIndex]+4);
1641 Float_t lowest = *(pList[globalIndex]+5);
1642
1643 //
1644 // compare the new signal with already existing list
1645 //
1646
1647 if(signal(ip,it)<lowest) continue; // neglect this track
8c555625 1648
8c2b3fd7 1649 //
8c555625 1650
8c2b3fd7 1651 if (signal(ip,it)>highest){
1652 *(pList[globalIndex]+5) = middle;
1653 *(pList[globalIndex]+4) = highest;
1654 *(pList[globalIndex]+3) = signal(ip,it);
1655
1656 *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
1657 *(pList[globalIndex]+1) = *pList[globalIndex];
1658 *pList[globalIndex] = label;
1659 }
1660 else if (signal(ip,it)>middle){
1661 *(pList[globalIndex]+5) = middle;
1662 *(pList[globalIndex]+4) = signal(ip,it);
1663
1664 *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
1665 *(pList[globalIndex]+1) = label;
1666 }
1667 else{
1668 *(pList[globalIndex]+5) = signal(ip,it);
1669 *(pList[globalIndex]+2) = label;
1670 }
1671 }
1672
8c555625 1673 } // end of loop over pads
1674 } // end of loop over time bins
1675
8c555625 1676}//end of GetList
1677//___________________________________________________________________
1678void AliTPC::MakeSector(Int_t isec,Int_t nrows,TTree *TH,
1679 Stat_t ntracks,TObjArray **row)
1680{
1681
1682 //-----------------------------------------------------------------
1683 // Prepares the sector digitization, creates the vectors of
1684 // tracks for each row of this sector. The track vector
1685 // contains the track label and the position of electrons.
1686 //-----------------------------------------------------------------
1687
1688 //-----------------------------------------------------------------
1689 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1690 //-----------------------------------------------------------------
1691
cc80f89e 1692 Float_t gasgain = fTPCParam->GetGasGain();
8c555625 1693 Int_t i;
e61fd20d 1694 Float_t xyz[5];
8c555625 1695
1696 AliTPChit *tpcHit; // pointer to a sigle TPC hit
39c8eb58 1697 //MI change
1698 TBranch * branch=0;
792bb11c 1699 if (fHitType>1) branch = TH->GetBranch("TPC2");
39c8eb58 1700 else branch = TH->GetBranch("TPC");
1701
8c555625 1702
1703 //----------------------------------------------
1704 // Create TObjArray-s, one for each row,
8c2b3fd7 1705 // each TObjArray will store the TVectors
1706 // of electrons, one TVectors per each track.
8c555625 1707 //----------------------------------------------
1708
b584c7dd 1709 Int_t *nofElectrons = new Int_t [nrows+2]; // electron counter for each row
8c2b3fd7 1710 TVector **tracks = new TVector* [nrows+2]; //pointers to the track vectors
de61d5d5 1711
b584c7dd 1712 for(i=0; i<nrows+2; i++){
8c555625 1713 row[i] = new TObjArray;
f74bb6f5 1714 nofElectrons[i]=0;
1715 tracks[i]=0;
8c555625 1716 }
8c555625 1717
37831078 1718
1719
8c555625 1720 //--------------------------------------------------------------------
1721 // Loop over tracks, the "track" contains the full history
1722 //--------------------------------------------------------------------
8c2b3fd7 1723
8c555625 1724 Int_t previousTrack,currentTrack;
1725 previousTrack = -1; // nothing to store so far!
1726
1727 for(Int_t track=0;track<ntracks;track++){
39c8eb58 1728 Bool_t isInSector=kTRUE;
8c555625 1729 ResetHits();
792bb11c 1730 isInSector = TrackInVolume(isec,track);
39c8eb58 1731 if (!isInSector) continue;
1732 //MI change
1733 branch->GetEntry(track); // get next track
8c2b3fd7 1734
39c8eb58 1735 //M.I. changes
8c555625 1736
39c8eb58 1737 tpcHit = (AliTPChit*)FirstHit(-1);
8c555625 1738
1739 //--------------------------------------------------------------
1740 // Loop over hits
1741 //--------------------------------------------------------------
1742
8c555625 1743
39c8eb58 1744 while(tpcHit){
8c555625 1745
1746 Int_t sector=tpcHit->fSector; // sector number
39c8eb58 1747 if(sector != isec){
1748 tpcHit = (AliTPChit*) NextHit();
1749 continue;
1750 }
8c555625 1751
8c2b3fd7 1752 currentTrack = tpcHit->Track(); // track number
39c8eb58 1753
8c2b3fd7 1754 if(currentTrack != previousTrack){
8c555625 1755
8c2b3fd7 1756 // store already filled fTrack
8c555625 1757
8c2b3fd7 1758 for(i=0;i<nrows+2;i++){
1759 if(previousTrack != -1){
1760 if(nofElectrons[i]>0){
1761 TVector &v = *tracks[i];
1762 v(0) = previousTrack;
e61fd20d 1763 tracks[i]->ResizeTo(5*nofElectrons[i]+1); // shrink if necessary
8c2b3fd7 1764 row[i]->Add(tracks[i]);
1765 }
1766 else {
1767 delete tracks[i]; // delete empty TVector
1768 tracks[i]=0;
1769 }
1770 }
1771
1772 nofElectrons[i]=0;
e61fd20d 1773 tracks[i] = new TVector(601); // TVectors for the next fTrack
8c2b3fd7 1774
1775 } // end of loop over rows
8c555625 1776
8c2b3fd7 1777 previousTrack=currentTrack; // update track label
1778 }
8c555625 1779
8c2b3fd7 1780 Int_t qI = (Int_t) (tpcHit->fQ); // energy loss (number of electrons)
8c555625 1781
8c2b3fd7 1782 //---------------------------------------------------
1783 // Calculate the electron attachment probability
1784 //---------------------------------------------------
8c555625 1785
cc80f89e 1786
8c2b3fd7 1787 Float_t time = 1.e6*(fTPCParam->GetZLength()-TMath::Abs(tpcHit->Z()))
1788 /fTPCParam->GetDriftV();
1789 // in microseconds!
1790 Float_t attProb = fTPCParam->GetAttCoef()*
1791 fTPCParam->GetOxyCont()*time; // fraction!
8c555625 1792
8c2b3fd7 1793 //-----------------------------------------------
1794 // Loop over electrons
1795 //-----------------------------------------------
1796 Int_t index[3];
1797 index[1]=isec;
1798 for(Int_t nel=0;nel<qI;nel++){
1799 // skip if electron lost due to the attachment
1800 if((gRandom->Rndm(0)) < attProb) continue; // electron lost!
1801 xyz[0]=tpcHit->X();
1802 xyz[1]=tpcHit->Y();
1803 xyz[2]=tpcHit->Z();
1804 //
1805 // protection for the nonphysical avalanche size (10**6 maximum)
1806 //
1807 Double_t rn=TMath::Max(gRandom->Rndm(0),1.93e-22);
1808 xyz[3]= (Float_t) (-gasgain*TMath::Log(rn));
1809 index[0]=1;
1810
1811 TransportElectron(xyz,index);
1812 Int_t rowNumber;
1813 fTPCParam->GetPadRow(xyz,index);
e61fd20d 1814 // Electron track time (for pileup simulation)
1815 xyz[4] = tpcHit->Time()/fTPCParam->GetTSample();
8c2b3fd7 1816 // row 0 - cross talk from the innermost row
1817 // row fNRow+1 cross talk from the outermost row
1818 rowNumber = index[2]+1;
1819 //transform position to local digit coordinates
1820 //relative to nearest pad row
1821 if ((rowNumber<0)||rowNumber>fTPCParam->GetNRow(isec)+1) continue;
1822 Float_t x1,y1;
1823 if (isec <fTPCParam->GetNInnerSector()) {
1824 x1 = xyz[1]*fTPCParam->GetInnerPadPitchWidth();
1825 y1 = fTPCParam->GetYInner(rowNumber);
1826 }
1827 else{
1828 x1=xyz[1]*fTPCParam->GetOuterPadPitchWidth();
1829 y1 = fTPCParam->GetYOuter(rowNumber);
1830 }
1831 // gain inefficiency at the wires edges - linear
1832 x1=TMath::Abs(x1);
1833 y1-=1.;
1834 if(x1>y1) xyz[3]*=TMath::Max(1.e-6,(y1-x1+1.));
1835
1836 nofElectrons[rowNumber]++;
1837 //----------------------------------
1838 // Expand vector if necessary
1839 //----------------------------------
1840 if(nofElectrons[rowNumber]>120){
1841 Int_t range = tracks[rowNumber]->GetNrows();
e61fd20d 1842 if((nofElectrons[rowNumber])>(range-1)/5){
8c2b3fd7 1843
e61fd20d 1844 tracks[rowNumber]->ResizeTo(range+500); // Add 100 electrons
fe4da5cc 1845 }
8c2b3fd7 1846 }
1847
1848 TVector &v = *tracks[rowNumber];
e61fd20d 1849 Int_t idx = 5*nofElectrons[rowNumber]-4;
8c2b3fd7 1850 Real_t * position = &(((TVector&)v)(idx)); //make code faster
e61fd20d 1851 memcpy(position,xyz,5*sizeof(Float_t));
8c2b3fd7 1852
1853 } // end of loop over electrons
39c8eb58 1854
8c2b3fd7 1855 tpcHit = (AliTPChit*)NextHit();
1856
1857 } // end of loop over hits
1858 } // end of loop over tracks
8c555625 1859
1860 //
1861 // store remaining track (the last one) if not empty
1862 //
8c2b3fd7 1863
1864 for(i=0;i<nrows+2;i++){
1865 if(nofElectrons[i]>0){
1866 TVector &v = *tracks[i];
1867 v(0) = previousTrack;
e61fd20d 1868 tracks[i]->ResizeTo(5*nofElectrons[i]+1); // shrink if necessary
8c2b3fd7 1869 row[i]->Add(tracks[i]);
1870 }
1871 else{
1872 delete tracks[i];
1873 tracks[i]=0;
1874 }
1875 }
1876
1877 delete [] tracks;
1878 delete [] nofElectrons;
8c555625 1879
cc80f89e 1880} // end of MakeSector
8c555625 1881
fe4da5cc 1882
1883//_____________________________________________________________________________
1884void AliTPC::Init()
1885{
1886 //
1887 // Initialise TPC detector after definition of geometry
1888 //
8c2b3fd7 1889 AliDebug(1,"*********************************************");
fe4da5cc 1890}
1891
1892//_____________________________________________________________________________
88cb7938 1893void AliTPC::MakeBranch(Option_t* option)
fe4da5cc 1894{
1895 //
1896 // Create Tree branches for the TPC.
1897 //
8c2b3fd7 1898 AliDebug(1,"");
fe4da5cc 1899 Int_t buffersize = 4000;
1900 char branchname[10];
1901 sprintf(branchname,"%s",GetName());
88cb7938 1902
1903 const char *h = strstr(option,"H");
8c2b3fd7 1904
88cb7938 1905 if ( h && (fHitType<=1) && (fHits == 0x0)) fHits = new TClonesArray("AliTPChit", 176);//skowron 20.06.03
1906
1907 AliDetector::MakeBranch(option);
8c2b3fd7 1908
5cf7bbad 1909 const char *d = strstr(option,"D");
8c2b3fd7 1910
1911 if (fDigits && fLoader->TreeD() && d) {
1912 MakeBranchInTree(gAlice->TreeD(), branchname, &fDigits, buffersize, 0);
1913 }
fe4da5cc 1914
88cb7938 1915 if (fHitType>1) MakeBranch2(option,0); // MI change 14.09.2000
fe4da5cc 1916}
1917
1918//_____________________________________________________________________________
1919void AliTPC::ResetDigits()
1920{
1921 //
1922 // Reset number of digits and the digits array for this detector
fe4da5cc 1923 //
1924 fNdigits = 0;
cc80f89e 1925 if (fDigits) fDigits->Clear();
fe4da5cc 1926}
1927
1928//_____________________________________________________________________________
1929void AliTPC::SetSecAL(Int_t sec)
1930{
8c555625 1931 //---------------------------------------------------
fe4da5cc 1932 // Activate/deactivate selection for lower sectors
8c555625 1933 //---------------------------------------------------
1934
1935 //-----------------------------------------------------------------
1936 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1937 //-----------------------------------------------------------------
fe4da5cc 1938 fSecAL = sec;
1939}
1940
1941//_____________________________________________________________________________
1942void AliTPC::SetSecAU(Int_t sec)
1943{
8c555625 1944 //----------------------------------------------------
fe4da5cc 1945 // Activate/deactivate selection for upper sectors
8c555625 1946 //---------------------------------------------------
1947
1948 //-----------------------------------------------------------------
1949 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1950 //-----------------------------------------------------------------
fe4da5cc 1951 fSecAU = sec;
1952}
1953
1954//_____________________________________________________________________________
1955void AliTPC::SetSecLows(Int_t s1,Int_t s2,Int_t s3,Int_t s4,Int_t s5, Int_t s6)
1956{
8c555625 1957 //----------------------------------------
fe4da5cc 1958 // Select active lower sectors
8c555625 1959 //----------------------------------------
1960
1961 //-----------------------------------------------------------------
1962 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1963 //-----------------------------------------------------------------
1964
fe4da5cc 1965 fSecLows[0] = s1;
1966 fSecLows[1] = s2;
1967 fSecLows[2] = s3;
1968 fSecLows[3] = s4;
1969 fSecLows[4] = s5;
1970 fSecLows[5] = s6;
1971}
1972
1973//_____________________________________________________________________________
1974void AliTPC::SetSecUps(Int_t s1,Int_t s2,Int_t s3,Int_t s4,Int_t s5, Int_t s6,
1975 Int_t s7, Int_t s8 ,Int_t s9 ,Int_t s10,
1976 Int_t s11 , Int_t s12)
1977{
8c555625 1978 //--------------------------------
fe4da5cc 1979 // Select active upper sectors
8c555625 1980 //--------------------------------
1981
1982 //-----------------------------------------------------------------
1983 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1984 //-----------------------------------------------------------------
1985
fe4da5cc 1986 fSecUps[0] = s1;
1987 fSecUps[1] = s2;
1988 fSecUps[2] = s3;
1989 fSecUps[3] = s4;
1990 fSecUps[4] = s5;
1991 fSecUps[5] = s6;
1992 fSecUps[6] = s7;
1993 fSecUps[7] = s8;
1994 fSecUps[8] = s9;
1995 fSecUps[9] = s10;
1996 fSecUps[10] = s11;
1997 fSecUps[11] = s12;
1998}
1999
2000//_____________________________________________________________________________
2001void AliTPC::SetSens(Int_t sens)
2002{
8c555625 2003
2004 //-------------------------------------------------------------
2005 // Activates/deactivates the sensitive strips at the center of
2006 // the pad row -- this is for the space-point resolution calculations
2007 //-------------------------------------------------------------
2008
2009 //-----------------------------------------------------------------
2010 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2011 //-----------------------------------------------------------------
2012
fe4da5cc 2013 fSens = sens;
2014}
2b06d5c3 2015
4b0fdcad 2016
73042f01 2017void AliTPC::SetSide(Float_t side=0.)
4b0fdcad 2018{
73042f01 2019 // choice of the TPC side
2020
4b0fdcad 2021 fSide = side;
2022
2023}
1283eee5 2024//____________________________________________________________________________
2025void AliTPC::SetGasMixt(Int_t nc,Int_t c1,Int_t c2,Int_t c3,Float_t p1,
2026 Float_t p2,Float_t p3)
2027{
fe4da5cc 2028
73042f01 2029 // gax mixture definition
2030
8c2b3fd7 2031 fNoComp = nc;
1283eee5 2032
8c2b3fd7 2033 fMixtComp[0]=c1;
2034 fMixtComp[1]=c2;
2035 fMixtComp[2]=c3;
1283eee5 2036
8c2b3fd7 2037 fMixtProp[0]=p1;
2038 fMixtProp[1]=p2;
2039 fMixtProp[2]=p3;
cc80f89e 2040}
2041//_____________________________________________________________________________
2042
2043void AliTPC::TransportElectron(Float_t *xyz, Int_t *index)
2044{
2045 //
2046 // electron transport taking into account:
2047 // 1. diffusion,
2048 // 2.ExB at the wires
2049 // 3. nonisochronity
2050 //
2051 // xyz and index must be already transformed to system 1
2052 //
2053
2054 fTPCParam->Transform1to2(xyz,index);
2055
2056 //add diffusion
2057 Float_t driftl=xyz[2];
2058 if(driftl<0.01) driftl=0.01;
2059 driftl=TMath::Sqrt(driftl);
73042f01 2060 Float_t sigT = driftl*(fTPCParam->GetDiffT());
2061 Float_t sigL = driftl*(fTPCParam->GetDiffL());
2062 xyz[0]=gRandom->Gaus(xyz[0],sigT);
2063 xyz[1]=gRandom->Gaus(xyz[1],sigT);
2064 xyz[2]=gRandom->Gaus(xyz[2],sigL);
cc80f89e 2065
2066 // ExB
2067
2068 if (fTPCParam->GetMWPCReadout()==kTRUE){
b584c7dd 2069 Float_t dx = fTPCParam->Transform2to2NearestWire(xyz,index);
cc80f89e 2070 xyz[1]+=dx*(fTPCParam->GetOmegaTau());
2071 }
b584c7dd 2072 //add nonisochronity (not implemented yet)
1283eee5 2073}
fe4da5cc 2074
fe4da5cc 2075ClassImp(AliTPChit)
2076
2077//_____________________________________________________________________________
2078AliTPChit::AliTPChit(Int_t shunt, Int_t track, Int_t *vol, Float_t *hits):
2079AliHit(shunt,track)
2080{
2081 //
2082 // Creates a TPC hit object
2083 //
2084 fSector = vol[0];
2085 fPadRow = vol[1];
2086 fX = hits[0];
2087 fY = hits[1];
2088 fZ = hits[2];
2089 fQ = hits[3];
e61fd20d 2090 fTime = hits[4];
fe4da5cc 2091}
2092
39c8eb58 2093//________________________________________________________________________
792bb11c 2094// Additional code because of the AliTPCTrackHitsV2
39c8eb58 2095
176aff27 2096void AliTPC::MakeBranch2(Option_t *option,const char */*file*/)
39c8eb58 2097{
2098 //
2099 // Create a new branch in the current Root Tree
2100 // The branch of fHits is automatically split
2101 // MI change 14.09.2000
8c2b3fd7 2102 AliDebug(1,"");
792bb11c 2103 if (fHitType<2) return;
39c8eb58 2104 char branchname[10];
2105 sprintf(branchname,"%s2",GetName());
2106 //
2107 // Get the pointer to the header
5cf7bbad 2108 const char *cH = strstr(option,"H");
39c8eb58 2109 //
8c2b3fd7 2110 if (fTrackHits && TreeH() && cH && fHitType&4) {
2111 AliDebug(1,"Making branch for Type 4 Hits");
88cb7938 2112 TreeH()->Branch(branchname,"AliTPCTrackHitsV2",&fTrackHits,fBufferSize,99);
8c2b3fd7 2113 }
792bb11c 2114
be5ffbfe 2115// if (fTrackHitsOld && TreeH() && cH && fHitType&2) {
2116// AliDebug(1,"Making branch for Type 2 Hits");
2117// AliObjectBranch * branch = new AliObjectBranch(branchname,"AliTPCTrackHits",&fTrackHitsOld,
2118// TreeH(),fBufferSize,99);
2119// TreeH()->GetListOfBranches()->Add(branch);
2120// }
39c8eb58 2121}
2122
2123void AliTPC::SetTreeAddress()
2124{
8c2b3fd7 2125 //Sets tree address for hits
2126 if (fHitType<=1) {
2127 if (fHits == 0x0 ) fHits = new TClonesArray("AliTPChit", 176);//skowron 20.06.03
2128 AliDetector::SetTreeAddress();
2129 }
792bb11c 2130 if (fHitType>1) SetTreeAddress2();
39c8eb58 2131}
2132
2133void AliTPC::SetTreeAddress2()
2134{
2135 //
2136 // Set branch address for the TrackHits Tree
2137 //
8c2b3fd7 2138 AliDebug(1,"");
88cb7938 2139
39c8eb58 2140 TBranch *branch;
2141 char branchname[20];
2142 sprintf(branchname,"%s2",GetName());
2143 //
2144 // Branch address for hit tree
88cb7938 2145 TTree *treeH = TreeH();
792bb11c 2146 if ((treeH)&&(fHitType&4)) {
39c8eb58 2147 branch = treeH->GetBranch(branchname);
8c2b3fd7 2148 if (branch) {
2149 branch->SetAddress(&fTrackHits);
2150 AliDebug(1,"fHitType&4 Setting");
2151 }
f2a509af 2152 else
8c2b3fd7 2153 AliDebug(1,"fHitType&4 Failed (can not find branch)");
f2a509af 2154
39c8eb58 2155 }
be5ffbfe 2156 // if ((treeH)&&(fHitType&2)) {
2157// branch = treeH->GetBranch(branchname);
2158// if (branch) {
2159// branch->SetAddress(&fTrackHitsOld);
2160// AliDebug(1,"fHitType&2 Setting");
2161// }
2162// else
2163// AliDebug(1,"fHitType&2 Failed (can not find branch)");
2164// }
b6e0d3fe 2165 //set address to TREETR
8c2b3fd7 2166
88cb7938 2167 TTree *treeTR = TreeTR();
b6e0d3fe 2168 if (treeTR && fTrackReferences) {
2169 branch = treeTR->GetBranch(GetName());
2170 if (branch) branch->SetAddress(&fTrackReferences);
2171 }
2172
39c8eb58 2173}
2174
2175void AliTPC::FinishPrimary()
2176{
792bb11c 2177 if (fTrackHits &&fHitType&4) fTrackHits->FlushHitStack();
be5ffbfe 2178 // if (fTrackHitsOld && fHitType&2) fTrackHitsOld->FlushHitStack();
39c8eb58 2179}
2180
2181
2182void AliTPC::AddHit2(Int_t track, Int_t *vol, Float_t *hits)
2183{
2184 //
2185 // add hit to the list
39c8eb58 2186 Int_t rtrack;
2187 if (fIshunt) {
5d12ce38 2188 int primary = gAlice->GetMCApp()->GetPrimary(track);
2189 gAlice->GetMCApp()->Particle(primary)->SetBit(kKeepBit);
39c8eb58 2190 rtrack=primary;
2191 } else {
2192 rtrack=track;
5d12ce38 2193 gAlice->GetMCApp()->FlagTrack(track);
39c8eb58 2194 }
792bb11c 2195 if (fTrackHits && fHitType&4)
39c8eb58 2196 fTrackHits->AddHitKartez(vol[0],rtrack, hits[0],
e61fd20d 2197 hits[1],hits[2],(Int_t)hits[3],hits[4]);
be5ffbfe 2198 // if (fTrackHitsOld &&fHitType&2 )
2199// fTrackHitsOld->AddHitKartez(vol[0],rtrack, hits[0],
2200// hits[1],hits[2],(Int_t)hits[3]);
792bb11c 2201
39c8eb58 2202}
2203
2204void AliTPC::ResetHits()
88cb7938 2205{
39c8eb58 2206 if (fHitType&1) AliDetector::ResetHits();
792bb11c 2207 if (fHitType>1) ResetHits2();
39c8eb58 2208}
2209
2210void AliTPC::ResetHits2()
2211{
2212 //
2213 //reset hits
792bb11c 2214 if (fTrackHits && fHitType&4) fTrackHits->Clear();
be5ffbfe 2215 // if (fTrackHitsOld && fHitType&2) fTrackHitsOld->Clear();
792bb11c 2216
39c8eb58 2217}
2218
2219AliHit* AliTPC::FirstHit(Int_t track)
2220{
792bb11c 2221 if (fHitType>1) return FirstHit2(track);
39c8eb58 2222 return AliDetector::FirstHit(track);
2223}
2224AliHit* AliTPC::NextHit()
2225{
9bdd974b 2226 //
2227 // gets next hit
2228 //
792bb11c 2229 if (fHitType>1) return NextHit2();
2230
39c8eb58 2231 return AliDetector::NextHit();
2232}
2233
2234AliHit* AliTPC::FirstHit2(Int_t track)
2235{
2236 //
2237 // Initialise the hit iterator
2238 // Return the address of the first hit for track
2239 // If track>=0 the track is read from disk
2240 // while if track<0 the first hit of the current
2241 // track is returned
2242 //
2243 if(track>=0) {
2244 gAlice->ResetHits();
88cb7938 2245 TreeH()->GetEvent(track);
39c8eb58 2246 }
2247 //
792bb11c 2248 if (fTrackHits && fHitType&4) {
39c8eb58 2249 fTrackHits->First();
2250 return fTrackHits->GetHit();
2251 }
be5ffbfe 2252 // if (fTrackHitsOld && fHitType&2) {
2253// fTrackHitsOld->First();
2254// return fTrackHitsOld->GetHit();
2255// }
792bb11c 2256
39c8eb58 2257 else return 0;
2258}
2259
2260AliHit* AliTPC::NextHit2()
2261{
2262 //
2263 //Return the next hit for the current track
2264
792bb11c 2265
be5ffbfe 2266// if (fTrackHitsOld && fHitType&2) {
2267// fTrackHitsOld->Next();
2268// return fTrackHitsOld->GetHit();
2269// }
39c8eb58 2270 if (fTrackHits) {
2271 fTrackHits->Next();
2272 return fTrackHits->GetHit();
2273 }
2274 else
2275 return 0;
2276}
2277
2278void AliTPC::LoadPoints(Int_t)
2279{
2280 //
2281 Int_t a = 0;
8c2b3fd7 2282
f2e8b846 2283 if(fHitType==1) AliDetector::LoadPoints(a);
2284 else LoadPoints2(a);
39c8eb58 2285}
2286
2287
2288void AliTPC::RemapTrackHitIDs(Int_t *map)
2289{
9bdd974b 2290 //
2291 // remapping
2292 //
39c8eb58 2293 if (!fTrackHits) return;
39c8eb58 2294
be5ffbfe 2295// if (fTrackHitsOld && fHitType&2){
2296// AliObjectArray * arr = fTrackHitsOld->fTrackHitsInfo;
2297// for (UInt_t i=0;i<arr->GetSize();i++){
2298// AliTrackHitsInfo * info = (AliTrackHitsInfo *)(arr->At(i));
2299// info->fTrackID = map[info->fTrackID];
2300// }
2301// }
2302// if (fTrackHitsOld && fHitType&4){
2303 if (fTrackHits && fHitType&4){
792bb11c 2304 TClonesArray * arr = fTrackHits->GetArray();;
2305 for (Int_t i=0;i<arr->GetEntriesFast();i++){
2306 AliTrackHitsParamV2 * info = (AliTrackHitsParamV2 *)(arr->At(i));
2307 info->fTrackID = map[info->fTrackID];
2308 }
2309 }
39c8eb58 2310}
2311
792bb11c 2312Bool_t AliTPC::TrackInVolume(Int_t id,Int_t track)
2313{
2314 //return bool information - is track in given volume
2315 //load only part of the track information
2316 //return true if current track is in volume
2317 //
2318 // return kTRUE;
be5ffbfe 2319 // if (fTrackHitsOld && fHitType&2) {
2320// TBranch * br = TreeH()->GetBranch("fTrackHitsInfo");
2321// br->GetEvent(track);
2322// AliObjectArray * ar = fTrackHitsOld->fTrackHitsInfo;
2323// for (UInt_t j=0;j<ar->GetSize();j++){
2324// if ( ((AliTrackHitsInfo*)ar->At(j))->fVolumeID==id) return kTRUE;
2325// }
2326// }
792bb11c 2327
2328 if (fTrackHits && fHitType&4) {
88cb7938 2329 TBranch * br1 = TreeH()->GetBranch("fVolumes");
2330 TBranch * br2 = TreeH()->GetBranch("fNVolumes");
792bb11c 2331 br2->GetEvent(track);
2332 br1->GetEvent(track);
2333 Int_t *volumes = fTrackHits->GetVolumes();
2334 Int_t nvolumes = fTrackHits->GetNVolumes();
2335 if (!volumes && nvolumes>0) {
8c2b3fd7 2336 AliWarning(Form("Problematic track\t%d\t%d",track,nvolumes));
792bb11c 2337 return kFALSE;
2338 }
2339 for (Int_t j=0;j<nvolumes; j++)
2340 if (volumes[j]==id) return kTRUE;
2341 }
2342
2343 if (fHitType&1) {
88cb7938 2344 TBranch * br = TreeH()->GetBranch("fSector");
792bb11c 2345 br->GetEvent(track);
2346 for (Int_t j=0;j<fHits->GetEntriesFast();j++){
2347 if ( ((AliTPChit*)fHits->At(j))->fSector==id) return kTRUE;
2348 }
2349 }
2350 return kFALSE;
2351
2352}
39c8eb58 2353
2354//_____________________________________________________________________________
2355void AliTPC::LoadPoints2(Int_t)
2356{
2357 //
2358 // Store x, y, z of all hits in memory
2359 //
be5ffbfe 2360 // if (fTrackHits == 0 && fTrackHitsOld==0) return;
2361 if (fTrackHits == 0 ) return;
39c8eb58 2362 //
792bb11c 2363 Int_t nhits =0;
2364 if (fHitType&4) nhits = fTrackHits->GetEntriesFast();
be5ffbfe 2365 // if (fHitType&2) nhits = fTrackHitsOld->GetEntriesFast();
792bb11c 2366
39c8eb58 2367 if (nhits == 0) return;
5d12ce38 2368 Int_t tracks = gAlice->GetMCApp()->GetNtrack();
39c8eb58 2369 if (fPoints == 0) fPoints = new TObjArray(tracks);
2370 AliHit *ahit;
2371 //
2372 Int_t *ntrk=new Int_t[tracks];
2373 Int_t *limi=new Int_t[tracks];
2374 Float_t **coor=new Float_t*[tracks];
2375 for(Int_t i=0;i<tracks;i++) {
2376 ntrk[i]=0;
2377 coor[i]=0;
2378 limi[i]=0;
2379 }
2380 //
2381 AliPoints *points = 0;
2382 Float_t *fp=0;
2383 Int_t trk;
2384 Int_t chunk=nhits/4+1;
2385 //
2386 // Loop over all the hits and store their position
2387 //
2388 ahit = FirstHit2(-1);
39c8eb58 2389 while (ahit){
39c8eb58 2390 trk=ahit->GetTrack();
2391 if(ntrk[trk]==limi[trk]) {
2392 //
2393 // Initialise a new track
2394 fp=new Float_t[3*(limi[trk]+chunk)];
2395 if(coor[trk]) {
2396 memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
2397 delete [] coor[trk];
2398 }
2399 limi[trk]+=chunk;
2400 coor[trk] = fp;
2401 } else {
2402 fp = coor[trk];
2403 }
2404 fp[3*ntrk[trk] ] = ahit->X();
2405 fp[3*ntrk[trk]+1] = ahit->Y();
2406 fp[3*ntrk[trk]+2] = ahit->Z();
2407 ntrk[trk]++;
2408 ahit = NextHit2();
2409 }
792bb11c 2410
2411
2412
39c8eb58 2413 //
2414 for(trk=0; trk<tracks; ++trk) {
2415 if(ntrk[trk]) {
2416 points = new AliPoints();
2417 points->SetMarkerColor(GetMarkerColor());
2418 points->SetMarkerSize(GetMarkerSize());
2419 points->SetDetector(this);
2420 points->SetParticle(trk);
2421 points->SetPolyMarker(ntrk[trk],coor[trk],GetMarkerStyle());
2422 fPoints->AddAt(points,trk);
2423 delete [] coor[trk];
2424 coor[trk]=0;
2425 }
2426 }
2427 delete [] coor;
2428 delete [] ntrk;
2429 delete [] limi;
2430}
2431
2432
2433//_____________________________________________________________________________
2434void AliTPC::LoadPoints3(Int_t)
2435{
2436 //
2437 // Store x, y, z of all hits in memory
2438 // - only intersection point with pad row
2439 if (fTrackHits == 0) return;
2440 //
2441 Int_t nhits = fTrackHits->GetEntriesFast();
2442 if (nhits == 0) return;
5d12ce38 2443 Int_t tracks = gAlice->GetMCApp()->GetNtrack();
39c8eb58 2444 if (fPoints == 0) fPoints = new TObjArray(2*tracks);
2445 fPoints->Expand(2*tracks);
2446 AliHit *ahit;
2447 //
2448 Int_t *ntrk=new Int_t[tracks];
2449 Int_t *limi=new Int_t[tracks];
2450 Float_t **coor=new Float_t*[tracks];
2451 for(Int_t i=0;i<tracks;i++) {
2452 ntrk[i]=0;
2453 coor[i]=0;
2454 limi[i]=0;
2455 }
2456 //
2457 AliPoints *points = 0;
2458 Float_t *fp=0;
2459 Int_t trk;
2460 Int_t chunk=nhits/4+1;
2461 //
2462 // Loop over all the hits and store their position
2463 //
2464 ahit = FirstHit2(-1);
39c8eb58 2465
2466 Int_t lastrow = -1;
2467 while (ahit){
39c8eb58 2468 trk=ahit->GetTrack();
2469 Float_t x[3]={ahit->X(),ahit->Y(),ahit->Z()};
2470 Int_t index[3]={1,((AliTPChit*)ahit)->fSector,0};
2471 Int_t currentrow = fTPCParam->GetPadRow(x,index) ;
2472 if (currentrow!=lastrow){
2473 lastrow = currentrow;
2474 //later calculate intersection point
2475 if(ntrk[trk]==limi[trk]) {
2476 //
2477 // Initialise a new track
2478 fp=new Float_t[3*(limi[trk]+chunk)];
2479 if(coor[trk]) {
2480 memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
2481 delete [] coor[trk];
2482 }
2483 limi[trk]+=chunk;
2484 coor[trk] = fp;
2485 } else {
2486 fp = coor[trk];
2487 }
2488 fp[3*ntrk[trk] ] = ahit->X();
2489 fp[3*ntrk[trk]+1] = ahit->Y();
2490 fp[3*ntrk[trk]+2] = ahit->Z();
2491 ntrk[trk]++;
2492 }
2493 ahit = NextHit2();
2494 }
2495
2496 //
2497 for(trk=0; trk<tracks; ++trk) {
2498 if(ntrk[trk]) {
2499 points = new AliPoints();
2500 points->SetMarkerColor(GetMarkerColor()+1);
2501 points->SetMarkerStyle(5);
2502 points->SetMarkerSize(0.2);
2503 points->SetDetector(this);
2504 points->SetParticle(trk);
39c8eb58 2505 points->SetPolyMarker(ntrk[trk],coor[trk],30);
2506 fPoints->AddAt(points,tracks+trk);
2507 delete [] coor[trk];
2508 coor[trk]=0;
2509 }
2510 }
2511 delete [] coor;
2512 delete [] ntrk;
2513 delete [] limi;
2514}
2515
2516
2517
88cb7938 2518AliLoader* AliTPC::MakeLoader(const char* topfoldername)
2519{
8c2b3fd7 2520 //Makes TPC loader
2521 fLoader = new AliTPCLoader(GetName(),topfoldername);
2522 return fLoader;
88cb7938 2523}
2524
42157e55 2525////////////////////////////////////////////////////////////////////////
2526AliTPCParam* AliTPC::LoadTPCParam(TFile *file) {
2527//
2528// load TPC paarmeters from a given file or create new if the object
2529// is not found there
88cb7938 2530// 12/05/2003 This method should be moved to the AliTPCLoader
2531// and one has to decide where to store the TPC parameters
2532// M.Kowalski
42157e55 2533 char paramName[50];
2534 sprintf(paramName,"75x40_100x60_150x60");
2535 AliTPCParam *paramTPC=(AliTPCParam*)file->Get(paramName);
2536 if (paramTPC) {
8c2b3fd7 2537 AliDebugClass(1,Form("TPC parameters %s found.",paramName));
42157e55 2538 } else {
8c2b3fd7 2539 AliWarningClass("TPC parameters not found. Create new (they may be incorrect)");
42157e55 2540 paramTPC = new AliTPCParamSR;
2541 }
2542 return paramTPC;
2543
2544// the older version of parameters can be accessed with this code.
2545// In some cases, we have old parameters saved in the file but
2546// digits were created with new parameters, it can be distinguish
2547// by the name of TPC TreeD. The code here is just for the case
2548// we would need to compare with old data, uncomment it if needed.
2549//
2550// char paramName[50];
2551// sprintf(paramName,"75x40_100x60");
2552// AliTPCParam *paramTPC=(AliTPCParam*)in->Get(paramName);
2553// if (paramTPC) {
2554// cout<<"TPC parameters "<<paramName<<" found."<<endl;
2555// } else {
2556// sprintf(paramName,"75x40_100x60_150x60");
2557// paramTPC=(AliTPCParam*)in->Get(paramName);
2558// if (paramTPC) {
2559// cout<<"TPC parameters "<<paramName<<" found."<<endl;
2560// } else {
2561// cerr<<"TPC parameters not found. Create new (they may be incorrect)."
2562// <<endl;
2563// paramTPC = new AliTPCParamSR;
2564// }
2565// }
2566// return paramTPC;
2567
2568}
2569
85a5290f 2570