]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/AliPHOSv1.cxx
forward declaration, replace assert by abort
[u/mrichter/AliRoot.git] / PHOS / AliPHOSv1.cxx
CommitLineData
7587f5a5 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
b2a60966 16/* $Id$ */
5f20d3fb 17
7587f5a5 18//_________________________________________________________________________
5f20d3fb 19// Implementation version v1 of PHOS Manager class
a3dfe79c 20//---
21// Layout EMC + PPSD has name GPS2:
ed4205d8 22// Produces cumulated hits
a3dfe79c 23//---
24// Layout EMC + CPV has name IHEP:
ed4205d8 25// Produces hits for CPV, cumulated hits
26//---
27// Layout EMC + CPV + PPSD has name GPS:
28// Produces hits for CPV, cumulated hits
29//---
5f20d3fb 30//*-- Author: Yves Schutz (SUBATECH)
b2a60966 31
7587f5a5 32
33// --- ROOT system ---
bea63bea 34
35#include "TBRIK.h"
36#include "TNode.h"
7587f5a5 37#include "TRandom.h"
94de3818 38#include "TTree.h"
7587f5a5 39
5f20d3fb 40
7587f5a5 41// --- Standard library ---
42
de9ec31b 43#include <stdio.h>
44#include <string.h>
45#include <stdlib.h>
46#include <strstream.h>
7587f5a5 47
48// --- AliRoot header files ---
49
50#include "AliPHOSv1.h"
51#include "AliPHOSHit.h"
52#include "AliPHOSDigit.h"
bea63bea 53#include "AliPHOSReconstructioner.h"
b37750a6 54#include "AliPHOSSDigitizer.h"
7587f5a5 55#include "AliRun.h"
56#include "AliConst.h"
94de3818 57#include "AliMC.h"
7587f5a5 58
59ClassImp(AliPHOSv1)
60
bea63bea 61//____________________________________________________________________________
02ab1add 62AliPHOSv1::AliPHOSv1():
63AliPHOSv0()
bea63bea 64{
5f20d3fb 65 // ctor
ed4205d8 66
67 fReconstructioner = 0;
68 fTrackSegmentMaker = 0;
037cc66d 69
bea63bea 70}
71
7587f5a5 72//____________________________________________________________________________
73AliPHOSv1::AliPHOSv1(const char *name, const char *title):
e04976bd 74AliPHOSv0(name,title)
7587f5a5 75{
5f20d3fb 76 // ctor : title is used to identify the layout
fa412d9b 77 // GPS2 = 5 modules (EMC + PPSD)
78 // IHEP = 5 modules (EMC + CPV )
ed4205d8 79 // MIXT = 4 modules (EMC + CPV ) and 1 module (EMC + PPSD)
5f20d3fb 80 //
ed4205d8 81 // We store hits :
5f20d3fb 82 // - fHits (the "normal" one), which retains the hits associated with
83 // the current primary particle being tracked
84 // (this array is reset after each primary has been tracked).
85 //
fa412d9b 86
5f20d3fb 87 fPinElectronicNoise = 0.010 ;
037cc66d 88 fDigitThreshold = 0.01 ; // 1 GeV
89 fDigitizeA= 0. ;
90 fDigitizeB = 10000000. ;
91
5f20d3fb 92
93 // We do not want to save in TreeH the raw hits
94 // But save the cumulated hits instead (need to create the branch myself)
95 // It is put in the Digit Tree because the TreeH is filled after each primary
fa412d9b 96 // and the TreeD at the end of the event (branch is set in FinishEvent() ).
5f20d3fb 97
ed4205d8 98 fHits= new TClonesArray("AliPHOSHit",1000) ;
5f20d3fb 99
ed4205d8 100 fNhits = 0 ;
5f20d3fb 101
ed4205d8 102 fReconstructioner = 0;
103 fTrackSegmentMaker = 0;
5f20d3fb 104
5f20d3fb 105 fIshunt = 1 ; // All hits are associated with primary particles
fa412d9b 106
5f20d3fb 107}
108
109//____________________________________________________________________________
110AliPHOSv1::AliPHOSv1(AliPHOSReconstructioner * Reconstructioner, const char *name, const char *title):
111 AliPHOSv0(name,title)
112{
113 // ctor : title is used to identify the layout
114 // GPS2 = 5 modules (EMC + PPSD)
5f20d3fb 115
116 fPinElectronicNoise = 0.010 ;
117
118 // We do not want to save in TreeH the raw hits
5f20d3fb 119
ed4205d8 120 fDigits = 0 ;
121 fHits= new TClonesArray("AliPHOSHit",1000) ;
b73f246d 122
ed4205d8 123 fNhits = 0 ;
5f20d3fb 124
125 fIshunt = 1 ; // All hits are associated with primary particles
126
127 // gets an instance of the geometry parameters class
128 fGeom = AliPHOSGeometry::GetInstance(title, "") ;
129
130 if (fGeom->IsInitialized() )
88bdfa12 131 cout << "AliPHOS" << Version() << " : PHOS geometry intialized for " << fGeom->GetName() << endl ;
5f20d3fb 132 else
fc879520 133 cout << "AliPHOS" << Version() << " : PHOS geometry initialization failed !" << endl ;
5f20d3fb 134
135 // Defining the PHOS Reconstructioner
136
137 fReconstructioner = Reconstructioner ;
138
7587f5a5 139}
b2a60966 140
7587f5a5 141//____________________________________________________________________________
bea63bea 142AliPHOSv1::~AliPHOSv1()
b2a60966 143{
bea63bea 144 // dtor
5f20d3fb 145
ed4205d8 146 if ( fHits) {
147 fHits->Delete() ;
148 delete fHits ;
149 fHits = 0 ;
8dfa469d 150 }
5f20d3fb 151
037cc66d 152 if ( fSDigits) {
153 fSDigits->Delete() ;
154 delete fSDigits ;
155 fSDigits = 0 ;
156 }
157
ed4205d8 158 if ( fDigits) {
159 fDigits->Delete() ;
160 delete fDigits ;
161 fDigits = 0 ;
162 }
5f20d3fb 163
ed4205d8 164 if ( fEmcRecPoints ) {
165 fEmcRecPoints->Delete() ;
166 delete fEmcRecPoints ;
167 fEmcRecPoints = 0 ;
168 }
169
170 if ( fPpsdRecPoints ) {
171 fPpsdRecPoints->Delete() ;
172 delete fPpsdRecPoints ;
173 fPpsdRecPoints = 0 ;
174 }
fad3e5b9 175
ed4205d8 176 if ( fTrackSegments ) {
177 fTrackSegments->Delete() ;
178 delete fTrackSegments ;
179 fTrackSegments = 0 ;
180 }
181
7587f5a5 182}
183
7587f5a5 184//____________________________________________________________________________
b37750a6 185void AliPHOSv1::AddHit(Int_t shunt, Int_t primary, Int_t tracknumber, Int_t Id, Float_t * hits)
bea63bea 186{
187 // Add a hit to the hit list.
5f20d3fb 188 // A PHOS hit is the sum of all hits in a single crystal
189 // or in a single PPSD gas cell
bea63bea 190
5f20d3fb 191 Int_t hitCounter ;
bea63bea 192 AliPHOSHit *newHit ;
5f20d3fb 193 AliPHOSHit *curHit ;
194 Bool_t deja = kFALSE ;
bea63bea 195
b37750a6 196 newHit = new AliPHOSHit(shunt, primary, tracknumber, Id, hits) ;
bea63bea 197
7854a24a 198 for ( hitCounter = fNhits-1 ; hitCounter >= 0 && !deja ; hitCounter-- ) {
ed4205d8 199 curHit = (AliPHOSHit*) (*fHits)[hitCounter] ;
b37750a6 200 if(curHit->GetPrimary() != primary) break ; // We add hits with the same primary, while GEANT treats primaries consequently
ed4205d8 201 if( *curHit == *newHit ) {
202 *curHit = *curHit + *newHit ;
203 deja = kTRUE ;
5f20d3fb 204 }
205 }
206
207 if ( !deja ) {
ed4205d8 208 new((*fHits)[fNhits]) AliPHOSHit(*newHit) ;
209 fNhits++ ;
5f20d3fb 210 }
211
bea63bea 212 delete newHit;
bea63bea 213}
214
ed4205d8 215//____________________________________________________________________________
037cc66d 216void AliPHOSv1::Hits2SDigits(){
b37750a6 217 char * fileSDigits = 0 ;
218 AliPHOSSDigitizer * sd = new AliPHOSSDigitizer(fileSDigits) ;
219 sd->SetPedestalParameter(fDigitizeA) ;
220 sd->SetSlopeParameter(fDigitizeB) ;
221 sd->Exec("") ;
222 delete sd ;
037cc66d 223}
b37750a6 224
037cc66d 225//____________________________________________________________________________
226void AliPHOSv1::SDigits2Digits(){
227 //Adds noise to the summable digits and removes everething below thresholds
228 //Note, that sDigits should be SORTED in accordance with abs ID.
229
230
231 gAlice->TreeS()->GetEvent(0) ;
037cc66d 232
ad8cfaf4 233 // First calculate noise induced by the PIN diode of the PbWO crystals
037cc66d 234 Int_t iCurSDigit = 0 ;
ad8cfaf4 235
037cc66d 236 //we assume, that there is al least one EMC digit...
550bee17 237 if(fSDigits->GetEntries() == 0) {
238 cout << "PHOS::SDigits2Digits> No SDigits !!! Do not produce Digits " << endl ;
239 return ;
240 }
037cc66d 241
550bee17 242 Int_t idCurSDigit = ((AliPHOSDigit *)fSDigits->At(0))->GetId() ;
037cc66d 243
244 Int_t absID ;
245 for(absID = 1; absID < fGeom->GetNModules()*fGeom->GetNPhi()*fGeom->GetNZ(); absID++){
037cc66d 246 Float_t noise = gRandom->Gaus(0., fPinElectronicNoise) ;
247 if(absID < idCurSDigit ){
037cc66d 248 if(noise >fDigitThreshold ){
037cc66d 249 new((*fDigits)[fNdigits]) AliPHOSDigit( -1,absID,Digitize(noise) ) ;
037cc66d 250 fNdigits++ ;
251 }
252 }
253 else{ //add noise and may be remove the true hit
037cc66d 254 Float_t signal = noise + Calibrate(((AliPHOSDigit *)fSDigits->At(iCurSDigit))->GetAmp()) ;
037cc66d 255 if( signal >fDigitThreshold ){
037cc66d 256 AliPHOSDigit * digit = (AliPHOSDigit*) fSDigits->At(iCurSDigit) ;
257 new((*fDigits)[fNdigits]) AliPHOSDigit( *digit ) ;
258 ((AliPHOSDigit *)fDigits->At(fNdigits))->SetAmp(Digitize(signal));
037cc66d 259 fNdigits++ ;
260 }
261
262 if(iCurSDigit < fSDigits->GetEntries()-1){
263 iCurSDigit++ ;
264 idCurSDigit = ((AliPHOSDigit*)fSDigits->At(iCurSDigit))->GetId() ;
265 }
266 else
267 idCurSDigit = 10000000; //no real hits left
268 }
ed4205d8 269
037cc66d 270 }
271
272 //remove PPSD/CPV digits below thresholds
273 Int_t idigit ;
274 for(idigit = iCurSDigit; idigit < fSDigits->GetEntries() ; idigit++){ //loop over CPV/PPSD digits
275
276 AliPHOSDigit * digit = (AliPHOSDigit *) fSDigits->At(idigit) ;
277 Float_t ene = Calibrate(digit->GetAmp()) ;
278
279 Int_t relid[4] ;
280 fGeom->AbsToRelNumbering(digit->GetId(), relid) ;
281 if ( relid[0] > fGeom->GetNCPVModules() ){ //ppsd
282 if ( ( (relid[1] > 0) && (ene > fPpsdEnergyThreshold)) || //PPSD digit
283 ( (relid[1] < 0) && (ene > fCpvEnergyThreshold ) ) ) //CPV digit
284 new((*fDigits)[fNdigits]) AliPHOSDigit( *digit ) ;
285 fNdigits++ ;
bea63bea 286 }
037cc66d 287 }
ed4205d8 288
bea63bea 289 fDigits->Compress() ;
ed4205d8 290
291 fNdigits = fDigits->GetEntries() ;
292 fDigits->Expand(fNdigits) ;
bea63bea 293
037cc66d 294 Int_t i ;
bea63bea 295 for (i = 0 ; i < fNdigits ; i++) {
037cc66d 296 AliPHOSDigit * digit = (AliPHOSDigit *) fDigits->At(i) ;
297 digit->SetIndexInList(i) ;
bea63bea 298 }
fa412d9b 299
ed4205d8 300 gAlice->TreeD()->Fill() ;
5f20d3fb 301
ed4205d8 302 gAlice->TreeD()->Write(0,TObject::kOverwrite) ;
303
304}
2ab0c725 305
5f20d3fb 306//___________________________________________________________________________
2ab0c725 307void AliPHOSv1::MakeBranch(Option_t* opt, char *file)
037cc66d 308{
309
5cf7bbad 310 const char *cH ;
5f20d3fb 311 // Create new branche in the current Root Tree in the digit Tree
5f20d3fb 312 AliDetector::MakeBranch(opt) ;
037cc66d 313
314
315 cH = strstr(opt,"S");
316 //Create a branch for SDigits
317 if( cH ){
318 char branchname[20];
319 sprintf(branchname,"%s",GetName());
320 if(fSDigits)
321 fSDigits->Clear();
ad8cfaf4 322
037cc66d 323 fnSdigits = 0 ;
037cc66d 324 gAlice->MakeBranchInTree(gAlice->TreeS(),branchname,&fSDigits,fBufferSize,file);
fa412d9b 325 }
ed4205d8 326
037cc66d 327 cH = strstr(opt,"D");
328 //Create a branch for Digits
329 if( cH ){
330 char branchname[20];
331 sprintf(branchname,"%s",GetName());
ad8cfaf4 332
333 if(fDigits)
037cc66d 334 fDigits->Clear();
037cc66d 335
ad8cfaf4 336 gAlice->MakeBranchInTree(gAlice->TreeD(),branchname,&fDigits,fBufferSize,file);
037cc66d 337 }
338
339 cH = strstr(opt,"R");
340 //Create a branch for Reconstruction
341 if( cH ){
342 char branchname[20];
343
344 Int_t splitlevel = 0 ;
ad8cfaf4 345
346 if(fEmcRecPoints)
347 fEmcRecPoints->Delete() ;
037cc66d 348
349 if ( fEmcRecPoints && gAlice->TreeR() ) {
350 sprintf(branchname,"%sEmcRP",GetName()) ;
3247125a 351 gAlice->MakeBranchInTree(gAlice->TreeR(),branchname,"TObjArray",&fEmcRecPoints, fBufferSize, splitlevel,file);
037cc66d 352 }
353
ad8cfaf4 354 if(fPpsdRecPoints)
355 fPpsdRecPoints->Delete() ;
037cc66d 356
357 if ( fPpsdRecPoints && gAlice->TreeR() ) {
358 sprintf(branchname,"%sPpsdRP",GetName()) ;
3247125a 359 gAlice->MakeBranchInTree(gAlice->TreeR(),branchname,"TObjArray",&fPpsdRecPoints, fBufferSize, splitlevel,file);
037cc66d 360 }
361
ad8cfaf4 362 if(fTrackSegments)
3247125a 363 fTrackSegments->Clear() ;
037cc66d 364
365 if ( fTrackSegments && gAlice->TreeR() ) {
366 sprintf(branchname,"%sTS",GetName()) ;
3247125a 367 gAlice->MakeBranchInTree(gAlice->TreeR(),branchname,&fTrackSegments,fBufferSize,file);
037cc66d 368 }
369
ad8cfaf4 370 if(fRecParticles)
3247125a 371 fRecParticles->Clear() ;
037cc66d 372
373 if ( fRecParticles && gAlice->TreeR() ) {
374 sprintf(branchname,"%sRP",GetName()) ;
3247125a 375 gAlice->MakeBranchInTree(gAlice->TreeR(),branchname,&fRecParticles,fBufferSize,file);
037cc66d 376 }
377
378 }
379
bea63bea 380}
381
5f20d3fb 382//_____________________________________________________________________________
383void AliPHOSv1::Reconstruction(AliPHOSReconstructioner * Reconstructioner)
384{
385 // 1. Reinitializes the existing RecPoint, TrackSegment, and RecParticles Lists and
386 // 2. Creates TreeR with a branch for each list
387 // 3. Steers the reconstruction processes
388 // 4. Saves the 3 lists in TreeR
389 // 5. Write the Tree to File
390
391 fReconstructioner = Reconstructioner ;
037cc66d 392
5f20d3fb 393 // 1.
394
395 // gAlice->MakeTree("R") ;
5f20d3fb 396
037cc66d 397 MakeBranch("R") ;
5f20d3fb 398
399 // 3.
b73f246d 400
fad3e5b9 401 fReconstructioner->Make(fDigits, fEmcRecPoints, fPpsdRecPoints, fTrackSegments, fRecParticles);
b73f246d 402
fad3e5b9 403 printf("Reconstruction: %d %d %d %d\n",
404 fEmcRecPoints->GetEntries(),fPpsdRecPoints->GetEntries(),
b73f246d 405 fTrackSegments->GetEntries(),fRecParticles->GetEntries());
5f20d3fb 406
407 // 4. Expand or Shrink the arrays to the proper size
408
409 Int_t size ;
410
411 size = fEmcRecPoints->GetEntries() ;
412 fEmcRecPoints->Expand(size) ;
ed4205d8 413
5f20d3fb 414 size = fPpsdRecPoints->GetEntries() ;
415 fPpsdRecPoints->Expand(size) ;
416
417 size = fTrackSegments->GetEntries() ;
418 fTrackSegments->Expand(size) ;
419
420 size = fRecParticles->GetEntries() ;
421 fRecParticles->Expand(size) ;
422
423 gAlice->TreeR()->Fill() ;
5f20d3fb 424 // 5.
425
4a2ca5e9 426 gAlice->TreeR()->Write(0,TObject::kOverwrite) ;
5f20d3fb 427
428 // Deleting reconstructed objects
429 ResetReconstruction();
430
431}
432
5f20d3fb 433//____________________________________________________________________________
434void AliPHOSv1::ResetReconstruction()
435{
436 // Deleting reconstructed objects
437
b73f246d 438 if ( fEmcRecPoints ) fEmcRecPoints ->Delete();
5f20d3fb 439 if ( fPpsdRecPoints ) fPpsdRecPoints->Delete();
440 if ( fTrackSegments ) fTrackSegments->Delete();
b73f246d 441 if ( fRecParticles ) fRecParticles ->Delete();
5f20d3fb 442
443}
5f20d3fb 444
5f20d3fb 445//____________________________________________________________________________
446
7587f5a5 447void AliPHOSv1::StepManager(void)
448{
b2a60966 449 // Accumulates hits as long as the track stays in a single crystal or PPSD gas Cell
b2a60966 450
4f5bbbd4 451 Int_t relid[4] ; // (box, layer, row, column) indices
452 Int_t absid ; // absolute cell ID number
2168f43b 453 Float_t xyze[4]={0,0,0,0} ; // position wrt MRS and energy deposited
4f5bbbd4 454 TLorentzVector pos ; // Lorentz vector of the track current position
fa412d9b 455 Int_t copy ;
7587f5a5 456
bea63bea 457 Int_t tracknumber = gAlice->CurrentTrack() ;
fa412d9b 458 Int_t primary = gAlice->GetPrimary( gAlice->CurrentTrack() );
459 TString name = fGeom->GetName() ;
037cc66d 460
461
ed4205d8 462 if ( name == "GPS2" || name == "MIXT" ) { // ======> CPV is a GPS' PPSD
fa412d9b 463
b2a60966 464 if( gMC->CurrentVolID(copy) == gMC->VolId("GCEL") ) // We are inside a gas cell
7587f5a5 465 {
466 gMC->TrackPosition(pos) ;
467 xyze[0] = pos[0] ;
468 xyze[1] = pos[1] ;
469 xyze[2] = pos[2] ;
bea63bea 470 xyze[3] = gMC->Edep() ;
7587f5a5 471
b37750a6 472 if ( xyze[3] != 0 ) { // there is deposited energy
7587f5a5 473 gMC->CurrentVolOffID(5, relid[0]) ; // get the PHOS Module number
fad3e5b9 474 if ( name == "MIXT" && strcmp(gMC->CurrentVolOffName(5),"PHO1") == 0 ){
ed4205d8 475 relid[0] += fGeom->GetNModules() - fGeom->GetNPPSDModules();
fad3e5b9 476 }
7587f5a5 477 gMC->CurrentVolOffID(3, relid[1]) ; // get the Micromegas Module number
ed4205d8 478 // 1-> fGeom->GetNumberOfModulesPhi() * fGeom->GetNumberOfModulesZ() upper
479 // > fGeom->GetNumberOfModulesPhi() * fGeom->GetNumberOfModulesZ() lower
7587f5a5 480 gMC->CurrentVolOffID(1, relid[2]) ; // get the row number of the cell
481 gMC->CurrentVolID(relid[3]) ; // get the column number
482
483 // get the absolute Id number
484
bea63bea 485 fGeom->RelToAbsNumbering(relid, absid) ;
7587f5a5 486
bea63bea 487 // add current hit to the hit list
b37750a6 488 AddHit(fIshunt, primary, tracknumber, absid, xyze);
037cc66d 489
7587f5a5 490
491 } // there is deposited energy
fa412d9b 492 } // We are inside the gas of the CPV
493 } // GPS2 configuration
494
ed4205d8 495 if ( name == "IHEP" || name == "MIXT" ) { // ======> CPV is a IHEP's one
fa412d9b 496
497 // Yuri Kharlov, 28 September 2000
498
499 if( gMC->CurrentVolID(copy) == gMC->VolId("CPVQ") &&
b37750a6 500 (gMC->IsTrackEntering() ) &&
037cc66d 501 gMC->TrackCharge() != 0) {
fa412d9b 502
b37750a6 503 gMC -> TrackPosition(pos);
504 Float_t xyzm[3], xyzd[3] ;
505 Int_t i;
506 for (i=0; i<3; i++) xyzm[i] = pos[i];
507 gMC -> Gmtod (xyzm, xyzd, 1); // transform coordinate from master to daughter system
508
509 Float_t xyd[3]={0,0,0} ; //local posiiton of the entering
510 xyd[0] = xyzd[0];
511 xyd[1] =-xyzd[1];
512 xyd[2] =-xyzd[2];
513
514
515 // Current momentum of the hit's track in the local ref. system
516 TLorentzVector pmom ; //momentum of the particle initiated hit
517 gMC -> TrackMomentum(pmom);
518 Float_t pm[3], pd[3];
519 for (i=0; i<3; i++) pm[i] = pmom[i];
520 gMC -> Gmtod (pm, pd, 2); // transform 3-momentum from master to daughter system
521 pmom[0] = pd[0];
522 pmom[1] =-pd[1];
523 pmom[2] =-pd[2];
524
037cc66d 525 // Digitize the current CPV hit:
526
527 // 1. find pad response and
fa412d9b 528
a3dfe79c 529 Int_t moduleNumber;
530 gMC->CurrentVolOffID(3,moduleNumber);
531 moduleNumber--;
fa412d9b 532
fa412d9b 533
3d402178 534 TClonesArray *cpvDigits = new TClonesArray("AliPHOSCPVDigit",0); // array of digits for current hit
a3dfe79c 535 CPVDigitize(pmom,xyd,moduleNumber,cpvDigits);
fa412d9b 536
537 Float_t xmean = 0;
538 Float_t zmean = 0;
539 Float_t qsum = 0;
cd461ab8 540 Int_t idigit,ndigits;
fa412d9b 541
542 // 2. go through the current digit list and sum digits in pads
543
544 ndigits = cpvDigits->GetEntriesFast();
cd461ab8 545 for (idigit=0; idigit<ndigits-1; idigit++) {
3d402178 546 AliPHOSCPVDigit *cpvDigit1 = (AliPHOSCPVDigit*) cpvDigits->UncheckedAt(idigit);
fa412d9b 547 Float_t x1 = cpvDigit1->GetXpad() ;
548 Float_t z1 = cpvDigit1->GetYpad() ;
549 for (Int_t jdigit=idigit+1; jdigit<ndigits; jdigit++) {
3d402178 550 AliPHOSCPVDigit *cpvDigit2 = (AliPHOSCPVDigit*) cpvDigits->UncheckedAt(jdigit);
fa412d9b 551 Float_t x2 = cpvDigit2->GetXpad() ;
552 Float_t z2 = cpvDigit2->GetYpad() ;
553 if (x1==x2 && z1==z2) {
554 Float_t qsum = cpvDigit1->GetQpad() + cpvDigit2->GetQpad() ;
555 cpvDigit2->SetQpad(qsum) ;
556 cpvDigits->RemoveAt(idigit) ;
557 }
558 }
559 }
560 cpvDigits->Compress() ;
561
562 // 3. add digits to temporary hit list fTmpHits
563
564 ndigits = cpvDigits->GetEntriesFast();
cd461ab8 565 for (idigit=0; idigit<ndigits; idigit++) {
3d402178 566 AliPHOSCPVDigit *cpvDigit = (AliPHOSCPVDigit*) cpvDigits->UncheckedAt(idigit);
a3dfe79c 567 relid[0] = moduleNumber + 1 ; // CPV (or PHOS) module number
fa412d9b 568 relid[1] =-1 ; // means CPV
569 relid[2] = cpvDigit->GetXpad() ; // column number of a pad
570 relid[3] = cpvDigit->GetYpad() ; // row number of a pad
571
572 // get the absolute Id number
573 fGeom->RelToAbsNumbering(relid, absid) ;
574
575 // add current digit to the temporary hit list
576 xyze[0] = 0. ;
577 xyze[1] = 0. ;
578 xyze[2] = 0. ;
579 xyze[3] = cpvDigit->GetQpad() ; // amplitude in a pad
580 primary = -1; // No need in primary for CPV
b37750a6 581 AddHit(fIshunt, primary, tracknumber, absid, xyze);
fa412d9b 582
583 if (cpvDigit->GetQpad() > 0.02) {
584 xmean += cpvDigit->GetQpad() * (cpvDigit->GetXpad() + 0.5);
585 zmean += cpvDigit->GetQpad() * (cpvDigit->GetYpad() + 0.5);
586 qsum += cpvDigit->GetQpad();
587 }
588 }
589 delete cpvDigits;
590 }
591 } // end of IHEP configuration
7587f5a5 592
037cc66d 593
fa412d9b 594 if(gMC->CurrentVolID(copy) == gMC->VolId("PXTL") ) { // We are inside a PBWO crystal
595 gMC->TrackPosition(pos) ;
596 xyze[0] = pos[0] ;
597 xyze[1] = pos[1] ;
598 xyze[2] = pos[2] ;
599 xyze[3] = gMC->Edep() ;
ed4205d8 600
037cc66d 601
b37750a6 602 if ( xyze[3] != 0 ) { // Track is inside the crystal and deposits some energy
ed4205d8 603
fa412d9b 604 gMC->CurrentVolOffID(10, relid[0]) ; // get the PHOS module number ;
037cc66d 605
fad3e5b9 606 if ( name == "MIXT" && strcmp(gMC->CurrentVolOffName(10),"PHO1") == 0 )
607 relid[0] += fGeom->GetNModules() - fGeom->GetNPPSDModules();
608
fa412d9b 609 relid[1] = 0 ; // means PBW04
610 gMC->CurrentVolOffID(4, relid[2]) ; // get the row number inside the module
611 gMC->CurrentVolOffID(3, relid[3]) ; // get the cell number inside the module
612
613 // get the absolute Id number
fa412d9b 614 fGeom->RelToAbsNumbering(relid, absid) ;
ed4205d8 615
fa412d9b 616 // add current hit to the hit list
b37750a6 617 AddHit(fIshunt, primary,tracknumber, absid, xyze);
037cc66d 618
ed4205d8 619
fa412d9b 620 } // there is deposited energy
621 } // we are inside a PHOS Xtal
037cc66d 622
623
fa412d9b 624}
625
626//____________________________________________________________________________
627void AliPHOSv1::CPVDigitize (TLorentzVector p, Float_t *zxhit, Int_t moduleNumber, TClonesArray *cpvDigits)
628{
629 // ------------------------------------------------------------------------
630 // Digitize one CPV hit:
631 // On input take exact 4-momentum p and position zxhit of the hit,
632 // find the pad response around this hit and
633 // put the amplitudes in the pads into array digits
634 //
635 // Author: Yuri Kharlov (after Serguei Sadovsky)
636 // 2 October 2000
637 // ------------------------------------------------------------------------
638
a3dfe79c 639 const Float_t kCelWr = fGeom->GetPadSizePhi()/2; // Distance between wires (2 wires above 1 pad)
640 const Float_t kDetR = 0.1; // Relative energy fluctuation in track for 100 e-
641 const Float_t kdEdx = 4.0; // Average energy loss in CPV;
642 const Int_t kNgamz = 5; // Ionization size in Z
643 const Int_t kNgamx = 9; // Ionization size in Phi
644 const Float_t kNoise = 0.03; // charge noise in one pad
fa412d9b 645
646 Float_t rnor1,rnor2;
647
648 // Just a reminder on axes notation in the CPV module:
649 // axis Z goes along the beam
650 // axis X goes across the beam in the module plane
651 // axis Y is a normal to the module plane showing from the IP
652
653 Float_t hitX = zxhit[0];
654 Float_t hitZ =-zxhit[1];
655 Float_t pX = p.Px();
656 Float_t pZ =-p.Pz();
657 Float_t pNorm = p.Py();
a3dfe79c 658 Float_t eloss = kdEdx;
3d402178 659
7eb9d12d 660// cout << "CPVDigitize: YVK : "<<hitX<<" "<<hitZ<<" | "<<pX<<" "<<pZ<<" "<<pNorm<<endl;
661
fa412d9b 662 Float_t dZY = pZ/pNorm * fGeom->GetCPVGasThickness();
663 Float_t dXY = pX/pNorm * fGeom->GetCPVGasThickness();
664 gRandom->Rannor(rnor1,rnor2);
a3dfe79c 665 eloss *= (1 + kDetR*rnor1) *
666 TMath::Sqrt((1 + ( pow(dZY,2) + pow(dXY,2) ) / pow(fGeom->GetCPVGasThickness(),2)));
fa412d9b 667 Float_t zhit1 = hitZ + fGeom->GetCPVActiveSize(1)/2 - dZY/2;
668 Float_t xhit1 = hitX + fGeom->GetCPVActiveSize(0)/2 - dXY/2;
669 Float_t zhit2 = zhit1 + dZY;
670 Float_t xhit2 = xhit1 + dXY;
671
a3dfe79c 672 Int_t iwht1 = (Int_t) (xhit1 / kCelWr); // wire (x) coordinate "in"
673 Int_t iwht2 = (Int_t) (xhit2 / kCelWr); // wire (x) coordinate "out"
fa412d9b 674
675 Int_t nIter;
676 Float_t zxe[3][5];
677 if (iwht1==iwht2) { // incline 1-wire hit
678 nIter = 2;
679 zxe[0][0] = (zhit1 + zhit2 - dZY*0.57735) / 2;
a3dfe79c 680 zxe[1][0] = (iwht1 + 0.5) * kCelWr;
681 zxe[2][0] = eloss/2;
fa412d9b 682 zxe[0][1] = (zhit1 + zhit2 + dZY*0.57735) / 2;
a3dfe79c 683 zxe[1][1] = (iwht1 + 0.5) * kCelWr;
684 zxe[2][1] = eloss/2;
fa412d9b 685 }
686 else if (TMath::Abs(iwht1-iwht2) != 1) { // incline 3-wire hit
687 nIter = 3;
688 Int_t iwht3 = (iwht1 + iwht2) / 2;
a3dfe79c 689 Float_t xwht1 = (iwht1 + 0.5) * kCelWr; // wire 1
690 Float_t xwht2 = (iwht2 + 0.5) * kCelWr; // wire 2
691 Float_t xwht3 = (iwht3 + 0.5) * kCelWr; // wire 3
fa412d9b 692 Float_t xwr13 = (xwht1 + xwht3) / 2; // center 13
693 Float_t xwr23 = (xwht2 + xwht3) / 2; // center 23
694 Float_t dxw1 = xhit1 - xwr13;
695 Float_t dxw2 = xhit2 - xwr23;
a3dfe79c 696 Float_t egm1 = TMath::Abs(dxw1) / ( TMath::Abs(dxw1) + TMath::Abs(dxw2) + kCelWr );
697 Float_t egm2 = TMath::Abs(dxw2) / ( TMath::Abs(dxw1) + TMath::Abs(dxw2) + kCelWr );
698 Float_t egm3 = kCelWr / ( TMath::Abs(dxw1) + TMath::Abs(dxw2) + kCelWr );
fa412d9b 699 zxe[0][0] = (dXY*(xwr13-xwht1)/dXY + zhit1 + zhit1) / 2;
700 zxe[1][0] = xwht1;
a3dfe79c 701 zxe[2][0] = eloss * egm1;
fa412d9b 702 zxe[0][1] = (dXY*(xwr23-xwht1)/dXY + zhit1 + zhit2) / 2;
703 zxe[1][1] = xwht2;
a3dfe79c 704 zxe[2][1] = eloss * egm2;
fa412d9b 705 zxe[0][2] = dXY*(xwht3-xwht1)/dXY + zhit1;
706 zxe[1][2] = xwht3;
a3dfe79c 707 zxe[2][2] = eloss * egm3;
fa412d9b 708 }
709 else { // incline 2-wire hit
710 nIter = 2;
a3dfe79c 711 Float_t xwht1 = (iwht1 + 0.5) * kCelWr;
712 Float_t xwht2 = (iwht2 + 0.5) * kCelWr;
fa412d9b 713 Float_t xwr12 = (xwht1 + xwht2) / 2;
714 Float_t dxw1 = xhit1 - xwr12;
715 Float_t dxw2 = xhit2 - xwr12;
716 Float_t egm1 = TMath::Abs(dxw1) / ( TMath::Abs(dxw1) + TMath::Abs(dxw2) );
717 Float_t egm2 = TMath::Abs(dxw2) / ( TMath::Abs(dxw1) + TMath::Abs(dxw2) );
718 zxe[0][0] = (zhit1 + zhit2 - dZY*egm1) / 2;
719 zxe[1][0] = xwht1;
a3dfe79c 720 zxe[2][0] = eloss * egm1;
fa412d9b 721 zxe[0][1] = (zhit1 + zhit2 + dZY*egm2) / 2;
722 zxe[1][1] = xwht2;
a3dfe79c 723 zxe[2][1] = eloss * egm2;
fa412d9b 724 }
bea63bea 725
fa412d9b 726 // Finite size of ionization region
727
ed4205d8 728 Int_t nCellZ = fGeom->GetNumberOfCPVPadsZ();
729 Int_t nCellX = fGeom->GetNumberOfCPVPadsPhi();
a3dfe79c 730 Int_t nz3 = (kNgamz+1)/2;
731 Int_t nx3 = (kNgamx+1)/2;
732 cpvDigits->Expand(nIter*kNgamx*kNgamz);
fa412d9b 733 TClonesArray &ldigits = *(TClonesArray *)cpvDigits;
734
735 for (Int_t iter=0; iter<nIter; iter++) {
736
737 Float_t zhit = zxe[0][iter];
738 Float_t xhit = zxe[1][iter];
739 Float_t qhit = zxe[2][iter];
740 Float_t zcell = zhit / fGeom->GetPadSizeZ();
741 Float_t xcell = xhit / fGeom->GetPadSizePhi();
742 if ( zcell<=0 || xcell<=0 ||
743 zcell>=nCellZ || xcell>=nCellX) return;
744 Int_t izcell = (Int_t) zcell;
745 Int_t ixcell = (Int_t) xcell;
746 Float_t zc = zcell - izcell - 0.5;
747 Float_t xc = xcell - ixcell - 0.5;
a3dfe79c 748 for (Int_t iz=1; iz<=kNgamz; iz++) {
fa412d9b 749 Int_t kzg = izcell + iz - nz3;
750 if (kzg<=0 || kzg>nCellZ) continue;
751 Float_t zg = (Float_t)(iz-nz3) - zc;
a3dfe79c 752 for (Int_t ix=1; ix<=kNgamx; ix++) {
fa412d9b 753 Int_t kxg = ixcell + ix - nx3;
754 if (kxg<=0 || kxg>nCellX) continue;
755 Float_t xg = (Float_t)(ix-nx3) - xc;
756
757 // Now calculate pad response
758 Float_t qpad = CPVPadResponseFunction(qhit,zg,xg);
a3dfe79c 759 qpad += kNoise*rnor2;
fa412d9b 760 if (qpad<0) continue;
761
762 // Fill the array with pad response ID and amplitude
3d402178 763 new(ldigits[cpvDigits->GetEntriesFast()]) AliPHOSCPVDigit(kxg,kzg,qpad);
fa412d9b 764 }
fa412d9b 765 }
fa412d9b 766 }
767}
768
769//____________________________________________________________________________
770Float_t AliPHOSv1::CPVPadResponseFunction(Float_t qhit, Float_t zhit, Float_t xhit) {
771 // ------------------------------------------------------------------------
772 // Calculate the amplitude in one CPV pad using the
773 // cumulative pad response function
774 // Author: Yuri Kharlov (after Serguei Sadovski)
775 // 3 October 2000
776 // ------------------------------------------------------------------------
777
778 Double_t dz = fGeom->GetPadSizeZ() / 2;
779 Double_t dx = fGeom->GetPadSizePhi() / 2;
780 Double_t z = zhit * fGeom->GetPadSizeZ();
781 Double_t x = xhit * fGeom->GetPadSizePhi();
782 Double_t amplitude = qhit *
783 (CPVCumulPadResponse(z+dz,x+dx) - CPVCumulPadResponse(z+dz,x-dx) -
784 CPVCumulPadResponse(z-dz,x+dx) + CPVCumulPadResponse(z-dz,x-dx));
785 return (Float_t)amplitude;
7587f5a5 786}
787
fa412d9b 788//____________________________________________________________________________
789Double_t AliPHOSv1::CPVCumulPadResponse(Double_t x, Double_t y) {
790 // ------------------------------------------------------------------------
791 // Cumulative pad response function
792 // It includes several terms from the CF decomposition in electrostatics
793 // Note: this cumulative function is wrong since omits some terms
794 // but the cell amplitude obtained with it is correct because
795 // these omitting terms cancel
796 // Author: Yuri Kharlov (after Serguei Sadovski)
797 // 3 October 2000
798 // ------------------------------------------------------------------------
799
a3dfe79c 800 const Double_t kA=1.0;
801 const Double_t kB=0.7;
fa412d9b 802
803 Double_t r2 = x*x + y*y;
804 Double_t xy = x*y;
805 Double_t cumulPRF = 0;
806 for (Int_t i=0; i<=4; i++) {
a3dfe79c 807 Double_t b1 = (2*i + 1) * kB;
fa412d9b 808 cumulPRF += TMath::Power(-1,i) * TMath::ATan( xy / (b1*TMath::Sqrt(b1*b1 + r2)) );
809 }
a3dfe79c 810 cumulPRF *= kA/(2*TMath::Pi());
fa412d9b 811 return cumulPRF;
812}
7eb9d12d 813