Added function to write thermus input files
authormfloris <michele.floris@cern.ch>
Thu, 6 Mar 2014 12:35:06 +0000 (13:35 +0100)
committermfloris <michele.floris@cern.ch>
Thu, 6 Mar 2014 12:35:49 +0000 (13:35 +0100)
PWGLF/ThermalFits/AliParticleYield.cxx
PWGLF/ThermalFits/AliParticleYield.h
PWGLF/ThermalFits/TestReadTable.C

index 6534cc4..2ccd2e8 100644 (file)
@@ -1,4 +1,5 @@
 #include <iostream>
+#include <stdio.h>
 #include <fstream>
 #include <iomanip>
 #include "AliParticleYield.h"
@@ -332,38 +333,96 @@ void AliParticleYield::SaveAsASCIIFile(TClonesArray * arr, const char * fileName
 
   // The columns should be:
   // PDG   NAME  SYSTEM  SQRTS  VALUE  STAT  SYST  NORM  YMIN  YMAX  STATUS  TYPE  CENTR     ISSUM TAG
-  
+  if(!arr) {
+    Printf("<AliParticleYield::SaveAsASCIIFile> Error: no array provided");
+    return;
+  }
+  if(!fileName) {
+    Printf("<AliParticleYield::SaveAsASCIIFile> Error: no filename provided");
+  }
 
 
   ofstream fileOut(fileName);
   //print header
   fileOut << FormatCol("PDG", colWidth, separator) <<   FormatCol("NAME", colWidth, separator) <<  FormatCol("SYSTEM", colWidth, separator) <<  FormatCol("SQRTS", colWidth, separator) <<  FormatCol("VALUE", colWidth, separator) <<  FormatCol("STAT" , colWidth, separator)<<  FormatCol("SYST", colWidth, separator) <<  FormatCol("NORM", colWidth, separator) <<  FormatCol("YMIN", colWidth, separator) <<  FormatCol("YMAX", colWidth, separator) <<  FormatCol("STATUS", colWidth, separator) <<  FormatCol("TYPE", colWidth, separator) <<  FormatCol("CENTR", colWidth, separator) <<     FormatCol("ISSUM", colWidth, separator) <<  FormatCol("TAG", colWidth, separator) << endl;
   
+
+  // This is used for float numbers in the table.
+  // The "g" options switches between the normal or scientific notation, whathever is more appropriate.
+  // We want to have up to fSignificantDigits digits after the .
+  char format[20];
+  snprintf(format,20,"%%%dg", fSignificantDigits);
+
   TIter iter(arr);
   AliParticleYield * part = 0;
   while ((part = (AliParticleYield*) iter.Next())){    
     fileOut 
-      << FormatCol(Form("%d",part->GetPdgCode())                                                  , colWidth , separator) 
-      << FormatCol(part->GetPartName()                                                            , colWidth , separator)          
-      << FormatCol(Form("%d", part->GetCollisionSystem())                                         , colWidth , separator) 
-      << FormatCol(Form("%2.2f", part->GetSqrtS())                                                , colWidth , separator)          
-      << FormatCol(Form("%3.3f", RoundToSignificantFigures(part->GetYield(),    fSignificantDigits)) , colWidth , separator)
-      << FormatCol(Form("%3.3f", RoundToSignificantFigures(part->GetStatError(),fSignificantDigits)) , colWidth , separator) 
-      << FormatCol(Form("%3.3f", RoundToSignificantFigures(part->GetSystError(),fSignificantDigits)) , colWidth , separator)
-      << FormatCol(Form("%3.3f", RoundToSignificantFigures(part->GetNormError(),fSignificantDigits)) , colWidth , separator)   
-      << FormatCol(Form("%2.2f", part->GetYMin())                                                 , colWidth , separator) 
-      << FormatCol(Form("%2.2f", part->GetYMax())                                                 , colWidth , separator)          
-      << FormatCol(Form("%d",part->GetStatus()          )                                         , colWidth , separator) 
-      << FormatCol(Form("%d",part->GetMeasurementType() )                                         , colWidth , separator)       
-      << FormatCol(part->GetCentr()                                                               , colWidth , separator) 
-      << FormatCol(Form("%d",part->GetIsSum())                                                    , colWidth , separator) 
-      << FormatCol(part->GetTag()                                                                 , colWidth , separator) 
+      << FormatCol(Form("%d",part->GetPdgCode())                                                    , colWidth , separator) 
+      << FormatCol(part->GetPartName()                                                              , colWidth , separator)        
+      << FormatCol(Form("%d", part->GetCollisionSystem())                                           , colWidth , separator) 
+      << FormatCol(Form(format, part->GetSqrtS())                                                   , colWidth , separator)        
+      << FormatCol(Form(format, RoundToSignificantFigures(part->GetYield(),    fSignificantDigits)) , colWidth , separator)
+      << FormatCol(Form(format, RoundToSignificantFigures(part->GetStatError(),fSignificantDigits)) , colWidth , separator) 
+      << FormatCol(Form(format, RoundToSignificantFigures(part->GetSystError(),fSignificantDigits)) , colWidth , separator)
+      << FormatCol(Form(format, RoundToSignificantFigures(part->GetNormError(),fSignificantDigits)) , colWidth , separator)    
+      << FormatCol(Form(format, part->GetYMin())                                                    , colWidth , separator) 
+      << FormatCol(Form(format, part->GetYMax())                                                    , colWidth , separator)        
+      << FormatCol(Form("%d",part->GetStatus()          )                                           , colWidth , separator) 
+      << FormatCol(Form("%d",part->GetMeasurementType() )                                           , colWidth , separator)       
+      << FormatCol(part->GetCentr()                                                                 , colWidth , separator) 
+      << FormatCol(Form("%d",part->GetIsSum())                                                      , colWidth , separator) 
+      << FormatCol(part->GetTag()                                                                   , colWidth , separator) 
       << endl;
   }
 
 
 }
 
