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