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