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