LCOV - code coverage report
Current view: top level - STEER/STEERBase - AliTRDPIDParams.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 155 0.6 %
Date: 2016-06-14 17:26:59 Functions: 1 39 2.6 %

          Line data    Source code
       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             : //
      16             : // Container for TRD Threshold parameters stored in the OADB
      17             : //
      18             : // Author: Markus Fasel <M.Fasel@gsi.de>
      19             : //
      20             : #include <TList.h>
      21             : #include <TMath.h>
      22             : #include <TSortedList.h>
      23             : 
      24             : #include "AliLog.h"
      25             : 
      26             : #include "AliTRDPIDParams.h"
      27             : 
      28         176 : ClassImp(AliTRDPIDParams)
      29             : //ClassImp(AliTRDPIDParams::AliTRDPIDThresholds)
      30             : //ClassImp(AliTRDPIDParams::AliTRDPIDCentrality)
      31             : 
      32             : const Double_t AliTRDPIDParams::kVerySmall = 1e-5;
      33             : 
      34             : //____________________________________________________________
      35             : AliTRDPIDParams::AliTRDPIDParams():
      36           0 :   TNamed(),
      37           0 :   fEntries(NULL)
      38           0 : {
      39             :   //
      40             :   // Dummy constructor
      41             :   //
      42           0 : }
      43             : 
      44             : //____________________________________________________________
      45             : AliTRDPIDParams::AliTRDPIDParams(const char *name) :
      46           0 :   TNamed(name, ""),
      47           0 :   fEntries(NULL)
      48           0 : {
      49             :   //
      50             :   // Default constructor
      51             :   //
      52           0 :   fEntries = new TList;
      53           0 : }
      54             : 
      55             : //____________________________________________________________
      56             : AliTRDPIDParams::AliTRDPIDParams(const AliTRDPIDParams &ref):
      57           0 : TNamed(ref),
      58           0 : fEntries(NULL)
      59           0 : {
      60             :     //
      61             :     // Copy constructor
      62             :     //
      63             : 
      64           0 :     fEntries=(TList*)ref.fEntries->Clone();
      65           0 : }
      66             : 
      67             : //____________________________________________________________
      68           0 : AliTRDPIDParams::~AliTRDPIDParams(){
      69             :   //
      70             :   // Destructor
      71             :   //
      72           0 :   delete fEntries;
      73           0 : }
      74             : 
      75             : //____________________________________________________________
      76             : void AliTRDPIDParams::AddCentralityClass(Double_t minCentrality, Double_t maxCentrality){
      77             :   // 
      78             :   // Add new centrality class
      79             :   //
      80             :   
      81             :   // check whether centrality class already exists
      82           0 :   AliTRDPIDCentrality *checklow = FindCentrality(minCentrality + 0.01),
      83           0 :                       *checkhigh = FindCentrality(maxCentrality - 0.01);
      84             : 
      85           0 :   if(!checklow && ! checkhigh)
      86           0 :     fEntries->Add(new AliTRDPIDCentrality(minCentrality, maxCentrality));
      87           0 : }
      88             : 
      89             : //____________________________________________________________ 
      90             : AliTRDPIDParams::AliTRDPIDCentrality *AliTRDPIDParams::FindCentrality(Double_t val) const {
      91             :   //
      92             :   // Find centrality bin
      93             :   //
      94           0 :   TIter centralities(fEntries);
      95             :   AliTRDPIDCentrality *obj(NULL), *tmp(NULL);
      96           0 :   while((obj = dynamic_cast<AliTRDPIDCentrality *>(centralities()))){
      97           0 :     if(val >= obj->GetMinCentrality() && val <= obj->GetMaxCentrality()){
      98             :       tmp = obj;
      99           0 :       break;
     100             :     }
     101             :   }
     102             :   return tmp;
     103           0 : }
     104             : 
     105             : //____________________________________________________________
     106             : Bool_t AliTRDPIDParams::GetThresholdParameters(Int_t ntracklets, Double_t efficiency, Double_t *params, Double_t centrality) const{
     107             :   //
     108             :   // Retrieve params
     109             :   // Use IsEqual definition
     110             :   //
     111           0 :   AliTRDPIDCentrality *cent = FindCentrality(centrality);
     112           0 :   if(!cent)cent = FindCentrality(-1);// try default class
     113           0 :   if(!cent){
     114           0 :       AliDebug(1, "Centrality class not available");
     115           0 :       return kFALSE;
     116             :   }
     117             :   
     118           0 :   cent->GetThresholdParameters(ntracklets, efficiency, params);
     119           0 :   return kTRUE;
     120           0 : }
     121             : 
     122             : //____________________________________________________________
     123             : void AliTRDPIDParams::SetThresholdParameters(Int_t ntracklets, Double_t effMin, Double_t effMax, Double_t *params, Double_t centrality){
     124             :   //
     125             :   // Set new threshold parameters
     126             :   //
     127           0 :   AliTRDPIDCentrality *cent = FindCentrality(centrality);
     128           0 :   if(cent) cent->SetThresholdParameters(ntracklets, effMin, effMax, params);
     129           0 :   else AliDebug(1, "Centrality class not available");
     130           0 : }
     131             : 
     132             : //____________________________________________________________
     133             : void AliTRDPIDParams::Print(Option_t *) const {
     134           0 :   TIter centIter(fEntries);
     135             :   AliTRDPIDCentrality *cent;
     136           0 :   while((cent = dynamic_cast<AliTRDPIDCentrality *>(centIter()))) cent->Print(NULL);
     137           0 : }
     138             : 
     139             : //____________________________________________________________
     140             : AliTRDPIDParams::AliTRDPIDThresholds::AliTRDPIDThresholds():
     141           0 :   TObject(),
     142           0 :   fNTracklets(0)
     143           0 : {
     144             :    // 
     145             :    // Default constructor
     146             :    //
     147           0 :    memset(fParams, 0, sizeof(Double_t) * 4);
     148           0 :    memset(fEfficiency, 0, sizeof(Double_t) * 2);
     149           0 : }
     150             : 
     151             : //____________________________________________________________
     152             : AliTRDPIDParams::AliTRDPIDThresholds::AliTRDPIDThresholds(Int_t nTracklets, Double_t effMin, Double_t effMax, Double_t *params) :
     153           0 :   TObject(),
     154           0 :   fNTracklets(nTracklets)
     155           0 : {
     156             :   //
     157             :   // Default Constructor 
     158             :   //
     159           0 :   fEfficiency[0] = effMin;
     160           0 :   fEfficiency[1] = effMax;  
     161           0 :   if(params) memcpy(fParams, params, sizeof(Double_t) * 4);
     162           0 :   else memset(fParams, 0, sizeof(Double_t) * 4);
     163           0 : }
     164             : 
     165             : //____________________________________________________________
     166             : AliTRDPIDParams::AliTRDPIDThresholds::AliTRDPIDThresholds(Int_t nTracklets, Double_t eff, Double_t *params) :
     167           0 :   TObject(),
     168           0 :   fNTracklets(nTracklets)
     169           0 : {
     170             :   //
     171             :   // Constructor used to find object in sorted list
     172             :   //
     173           0 :   fEfficiency[0] = fEfficiency[1] = eff;  
     174           0 :   if(params) memcpy(fParams, params, sizeof(Double_t) * 4);
     175           0 :   else memset(fParams, 0, sizeof(Double_t) * 4);
     176           0 : }
     177             : 
     178             : //____________________________________________________________
     179             : AliTRDPIDParams::AliTRDPIDThresholds::AliTRDPIDThresholds(const AliTRDPIDThresholds &ref) :
     180           0 :   TObject(ref),
     181           0 :   fNTracklets(ref.fNTracklets)
     182           0 : {
     183             :   //
     184             :   // Copy constructor
     185             :   //
     186           0 :   memcpy(fParams, ref.fParams, sizeof(Double_t) * 4);
     187           0 :   memcpy(fEfficiency, ref.fEfficiency, sizeof(Double_t) * 2);
     188           0 : }
     189             : 
     190             : //____________________________________________________________
     191             : AliTRDPIDParams::AliTRDPIDThresholds &AliTRDPIDParams::AliTRDPIDThresholds::operator=(const AliTRDPIDThresholds &ref){
     192             :   //
     193             :   // Assignment operator
     194             :   //
     195           0 :   if(&ref == this) return *this;
     196             : 
     197           0 :   TObject::operator=(ref);
     198             : 
     199           0 :   fNTracklets = ref.fNTracklets;
     200           0 :   memcpy(fEfficiency, ref.fEfficiency, sizeof(Double_t) * 2);
     201           0 :   memcpy(fParams, ref.fParams, sizeof(Double_t) * 4);
     202           0 :   return *this;
     203           0 : }
     204             :         
     205             : //____________________________________________________________
     206             : Int_t AliTRDPIDParams::AliTRDPIDThresholds::Compare(const TObject *ref) const{
     207             :   //
     208             :   // Compares two objects
     209             :   // Order:
     210             :   //   First compare number of tracklets, if they are equal compare electron efficiency
     211             :   //
     212           0 :   const AliTRDPIDThresholds *refObj = static_cast<const AliTRDPIDThresholds *>(ref);
     213           0 :   if(fNTracklets < refObj->GetNTracklets()) return -1;
     214           0 :   else if(fNTracklets > refObj->GetNTracklets()) return 1;
     215             :   else{
     216           0 :     if(fEfficiency[1] < refObj->GetElectronEfficiency(0)) return -1;
     217           0 :     else if(fEfficiency[0] > refObj->GetElectronEfficiency(1)) return 1;
     218           0 :     else return 0;
     219             :   }
     220           0 : }
     221             : 
     222             : //____________________________________________________________
     223             : Bool_t AliTRDPIDParams::AliTRDPIDThresholds::IsEqual(const TObject *ref) const {
     224             :   //
     225             :   // Check for equality 
     226             :   // Tracklets and Efficiency are used
     227             :   //
     228           0 :   const AliTRDPIDThresholds *refObj = dynamic_cast<const AliTRDPIDThresholds *>(ref);
     229           0 :   if(!refObj) return kFALSE;
     230           0 :   Bool_t eqNTracklets = fNTracklets == refObj->GetNTracklets();
     231             :   Bool_t eqEff = kFALSE;
     232           0 :   Bool_t hasRange = TMath::Abs(fEfficiency[1] - fEfficiency[0]) > kVerySmall;
     233           0 :   Bool_t hasRangeRef = TMath::Abs(refObj->GetElectronEfficiency(1) - refObj->GetElectronEfficiency(0)) > kVerySmall;
     234           0 :   if(hasRange && hasRangeRef){
     235             :     // Both have ranges, check if they match
     236           0 :     eqEff = TMath::Abs(fEfficiency[0] - refObj->GetElectronEfficiency(0)) < kVerySmall && TMath::Abs(fEfficiency[1] - refObj->GetElectronEfficiency(1)) < kVerySmall;
     237           0 :   } else if(hasRange){
     238             :     // this object has ranges, check if the efficiency of ref is inside the range
     239           0 :     eqEff = refObj->GetElectronEfficiency(0) >= fEfficiency[0] && refObj->GetElectronEfficiency(0) < fEfficiency[1];
     240           0 :   } else {
     241             :     // ref has ranges, check if this is in range
     242           0 :     eqEff = fEfficiency[0] >= refObj->GetElectronEfficiency(0) && fEfficiency[0] < refObj->GetElectronEfficiency(1);
     243             :   }
     244             :   
     245           0 :   return  eqNTracklets && eqEff;
     246           0 : }
     247             : 
     248             : //____________________________________________________________
     249           0 : AliTRDPIDParams::AliTRDPIDCentrality::AliTRDPIDCentrality():
     250           0 :   fEntries(NULL),
     251           0 :   fMinCentrality(-1.),
     252           0 :   fMaxCentrality(-1.)
     253           0 : {
     254             :   //
     255             :   // Dummy constructor
     256             :   //
     257           0 : }
     258             : 
     259             : //____________________________________________________________
     260           0 : AliTRDPIDParams::AliTRDPIDCentrality::AliTRDPIDCentrality(Double_t minCentrality, Double_t maxCentrality):
     261           0 :   fEntries(NULL),
     262           0 :   fMinCentrality(minCentrality),
     263           0 :   fMaxCentrality(maxCentrality)
     264           0 : {
     265             :   //
     266             :   // Default constructor
     267             :   //
     268           0 :   fEntries = new TSortedList;
     269           0 :   fEntries->SetOwner();
     270           0 : }
     271             : 
     272             : //____________________________________________________________
     273             : AliTRDPIDParams::AliTRDPIDCentrality::AliTRDPIDCentrality(const AliTRDPIDParams::AliTRDPIDCentrality &ref):
     274           0 : TObject(),
     275           0 : fEntries(NULL),
     276           0 :   fMinCentrality(ref.fMinCentrality),
     277           0 :   fMaxCentrality(ref.fMaxCentrality)
     278           0 : {
     279             :   //
     280             :   // Copy constructor
     281             :   //
     282           0 :   fEntries = new TSortedList;
     283             :   // Coply entries to the new list
     284           0 :   TIter entries(ref.fEntries);
     285             :   TObject *o;
     286           0 :   while((o = entries())) fEntries->Add(o);
     287           0 : }
     288             : 
     289             : //____________________________________________________________
     290             : AliTRDPIDParams::AliTRDPIDCentrality &AliTRDPIDParams::AliTRDPIDCentrality::operator=(const AliTRDPIDCentrality &ref){
     291             :   //
     292             :   // Assignment operator
     293             :   //
     294           0 :   if(&ref != this){
     295           0 :     if(fEntries) delete fEntries;
     296           0 :     fEntries = new TSortedList;
     297           0 :     TIter entries(ref.fEntries);
     298             :     TObject *o;
     299           0 :     while((o = entries())) fEntries->Add(o);
     300           0 :     fMinCentrality = ref.fMinCentrality;
     301           0 :     fMaxCentrality = ref.fMaxCentrality;
     302           0 :   }
     303           0 :   return *this;
     304           0 : }
     305             : 
     306             : //____________________________________________________________
     307           0 : AliTRDPIDParams::AliTRDPIDCentrality::~AliTRDPIDCentrality(){
     308             :   //
     309             :   // Destructor
     310             :   //
     311           0 :   if(fEntries) delete fEntries;
     312           0 : }
     313             : 
     314             : //____________________________________________________________
     315             : Bool_t AliTRDPIDParams::AliTRDPIDCentrality::GetThresholdParameters(Int_t ntracklets, Double_t efficiency, Double_t *params) const{
     316             :   // 
     317             :   // Get the threshold parameters
     318             :   //
     319           0 :   AliTRDPIDThresholds test(ntracklets, efficiency);
     320           0 :   TObject *result = fEntries->FindObject(&test);
     321           0 :   if(!result){ 
     322           0 :     AliDebug(1, Form("No threshold params found for %d tracklets and an electron efficiency of %f", ntracklets, efficiency));
     323           0 :     return kFALSE;
     324             :   }
     325           0 :   AliTRDPIDThresholds *parResult = static_cast<AliTRDPIDThresholds *>(result);
     326           0 :   AliDebug(1, Form("Threshold params found: NTracklets %d, Electron Efficiency %f", parResult->GetNTracklets(), parResult->GetElectronEfficiency()));
     327           0 :   memcpy(params, parResult->GetThresholdParams(), sizeof(Double_t) * 4);
     328             :   return kTRUE;
     329           0 : }
     330             : 
     331             : //____________________________________________________________
     332             : void AliTRDPIDParams::AliTRDPIDCentrality::SetThresholdParameters(Int_t ntracklets, Double_t effMin, Double_t effMax, Double_t *params){
     333             :   // 
     334             :   // Store new Params in the Object
     335             :   //
     336           0 :   if(effMin > effMax){
     337           0 :     AliError("Min. efficiency has to be >= max. efficiency");
     338           0 :     return;
     339             :   }
     340           0 :   AliDebug(1, Form("Save Parameters for %d tracklets at and electron efficiency of [%f|%f]", ntracklets, effMin, effMax));
     341           0 :   fEntries->Add(new AliTRDPIDThresholds(ntracklets, effMin, effMax, params));
     342           0 : }
     343             : 
     344             : //____________________________________________________________
     345             : void AliTRDPIDParams::AliTRDPIDCentrality::Print(Option_t *) const {
     346           0 :   printf("Min. Centrality: %f, Max. Centrality: %f\n", fMinCentrality, fMaxCentrality);
     347           0 :   printf("Available thresholds:\n");
     348           0 :   printf("_________________________________________\n");
     349           0 :   TIter objects(fEntries);
     350             :   AliTRDPIDThresholds *par;
     351           0 :   while((par = dynamic_cast<AliTRDPIDThresholds *>(objects()))){
     352           0 :     printf("Number of tracklets %d, Electron efficiency %f\n", par->GetNTracklets(), 0.5*(par->GetElectronEfficiency(0)+par->GetElectronEfficiency(1)));
     353             :   }
     354           0 : }
     355             : 

Generated by: LCOV version 1.11