]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/AliPHOSv1.cxx
initialize pointer data member to zero in the default ctor to avoid problems with...
[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
20// Layout EMC + PPSD has name GPS2
21// Produces cumulated hits (no hits) and digits
22//*-- Author: Yves Schutz (SUBATECH)
b2a60966 23
7587f5a5 24
25// --- ROOT system ---
bea63bea 26
27#include "TBRIK.h"
28#include "TNode.h"
7587f5a5 29#include "TRandom.h"
30
5f20d3fb 31
7587f5a5 32// --- Standard library ---
33
de9ec31b 34#include <stdio.h>
35#include <string.h>
36#include <stdlib.h>
37#include <strstream.h>
7587f5a5 38
39// --- AliRoot header files ---
40
41#include "AliPHOSv1.h"
42#include "AliPHOSHit.h"
43#include "AliPHOSDigit.h"
bea63bea 44#include "AliPHOSReconstructioner.h"
7587f5a5 45#include "AliRun.h"
46#include "AliConst.h"
47
48ClassImp(AliPHOSv1)
49
bea63bea 50//____________________________________________________________________________
51AliPHOSv1::AliPHOSv1()
52{
5f20d3fb 53 // ctor
bea63bea 54 fNTmpHits = 0 ;
55 fTmpHits = 0 ;
56}
57
7587f5a5 58//____________________________________________________________________________
59AliPHOSv1::AliPHOSv1(const char *name, const char *title):
60 AliPHOSv0(name,title)
61{
5f20d3fb 62 // ctor : title is used to identify the layout
63 // GPS2 = 5 modules (EMC + PPSD)
64 // We use 2 arrays of hits :
65 //
66 // - fHits (the "normal" one), which retains the hits associated with
67 // the current primary particle being tracked
68 // (this array is reset after each primary has been tracked).
69 //
70 // - fTmpHits, which retains all the hits of the current event. It
71 // is used for the digitization part.
4a2ca5e9 72
5f20d3fb 73 fPinElectronicNoise = 0.010 ;
74 fDigitThreshold = 1. ; // 1 GeV
75
76 // We do not want to save in TreeH the raw hits
77 // But save the cumulated hits instead (need to create the branch myself)
78 // It is put in the Digit Tree because the TreeH is filled after each primary
79 // and the TreeD at the end of the event (branch is set in FinishEvent() ).
80
81 fTmpHits= new TClonesArray("AliPHOSHit",1000) ;
82
83 fNTmpHits = fNhits = 0 ;
84
85 fDigits = new TClonesArray("AliPHOSDigit",1000) ;
86
87
88 fIshunt = 1 ; // All hits are associated with primary particles
89
90}
91
92//____________________________________________________________________________
93AliPHOSv1::AliPHOSv1(AliPHOSReconstructioner * Reconstructioner, const char *name, const char *title):
94 AliPHOSv0(name,title)
95{
96 // ctor : title is used to identify the layout
97 // GPS2 = 5 modules (EMC + PPSD)
98 // We use 2 arrays of hits :
99 //
100 // - fHits (the "normal" one), which retains the hits associated with
101 // the current primary particle being tracked
102 // (this array is reset after each primary has been tracked).
103 //
104 // - fTmpHits, which retains all the hits of the current event. It
105 // is used for the digitization part.
106
107 fPinElectronicNoise = 0.010 ;
108
109 // We do not want to save in TreeH the raw hits
110 //fHits = new TClonesArray("AliPHOSHit",100) ;
111
112 fDigits = new TClonesArray("AliPHOSDigit",1000) ;
113 fTmpHits= new TClonesArray("AliPHOSHit",1000) ;
114
115 fNTmpHits = fNhits = 0 ;
116
117 fIshunt = 1 ; // All hits are associated with primary particles
118
119 // gets an instance of the geometry parameters class
120 fGeom = AliPHOSGeometry::GetInstance(title, "") ;
121
122 if (fGeom->IsInitialized() )
88bdfa12 123 cout << "AliPHOS" << Version() << " : PHOS geometry intialized for " << fGeom->GetName() << endl ;
5f20d3fb 124 else
88bdfa12 125 cout << "AliPHOS" << Version() << " : PHOS geometry initialization failed !" << endl ;
5f20d3fb 126
127 // Defining the PHOS Reconstructioner
128
129 fReconstructioner = Reconstructioner ;
130
131
7587f5a5 132}
b2a60966 133
7587f5a5 134//____________________________________________________________________________
bea63bea 135AliPHOSv1::~AliPHOSv1()
b2a60966 136{
bea63bea 137 // dtor
5f20d3fb 138
8dfa469d 139 if ( fTmpHits) {
140 fTmpHits->Delete() ;
141 delete fTmpHits ;
142 fTmpHits = 0 ;
143 }
5f20d3fb 144
145 if ( fEmcRecPoints ) {
8dfa469d 146 fEmcRecPoints->Delete() ;
147 delete fEmcRecPoints ;
148 fEmcRecPoints = 0 ;
149 }
5f20d3fb 150
8dfa469d 151 if ( fPpsdRecPoints ) {
152 fPpsdRecPoints->Delete() ;
153 delete fPpsdRecPoints ;
154 fPpsdRecPoints = 0 ;
155 }
5f20d3fb 156
8dfa469d 157 if ( fTrackSegments ) {
158 fTrackSegments->Delete() ;
159 delete fTrackSegments ;
160 fTrackSegments = 0 ;
161 }
5f20d3fb 162
7587f5a5 163}
164
7587f5a5 165//____________________________________________________________________________
bea63bea 166void AliPHOSv1::AddHit(Int_t shunt, Int_t primary, Int_t tracknumber, Int_t Id, Float_t * hits)
167{
168 // Add a hit to the hit list.
5f20d3fb 169 // A PHOS hit is the sum of all hits in a single crystal
170 // or in a single PPSD gas cell
bea63bea 171
5f20d3fb 172 Int_t hitCounter ;
173 TClonesArray &ltmphits = *fTmpHits ;
bea63bea 174 AliPHOSHit *newHit ;
5f20d3fb 175 AliPHOSHit *curHit ;
176 Bool_t deja = kFALSE ;
bea63bea 177
5f20d3fb 178 // In any case, fills the fTmpHit TClonesArray (with "accumulated hits")
bea63bea 179
180 newHit = new AliPHOSHit(shunt, primary, tracknumber, Id, hits) ;
181
5f20d3fb 182 // We do not want to save in TreeH the raw hits
bea63bea 183 // TClonesArray &lhits = *fHits;
bea63bea 184
5f20d3fb 185 for ( hitCounter = 0 ; hitCounter < fNTmpHits && !deja ; hitCounter++ ) {
186 curHit = (AliPHOSHit*) ltmphits[hitCounter] ;
187 if( *curHit == *newHit ) {
188 *curHit = *curHit + *newHit ;
189 deja = kTRUE ;
190 }
191 }
192
193 if ( !deja ) {
194 new(ltmphits[fNTmpHits]) AliPHOSHit(*newHit) ;
195 fNTmpHits++ ;
196 }
197
bea63bea 198 // We do not want to save in TreeH the raw hits
199 // new(lhits[fNhits]) AliPHOSHit(*newHit) ;
200 // fNhits++ ;
201
202 // Please note that the fTmpHits array must survive up to the
203 // end of the events, so it does not appear e.g. in ResetHits() (
204 // which is called at the end of each primary).
205
206 delete newHit;
207
208}
209
5f20d3fb 210//___________________________________________________________________________
211Int_t AliPHOSv1::Digitize(Float_t Energy)
212{
213 // Applies the energy calibration
214
215 Float_t fB = 100000000. ;
216 Float_t fA = 0. ;
217 Int_t chan = Int_t(fA + Energy*fB ) ;
218 return chan ;
219}
bea63bea 220
221//___________________________________________________________________________
222void AliPHOSv1::FinishEvent()
223{
224 // Makes the digits from the sum of summed hit in a single crystal or PPSD gas cell
225 // Adds to the energy the electronic noise
226 // Keeps digits with energy above fDigitThreshold
227
228 // Save the cumulated hits instead of raw hits (need to create the branch myself)
229 // It is put in the Digit Tree because the TreeH is filled after each primary
230 // and the TreeD at the end of the event.
231
5f20d3fb 232
bea63bea 233 Int_t i ;
234 Int_t relid[4];
235 Int_t j ;
236 TClonesArray &lDigits = *fDigits ;
237 AliPHOSHit * hit ;
238 AliPHOSDigit * newdigit ;
239 AliPHOSDigit * curdigit ;
240 Bool_t deja = kFALSE ;
241
5f20d3fb 242 for ( i = 0 ; i < fNTmpHits ; i++ ) {
243 hit = (AliPHOSHit*)fTmpHits->At(i) ;
4a2ca5e9 244
245 // Assign primary number only if contribution is significant
246 if( hit->GetEnergy() > fDigitThreshold)
247 newdigit = new AliPHOSDigit( hit->GetPrimary(), hit->GetId(), Digitize( hit->GetEnergy() ) ) ;
248 else
249 newdigit = new AliPHOSDigit( -1 , hit->GetId(), Digitize( hit->GetEnergy() ) ) ;
bea63bea 250 deja =kFALSE ;
251 for ( j = 0 ; j < fNdigits ; j++) {
252 curdigit = (AliPHOSDigit*) lDigits[j] ;
253 if ( *curdigit == *newdigit) {
254 *curdigit = *curdigit + *newdigit ;
255 deja = kTRUE ;
256 }
257 }
258 if ( !deja ) {
259 new(lDigits[fNdigits]) AliPHOSDigit(* newdigit) ;
260 fNdigits++ ;
261 }
262
263 delete newdigit ;
264 }
265
266 // Noise induced by the PIN diode of the PbWO crystals
267
268 Float_t energyandnoise ;
269 for ( i = 0 ; i < fNdigits ; i++ ) {
270 newdigit = (AliPHOSDigit * ) fDigits->At(i) ;
271 fGeom->AbsToRelNumbering(newdigit->GetId(), relid) ;
272
273 if (relid[1]==0){ // Digits belong to EMC (PbW0_4 crystals)
274 energyandnoise = newdigit->GetAmp() + Digitize(gRandom->Gaus(0., fPinElectronicNoise)) ;
275
276 if (energyandnoise < 0 )
277 energyandnoise = 0 ;
278
279 if ( newdigit->GetAmp() < fDigitThreshold ) // if threshold not surpassed, remove digit from list
280 fDigits->RemoveAt(i) ;
281 }
282 }
283
284 fDigits->Compress() ;
285
286 fNdigits = fDigits->GetEntries() ;
287 for (i = 0 ; i < fNdigits ; i++) {
288 newdigit = (AliPHOSDigit *) fDigits->At(i) ;
289 newdigit->SetIndexInList(i) ;
290 }
5f20d3fb 291
292}
293
294//___________________________________________________________________________
295void AliPHOSv1::MakeBranch(Option_t* opt)
296{
297 // Create new branche in the current Root Tree in the digit Tree
298
299 AliDetector::MakeBranch(opt) ;
300
301 char branchname[10];
302 sprintf(branchname,"%s",GetName());
303 char *cdD = strstr(opt,"D");
304 if (fDigits && gAlice->TreeD() && cdD) {
305 gAlice->TreeD()->Branch(branchname, &fDigits, fBufferSize);
306 }
307
308 // Create new branche PHOSCH in the current Root Tree in the digit Tree for accumulated Hits
309 if ( ! (gAlice->IsLegoRun()) ) { // only when not in lego plot mode
310 if ( fTmpHits && gAlice->TreeD() && cdD) {
311 char branchname[10] ;
312 sprintf(branchname, "%sCH", GetName()) ;
313 gAlice->TreeD()->Branch(branchname, &fTmpHits, fBufferSize) ;
314 }
315 }
bea63bea 316
317}
318
5f20d3fb 319
320//_____________________________________________________________________________
321void AliPHOSv1::Reconstruction(AliPHOSReconstructioner * Reconstructioner)
322{
323 // 1. Reinitializes the existing RecPoint, TrackSegment, and RecParticles Lists and
324 // 2. Creates TreeR with a branch for each list
325 // 3. Steers the reconstruction processes
326 // 4. Saves the 3 lists in TreeR
327 // 5. Write the Tree to File
328
329 fReconstructioner = Reconstructioner ;
330
331 char branchname[10] ;
332
333 // 1.
334
335 // gAlice->MakeTree("R") ;
336 Int_t splitlevel = 0 ;
337
338 if (fEmcRecPoints) {
339 fEmcRecPoints->Delete() ;
340 delete fEmcRecPoints ;
341 fEmcRecPoints = 0 ;
342 }
343
344 // fEmcRecPoints= new AliPHOSRecPoint::RecPointsList("AliPHOSEmcRecPoint", 1000) ; if TClonesArray
345 fEmcRecPoints= new AliPHOSRecPoint::RecPointsList(2000) ;
346
347 if ( fEmcRecPoints && gAlice->TreeR() ) {
348 sprintf(branchname,"%sEmcRP",GetName()) ;
349
350 // gAlice->TreeR()->Branch(branchname, &fEmcRecPoints, fBufferSize); if TClonesArray
351 gAlice->TreeR()->Branch(branchname, "TObjArray", &fEmcRecPoints, fBufferSize, splitlevel) ;
352 }
353
354 if (fPpsdRecPoints) {
355 fPpsdRecPoints->Delete() ;
356 delete fPpsdRecPoints ;
357 fPpsdRecPoints = 0 ;
358 }
359
360 // fPpsdRecPoints = new AliPHOSRecPoint::RecPointsList("AliPHOSPpsdRecPoint", 1000) ; if TClonesArray
361 fPpsdRecPoints = new AliPHOSRecPoint::RecPointsList(2000) ;
362
363 if ( fPpsdRecPoints && gAlice->TreeR() ) {
364 sprintf(branchname,"%sPpsdRP",GetName()) ;
365
366 // gAlice->TreeR()->Branch(branchname, &fPpsdRecPoints, fBufferSize); if TClonesArray
367 gAlice->TreeR()->Branch(branchname, "TObjArray", &fPpsdRecPoints, fBufferSize, splitlevel) ;
368 }
369
370 if (fTrackSegments) {
371 fTrackSegments->Delete() ;
372 delete fTrackSegments ;
373 fTrackSegments = 0 ;
374 }
375
376 fTrackSegments = new AliPHOSTrackSegment::TrackSegmentsList("AliPHOSTrackSegment", 2000) ;
377 if ( fTrackSegments && gAlice->TreeR() ) {
378 sprintf(branchname,"%sTS",GetName()) ;
379 gAlice->TreeR()->Branch(branchname, &fTrackSegments, fBufferSize) ;
380 }
381
382 if (fRecParticles) {
383 fRecParticles->Delete() ;
384 delete fRecParticles ;
385 fRecParticles = 0 ;
386 }
387 fRecParticles = new AliPHOSRecParticle::RecParticlesList("AliPHOSRecParticle", 2000) ;
388 if ( fRecParticles && gAlice->TreeR() ) {
389 sprintf(branchname,"%sRP",GetName()) ;
390 gAlice->TreeR()->Branch(branchname, &fRecParticles, fBufferSize) ;
391 }
392
393 // 3.
394
395 fReconstructioner->Make(fDigits, fEmcRecPoints, fPpsdRecPoints, fTrackSegments, fRecParticles);
396
397 // 4. Expand or Shrink the arrays to the proper size
398
399 Int_t size ;
400
401 size = fEmcRecPoints->GetEntries() ;
402 fEmcRecPoints->Expand(size) ;
403
404 size = fPpsdRecPoints->GetEntries() ;
405 fPpsdRecPoints->Expand(size) ;
406
407 size = fTrackSegments->GetEntries() ;
408 fTrackSegments->Expand(size) ;
409
410 size = fRecParticles->GetEntries() ;
411 fRecParticles->Expand(size) ;
412
413 gAlice->TreeR()->Fill() ;
414 cout << "filled" << endl ;
415 // 5.
416
4a2ca5e9 417 gAlice->TreeR()->Write(0,TObject::kOverwrite) ;
5f20d3fb 418 cout << "writen" << endl ;
419
420 // Deleting reconstructed objects
421 ResetReconstruction();
422
423}
424
425//____________________________________________________________________________
426void AliPHOSv1::ResetDigits()
427{
428 // May sound strange, but cumulative hits are store in digits Tree
429 AliDetector::ResetDigits();
430 if( fTmpHits ) {
431 fTmpHits->Delete();
432 fNTmpHits = 0 ;
433 }
434}
435//____________________________________________________________________________
436void AliPHOSv1::ResetReconstruction()
437{
438 // Deleting reconstructed objects
439
440 if ( fEmcRecPoints ) fEmcRecPoints->Delete();
441 if ( fPpsdRecPoints ) fPpsdRecPoints->Delete();
442 if ( fTrackSegments ) fTrackSegments->Delete();
443 if ( fRecParticles ) fRecParticles->Delete();
444
445}
446//____________________________________________________________________________
447
448//____________________________________________________________________________
449void AliPHOSv1::SetTreeAddress()
450{
451 // TBranch *branch;
452 AliPHOS::SetTreeAddress();
453
454 // //Branch address for TreeR: RecPpsdRecPoint
455// TTree *treeR = gAlice->TreeR();
456// if ( treeR && fPpsdRecPoints ) {
457// branch = treeR->GetBranch("PHOSPpsdRP");
458// if (branch) branch->SetAddress(&fPpsdRecPoints) ;
459 // }
460}
461
462//____________________________________________________________________________
463
7587f5a5 464void AliPHOSv1::StepManager(void)
465{
b2a60966 466 // Accumulates hits as long as the track stays in a single crystal or PPSD gas Cell
b2a60966 467
7587f5a5 468 Int_t relid[4] ; // (box, layer, row, column) indices
469 Float_t xyze[4] ; // position wrt MRS and energy deposited
470 TLorentzVector pos ;
bea63bea 471 Int_t copy ;
7587f5a5 472
bea63bea 473 Int_t tracknumber = gAlice->CurrentTrack() ;
5f20d3fb 474 Int_t primary = gAlice->GetPrimary( gAlice->CurrentTrack() );
bea63bea 475 TString name = fGeom->GetName() ;
7587f5a5 476 if ( name == "GPS2" ) { // the CPV is a PPSD
b2a60966 477 if( gMC->CurrentVolID(copy) == gMC->VolId("GCEL") ) // We are inside a gas cell
7587f5a5 478 {
479 gMC->TrackPosition(pos) ;
480 xyze[0] = pos[0] ;
481 xyze[1] = pos[1] ;
482 xyze[2] = pos[2] ;
bea63bea 483 xyze[3] = gMC->Edep() ;
7587f5a5 484
485 if ( xyze[3] != 0 ) { // there is deposited energy
486 gMC->CurrentVolOffID(5, relid[0]) ; // get the PHOS Module number
487 gMC->CurrentVolOffID(3, relid[1]) ; // get the Micromegas Module number
488 // 1-> Geom->GetNumberOfModulesPhi() * fGeom->GetNumberOfModulesZ() upper
489 // > fGeom->GetNumberOfModulesPhi() * fGeom->GetNumberOfModulesZ() lower
490 gMC->CurrentVolOffID(1, relid[2]) ; // get the row number of the cell
491 gMC->CurrentVolID(relid[3]) ; // get the column number
492
493 // get the absolute Id number
494
495 Int_t absid ;
bea63bea 496 fGeom->RelToAbsNumbering(relid, absid) ;
7587f5a5 497
bea63bea 498 // add current hit to the hit list
499 AddHit(fIshunt, primary, tracknumber, absid, xyze);
7587f5a5 500
501 } // there is deposited energy
502 } // We are inside the gas of the CPV
503 } // GPS2 configuration
504
bea63bea 505 if(gMC->CurrentVolID(copy) == gMC->VolId("PXTL") ) // We are inside a PBWO crystal
7587f5a5 506 {
507 gMC->TrackPosition(pos) ;
508 xyze[0] = pos[0] ;
509 xyze[1] = pos[1] ;
510 xyze[2] = pos[2] ;
a333c916 511 xyze[3] = gMC->Edep() ;
7587f5a5 512
7587f5a5 513 if ( xyze[3] != 0 ) {
514 gMC->CurrentVolOffID(10, relid[0]) ; // get the PHOS module number ;
bea63bea 515 relid[1] = 0 ; // means PBW04
7587f5a5 516 gMC->CurrentVolOffID(4, relid[2]) ; // get the row number inside the module
517 gMC->CurrentVolOffID(3, relid[3]) ; // get the cell number inside the module
518
5f20d3fb 519 // get the absolute Id number
520
7587f5a5 521 Int_t absid ;
bea63bea 522 fGeom->RelToAbsNumbering(relid, absid) ;
523
5f20d3fb 524 // add current hit to the hit list
bea63bea 525
5f20d3fb 526 AddHit(fIshunt, primary,tracknumber, absid, xyze);
527
7587f5a5 528 } // there is deposited energy
5f20d3fb 529 } // we are inside a PHOS Xtal
7587f5a5 530}
531