1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 /* History of cvs commits:
21 * Revision 1.39 2006/04/22 15:04:24 hristov
22 * Effective C++ initialization of data members in the default constructor
24 * Revision 1.38 2006/04/22 10:30:17 hristov
25 * Add fEnergy to AliPHOSDigit and operate with EMC amplitude in energy units (Yu.Kharlov)
27 * Revision 1.37 2005/05/28 14:19:04 schutz
28 * Compilation warnings fixed by T.P.
32 //_________________________________________________________________________
35 // 3 identifiers for the primary particle(s) at the origine of the digit
36 // The digits are made in FinishEvent() by summing all the hits in a single PHOS crystal or PPSD gas cell
38 //*-- Author: Laurent Aphecetche & Yves Schutz (SUBATECH) & Dmitri Peressounko (RRC KI & SUBATECH)
41 // --- ROOT system ---
45 // --- Standard library ---
47 // --- AliRoot header files ---
49 #include "AliPHOSDigit.h"
54 ClassImp(AliPHOSDigit)
56 //____________________________________________________________________________
57 AliPHOSDigit::AliPHOSDigit() :
73 //____________________________________________________________________________
74 AliPHOSDigit::AliPHOSDigit(Int_t primary, Int_t id, Int_t digEnergy, Float_t time, Int_t index) :
93 fIndexInList = index ;
97 fPrimary = new Int_t[fNprimary] ;
98 fPrimary[0] = primary ;
100 else{ //If the contribution of this primary smaller than fDigitThreshold (AliPHOSv1)
106 //____________________________________________________________________________
107 AliPHOSDigit::AliPHOSDigit(Int_t primary, Int_t id, Float_t energy, Float_t time, Int_t index) :
119 // ctor with all data
126 fIndexInList = index ;
129 fPrimary = new Int_t[fNprimary] ;
130 fPrimary[0] = primary ;
132 else{ //If the contribution of this primary smaller than fDigitThreshold (AliPHOSv1)
138 //____________________________________________________________________________
139 AliPHOSDigit::AliPHOSDigit(const AliPHOSDigit & digit) :
142 fNprimary(digit.fNprimary),
144 fEnergy(digit.fEnergy),
146 fTimeR(digit.fTimeR),
154 fPrimary = new Int_t[fNprimary] ;
155 for (Int_t i = 0; i < fNprimary ; i++)
156 fPrimary[i] = digit.fPrimary[i] ;
162 fIndexInList = digit.fIndexInList ;
165 //____________________________________________________________________________
166 AliPHOSDigit & AliPHOSDigit::operator = (const AliPHOSDigit &)
168 Fatal("operator =", "not implemented");
171 //____________________________________________________________________________
172 AliPHOSDigit::~AliPHOSDigit()
174 // Delete array of primaries if any
175 if (fPrimary) delete [] fPrimary ;
176 // Delete arrays of ALTRO samples if any
177 if (fSamplesHG) delete [] fSamplesHG;
178 if (fSamplesLG) delete [] fSamplesLG;
181 //____________________________________________________________________________
182 void AliPHOSDigit::Clear(const Option_t*)
184 // Delete array of primaries if any
185 delete[] fSamplesHG; fSamplesHG = NULL ;
186 delete[] fSamplesLG; fSamplesLG = NULL ;
187 delete[] fPrimary; fPrimary = NULL ;
191 //____________________________________________________________________________
192 Int_t AliPHOSDigit::Compare(const TObject * obj) const
194 // Compares two digits with respect to its Id
195 // to sort according increasing Id
199 AliPHOSDigit * digit = (AliPHOSDigit *)obj ;
201 Int_t iddiff = fId - digit->GetId() ;
205 else if ( iddiff < 0 )
214 //____________________________________________________________________________
215 Int_t AliPHOSDigit::GetPrimary(Int_t index) const
217 // retrieves the primary particle number given its index in the list
219 if ( index <= fNprimary && index > 0){
220 rv = fPrimary[index-1] ;
227 //____________________________________________________________________________
228 void AliPHOSDigit::SetALTROSamplesHG(Int_t nSamplesHG, Int_t *samplesHG)
230 fNSamplesHG = nSamplesHG;
231 if (fSamplesHG) delete [] fSamplesHG;
232 fSamplesHG = new UShort_t[fNSamplesHG];
234 for (i=0; i<fNSamplesHG; i++) {
235 fSamplesHG[i] = samplesHG[i];
238 //____________________________________________________________________________
239 void AliPHOSDigit::SetALTROSamplesLG(Int_t nSamplesLG, Int_t *samplesLG)
241 fNSamplesLG = nSamplesLG;
242 if (fSamplesLG) delete [] fSamplesLG;
243 fSamplesLG = new UShort_t[fNSamplesLG];
245 for (i=0; i<fNSamplesLG; i++) {
246 fSamplesLG[i] = samplesLG[i];
249 //____________________________________________________________________________
250 void AliPHOSDigit::Print(const Option_t *) const
252 // Print the digit together with list of primaries
253 TString line = Form("PHOS digit: E=%.3f, Id=%d, Time=%.3e, TimeR=%.3e, NPrim=%d, nHG=%d, nLG=%d \n",
254 fEnergy,fId,fTime,fTimeR,fNprimary,fNSamplesHG,fNSamplesLG);
255 line += "\tList of primaries: ";
256 for (Int_t index = 0; index <fNprimary; index ++ )
257 line += Form(" %d ",fPrimary[index]);
259 line += "\tSamples HG: ";
260 for (Int_t i = 0; i <fNSamplesHG; i++)
261 line += Form(" %d ",fSamplesHG[i]);
263 line += "\tSamples LG: ";
264 for (Int_t i = 0; i <fNSamplesLG; i++)
265 line += Form(" %d ",fSamplesLG[i]);
269 //____________________________________________________________________________
270 void AliPHOSDigit::ShiftPrimary(Int_t shift)
272 //shifts primary number to BIG offset, to separate primary in different TreeK
273 for(Int_t index = 0; index <fNprimary; index ++ ){
274 fPrimary[index]+= shift ;
277 //____________________________________________________________________________
278 Bool_t AliPHOSDigit::operator==(AliPHOSDigit const & digit) const
280 // Two digits are equal if they have the same Id
282 if ( fId == digit.fId )
288 //____________________________________________________________________________
289 AliPHOSDigit& AliPHOSDigit::operator+=(AliPHOSDigit const & digit)
292 // Adds the amplitude of digits and completes the list of primary particles
293 if(digit.fNprimary>0){
294 Int_t *tmp = new Int_t[fNprimary+digit.fNprimary] ;
295 if(fAmp < digit.fAmp || fEnergy < digit.fEnergy){//most energetic primary in second digit => first primaries in list from second digit
296 for (Int_t index = 0 ; index < digit.fNprimary ; index++)
297 tmp[index]=(digit.fPrimary)[index] ;
298 for (Int_t index = 0 ; index < fNprimary ; index++)
299 tmp[index+digit.fNprimary]=fPrimary[index] ;
301 else{ //add new primaries to the end
302 for (Int_t index = 0 ; index < fNprimary ; index++)
303 tmp[index]=fPrimary[index] ;
304 for (Int_t index = 0 ; index < digit.fNprimary ; index++)
305 tmp[index+fNprimary]=(digit.fPrimary)[index] ;
311 fNprimary+=digit.fNprimary ;
313 fEnergy += digit.fEnergy ;
314 if(fTime > digit.fTime)
315 fTime = digit.fTime ;
318 // Add high-gain ALTRO samples
320 if (digit.fNSamplesHG > fNSamplesHG) {
321 UShort_t newNSamplesHG = digit.fNSamplesHG;
322 UShort_t *newSamplesHG = new UShort_t[newNSamplesHG];
323 for (i=0; i<newNSamplesHG; i++) {
325 newSamplesHG[i] = TMath::Max(1023,fSamplesHG[i] + (digit.fSamplesHG)[i]);
327 newSamplesHG[i] = (digit.fSamplesHG)[i];
329 delete [] fSamplesHG;
330 fSamplesHG = new UShort_t[newNSamplesHG];
331 for (i=0; i<newNSamplesHG; i++) {
332 fSamplesHG[i] = newSamplesHG[i];
334 delete [] newSamplesHG;
337 for (i=0; i<fNSamplesHG; i++)
338 fSamplesHG[i] = TMath::Max(1023,fSamplesHG[i] + (digit.fSamplesHG)[i]);
341 // Add low-gain ALTRO samples
342 if (digit.fNSamplesLG > fNSamplesLG) {
343 UShort_t newNSamplesLG = digit.fNSamplesLG;
344 UShort_t *newSamplesLG = new UShort_t[newNSamplesLG];
345 for (i=0; i<newNSamplesLG; i++) {
347 newSamplesLG[i] = TMath::Max(1023,fSamplesLG[i] + (digit.fSamplesLG)[i]);
349 newSamplesLG[i] = (digit.fSamplesLG)[i];
351 delete [] fSamplesLG;
352 fSamplesLG = new UShort_t[newNSamplesLG];
353 for (i=0; i<newNSamplesLG; i++) {
354 fSamplesLG[i] = newSamplesLG[i];
356 delete [] newSamplesLG;
359 for (i=0; i<fNSamplesLG; i++)
360 fSamplesLG[i] = TMath::Max(1023,fSamplesLG[i] + (digit.fSamplesLG)[i]);
363 //If at least one digit in LG, then sum also
364 fIsLG=fIsLG||digit.fIsLG ;
368 //____________________________________________________________________________
369 AliPHOSDigit& AliPHOSDigit::operator *= (Float_t factor)
371 // Multiplies the amplitude by a factor
373 Float_t tempo = static_cast<Float_t>(fAmp) ;
375 fAmp = static_cast<Int_t>(TMath::Ceil(tempo)) ;
379 //____________________________________________________________________________
380 ostream& operator << ( ostream& out , const AliPHOSDigit & digit)
382 // Prints the data of the digit
384 // out << "ID " << digit.fId << " Energy = " << digit.fAmp << " Time = " << digit.fTime << endl ;
386 // for(i=0;i<digit.fNprimary;i++)
387 // out << "Primary " << i+1 << " = " << digit.fPrimary[i] << endl ;
388 // out << "Position in list = " << digit.fIndexInList << endl ;
389 digit.Warning("operator <<", "Implement differently") ;