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