]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EMCAL/AliEMCALDigit.cxx
The array for primaries and parents increments itself when needed
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALDigit.cxx
CommitLineData
61e0abb5 1/**************************************************************************
0c22a365 2
61e0abb5 3 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
0c22a365 4
61e0abb5 5 * *
0c22a365 6
61e0abb5 7 * Author: The ALICE Off-line Project. *
0c22a365 8
61e0abb5 9 * Contributors are mentioned in the code where appropriate. *
0c22a365 10
61e0abb5 11 * *
0c22a365 12
61e0abb5 13 * Permission to use, copy, modify and distribute this software and its *
0c22a365 14
61e0abb5 15 * documentation strictly for non-commercial purposes is hereby granted *
0c22a365 16
61e0abb5 17 * without fee, provided that the above copyright notice appears in all *
0c22a365 18
61e0abb5 19 * copies and that both the copyright notice and this permission notice *
0c22a365 20
61e0abb5 21 * appear in the supporting documentation. The authors make no claims *
0c22a365 22
61e0abb5 23 * about the suitability of this software for any purpose. It is *
0c22a365 24
61e0abb5 25 * provided "as is" without express or implied warranty. *
0c22a365 26
61e0abb5 27 **************************************************************************/
28
0c22a365 29
30
ffa6d63b 31/* $Id: */
61e0abb5 32
0c22a365 33
34
61e0abb5 35//_________________________________________________________________________
0c22a365 36
ffa6d63b 37// EMCAL digit:
0c22a365 38
ffa6d63b 39// A Digit is the sum of the energy lost in an EMCAL Tower
0c22a365 40
ffa6d63b 41// It also stores information on Primary, and enterring particle
0c22a365 42
ffa6d63b 43// tracknumbers Digits are created using AliEMCALSDigitizer, followed
0c22a365 44
ffa6d63b 45// by AliEMCALDigitizer
0c22a365 46
61e0abb5 47//
0c22a365 48
ffa6d63b 49//*-- Author: Sahal Yacoob (LBL)
0c22a365 50
ffa6d63b 51// based on : AliPHOSDigit
0c22a365 52
814ad4bf 53//__________________________________________________________________________
61e0abb5 54
0c22a365 55
56
61e0abb5 57// --- ROOT system ---
58
0c22a365 59
60
61e0abb5 61// --- Standard library ---
62
0c22a365 63
64
61e0abb5 65#include <iostream.h>
66
0c22a365 67
68
61e0abb5 69// --- AliRoot header files ---
70
0c22a365 71
72
61e0abb5 73#include "AliEMCALDigit.h"
0c22a365 74
814ad4bf 75#include "AliEMCALGeometry.h"
0c22a365 76
88d764f0 77#include "AliEMCALGetter.h"
61e0abb5 78
79
0c22a365 80
81
82
61e0abb5 83ClassImp(AliEMCALDigit)
84
0c22a365 85
86
61e0abb5 87//____________________________________________________________________________
0c22a365 88
da98933e 89 AliEMCALDigit::AliEMCALDigit()
0c22a365 90
61e0abb5 91{
0c22a365 92
61e0abb5 93 // default ctor
94
0c22a365 95
96
97 fIndexInList = 0 ;
98
61e0abb5 99 fNprimary = 0 ;
0c22a365 100
ef733077 101 fNMaxPrimary = 0 ;
0c22a365 102
61e0abb5 103 fNiparent = 0 ;
0c22a365 104
105
ef733077 106 fNMaxiparent = 0;
0c22a365 107
ef733077 108 fPrimary = 0 ;
0c22a365 109
ef733077 110 fIparent = 0 ;
0c22a365 111
112 fMaxIter = 0;
61e0abb5 113}
114
0c22a365 115
116
61e0abb5 117//____________________________________________________________________________
0c22a365 118
814ad4bf 119AliEMCALDigit::AliEMCALDigit(Int_t primary, Int_t iparent, Int_t id, Int_t DigEnergy, Float_t time, Int_t index)
0c22a365 120
61e0abb5 121{
0c22a365 122
61e0abb5 123 // ctor with all data
124
0c22a365 125
126
127 fNMaxPrimary = 5 ;
128
129 fNMaxiparent = 40 ;
130
88d764f0 131 fPrimary = new Int_t[fNMaxPrimary] ;
0c22a365 132
88d764f0 133 fIparent = new Int_t[fNMaxiparent] ;
0c22a365 134
61e0abb5 135 fAmp = DigEnergy ;
0c22a365 136
814ad4bf 137 fTime = time ;
0c22a365 138
61e0abb5 139 fId = id ;
0c22a365 140
61e0abb5 141 fIndexInList = index ;
0c22a365 142
143 fMaxIter = 5;
61e0abb5 144 if( primary != -1){
0c22a365 145
61e0abb5 146 fNprimary = 1 ;
0c22a365 147
7b62cd84 148 fPrimary[0] = primary ;
0c22a365 149
61e0abb5 150 fNiparent = 1 ;
0c22a365 151
61e0abb5 152 fIparent[0] = iparent ;
0c22a365 153
7b62cd84 154}
0c22a365 155
61e0abb5 156 else{ //If the contribution of this primary smaller than fDigitThreshold (AliEMCALv1)
0c22a365 157
61e0abb5 158 fNprimary = 0 ;
0c22a365 159
61e0abb5 160 fPrimary[0] = -1 ;
0c22a365 161
61e0abb5 162 fNiparent = 0 ;
0c22a365 163
61e0abb5 164 fIparent[0] = -1 ;
165
0c22a365 166
167
61e0abb5 168 }
0c22a365 169
61e0abb5 170 Int_t i ;
0c22a365 171
61e0abb5 172 for ( i = 1; i < fNMaxPrimary ; i++)
0c22a365 173
61e0abb5 174 fPrimary[i] = -1 ;
175
0c22a365 176
177
f807c3bd 178 for ( i =1; i< fNMaxiparent ; i++)
0c22a365 179
f807c3bd 180 fIparent[i] = -1 ;
0c22a365 181
61e0abb5 182}
183
0c22a365 184
185
61e0abb5 186//____________________________________________________________________________
0c22a365 187
61e0abb5 188AliEMCALDigit::AliEMCALDigit(const AliEMCALDigit & digit)
0c22a365 189
61e0abb5 190{
0c22a365 191
61e0abb5 192 // copy ctor
0c22a365 193
61e0abb5 194
195
0c22a365 196
197
61e0abb5 198 fNMaxPrimary = digit.fNMaxPrimary ;
0c22a365 199
61e0abb5 200 fNMaxiparent = digit.fNMaxiparent ;
0c22a365 201
88d764f0 202 fPrimary = new Int_t[fNMaxPrimary] ;
0c22a365 203
88d764f0 204 fIparent = new Int_t[fNMaxiparent] ;
0c22a365 205
61e0abb5 206 Int_t i ;
0c22a365 207
61e0abb5 208 for ( i = 0; i < fNMaxPrimary ; i++)
0c22a365 209
61e0abb5 210 fPrimary[i] = digit.fPrimary[i] ;
0c22a365 211
61e0abb5 212 Int_t j ;
0c22a365 213
61e0abb5 214 for (j = 0; j< fNMaxiparent ; j++)
0c22a365 215
61e0abb5 216 fIparent[j] = digit.fIparent[j] ;
0c22a365 217
61e0abb5 218 fAmp = digit.fAmp ;
0c22a365 219
814ad4bf 220 fTime = digit.fTime ;
0c22a365 221
61e0abb5 222 fId = digit.fId;
0c22a365 223
224 fMaxIter = digit.fMaxIter;
61e0abb5 225 fIndexInList = digit.fIndexInList ;
0c22a365 226
61e0abb5 227 fNprimary = digit.fNprimary ;
0c22a365 228
61e0abb5 229 fNiparent = digit.fNiparent ;
0c22a365 230
61e0abb5 231}
232
0c22a365 233
234
61e0abb5 235//____________________________________________________________________________
0c22a365 236
61e0abb5 237AliEMCALDigit::~AliEMCALDigit()
0c22a365 238
61e0abb5 239{
0c22a365 240
61e0abb5 241 // Delete array of primiries if any
0c22a365 242
88d764f0 243 delete [] fPrimary ;
0c22a365 244
88d764f0 245 delete [] fIparent ;
0c22a365 246
61e0abb5 247}
248
0c22a365 249
250
61e0abb5 251//____________________________________________________________________________
0c22a365 252
61e0abb5 253Int_t AliEMCALDigit::Compare(const TObject * obj) const
0c22a365 254
61e0abb5 255{
0c22a365 256
61e0abb5 257 // Compares two digits with respect to its Id
0c22a365 258
61e0abb5 259 // to sort according increasing Id
260
0c22a365 261
262
61e0abb5 263 Int_t rv ;
264
0c22a365 265
266
61e0abb5 267 AliEMCALDigit * digit = (AliEMCALDigit *)obj ;
268
0c22a365 269
270
61e0abb5 271 Int_t iddiff = fId - digit->GetId() ;
272
0c22a365 273
274
61e0abb5 275 if ( iddiff > 0 )
0c22a365 276
61e0abb5 277 rv = 1 ;
0c22a365 278
61e0abb5 279 else if ( iddiff < 0 )
0c22a365 280
61e0abb5 281 rv = -1 ;
0c22a365 282
61e0abb5 283 else
0c22a365 284
61e0abb5 285 rv = 0 ;
0c22a365 286
61e0abb5 287
0c22a365 288
61e0abb5 289 return rv ;
290
0c22a365 291
292
61e0abb5 293}
294
0c22a365 295
296
814ad4bf 297//____________________________________________________________________________
0c22a365 298
814ad4bf 299const Float_t AliEMCALDigit::GetEta() const
0c22a365 300
814ad4bf 301{
0c22a365 302
814ad4bf 303 Float_t eta=-10., phi=-10.;
0c22a365 304
563aa66c 305 Int_t id = GetId();
0c22a365 306
da98933e 307 const AliEMCALGeometry *g = AliEMCALGetter::GetInstance()->EMCALGeometry();
0c22a365 308
563aa66c 309 g->EtaPhiFromIndex(id,eta,phi);
0c22a365 310
814ad4bf 311 return eta ;
0c22a365 312
814ad4bf 313}
314
0c22a365 315
316
814ad4bf 317//____________________________________________________________________________
0c22a365 318
814ad4bf 319const Float_t AliEMCALDigit::GetPhi() const
0c22a365 320
814ad4bf 321{
0c22a365 322
814ad4bf 323 Float_t eta=-10., phi=-10.;
0c22a365 324
563aa66c 325 Int_t id = GetId();
0c22a365 326
da98933e 327 const AliEMCALGeometry *g = AliEMCALGetter::GetInstance()->EMCALGeometry();
0c22a365 328
563aa66c 329 g->EtaPhiFromIndex(id,eta,phi);
0c22a365 330
814ad4bf 331 return phi ;
0c22a365 332
814ad4bf 333}
334
0c22a365 335
336
61e0abb5 337//____________________________________________________________________________
0c22a365 338
61e0abb5 339Int_t AliEMCALDigit::GetPrimary(Int_t index) const
0c22a365 340
61e0abb5 341{
0c22a365 342
61e0abb5 343 // retrieves the primary particle number given its index in the list
0c22a365 344
61e0abb5 345 Int_t rv = -1 ;
0c22a365 346
814ad4bf 347 if ( index <= fNprimary && index > 0){
0c22a365 348
61e0abb5 349 rv = fPrimary[index-1] ;
0c22a365 350
61e0abb5 351 }
352
0c22a365 353
354
61e0abb5 355 return rv ;
0c22a365 356
61e0abb5 357
0c22a365 358
61e0abb5 359}
360
0c22a365 361
362
61e0abb5 363//____________________________________________________________________________
0c22a365 364
61e0abb5 365Int_t AliEMCALDigit::GetIparent(Int_t index) const
0c22a365 366
61e0abb5 367{
0c22a365 368
61e0abb5 369 // retrieves the primary particle number given its index in the list
0c22a365 370
61e0abb5 371 Int_t rv = -1 ;
0c22a365 372
61e0abb5 373 if ( index <= fNiparent ){
0c22a365 374
61e0abb5 375 rv = fIparent[index-1] ;
0c22a365 376
61e0abb5 377 }
378
0c22a365 379
380
61e0abb5 381 return rv ;
0c22a365 382
61e0abb5 383
0c22a365 384
61e0abb5 385}
386
0c22a365 387
388
88d764f0 389//______________________________________________________________________
0c22a365 390
88d764f0 391const Bool_t AliEMCALDigit::IsInPreShower() const
0c22a365 392
88d764f0 393{
0c22a365 394
88d764f0 395 Bool_t rv = kFALSE ;
0c22a365 396
88d764f0 397 const AliEMCALGeometry * geom = AliEMCALGetter::GetInstance()->EMCALGeometry() ;
0c22a365 398
88d764f0 399 if( GetId() > (geom->GetNZ() * geom->GetNPhi() ))
0c22a365 400
88d764f0 401 rv = kTRUE;
0c22a365 402
88d764f0 403 return rv;
0c22a365 404
88d764f0 405}
61e0abb5 406
0c22a365 407
408
61e0abb5 409//____________________________________________________________________________
0c22a365 410
61e0abb5 411void AliEMCALDigit::ShiftPrimary(Int_t shift){
0c22a365 412
61e0abb5 413 //shifts primary nimber to BIG offset, to separate primary in different TreeK
0c22a365 414
61e0abb5 415 Int_t index ;
0c22a365 416
61e0abb5 417 for(index = 0; index <fNprimary; index++ ){
0c22a365 418
61e0abb5 419 fPrimary[index] = fPrimary[index]+ shift * 10000000 ;}
0c22a365 420
61e0abb5 421 for(index =0; index <fNiparent; index++){
0c22a365 422
61e0abb5 423 fIparent[index] = fIparent[index] + shift * 10000000 ;}
0c22a365 424
61e0abb5 425}
0c22a365 426
61e0abb5 427//____________________________________________________________________________
0c22a365 428
61e0abb5 429Bool_t AliEMCALDigit::operator==(AliEMCALDigit const & digit) const
0c22a365 430
61e0abb5 431{
0c22a365 432
61e0abb5 433 // Two digits are equal if they have the same Id
0c22a365 434
61e0abb5 435
0c22a365 436
61e0abb5 437 if ( fId == digit.fId )
0c22a365 438
61e0abb5 439 return kTRUE ;
0c22a365 440
61e0abb5 441 else
0c22a365 442
61e0abb5 443 return kFALSE ;
0c22a365 444
61e0abb5 445}
0c22a365 446
61e0abb5 447
0c22a365 448
61e0abb5 449//____________________________________________________________________________
0c22a365 450
61e0abb5 451AliEMCALDigit& AliEMCALDigit::operator+(AliEMCALDigit const & digit)
0c22a365 452
61e0abb5 453{
0c22a365 454
61e0abb5 455 // Adds the amplitude of digits and completes the list of primary particles
0c22a365 456
61e0abb5 457 // if amplitude is larger than
0c22a365 458
61e0abb5 459
0c22a365 460
61e0abb5 461 fAmp += digit.fAmp ;
0c22a365 462
814ad4bf 463 if(fTime > digit.fTime)
0c22a365 464
814ad4bf 465 fTime = digit.fTime ;
7b62cd84 466
0c22a365 467
468
61e0abb5 469 Int_t max1 = fNprimary ;
0c22a365 470
61e0abb5 471 Int_t max2 = fNiparent ;
0c22a365 472
61e0abb5 473 Int_t index ;
0c22a365 474
7b62cd84 475 for (index = 0 ; index < digit.fNprimary ; index++){
0c22a365 476
61e0abb5 477 Bool_t deja = kTRUE ;
0c22a365 478
61e0abb5 479 Int_t old ;
0c22a365 480
61e0abb5 481 for ( old = 0 ; (old < max1) && deja; old++) { //already have this primary?
0c22a365 482
7b62cd84 483 if(fPrimary[old] == digit.fPrimary[index])
0c22a365 484
61e0abb5 485 deja = kFALSE;
0c22a365 486
61e0abb5 487 }
0c22a365 488
61e0abb5 489 if(deja){
0c22a365 490
7b62cd84 491 if(max1<fNMaxPrimary){ fPrimary[max1] = digit.fPrimary[index] ;
0c22a365 492
61e0abb5 493 fNprimary++ ;
0c22a365 494
7b62cd84 495 max1++;}
0c22a365 496
7b62cd84 497 if(fNprimary==fNMaxPrimary) {
0c22a365 498
499 fNMaxPrimary += fMaxIter ;
500 Int_t tempo[fNprimary] ;
501 Int_t i ;
502 for (i=0; i < fNprimary; i++)
503 tempo[i] = fPrimary[i] ;
504 delete [] fPrimary ;
505 fPrimary = new Int_t[fNMaxPrimary];
506 for (i=0; i < fNprimary; i++)
507 fPrimary[i] = tempo[i] ;
508 //delete [] tempo ;
509 for (i=fNprimary; i < fNMaxPrimary; i++)
510 fPrimary[i] = -1 ;
511cout << "AliEMCALDigit >> NMaxPrimary has been increased to "<< fNMaxPrimary << endl ;
512
f807c3bd 513 return *this ;
0c22a365 514
61e0abb5 515 }
0c22a365 516
61e0abb5 517 }
0c22a365 518
61e0abb5 519 }
0c22a365 520
61e0abb5 521
0c22a365 522
61e0abb5 523 for (index = 0 ; index < digit.fNiparent ; index++){
0c22a365 524
61e0abb5 525 Bool_t dejavu = kTRUE ;
0c22a365 526
61e0abb5 527 Int_t old ;
0c22a365 528
61e0abb5 529 for ( old = 0 ; (old < max2) && dejavu; old++) { //already have this primary?
0c22a365 530
7b62cd84 531 if(fIparent[old] == digit.fIparent[index])
0c22a365 532
61e0abb5 533 dejavu = kFALSE;
0c22a365 534
61e0abb5 535 }
0c22a365 536
61e0abb5 537 if(dejavu){
0c22a365 538
7b62cd84 539 if(max2<fNMaxiparent){ fIparent[max2] = digit.fIparent[index] ;
0c22a365 540
61e0abb5 541 fNiparent++ ;
0c22a365 542
7b62cd84 543 max2++;}
0c22a365 544
7b62cd84 545 if(fNiparent==fNMaxiparent) {
0c22a365 546
547 fNMaxiparent += fMaxIter ;
548 Int_t tempo[fNiparent] ;
549 Int_t i ;
550 for (i=0; i < fNiparent; i++)
551 tempo[i] = fIparent[i] ;
552 delete [] fIparent ;
553 fIparent = new Int_t[fNMaxiparent];
554 for (i=0; i < fNiparent; i++)
555 fIparent[i] = tempo[i] ;
556 // delete [] tempo ;
557 for (i=fNiparent; i < fNMaxiparent; i++)
558 fIparent[i] = -1 ;
559 cout << "AliEMCALDigit >> Increasing fNMaxiparent to " << fNMaxiparent << endl ;
560
61e0abb5 561 return *this ;
0c22a365 562
61e0abb5 563 }
0c22a365 564
61e0abb5 565 }
0c22a365 566
61e0abb5 567 }
0c22a365 568
61e0abb5 569
0c22a365 570
61e0abb5 571 return *this ;
0c22a365 572
61e0abb5 573}
574
0c22a365 575
576
563aa66c 577//____________________________________________________________________________
0c22a365 578
563aa66c 579AliEMCALDigit& AliEMCALDigit::operator*(Float_t factor)
0c22a365 580
563aa66c 581{
0c22a365 582
563aa66c 583 // Multiplies the amplitude by a factor
0c22a365 584
563aa66c 585
0c22a365 586
563aa66c 587 Float_t tempo = static_cast<Float_t>(fAmp) ;
0c22a365 588
563aa66c 589 tempo *= factor ;
0c22a365 590
563aa66c 591 fAmp = static_cast<Int_t>(TMath::Ceil(tempo)) ;
0c22a365 592
563aa66c 593 return *this ;
0c22a365 594
563aa66c 595}
596
0c22a365 597
598
61e0abb5 599//____________________________________________________________________________
0c22a365 600
61e0abb5 601ostream& operator << ( ostream& out , const AliEMCALDigit & digit)
0c22a365 602
61e0abb5 603{
0c22a365 604
61e0abb5 605 // Prints the data of the digit
0c22a365 606
61e0abb5 607
0c22a365 608
814ad4bf 609 out << "ID " << digit.fId << " Energy = " << digit.fAmp << " Time = " << digit.fTime << endl ;
0c22a365 610
61e0abb5 611 Int_t i,j ;
0c22a365 612
61e0abb5 613 for(i=0;i<digit.fNprimary;i++)
0c22a365 614
61e0abb5 615 out << "Primary " << i+1 << " = " << digit.fPrimary[i] << endl ;
0c22a365 616
61e0abb5 617
0c22a365 618
61e0abb5 619 for(j=0;j<digit.fNiparent;j++)
0c22a365 620
61e0abb5 621 out << "Iparent " << j+1 << " = " << digit.fIparent[j] << endl ;
0c22a365 622
61e0abb5 623 out << "Position in list = " << digit.fIndexInList << endl ;
0c22a365 624
61e0abb5 625 return out ;
0c22a365 626
61e0abb5 627}
628
629
0c22a365 630
631
632