ROOT logo
/**************************************************************************
 * Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
 *                                                                        *
 * Author: The ALICE Off-line Project.                                    *
 * Contributors are mentioned in the code where appropriate.              *
 *                                                                        *
 * Permission to use, copy, modify and distribute this software and its   *
 * documentation strictly for non-commercial purposes is hereby granted   *
 * without fee, provided that the above copyright notice appears in all   *
 * copies and that both the copyright notice and this permission notice   *
 * appear in the supporting documentation. The authors make no claims     *
 * about the suitability of this software for any purpose. It is          *
 * provided "as is" without express or implied warranty.                  *
 **************************************************************************/

/* $Id$ */

//-------------------------------------------------------------------------
//     AOD calorimeter cluster class (for PHOS and EMCAL)
//     Author: Markus Oldenburg, CERN
//-------------------------------------------------------------------------

#include <TLorentzVector.h>
#include "AliAODCaloCluster.h"

ClassImp(AliAODCaloCluster)

//______________________________________________________________________________
AliAODCaloCluster::AliAODCaloCluster() : 
  AliAODCluster(),
  fDistToBadChannel(-999.),
  fDispersion(-1),
  fM20(0.),
  fM02(0.),
  fEmcCpvDistance(-999.),
  fTrackDx(-999),
  fTrackDz(-999),
  fNExMax(0), 
  fTOF(0.),
  fCoreEnergy(0.),
  fTracksMatched(),
  fNCells(0),
  fCellsAbsId(0x0),
  fCellsAmpFraction(0x0)
{
  // default constructor

}

//______________________________________________________________________________
AliAODCaloCluster::AliAODCaloCluster(Int_t id,
				     UInt_t nLabel,
				     Int_t *label, 
				     Double_t energy,
				     Double_t x[3],
				     Double_t pid[13],
				     Char_t ttype,
				     UInt_t selectInfo) :
  AliAODCluster(id, nLabel, label, energy, x, pid, ttype, selectInfo),
  fDistToBadChannel(-999.),
  fDispersion(-1),
  fM20(0.),
  fM02(0.),
  fEmcCpvDistance(-999.),
  fTrackDx(-999),
  fTrackDz(-999),
  fNExMax(0),
  fTOF(0.),
  fCoreEnergy(0.),
  fTracksMatched(),
  fNCells(0),
  fCellsAbsId(0x0),
  fCellsAmpFraction(0x0)
{
  // constructor

}

//______________________________________________________________________________
AliAODCaloCluster::AliAODCaloCluster(Int_t id,
				     UInt_t nLabel,
				     Int_t *label, 
				     Float_t energy,
				     Float_t x[3],
				     Float_t pid[13],
				     Char_t ttype,
				     UInt_t selectInfo) :
  AliAODCluster(id, nLabel, label, energy, x, pid, ttype, selectInfo),
  fDistToBadChannel(-999.),
  fDispersion(-1),
  fM20(0.),
  fM02(0.),
  fEmcCpvDistance(-999.),
  fTrackDx(-999),
  fTrackDz(-999),
  fNExMax(0),
  fTOF(0.),
  fCoreEnergy(0.),
  fTracksMatched(),
  fNCells(0),
  fCellsAbsId(0x0),
  fCellsAmpFraction(0x0)
{
  // constructor
}


//______________________________________________________________________________
AliAODCaloCluster::~AliAODCaloCluster() 
{
  // destructor
  if(fCellsAmpFraction) delete[] fCellsAmpFraction; fCellsAmpFraction=0;
  if(fCellsAbsId)       delete[] fCellsAbsId;       fCellsAbsId = 0;
}

//______________________________________________________________________________
void AliAODCaloCluster::Clear(const Option_t*) 
{
  // clear
  RemoveLabel();
  if(fCellsAmpFraction) delete[] fCellsAmpFraction; fCellsAmpFraction=0;
  if(fCellsAbsId)       delete[] fCellsAbsId;       fCellsAbsId = 0;
}

