ROOT logo
/**************************************************************************
 * Copyright(c) 1998-1999, 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.                  *
 **************************************************************************/


///////////////////////////////////////////////////////////////////////////
//                       Detector PID                                    //
//                                                                       //
//                                                                       //
/*

This class is supposed to store the detector pid values for all detectors
  and all particle species.
It is meant to be used to buffer the PID values as a transient object in
  AliESDtrack and AliAODTrack, respectively.
The calculation filling and association to the track is done in
  AliAnalysisTaskPID response.
The idea of this object is to save computing time in an analysis train with
  many analyses where access to pid is done often



*/
//                                                                       //
///////////////////////////////////////////////////////////////////////////

#include "AliPIDValues.h"

#include "AliDetectorPID.h"

ClassImp(AliDetectorPID)


AliDetectorPID::AliDetectorPID() :
  TObject(),
  fArrNsigmas("AliPIDValues",AliPIDResponse::kNdetectors),
  fArrRawProbabilities("AliPIDValues",AliPIDResponse::kNdetectors)
{
  //
  // default constructor
  //
  
}

//_______________________________________________________________________
AliDetectorPID::AliDetectorPID(const AliDetectorPID &pid) :
  TObject(pid),
  fArrNsigmas(pid.fArrNsigmas),
  fArrRawProbabilities(pid.fArrRawProbabilities)
{
  //
  // copy constructor
  //
  
}

//_______________________________________________________________________
AliDetectorPID::~AliDetectorPID()
{
  //
  // destructor
  //
  fArrNsigmas.Delete();
  fArrRawProbabilities.Delete();
}

//_______________________________________________________________________
AliDetectorPID& AliDetectorPID::operator= (const AliDetectorPID &pid)
{
  //
  // assignment operator
  //
  
  if (this==&pid) return *this;

  TObject::operator=(pid);
  
  fArrNsigmas.Clear();
  fArrRawProbabilities.Clear();
  
  AliPIDValues *val=0x0;
  for (Int_t idet=0; idet<(Int_t)AliPIDResponse::kNdetectors; ++idet){
    val=static_cast<AliPIDValues*>(pid.fArrNsigmas.UncheckedAt(idet));
    if (val) new (fArrNsigmas[idet]) AliPIDValues(*val);

    val=static_cast<AliPIDValues*>(pid.fArrRawProbabilities.UncheckedAt(idet));
    if (val) new (fArrRawProbabilities[idet]) AliPIDValues(*val);
  }

  return *this;
}

//_______________________________________________________________________
void AliDetectorPID::SetRawProbability(AliPIDResponse::EDetector det, const Double_t prob[],
                                       Int_t nspecies, AliPIDResponse::EDetPidStatus status)
{
  //
  // set raw probabilities for nspecies for 'det'ector
  //
  
  AliPIDValues *val=static_cast<AliPIDValues*>(fArrRawProbabilities.UncheckedAt(det));
  if (!val)
    val=new (fArrRawProbabilities[(Int_t)det]) AliPIDValues;

  val->SetValues(prob,nspecies,status);
}

//_______________________________________________________________________
void AliDetectorPID::SetNumberOfSigmas(AliPIDResponse::EDetector det, const Double_t nsig[], Int_t nspecies,
                                       AliPIDResponse::EDetPidStatus status)
{
  //
  // set number of sigmas for nspecies for 'det'ector
  //
  
  AliPIDValues *val=static_cast<AliPIDValues*>(fArrNsigmas.UncheckedAt(det));
  if (!val)
    val=new (fArrNsigmas[(Int_t)det]) AliPIDValues;

  val->SetValues(nsig,nspecies);
  val->SetPIDStatus(status);
}

//_______________________________________________________________________
AliPIDResponse::EDetPidStatus AliDetectorPID::GetRawProbability(AliPIDResponse::EDetector det, Double_t prob[], Int_t nspecies) const
{
  //
  // get raw probabilities for nspecies for 'det'ector
  //
  
  AliPIDValues *val=static_cast<AliPIDValues*>(fArrRawProbabilities.UncheckedAt((Int_t)det));
  if (!val) {
    for (Int_t i=0; i<nspecies; ++i) prob[i]=1.; //TODO: Is '1' the correct values or better 1/nspecies
    return AliPIDResponse::kDetNoSignal;
  }

  return val->GetValues(prob,nspecies);
}

//_______________________________________________________________________
AliPIDResponse::EDetPidStatus AliDetectorPID::GetNumberOfSigmas(AliPIDResponse::EDetector det, Double_t nsig[], Int_t nspecies) const
{
  AliPIDValues *val=static_cast<AliPIDValues*>(fArrNsigmas.UncheckedAt((Int_t)det));
  if (!val) {
    for (Int_t i=0; i<nspecies; ++i) nsig[i]=-999.;
    return AliPIDResponse::kDetNoSignal;
  }
  
  return val->GetValues(nsig,nspecies);
}

//_______________________________________________________________________
Double_t AliDetectorPID::GetRawProbability(AliPIDResponse::EDetector det, AliPID::EParticleType type) const
{
  //
  // get 'det'ector raw probability for particle 'type'
  //
  
  AliPIDValues *val=static_cast<AliPIDValues*>(fArrRawProbabilities.UncheckedAt((Int_t)det));
  if (!val) {
    return 0.; //TODO: Is '0' the correct value?
  }
  
  return val->GetValue(type);
}

//_______________________________________________________________________
Double_t AliDetectorPID::GetNumberOfSigmas(AliPIDResponse::EDetector det, AliPID::EParticleType type) const
{
  //
  // get 'det'ector number of sigmas for particle 'type'
  //
  AliPIDValues *val=static_cast<AliPIDValues*>(fArrNsigmas.UncheckedAt((Int_t)det));
  if (!val) {
    return -999.; //TODO: Is '-999.' the correct value?
  }
  
  return val->GetValue(type);
}

//_______________________________________________________________________
AliPIDResponse::EDetPidStatus AliDetectorPID::GetRawProbability(AliPIDResponse::EDetector det, AliPID::EParticleType type, Double_t &prob) const
{
  //
  // get 'det'ector raw probability for particle 'type'
  //
  
  AliPIDValues *val=static_cast<AliPIDValues*>(fArrRawProbabilities.UncheckedAt((Int_t)det));
  if (!val) {
    prob=0.;
    return AliPIDResponse::kDetNoSignal; 
  }
  
  prob=val->GetValue(type);
  return val->GetPIDStatus();
}

//_______________________________________________________________________
AliPIDResponse::EDetPidStatus AliDetectorPID::GetNumberOfSigmas(AliPIDResponse::EDetector det, AliPID::EParticleType type, Double_t &nsig) const
{
  //
  // get 'det'ector number of sigmas for particle 'type'
  //
  AliPIDValues *val=static_cast<AliPIDValues*>(fArrNsigmas.UncheckedAt((Int_t)det));
  if (!val) {
    nsig=-999.;
    return AliPIDResponse::kDetNoSignal; 
  }
  
  nsig=val->GetValue(type);
  return val->GetPIDStatus();
}


//_______________________________________________________________________
AliPIDResponse::EDetPidStatus AliDetectorPID::GetPIDStatus(AliPIDResponse::EDetector det) const
{
  //
  // return the detector PID status
  //
  
  AliPIDValues *val=static_cast<AliPIDValues*>(fArrRawProbabilities.UncheckedAt((Int_t)det));
  if (!val) val=static_cast<AliPIDValues*>(fArrNsigmas.UncheckedAt((Int_t)det));
  if (val) return val->GetPIDStatus();

  return AliPIDResponse::kDetNoSignal;
}

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