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