//______________________________________________________________________________
AliAODCaloCluster::AliAODCaloCluster(const AliAODCaloCluster& clus) :
  AliAODCluster(clus),
  fDistToBadChannel(clus.fDistToBadChannel),
  fDispersion(clus.fDispersion),
  fM20(clus.fM20),
  fM02(clus.fM02),
  fEmcCpvDistance(clus.fEmcCpvDistance),
  fTrackDx(clus.fTrackDx),
  fTrackDz(clus.fTrackDz),
  fNExMax(clus.fNExMax),
  fTOF(clus.fTOF),
  fCoreEnergy(clus.fCoreEnergy),
  fTracksMatched(clus.fTracksMatched),
  fNCells(clus.fNCells),
  fCellsAbsId(0x0),
  fCellsAmpFraction(0x0)
{
  // Copy constructor

  if (clus.fNCells > 0) {
    
    if(clus.fCellsAbsId){
      fCellsAbsId = new UShort_t[clus.fNCells];
      for (Int_t i=0; i<clus.fNCells; i++)
        fCellsAbsId[i]=clus.fCellsAbsId[i];
    }
    
    if(clus.fCellsAmpFraction){
      fCellsAmpFraction = new Double32_t[clus.fNCells];
      for (Int_t i=0; i<clus.fNCells; i++)
        fCellsAmpFraction[i]=clus.fCellsAmpFraction[i];
    }
    
  }
  
}

//______________________________________________________________________________
AliAODCaloCluster& AliAODCaloCluster::operator=(const AliAODCaloCluster& clus)
{
  // Assignment operator
  if(this!=&clus) {

    AliAODCluster::operator=(clus);

    fDistToBadChannel = clus.fDistToBadChannel;
    fDispersion = clus.fDispersion;
    fM20 = clus.fM20;
    fM02 = clus.fM02;
    fEmcCpvDistance = clus.fEmcCpvDistance;
    fTrackDx=clus.fTrackDx;
    fTrackDz=clus.fTrackDz;
    fNExMax = clus.fNExMax;
    fTOF = clus.fTOF;
    fCoreEnergy = clus.fCoreEnergy;
    fTracksMatched = clus.fTracksMatched;

    fNCells= clus. fNCells;
    // delete anyway 
    if(fCellsAbsId)delete [] fCellsAbsId;
    if(fCellsAmpFraction)delete [] fCellsAmpFraction;

    if (clus.fNCells > 0) {
      
      if(clus.fCellsAbsId){
	fCellsAbsId = new UShort_t[clus.fNCells];
	for (Int_t i=0; i<clus.fNCells; i++)
	  fCellsAbsId[i]=clus.fCellsAbsId[i];
      }
      
      if(clus.fCellsAmpFraction){
	fCellsAmpFraction = new Double32_t[clus.fNCells];
	for (Int_t i=0; i<clus.fNCells; i++)
	  fCellsAmpFraction[i]=clus.fCellsAmpFraction[i];
      }
      
    }

  }

  return *this;
}

//_______________________________________________________________________
Bool_t AliAODCaloCluster::HasTrackMatched(TObject *trk) const
{
  // Checks if the given track contributed to this cluster.

  TRefArrayIter iter(&fTracksMatched);
  while (TObject *track = iter.Next()) {
    if (trk == track) return kTRUE;
  }
  return kFALSE;
}

//_______________________________________________________________________
void AliAODCaloCluster::GetMomentum(TLorentzVector& p, Double_t *vertex ) const {
  // Returns TLorentzVector with momentum of the cluster. Only valid for clusters 
  // identified as photons or pi0 (overlapped gamma) produced on the vertex
  //Vertex can be recovered with esd pointer doing:  
  //" Double_t vertex[3] ; esd->GetVertex()->GetXYZ(vertex) ; "

  Double32_t energy = E();
  Float_t    pos[3];
  GetPosition(pos);
  
  if(vertex){//calculate direction from vertex
    pos[0]-=vertex[0];
    pos[1]-=vertex[1];
    pos[2]-=vertex[2];
  }
  
  Double_t r = TMath::Sqrt(pos[0]*pos[0]+
			   pos[1]*pos[1]+
			   pos[2]*pos[2]   ) ; 
  
  p.SetPxPyPzE( energy*pos[0]/r,  energy*pos[1]/r,  energy*pos[2]/r,  energy) ; 
  
}


