Added new library (libPWGLFthermalfits)
authormfloris <michele.floris@cern.ch>
Thu, 6 Mar 2014 10:34:34 +0000 (11:34 +0100)
committermfloris <michele.floris@cern.ch>
Thu, 6 Mar 2014 10:34:34 +0000 (11:34 +0100)
Added checks for duplicates to AliParticleYield

PWGLF/CMakelibPWGLFthermalfits.pkg [new file with mode: 0644]
PWGLF/PWGLFthermalfitsLinkDef.h [new file with mode: 0644]
PWGLF/ThermalFits/AliParticleYield.cxx
PWGLF/ThermalFits/AliParticleYield.h

diff --git a/PWGLF/CMakelibPWGLFthermalfits.pkg b/PWGLF/CMakelibPWGLFthermalfits.pkg
new file mode 100644 (file)
index 0000000..7ed9da0
--- /dev/null
@@ -0,0 +1,38 @@
+# -*- mode: CMake -*-
+#--------------------------------------------------------------------------------#
+# Package File for PWGLFresonances                                                #
+# Author : Johny Jose (johny.jose@cern.ch)                                       #
+# Variables Defined :                                                            #
+#                                                                                #
+# SRCS - C++ source files                                                        #
+# HDRS - C++ header files                                                        #
+# DHDR - ROOT Dictionary Linkdef header file                                     #
+# CSRCS - C source files                                                         #
+# CHDRS - C header files                                                         #
+# EINCLUDE - Include directories                                                 #
+# EDEFINE - Compiler definitions                                                 #
+# ELIBS - Extra libraries to link                                                #
+# ELIBSDIR - Extra library directories                                           #
+# PACKFFLAGS - Fortran compiler flags for package                                #
+# PACKCXXFLAGS - C++ compiler flags for package                                  #
+# PACKCFLAGS - C compiler flags for package                                      #
+# PACKSOFLAGS - Shared library linking flags                                     #
+# PACKLDFLAGS - Module linker flags                                              #
+# PACKBLIBS - Libraries to link (Executables only)                               #
+# EXPORT - Header files to be exported                                           #
+# CINTHDRS - Dictionary header files                                             #
+# CINTAUTOLINK - Set automatic dictionary generation                             #
+# ARLIBS - Archive Libraries and objects for linking (Executables only)          #
+# SHLIBS - Shared Libraries and objects for linking (Executables only)           #
+#--------------------------------------------------------------------------------#
+
+set ( SRCS ThermalFits/AliParticleYield.cxx
+ )
+
+string ( REPLACE ".cxx" ".h" HDRS "${SRCS}" )
+
+set ( DHDR PWGLFthermalfitsLinkDef.h)
+
+set ( EXPORT )
+
+set ( EINCLUDE  PWGLF/SPECTRA/Nuclei/B2 PWGLF/SPECTRA/PiKaPr/TPCTOF PWGLF/SPECTRA/PiKaPr/TPCTOFpA PWGLF/SPECTRA/PiKaPr/TOF/pp7 PWGLF/SPECTRA/ChargedHadrons/dNdPt TPC TOF PWGUD/base STEER/STEER STEER/ESD STEER/AOD STEER/CDB STEER/STEERBase ANALYSIS)
diff --git a/PWGLF/PWGLFthermalfitsLinkDef.h b/PWGLF/PWGLFthermalfitsLinkDef.h
new file mode 100644 (file)
index 0000000..8c1fe0e
--- /dev/null
@@ -0,0 +1,6 @@
+#ifdef __CINT__
+
+#pragma link C++ class AliParticleYield+;
+
+
+#endif
index 16da7b9..6534cc4 100644 (file)
@@ -22,6 +22,7 @@ ClassImp(AliParticleYield)
 const char * AliParticleYield::kStatusString[] = {"Published", "Preliminary", "Final, but not published", "May change"} ;
 const char * AliParticleYield::kSystemString[] = {"pp", "p-Pb", "Pb-Pb"} ;
 Int_t AliParticleYield::fSignificantDigits = 3;
