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