void  AliAODCaloCluster::SetCellsAbsId(UShort_t *array)
{
    //  Set the array of cell absId numbers 
    if (fNCells) {
      if(!fCellsAbsId)fCellsAbsId = new  UShort_t[fNCells];
      for (Int_t i = 0; i < fNCells; i++) fCellsAbsId[i] = array[i];
    }
}

void  AliAODCaloCluster::SetCellsAmplitudeFraction(Double32_t *array)
{
    //  Set the array of cell amplitude fraction
    if (fNCells) {
      if(!fCellsAmpFraction)fCellsAmpFraction = new  Double32_t[fNCells];
      for (Int_t i = 0; i < fNCells; i++) fCellsAmpFraction[i] = array[i];
    }
}
 AliAODCaloCluster.cxx:1
 AliAODCaloCluster.cxx:2
 AliAODCaloCluster.cxx:3
 AliAODCaloCluster.cxx:4
 AliAODCaloCluster.cxx:5
 AliAODCaloCluster.cxx:6
 AliAODCaloCluster.cxx:7
 AliAODCaloCluster.cxx:8
 AliAODCaloCluster.cxx:9
 AliAODCaloCluster.cxx:10
 AliAODCaloCluster.cxx:11
 AliAODCaloCluster.cxx:12
 AliAODCaloCluster.cxx:13
 AliAODCaloCluster.cxx:14
 AliAODCaloCluster.cxx:15
 AliAODCaloCluster.cxx:16
 AliAODCaloCluster.cxx:17
 AliAODCaloCluster.cxx:18
 AliAODCaloCluster.cxx:19
 AliAODCaloCluster.cxx:20
 AliAODCaloCluster.cxx:21
 AliAODCaloCluster.cxx:22
 AliAODCaloCluster.cxx:23
 AliAODCaloCluster.cxx:24
 AliAODCaloCluster.cxx:25
 AliAODCaloCluster.cxx:26
 AliAODCaloCluster.cxx:27
 AliAODCaloCluster.cxx:28
 AliAODCaloCluster.cxx:29
 AliAODCaloCluster.cxx:30
 AliAODCaloCluster.cxx:31
 AliAODCaloCluster.cxx:32
 AliAODCaloCluster.cxx:33
 AliAODCaloCluster.cxx:34
 AliAODCaloCluster.cxx:35
 AliAODCaloCluster.cxx:36
 AliAODCaloCluster.cxx:37
 AliAODCaloCluster.cxx:38
 AliAODCaloCluster.cxx:39
 AliAODCaloCluster.cxx:40
 AliAODCaloCluster.cxx:41
 AliAODCaloCluster.cxx:42
 AliAODCaloCluster.cxx:43
 AliAODCaloCluster.cxx:44
 AliAODCaloCluster.cxx:45
 AliAODCaloCluster.cxx:46
 AliAODCaloCluster.cxx:47
 AliAODCaloCluster.cxx:48
 AliAODCaloCluster.cxx:49
 AliAODCaloCluster.cxx:50
 AliAODCaloCluster.cxx:51
 AliAODCaloCluster.cxx:52
 AliAODCaloCluster.cxx:53
 AliAODCaloCluster.cxx:54
 AliAODCaloCluster.cxx:55
 AliAODCaloCluster.cxx:56
 AliAODCaloCluster.cxx:57
 AliAODCaloCluster.cxx:58
 AliAODCaloCluster.cxx:59
 AliAODCaloCluster.cxx:60
 AliAODCaloCluster.cxx:61
 AliAODCaloCluster.cxx:62
 AliAODCaloCluster.cxx:63
 AliAODCaloCluster.cxx:64
 AliAODCaloCluster.cxx:65
 AliAODCaloCluster.cxx:66
 AliAODCaloCluster.cxx:67
 AliAODCaloCluster.cxx:68
 AliAODCaloCluster.cxx:69
 AliAODCaloCluster.cxx:70
 AliAODCaloCluster.cxx:71
 AliAODCaloCluster.cxx:72
 AliAODCaloCluster.cxx:73
 AliAODCaloCluster.cxx:74
 AliAODCaloCluster.cxx:75
 AliAODCaloCluster.cxx:76
 AliAODCaloCluster.cxx:77
 AliAODCaloCluster.cxx:78
 AliAODCaloCluster.cxx:79
 AliAODCaloCluster.cxx:80
 AliAODCaloCluster.cxx:81
 AliAODCaloCluster.cxx:82
 AliAODCaloCluster.cxx:83
 AliAODCaloCluster.cxx:84
 AliAODCaloCluster.cxx:85
 AliAODCaloCluster.cxx:86
 AliAODCaloCluster.cxx:87
 AliAODCaloCluster.cxx:88
 AliAODCaloCluster.cxx:89
 AliAODCaloCluster.cxx:90
 AliAODCaloCluster.cxx:91
 AliAODCaloCluster.cxx:92
 AliAODCaloCluster.cxx:93
 AliAODCaloCluster.cxx:94
 AliAODCaloCluster.cxx:95
 AliAODCaloCluster.cxx:96
 AliAODCaloCluster.cxx:97
 AliAODCaloCluster.cxx:98
 AliAODCaloCluster.cxx:99
 AliAODCaloCluster.cxx:100
 AliAODCaloCluster.cxx:101
 AliAODCaloCluster.cxx:102
 AliAODCaloCluster.cxx:103
 AliAODCaloCluster.cxx:104
 AliAODCaloCluster.cxx:105
 AliAODCaloCluster.cxx:106
 AliAODCaloCluster.cxx:107
 AliAODCaloCluster.cxx:108
 AliAODCaloCluster.cxx:109
 AliAODCaloCluster.cxx:110
 AliAODCaloCluster.cxx:111
 AliAODCaloCluster.cxx:112
 AliAODCaloCluster.cxx:113
 AliAODCaloCluster.cxx:114
 AliAODCaloCluster.cxx:115
 AliAODCaloCluster.cxx:116
 AliAODCaloCluster.cxx:117
 AliAODCaloCluster.cxx:118
 AliAODCaloCluster.cxx:119
 AliAODCaloCluster.cxx:120
 AliAODCaloCluster.cxx:121
 AliAODCaloCluster.cxx:122
 AliAODCaloCluster.cxx:123
 AliAODCaloCluster.cxx:124
 AliAODCaloCluster.cxx:125
 AliAODCaloCluster.cxx:126
 AliAODCaloCluster.cxx:127
 AliAODCaloCluster.cxx:128
 AliAODCaloCluster.cxx:129
 AliAODCaloCluster.cxx:130
 AliAODCaloCluster.cxx:131
 AliAODCaloCluster.cxx:132
 AliAODCaloCluster.cxx:133
 AliAODCaloCluster.cxx:134
 AliAODCaloCluster.cxx:135
 AliAODCaloCluster.cxx:136
 AliAODCaloCluster.cxx:137
 AliAODCaloCluster.cxx:138
 AliAODCaloCluster.cxx:139
 AliAODCaloCluster.cxx:140
 AliAODCaloCluster.cxx:141
 AliAODCaloCluster.cxx:142
 AliAODCaloCluster.cxx:143
 AliAODCaloCluster.cxx:144
 AliAODCaloCluster.cxx:145
 AliAODCaloCluster.cxx:146
 AliAODCaloCluster.cxx:147
 AliAODCaloCluster.cxx:148
 AliAODCaloCluster.cxx:149
 AliAODCaloCluster.cxx:150
 AliAODCaloCluster.cxx:151
 AliAODCaloCluster.cxx:152
 AliAODCaloCluster.cxx:153
 AliAODCaloCluster.cxx:154
 AliAODCaloCluster.cxx:155
 AliAODCaloCluster.cxx:156
 AliAODCaloCluster.cxx:157
 AliAODCaloCluster.cxx:158
 AliAODCaloCluster.cxx:159
 AliAODCaloCluster.cxx:160
 AliAODCaloCluster.cxx:161
 AliAODCaloCluster.cxx:162
 AliAODCaloCluster.cxx:163
 AliAODCaloCluster.cxx:164
 AliAODCaloCluster.cxx:165
 AliAODCaloCluster.cxx:166
 AliAODCaloCluster.cxx:167
 AliAODCaloCluster.cxx:168
 AliAODCaloCluster.cxx:169
 AliAODCaloCluster.cxx:170
 AliAODCaloCluster.cxx:171
 AliAODCaloCluster.cxx:172
 AliAODCaloCluster.cxx:173
 AliAODCaloCluster.cxx:174
 AliAODCaloCluster.cxx:175
 AliAODCaloCluster.cxx:176
 AliAODCaloCluster.cxx:177
 AliAODCaloCluster.cxx:178
 AliAODCaloCluster.cxx:179
 AliAODCaloCluster.cxx:180
 AliAODCaloCluster.cxx:181
 AliAODCaloCluster.cxx:182
 AliAODCaloCluster.cxx:183
 AliAODCaloCluster.cxx:184
 AliAODCaloCluster.cxx:185
 AliAODCaloCluster.cxx:186
 AliAODCaloCluster.cxx:187
 AliAODCaloCluster.cxx:188
 AliAODCaloCluster.cxx:189
 AliAODCaloCluster.cxx:190
 AliAODCaloCluster.cxx:191
 AliAODCaloCluster.cxx:192
 AliAODCaloCluster.cxx:193
 AliAODCaloCluster.cxx:194
 AliAODCaloCluster.cxx:195
 AliAODCaloCluster.cxx:196
 AliAODCaloCluster.cxx:197
 AliAODCaloCluster.cxx:198
 AliAODCaloCluster.cxx:199
 AliAODCaloCluster.cxx:200
 AliAODCaloCluster.cxx:201
 AliAODCaloCluster.cxx:202
 AliAODCaloCluster.cxx:203
 AliAODCaloCluster.cxx:204
 AliAODCaloCluster.cxx:205
 AliAODCaloCluster.cxx:206
 AliAODCaloCluster.cxx:207
 AliAODCaloCluster.cxx:208
 AliAODCaloCluster.cxx:209
 AliAODCaloCluster.cxx:210
 AliAODCaloCluster.cxx:211
 AliAODCaloCluster.cxx:212
 AliAODCaloCluster.cxx:213
 AliAODCaloCluster.cxx:214
 AliAODCaloCluster.cxx:215
 AliAODCaloCluster.cxx:216
 AliAODCaloCluster.cxx:217
 AliAODCaloCluster.cxx:218
 AliAODCaloCluster.cxx:219
 AliAODCaloCluster.cxx:220
 AliAODCaloCluster.cxx:221
 AliAODCaloCluster.cxx:222
 AliAODCaloCluster.cxx:223
 AliAODCaloCluster.cxx:224
 AliAODCaloCluster.cxx:225
 AliAODCaloCluster.cxx:226
 AliAODCaloCluster.cxx:227
 AliAODCaloCluster.cxx:228
 AliAODCaloCluster.cxx:229
 AliAODCaloCluster.cxx:230
 AliAODCaloCluster.cxx:231
 AliAODCaloCluster.cxx:232
 AliAODCaloCluster.cxx:233
 AliAODCaloCluster.cxx:234
 AliAODCaloCluster.cxx:235
 AliAODCaloCluster.cxx:236
 AliAODCaloCluster.cxx:237
 AliAODCaloCluster.cxx:238
 AliAODCaloCluster.cxx:239
 AliAODCaloCluster.cxx:240
 AliAODCaloCluster.cxx:241
 AliAODCaloCluster.cxx:242
 AliAODCaloCluster.cxx:243
 AliAODCaloCluster.cxx:244
 AliAODCaloCluster.cxx:245
 AliAODCaloCluster.cxx:246
 AliAODCaloCluster.cxx:247
 AliAODCaloCluster.cxx:248
 AliAODCaloCluster.cxx:249
 AliAODCaloCluster.cxx:250
 AliAODCaloCluster.cxx:251
 AliAODCaloCluster.cxx:252
 AliAODCaloCluster.cxx:253
 AliAODCaloCluster.cxx:254
 AliAODCaloCluster.cxx:255
 AliAODCaloCluster.cxx:256
 AliAODCaloCluster.cxx:257
 AliAODCaloCluster.cxx:258
 AliAODCaloCluster.cxx:259
 AliAODCaloCluster.cxx:260
 AliAODCaloCluster.cxx:261
 AliAODCaloCluster.cxx:262
 AliAODCaloCluster.cxx:263