+Float_t AliParticleYield::fEpsilon = 0.000000000000000001;
 
 AliParticleYield::AliParticleYield() :
 TObject(),
@@ -123,7 +124,7 @@ TClonesArray * AliParticleYield::GetEntriesMatchingSelection(TTree * tree, TStri
   TEventList *elist = (TEventList*)gDirectory->Get("particlelist");
   Int_t npart = elist->GetN();
   for(Int_t ipart = 0; ipart < npart; ipart++){
-    std::cout << ipart << " " << elist->GetEntry(ipart) << std::endl;
+    //    std::cout << ipart << " " << elist->GetEntry(ipart) << std::endl;
     tree->GetEntry(elist->GetEntry(ipart));
     new((*arr)[ipart]) AliParticleYield(*part);// We need to clone part, because it is overwritten by the next read
   }
@@ -151,6 +152,10 @@ TClonesArray * AliParticleYield::ReadFromASCIIFile(const char * fileName, const
 
   TClonesArray * arr = new TClonesArray ("AliParticleYield");
   ifstream filestream (fileName);
+  if(!filestream.is_open()) {
+    Printf("Cannot open file %s\n", fileName);
+    exit(1);
+  }
   TString line;
   Int_t ipart = 0;
   while (line.ReadLine(filestream) ) {
@@ -216,11 +221,15 @@ TClonesArray * AliParticleYield::ReadFromASCIIFile(const char * fileName, const
     tag   = tag.Strip(TString::kTrailing, ' ');
     
     // add to array
-    new ((*arr)[ipart])  AliParticleYield(pdg,system,sqrts,yield,stat,syst,norm,ymin,ymax,status,type,centr,issum,tag);
-    ((AliParticleYield*)arr->At(ipart))->SetPartName(name); // Check name and PDG code consistency
-    ((AliParticleYield*)arr->At(ipart))->SetPdgCode2(pdg2); // Set second PDG code in case of ratios
-    ((AliParticleYield*)arr->At(ipart))->CheckTypeConsistency();
-    ipart ++;
+    AliParticleYield * part = new  AliParticleYield(pdg,system,sqrts,yield,stat,syst,norm,ymin,ymax,status,type,centr,issum,tag);
+    part->SetPartName(name); // Check name and PDG code consistency   
+    part->SetPdgCode2(pdg2); // Set second PDG code in case of ratios 
+    part->CheckTypeConsistency();                                     
+    if(!part->CheckForDuplicates(arr)) {
+      new ((*arr)[ipart++]) AliParticleYield(*part); 
+    }
+      //    delete part;
+
   }
 
 
@@ -449,3 +458,81 @@ void AliParticleYield::Print (Option_t *) const {
   Printf("Normalizaion uncertainty: %f", fNormError);
 }
 
+Bool_t AliParticleYield::operator==(const AliParticleYield& rhs) {
+  // Check if the two particles are identical
+
+  Bool_t isEqual = 
+    (fPdgCode         == rhs.fPdgCode         ) &&
+    (fPdgCode2        == rhs.fPdgCode2        ) &&
+    (fPartName        == rhs.fPartName        ) &&
+    (fCollisionSystem == rhs.fCollisionSystem ) &&
+    Compare2Floats(fSqrtS,rhs.fSqrtS          ) &&
+    Compare2Floats(fYield,rhs.fYield          ) &&
+    Compare2Floats(fStatError,rhs.fStatError  ) &&
+    Compare2Floats(fSystError,rhs.fSystError  ) &&
+    Compare2Floats(fNormError,rhs.fNormError  ) &&
+    Compare2Floats(fYMin,rhs.fYMin            ) &&
+    Compare2Floats(fYMax,rhs.fYMax            ) &&
+    (fStatus          == rhs.fStatus          ) &&
+    (fMeasurementType == rhs.fMeasurementType ) &&
+    (fCentr           == rhs.fCentr           ) &&
+    (fIsSum           == rhs.fIsSum           ) &&
+    (fTag             == rhs.fTag             ) ;
+  
+  return isEqual;
+  
+}
+Bool_t AliParticleYield::IsTheSameMeasurement(AliParticleYield &rhs) {
+
+  // Check the two particles represent the same measurement (independently of the values)
+  Bool_t isEqual = 
+    (fPdgCode         == rhs.fPdgCode         ) &&
+    (fPdgCode2        == rhs.fPdgCode2        ) &&
+    (fCollisionSystem == rhs.fCollisionSystem ) &&
+    Compare2Floats(fSqrtS,rhs.fSqrtS          ) &&
+    Compare2Floats(fYMin,rhs.fYMin            ) &&
+    Compare2Floats(fYMax,rhs.fYMax            ) &&
+    (fStatus          == rhs.fStatus          ) &&
+    (fCentr           == rhs.fCentr           ) &&
+    (fIsSum           == rhs.fIsSum           ) &&
+    (fTag             == rhs.fTag             ) ;
+  
+  return isEqual;
+
+
+}
+
+Bool_t AliParticleYield::CheckForDuplicates(TClonesArray * arr) {
+
+  // loop over all elements on the array and check for duplicates
+  TIter iter(arr);
+  AliParticleYield * part = 0;
+  Bool_t isDuplicate = kFALSE;
+
+  while ((part = (AliParticleYield*) iter.Next())) {
+    if (IsTheSameMeasurement(*part)){
+      AliWarning("Duplicated measurement found");
+      isDuplicate = kTRUE;
+      if (!((*this) == (*part))) {
+       part->Print();
+       Print();
+       AliFatal("The 2 particles are different!");
+      }
+    }
+  }
+  return isDuplicate;
+
+} 
+Bool_t AliParticleYield::Compare2Floats(Float_t a, Float_t b) {
+  // just a simple helper for the comparison methods
+  if(!a) {
+    if(!b) return kTRUE; // They are both 0;
+    return kFALSE;// return here to avoid division by 0
+  }
+  Bool_t areEqual = (TMath::Abs((a - b)/a) < fEpsilon); // If the relative difference is < epsilon, returns true
+  if(!areEqual) {
+    Printf("Warning: %f and %f are different", a,b); 
+  }
+  return areEqual;
+}
index d383a44..13dde1b 100644 (file)
@@ -54,11 +54,13 @@ public:
 
   // Misc helpers
   Bool_t CheckTypeConsistency() const;
-  virtual void Print (Option_t *) const;
+  Bool_t CheckForDuplicates(TClonesArray * arr) ;
+  virtual void Print (Option_t * opt = "") const;
   static Float_t GetError(TString error, Float_t yield) ;
   static const char * FormatCol(const char * text, Int_t width,  const char * sep) ;
   static Double_t RoundToSignificantFigures(double num, int n) ;  
-
+  Bool_t operator==(const AliParticleYield& rhs);
+  Bool_t IsTheSameMeasurement(AliParticleYield &rhs);
 
   // Getters
   TString GetCentr()           const{ return fCentr           ;}
@@ -118,6 +120,8 @@ public:
 
 private:
 
+  Bool_t Compare2Floats(Float_t a, Float_t b) ;
+
   Int_t   fPdgCode;         // PdgCode
   Int_t   fPdgCode2;        // The PdgCode of the second particle, only needed in case of a ratio
   TString fPartName;        // Particle name (redundant, we also have PDG code)
@@ -139,7 +143,7 @@ private:
 
 
   static Int_t fSignificantDigits; // Significant Digits to be used in values and errors
-
+  static Float_t fEpsilon; // Used for float conparisons
 
   ClassDef(AliParticleYield,1)
 };