]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EMCAL/AliEMCALDigit.cxx
Added method for filling TProfile
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALDigit.cxx
CommitLineData
61e0abb5 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
090026bf 16/* $Id$ */
61e0abb5 17
18//_________________________________________________________________________
ffa6d63b 19// EMCAL digit:
20// A Digit is the sum of the energy lost in an EMCAL Tower
21// It also stores information on Primary, and enterring particle
22// tracknumbers Digits are created using AliEMCALSDigitizer, followed
23// by AliEMCALDigitizer
61e0abb5 24//
ffa6d63b 25//*-- Author: Sahal Yacoob (LBL)
26// based on : AliPHOSDigit
814ad4bf 27//__________________________________________________________________________
61e0abb5 28
29// --- ROOT system ---
090026bf 30#include <Riostream.h>
31#include <TMath.h>
61e0abb5 32
33// --- Standard library ---
34
61e0abb5 35// --- AliRoot header files ---
36
37#include "AliEMCALDigit.h"
814ad4bf 38#include "AliEMCALGeometry.h"
61e0abb5 39
40ClassImp(AliEMCALDigit)
41
42//____________________________________________________________________________
514da33c 43AliEMCALDigit::AliEMCALDigit() :
829ba234 44AliDigitNew(),
45 fAmpFloat(0.),
46 fNSamples(0),
47 fSamples(0x0),
48 fNSamplesHG(0),
49 fSamplesHG(0x0),
514da33c 50 fNprimary(0),
51 fNMaxPrimary(5),
52 fPrimary(0x0),
af5bdd85 53 fDEPrimary(0x0),
514da33c 54 fNiparent(0),
55 fNMaxiparent(5),
56 fIparent(0x0),
af5bdd85 57 fDEParent(0x0),
514da33c 58 fMaxIter(0),
59 fTime(0.),
829ba234 60 fTimeR(0.),
61 fChi2(0.),
62 fNDF(0),
f4a4dc82 63 fDigitType(kUnknown)
514da33c 64
61e0abb5 65{
66 // default ctor
67
af5bdd85 68 // Need to initialise for reading old files
f4a4dc82 69 fPrimary = new Int_t[fNMaxPrimary] ;
af5bdd85 70 fDEPrimary = new Float_t[fNMaxPrimary] ;
f4a4dc82 71 fIparent = new Int_t[fNMaxiparent] ;
72 fDEParent = new Float_t[fNMaxiparent] ;
af5bdd85 73 for ( Int_t i = 0; i < fNMaxPrimary ; i++) {
f4a4dc82 74 fPrimary[i] = -1 ;
af5bdd85 75 fDEPrimary[i] = 0 ;
76 }
77
0ae8ae77 78 for ( Int_t i = 0; i < fNMaxiparent ; i++) {
f4a4dc82 79 fIparent[i] = -1 ;
af5bdd85 80 fDEParent[i] = 0 ;
81 }
61e0abb5 82}
83
84//____________________________________________________________________________
2cd0ffda 85AliEMCALDigit::AliEMCALDigit(Int_t primary, Int_t iparent, Int_t id, Float_t digEnergy, Float_t time, Int_t type, Int_t index, Float_t chi2, Int_t ndf, Float_t dE)
18a21c7c 86 : AliDigitNew(),
829ba234 87 fAmpFloat(digEnergy),
88 fNSamples(0),
f4a4dc82 89 fSamples(0x0),
829ba234 90 fNSamplesHG(0),
91 fSamplesHG(0x0),
18a21c7c 92 fNprimary(0),
93 fNMaxPrimary(25),
94 fPrimary(0x0),
af5bdd85 95 fDEPrimary(0x0),
18a21c7c 96 fNiparent(0),
97 fNMaxiparent(150),
98 fIparent(0x0),
af5bdd85 99 fDEParent(0x0),
18a21c7c 100 fMaxIter(5),
101 fTime(time),
829ba234 102 fTimeR(time),
2cd0ffda 103 fChi2(chi2),
104 fNDF(ndf),
f4a4dc82 105 fDigitType(type)
61e0abb5 106{
107 // ctor with all data
108
514da33c 109 // data memebrs of the base class (AliNewDigit)
829ba234 110 fAmp = 0;
514da33c 111 fId = id ;
112 fIndexInList = index ;
113
829ba234 114 // data member
f4a4dc82 115 fPrimary = new Int_t[fNMaxPrimary] ;
af5bdd85 116 fDEPrimary = new Float_t[fNMaxPrimary] ;
f4a4dc82 117 fIparent = new Int_t[fNMaxiparent] ;
118 fDEParent = new Float_t[fNMaxiparent] ;
61e0abb5 119 if( primary != -1){
120 fNprimary = 1 ;
7b62cd84 121 fPrimary[0] = primary ;
af5bdd85 122 fDEPrimary[0] = dE ;
61e0abb5 123 fNiparent = 1 ;
124 fIparent[0] = iparent ;
af5bdd85 125 fDEParent[0] = dE ;
126 }
61e0abb5 127 else{ //If the contribution of this primary smaller than fDigitThreshold (AliEMCALv1)
128 fNprimary = 0 ;
129 fPrimary[0] = -1 ;
af5bdd85 130 fDEPrimary[0] = 0 ;
61e0abb5 131 fNiparent = 0 ;
af5bdd85 132 fIparent[0] = -1 ;
133 fDEParent[0] = 0 ;
61e0abb5 134 }
135 Int_t i ;
af5bdd85 136 for ( i = 1; i < fNMaxPrimary ; i++) {
61e0abb5 137 fPrimary[i] = -1 ;
af5bdd85 138 fDEPrimary[i] = 0 ;
139 }
61e0abb5 140
af5bdd85 141 for ( i = 1; i< fNMaxiparent ; i++) {
f807c3bd 142 fIparent[i] = -1 ;
af5bdd85 143 fDEParent[i] = 0 ;
144 }
61e0abb5 145}
146
147//____________________________________________________________________________
18a21c7c 148AliEMCALDigit::AliEMCALDigit(const AliEMCALDigit & digit)
149 : AliDigitNew(digit),
f4a4dc82 150 fAmpFloat(digit.fAmpFloat),
151 fNSamples(digit.fNSamples),
e0dc3f7d 152 fSamples(),
829ba234 153 fNSamplesHG(digit.fNSamplesHG),
e0dc3f7d 154 fSamplesHG(),
18a21c7c 155 fNprimary(digit.fNprimary),
156 fNMaxPrimary(digit.fNMaxPrimary),
e0dc3f7d 157 fPrimary(),
158 fDEPrimary(),
18a21c7c 159 fNiparent(digit.fNiparent),
160 fNMaxiparent(digit.fNMaxiparent),
e0dc3f7d 161 fIparent(),
162 fDEParent(),
18a21c7c 163 fMaxIter(digit.fMaxIter),
164 fTime(digit.fTime),
829ba234 165 fTimeR(digit.fTimeR),
166 fChi2(digit.fChi2),
167 fNDF(digit.fNDF),
f4a4dc82 168 fDigitType(digit.fDigitType)
61e0abb5 169{
170 // copy ctor
514da33c 171 // data memebrs of the base class (AliNewDigit)
172 fAmp = digit.fAmp ;
173 fId = digit.fId;
174 fIndexInList = digit.fIndexInList ;
61e0abb5 175
829ba234 176 // data members
e0dc3f7d 177 if (fSamples ) delete [] fSamples ; fSamples = NULL ;
178 if (fSamplesHG ) delete [] fSamplesHG ; fSamplesHG = NULL ;
179 if (fPrimary ) delete [] fPrimary ; fPrimary = NULL ;
180 if (fDEPrimary) delete [] fDEPrimary ; fDEPrimary = NULL ;
181 if (fIparent ) delete [] fIparent ; fIparent = NULL ;
182 if (fDEParent) delete [] fDEParent ; fDEParent = NULL ;
183
184 if (fNSamples){
84f6f119 185 fSamples = new Int_t[fNSamples];
186 for (Int_t i=0; i < digit.fNSamples; i++) fSamples[i] = digit.fSamples[i];
187 }
e0dc3f7d 188
189 if (fNSamplesHG){
84f6f119 190 fSamplesHG = new Int_t[fNSamplesHG];
191 for (Int_t i=0; i < digit.fNSamplesHG; i++) fSamplesHG[i] = digit.fSamplesHG[i];
af5bdd85 192 }
e0dc3f7d 193
194
195 if (fNMaxPrimary){
84f6f119 196 fPrimary = new Int_t [fNMaxPrimary] ;
197 fDEPrimary = new Float_t[fNMaxPrimary] ;
198 for ( Int_t i = 0; i < fNMaxPrimary ; i++) {
199 fPrimary[i] = digit.fPrimary[i] ;
200 fDEPrimary[i] = digit.fDEPrimary[i] ;
201 }
202 }
e0dc3f7d 203
204 if (fNMaxiparent){
84f6f119 205 fIparent = new Int_t [fNMaxiparent] ;
206 fDEParent = new Float_t[fNMaxiparent] ;
207 for (Int_t j = 0; j< fNMaxiparent ; j++) {
af5bdd85 208 fIparent[j] = digit.fIparent[j] ;
84f6f119 209 fDEParent[j] = digit.fDEParent[j] ;
210 }
e0dc3f7d 211 }
212
61e0abb5 213}
214
215//____________________________________________________________________________
216AliEMCALDigit::~AliEMCALDigit()
217{
e0dc3f7d 218 // Delete array of primaries if any
219
220 if (fSamples ) delete [] fSamples ; fSamples = NULL ;
221 if (fSamplesHG ) delete [] fSamplesHG ; fSamplesHG = NULL ;
222 if (fPrimary ) delete [] fPrimary ; fPrimary = NULL ;
223 if (fDEPrimary) delete [] fDEPrimary ; fDEPrimary = NULL ;
224 if (fIparent ) delete [] fIparent ; fIparent = NULL ;
225 if (fDEParent) delete [] fDEParent ; fDEParent = NULL ;
226
227}
228
229
230//____________________________________________________________________________
231void AliEMCALDigit::Clear(const Option_t*)
232{
233 // Delete array of primaries if any
234 if (fSamples ) delete [] fSamples ; fSamples = NULL ;
235 if (fSamplesHG ) delete [] fSamplesHG ; fSamplesHG = NULL ;
236 if (fPrimary ) delete [] fPrimary ; fPrimary = NULL ;
237 if (fDEPrimary) delete [] fDEPrimary ; fDEPrimary = NULL ;
238 if (fIparent ) delete [] fIparent ; fIparent = NULL ;
239 if (fDEParent) delete [] fDEParent ; fDEParent = NULL ;
829ba234 240
61e0abb5 241}
242
243//____________________________________________________________________________
244Int_t AliEMCALDigit::Compare(const TObject * obj) const
245{
246 // Compares two digits with respect to its Id
247 // to sort according increasing Id
248
53e430a3 249 Int_t rv = 2 ;
61e0abb5 250
251 AliEMCALDigit * digit = (AliEMCALDigit *)obj ;
252
253 Int_t iddiff = fId - digit->GetId() ;
254
255 if ( iddiff > 0 )
256 rv = 1 ;
257 else if ( iddiff < 0 )
258 rv = -1 ;
259 else
260 rv = 0 ;
261
262 return rv ;
263
264}
265
814ad4bf 266//____________________________________________________________________________
88cb7938 267Float_t AliEMCALDigit::GetEta() const
14ce0a6e 268{
269 //return pseudorapidity for this digit
270 // should be change in EMCALGeometry - 19-nov-04
814ad4bf 271 Float_t eta=-10., phi=-10.;
563aa66c 272 Int_t id = GetId();
5dee926e 273 const AliEMCALGeometry *g = AliEMCALGeometry::GetInstance();
563aa66c 274 g->EtaPhiFromIndex(id,eta,phi);
814ad4bf 275 return eta ;
276}
277
278//____________________________________________________________________________
88cb7938 279Float_t AliEMCALDigit::GetPhi() const
14ce0a6e 280{
281 //return phi coordinate of digit
282 // should be change in EMCALGeometry - 19-nov-04
814ad4bf 283 Float_t eta=-10., phi=-10.;
563aa66c 284 Int_t id = GetId();
5dee926e 285 const AliEMCALGeometry *g = AliEMCALGeometry::GetInstance();
563aa66c 286 g->EtaPhiFromIndex(id,eta,phi);
814ad4bf 287 return phi ;
288}
289
829ba234 290//____________________________________________________________________________
291Bool_t AliEMCALDigit::GetFALTROSample(const Int_t iSample, Int_t& timeBin, Int_t& amp) const
292{
293 //Get FALTRO sample in time bin iSample
f4a4dc82 294 if (iSample >= fNSamples || iSample < 0 || fDigitType==kTrigger) return kFALSE;
829ba234 295
296 amp = fSamples[iSample] & 0xFFF;
297 timeBin = (fSamples[iSample] >> 12) & 0xFF;
298
299 return kTRUE;
300}
301//____________________________________________________________________________
302Bool_t AliEMCALDigit::GetALTROSampleLG(const Int_t iSample, Int_t& timeBin, Int_t& amp) const
303{
304 //Get Low Gain ALTRO sample in time bin iSample
f4a4dc82 305 if (iSample >= fNSamples || iSample < 0 || fDigitType==kLG) return kFALSE;
829ba234 306
307 amp = fSamples[iSample] & 0xFFF;
308 timeBin = (fSamples[iSample] >> 12) & 0xFF;
309
310 return kTRUE;
311}
312
313//____________________________________________________________________________
314void AliEMCALDigit::SetALTROSamplesLG(const Int_t nSamples, Int_t *samples)
315{
316 //Set array of ALTRO samples, Low Gain or FALTRO
317 fNSamples = nSamples;
318 fSamples = new Int_t[fNSamples];
319 for (Int_t i=0; i < fNSamples; i++) fSamples[i] = samples[i];
320}
321
322//____________________________________________________________________________
323void AliEMCALDigit::SetALTROSamplesHG(const Int_t nSamples, Int_t *samples)
324{
325 //Set array of ALTRO samples, High Gain.
326 fNSamplesHG = nSamples;
327 fSamplesHG = new Int_t[fNSamplesHG];
328 for (Int_t i=0; i < fNSamplesHG; i++) fSamplesHG[i] = samples[i];
329}
330
331
332//____________________________________________________________________________
333Bool_t AliEMCALDigit::GetALTROSampleHG(const Int_t iSample, Int_t& timeBin, Int_t& amp) const
334{
335 //Get High Gain ALTRO sample in time bin iSample
f4a4dc82 336 if (iSample >= fNSamplesHG || iSample < 0 || fDigitType==kHG) return kFALSE;
829ba234 337
338 amp = fSamplesHG[iSample] & 0xFFF;
339 timeBin = (fSamplesHG[iSample] >> 12) & 0xFF;
340
341 return kTRUE;
342}
343
344
61e0abb5 345//____________________________________________________________________________
346Int_t AliEMCALDigit::GetPrimary(Int_t index) const
347{
348 // retrieves the primary particle number given its index in the list
fdebddeb 349 if ( (index <= fNprimary) && (index > 0)){
af5bdd85 350 return fPrimary[index-1] ;
61e0abb5 351 }
352
af5bdd85 353 return -1 ;
354}
355
356//____________________________________________________________________________
357Float_t AliEMCALDigit::GetDEPrimary(Int_t index) const
358{
359 // retrieves the primary particle energy contribution
360 // given its index in the list
361 if ( (index <= fNprimary) && (index > 0)){
362 return fDEPrimary[index-1] ;
363 }
364
365 return 0 ;
61e0abb5 366
367}
368
369//____________________________________________________________________________
370Int_t AliEMCALDigit::GetIparent(Int_t index) const
371{
372 // retrieves the primary particle number given its index in the list
af5bdd85 373 if ( index <= fNiparent && index > 0){
374 return fIparent[index-1] ;
61e0abb5 375 }
376
af5bdd85 377 return -1 ;
61e0abb5 378
379}
380
af5bdd85 381//____________________________________________________________________________
382Float_t AliEMCALDigit::GetDEParent(Int_t index) const
383{
384 // retrieves the parent particle energy contribution
385 // given its index in the list
386 if ( (index <= fNiparent) && (index > 0)){
387 return fDEParent[index-1] ;
388 }
389
390 return 0;
391}
392
61e0abb5 393//____________________________________________________________________________
394void AliEMCALDigit::ShiftPrimary(Int_t shift){
fdebddeb 395 //shifts primary number to BIG offset, to separate primary in different TreeK
61e0abb5 396 Int_t index ;
397 for(index = 0; index <fNprimary; index++ ){
398 fPrimary[index] = fPrimary[index]+ shift * 10000000 ;}
399 for(index =0; index <fNiparent; index++){
400 fIparent[index] = fIparent[index] + shift * 10000000 ;}
401}
402//____________________________________________________________________________
403Bool_t AliEMCALDigit::operator==(AliEMCALDigit const & digit) const
404{
405 // Two digits are equal if they have the same Id
406
407 if ( fId == digit.fId )
408 return kTRUE ;
409 else
410 return kFALSE ;
411}
412
413//____________________________________________________________________________
0a4cb131 414AliEMCALDigit AliEMCALDigit::operator+(const AliEMCALDigit &digit)
61e0abb5 415{
416 // Adds the amplitude of digits and completes the list of primary particles
417 // if amplitude is larger than
418
829ba234 419 fAmpFloat += digit.fAmpFloat ;
420 for (Int_t i=0; i < fNSamples ; i++) fSamples[i] += digit.fSamples[i];
421 for (Int_t i=0; i < fNSamplesHG; i++) fSamplesHG[i] += digit.fSamplesHG[i];
d8c2bd69 422
829ba234 423 fAmp += digit.fAmp ;
814ad4bf 424 if(fTime > digit.fTime)
425 fTime = digit.fTime ;
3c80fef6 426 if (digit.fTimeR < fTimeR)
427 fTimeR = digit.fTimeR ;
d8c2bd69 428
61e0abb5 429 Int_t max1 = fNprimary ;
430 Int_t max2 = fNiparent ;
431 Int_t index ;
7b62cd84 432 for (index = 0 ; index < digit.fNprimary ; index++){
af5bdd85 433 Bool_t newPrim = kTRUE ;
61e0abb5 434 Int_t old ;
af5bdd85 435 for ( old = 0 ; (old < max1) && newPrim; old++) { //already have this primary?
436 if(fPrimary[old] == digit.fPrimary[index]) {
d8c2bd69 437 newPrim = kFALSE;
438 fDEPrimary[old] += digit.fDEPrimary[index];
af5bdd85 439 }
61e0abb5 440 }
af5bdd85 441 if (newPrim) {
442 if(max1<fNMaxPrimary){
d8c2bd69 443 fPrimary[max1] = digit.fPrimary[index] ;
444 fDEPrimary[max1] = digit.fDEPrimary[index] ;
445 fNprimary++ ;
446 max1++;
af5bdd85 447 }
7b62cd84 448 if(fNprimary==fNMaxPrimary) {
d8c2bd69 449
450 TString mess = " NMaxPrimary = " ;
451 mess += fNMaxPrimary ;
452 mess += " is too small" ;
453 AliFatal(mess.Data()) ;
454
61e0abb5 455 }
456 }
457 }
458
459 for (index = 0 ; index < digit.fNiparent ; index++){
af5bdd85 460 Bool_t newParent = kTRUE ;
61e0abb5 461 Int_t old ;
af5bdd85 462 for ( old = 0 ; (old < max2) && newParent; old++) { //already have this primary?
463 if(fIparent[old] == digit.fIparent[index]) {
d8c2bd69 464 newParent = kFALSE;
465 fDEParent[old] += digit.fDEParent[index];
af5bdd85 466 }
61e0abb5 467 }
af5bdd85 468 if(newParent){
469 if(max2<fNMaxiparent) {
d8c2bd69 470 fIparent[max2] = digit.fIparent[index] ;
471 fDEParent[max2] = digit.fDEParent[index] ;
472 fNiparent++ ;
473 max2++;
af5bdd85 474 }
7b62cd84 475 if(fNiparent==fNMaxiparent) {
d8c2bd69 476
477 TString mess = " NMaxiparent = " ;
478 mess += fNMaxiparent ;
479 mess += " is too small" ;
480 AliFatal(mess.Data()) ;
481
61e0abb5 482 }
483 }
484 }
485
486 return *this ;
487}
488
563aa66c 489//____________________________________________________________________________
0a4cb131 490AliEMCALDigit AliEMCALDigit::operator*(Float_t factor)
563aa66c 491{
492 // Multiplies the amplitude by a factor
493
829ba234 494 //Float_t tempo = static_cast<Float_t>(fAmp) ;
495 //tempo *= factor ;
496 //fAmp = static_cast<Int_t>(TMath::Floor(tempo)) ;
497
498 fAmpFloat *= factor;
499 for (Int_t i=0; i < fNSamples ; i++) fSamples[i] = Int_t(factor*fSamples[i]);
500 for (Int_t i=0; i < fNSamplesHG; i++) fSamplesHG[i] = Int_t(factor*fSamplesHG[i]);
501
af5bdd85 502 for(Int_t i=0; i < fNprimary; i++)
503 fDEPrimary[i] *= factor;
504 for(Int_t i=0; i < fNiparent; i++)
505 fDEParent[i] *= factor;
506
563aa66c 507 return *this ;
508}
509
61e0abb5 510//____________________________________________________________________________
511ostream& operator << ( ostream& out , const AliEMCALDigit & digit)
512{
513 // Prints the data of the digit
514
814ad4bf 515 out << "ID " << digit.fId << " Energy = " << digit.fAmp << " Time = " << digit.fTime << endl ;
53e430a3 516 for(Int_t i=0;i<digit.fNprimary;i++)
af5bdd85 517 out << "Primary " << i+1 << " = " << digit.fPrimary[i]
518 << " : DE " << digit.fDEPrimary[i] << endl ;
61e0abb5 519
53e430a3 520 for(Int_t j=0;j<digit.fNiparent;j++)
af5bdd85 521 out << "Iparent " << j+1 << " = " << digit.fIparent[j]
522 << " : DE " << digit.fDEParent[j] << endl ;
523 out << "Position in list = " << digit.fIndexInList << endl ;
61e0abb5 524 return out ;
525}
526
829ba234 527//____________________________________________________________________________
528void AliEMCALDigit::Print(const Option_t* /*opt*/) const
529{
530 //Print
f4a4dc82 531 printf("===\nDigit id: %4d / Energy %2.3f ; Time %e ; Time samples %d ; Chi2 %2.3f, NDF %d, Type? %d \n",
532 fId, fAmpFloat,fTime, fNSamples, fChi2, fNDF, fDigitType);
533 if(fDigitType==kTrigger){
829ba234 534 printf("FALTRO: ");
535 for (Int_t i=0; i < GetNFALTROSamples(); i++)
536 {
537 Int_t timeBin, amp;
538 GetFALTROSample(i, timeBin, amp);
539 printf(" (%d,%d) ",timeBin,amp);
540 }
541 printf("\n");
542 }//trigger
543 else{
544 printf("ALTRO, Low Gain: ");
545 for (Int_t i=0; i < GetNALTROSamplesLG(); i++)
546 {
547 Int_t timeBin, amp;
548 GetALTROSampleLG(i, timeBin, amp);
549 printf(" (%d,%d) ",timeBin,amp);
550 }
551 printf("\n");
552 printf("ALTRO, High Gain: ");
553 for (Int_t i=0; i < GetNALTROSamplesHG(); i++)
554 {
555 Int_t timeBin, amp;
556 GetALTROSampleHG(i, timeBin, amp);
557 printf(" (%d,%d) ",timeBin,amp);
558 }
559 printf("\n");
560 }//trigger
561
562}
563
564
61e0abb5 565