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