+void AliParticleYield::WriteThermusFile(TClonesArray * arr, const char * filename, Int_t colwidth) {
+  // Writes a txt file which can we used as input in therums fits
+
+  if(!arr) {
+    Printf("<AliParticleYield::WriteThermusFile> Error: no array provided");
+    return;
+  }
+  if(!filename) {
+    Printf("<AliParticleYield::WriteThermusFile> Error: no filename provided");
+  }
+
+  ofstream fileOut(filename);
+
+  TIter iter(arr);
+  AliParticleYield * part = 0;
+  char format[20];
+  // This is used for float numbers in the table.
+  // The "g" options switches between the normal or scientific notation, whathever is more appropriate.
+  // We want to have up to fSignificantDigits digits after the .
+  snprintf(format,20,"%%%dg", fSignificantDigits);
+  
+  //  snprintf(format, 20, "%d.%d%%f", fSignificantDigits, fSignificantDigits);
+  while ((part = (AliParticleYield*) iter.Next())){    
+    
+    if(part->IsTypeRatio()) { 
+      // If it's a ratio we have to write the 2 pdg codes
+      fileOut << FormatCol(Form("%d %d ",part->GetPdgCode(), part->GetPdgCode2())                              , colwidth) 
+             << FormatCol(part->GetTag()                                                                      , colwidth)
+             << FormatCol(Form(format, RoundToSignificantFigures(part->GetYield()      , fSignificantDigits)) , colwidth)
+             << FormatCol(Form(format, RoundToSignificantFigures(part->GetTotalError() , fSignificantDigits)) , colwidth)
+             << endl;
+    }
+    else {
+      fileOut << FormatCol(Form("%d",part->GetPdgCode())                                                       , colwidth) 
+             << FormatCol(part->GetTag()                                                                      , colwidth)
+             << FormatCol(Form(format, RoundToSignificantFigures(part->GetYield()      , fSignificantDigits)) , colwidth)
+             << FormatCol(Form(format, RoundToSignificantFigures(part->GetTotalError() , fSignificantDigits)) , colwidth)
+             << endl;      
+    }
+  
+  }
+  
+}
+
+
 const char * AliParticleYield::FormatCol(const char * text, Int_t width,  const char * sep) {
   
   TString format(Form("%%-%ds %s", width, sep));
index 13dde1b..cfa4bc8 100644 (file)
@@ -50,6 +50,7 @@ public:
   static TClonesArray * ReadFromASCIIFile(const char * fileName, const char * separators = " \t");
   static TTree * ReadFromASCIIFileAsTree(const char * fileName, const char * separators = " \t");
   static void SaveAsASCIIFile(TClonesArray * arr, const char * filename, const char * separator = " ", Int_t colWidth = 7);  
+  static void WriteThermusFile(TClonesArray * arr, const char * filename, Int_t colWidth = 10);
   static TClonesArray * GetEntriesMatchingSelection(TTree * tree, TString selection); 
 
   // Misc helpers
@@ -57,7 +58,7 @@ public:
   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 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);
index d500fbd..128122c 100644 (file)
@@ -1,9 +1,10 @@
 void TestReadTable() {
 
-  gROOT->LoadMacro("AliParticleYield.cxx+");
+  LoadLibs();
   TClonesArray * arr = AliParticleYield::ReadFromASCIIFile("./PbPb_2760.txt");
   std::cout << "------------------------------ All Part ------------------------------" << std::endl;
   arr->Print();
+  AliParticleYield::WriteThermusFile(arr, "thermus.txt" );
 
   // Get it as tree
   TTree * tree = AliParticleYield::ReadFromASCIIFileAsTree("./PbPb_2760.txt");
@@ -13,6 +14,7 @@ void TestReadTable() {
   arr =AliParticleYield::GetEntriesMatchingSelection(tree, "fCentr == \"V0M0010\" && fStatus == 0");
   std::cout << "------------------------------ CENTR = 0-10%, Status = 0 ------------------------------" << std::endl;
   arr->Print();
+
   delete arr;
   arr =AliParticleYield::GetEntriesMatchingSelection(tree, "fCentr == \"V0M0020\" && !IsTypeRatio()");
   std::cout << "------------------------------ CENTR = 0-20%, no ratios ------------------------------" << std::endl;
@@ -24,3 +26,30 @@ void TestReadTable() {
   AliParticleYield::SaveAsASCIIFile(arr,"pippo.txt");
 
 }
+
+void LoadLibs() {
+
+  gSystem->Load("libCore.so");  
+  gSystem->Load("libGeom.so");
+  gSystem->Load("libPhysics.so");
+  gSystem->Load("libVMC");
+  gSystem->Load("libTree");
+  gSystem->Load("libProof");
+  gSystem->Load("libMatrix");
+  gSystem->Load("libMinuit");
+  gSystem->Load("libSTEERBase");
+  gSystem->Load("libESD");
+  gSystem->Load("libAOD");
+  gSystem->Load("libANALYSIS");
+  gSystem->Load("libOADB");
+  gSystem->Load("libANALYSISalice");
+  gSystem->Load("libTENDER");
+  gSystem->Load("libCORRFW");
+  gSystem->Load("libMinuit");
+  gSystem->Load("libPWGTools");
+  //  gROOT->LoadMacro("AliParticleYield.cxx+");
+
+  gSystem->Load("libPWGLFthermalfits");
+  
+
+}