From b2811f91fe0e257de14966f2eacd5aacefc34584 Mon Sep 17 00:00:00 2001
From: adrien-matta <a.matta@surrey.ac.uk>
Date: Mon, 8 Jun 2015 11:46:19 +0100
Subject: [PATCH] * Adding name to Spectra class * Spectra are now written into
 a detector folder inside the * ControlSpectra folder

---
 NPLib/CATS/TCATSSpectra.cxx         |  3 ++-
 NPLib/Charissa/TCharissaSpectra.cxx |  5 +++--
 NPLib/Core/NPVSpectra.cxx           | 31 ++++++++++++++---------------
 NPLib/Core/NPVSpectra.h             |  6 ++++++
 NPLib/Exogam/TExogamSpectra.cxx     |  2 ++
 NPLib/MUST2/TMust2Spectra.cxx       |  2 ++
 NPLib/Sharc/TSharcSpectra.cxx       |  3 ++-
 NPLib/Tiara/TTiaraBarrelSpectra.cxx |  2 ++
 NPLib/Tiara/TTiaraHyballSpectra.cxx |  1 +
 9 files changed, 35 insertions(+), 20 deletions(-)

diff --git a/NPLib/CATS/TCATSSpectra.cxx b/NPLib/CATS/TCATSSpectra.cxx
index 99257513d..d18c5ce99 100644
--- a/NPLib/CATS/TCATSSpectra.cxx
+++ b/NPLib/CATS/TCATSSpectra.cxx
@@ -44,6 +44,7 @@ using namespace std;
 
 ////////////////////////////////////////////////////////////////////////////////
 TCATSSpectra::TCATSSpectra(){
+  SetName("CATS");
   fNumberOfCats = 0;
   fStripsNumber = 28;
 
@@ -60,7 +61,7 @@ TCATSSpectra::TCATSSpectra(unsigned int NumberOfCats){
     cout << "TCATSSpectra: Initalising control spectra for " << NumberOfCats << " detectors" << endl; 
     cout << "************************************************" << endl;
   }
-
+  SetName("CATS");
   fNumberOfCats = NumberOfCats;
   fStripsNumber = 28;
   // An histo of size fEventLoopSize is reset every fEventLoopSize to monitor the
diff --git a/NPLib/Charissa/TCharissaSpectra.cxx b/NPLib/Charissa/TCharissaSpectra.cxx
index 868468e31..28fa2dda4 100644
--- a/NPLib/Charissa/TCharissaSpectra.cxx
+++ b/NPLib/Charissa/TCharissaSpectra.cxx
@@ -40,8 +40,8 @@ using namespace std;
 
 
 ////////////////////////////////////////////////////////////////////////////////
-TCharissaSpectra::TCharissaSpectra()
-{
+TCharissaSpectra::TCharissaSpectra(){
+  SetName("Charissa");
   fNumberOfTelescope =  0;
   fStripX            = 16;
   fStripY            = 16;
@@ -59,6 +59,7 @@ TCharissaSpectra::TCharissaSpectra(unsigned int NumberOfTelescope)
       << NumberOfTelescope << " Telescopes" << endl
       << "************************************************" << endl ;
 
+  SetName("Charissa");
   fNumberOfTelescope = NumberOfTelescope;
   fStripX            = 16;
   fStripY            = 16;
diff --git a/NPLib/Core/NPVSpectra.cxx b/NPLib/Core/NPVSpectra.cxx
index 2d460973d..d03f73dac 100644
--- a/NPLib/Core/NPVSpectra.cxx
+++ b/NPLib/Core/NPVSpectra.cxx
@@ -5,7 +5,7 @@
  * For the list of contributors see $NPTOOL/Licence/Contributors             *
  *****************************************************************************/
 
-/*****************************************************************************
+/****************************************************************************
  * Original Author: N. de Sereville  contact address: deserevi@ipno.in2p3.fr *
  *                                                                           *
  * Creation Date  : dec 2013                                                 *
@@ -36,19 +36,15 @@
 #include <cstdlib>
 using namespace std;
 
-
-VSpectra::VSpectra()
-{
+////////////////////////////////////////////////////////////////////////////////
+VSpectra::VSpectra(){
+  m_name="no_name";
 }
 
-
-
-VSpectra::~VSpectra()
-{
+////////////////////////////////////////////////////////////////////////////////
+VSpectra::~VSpectra(){
 }
 
-
-
 ////////////////////////////////////////////////////////////////////////////////
 TH1* VSpectra::AddHisto1D(string name, string title, Int_t nbinsx, Double_t xlow, Double_t xup, string family){
   // create histo
@@ -102,8 +98,7 @@ TH1* VSpectra::GetHisto(string& family, string& name){
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void VSpectra::WriteSpectra(string filename)
-{
+void VSpectra::WriteSpectra(string filename){
    TFile* f = NULL; 
    if (filename != "VOID") {
       f = new TFile(filename.c_str(), "RECREATE");
@@ -114,11 +109,12 @@ void VSpectra::WriteSpectra(string filename)
    }
 
    // created dedicated directory for spectra
-   TDirectory *dir = (TDirectory*) f->Get("ControlSpectra");
+    string dirname = "ControlSpectra/"+m_name;
+   TDirectory *dir = (TDirectory*) f->Get(dirname.c_str());
    if (!dir) {
-      f->mkdir("ControlSpectra");
-      f->cd("ControlSpectra");
+      f->mkdir(dirname.c_str());
    }
+   f->cd(dirname.c_str());
 
    // write all histos
    map< vector<string>, TH1* >::iterator it;
@@ -126,9 +122,12 @@ void VSpectra::WriteSpectra(string filename)
       it->second->Write();
    }
 
+   // Go back to root directory
+   f->cd();
+
    // close file and delete associate pointer only in case
    // of filename.
-   if (filename != "VOID") {
+       if (filename != "VOID") {
       f->Close();
       delete f;
    }
diff --git a/NPLib/Core/NPVSpectra.h b/NPLib/Core/NPVSpectra.h
index b0ce819cf..f66bf9935 100644
--- a/NPLib/Core/NPVSpectra.h
+++ b/NPLib/Core/NPVSpectra.h
@@ -67,6 +67,12 @@ class VSpectra {
   private:
     // map holding histo pointers and their family names
     map< vector<string>, TH1* > fMapHisto;
+
+  private: // Name of the Detector
+   string m_name;
+
+  public:
+   inline void SetName(string name) {m_name=name;}
 };
 
 #endif
diff --git a/NPLib/Exogam/TExogamSpectra.cxx b/NPLib/Exogam/TExogamSpectra.cxx
index 8676ed3c3..a3b1e9634 100644
--- a/NPLib/Exogam/TExogamSpectra.cxx
+++ b/NPLib/Exogam/TExogamSpectra.cxx
@@ -40,6 +40,7 @@ using namespace NPUNITS;
 
 ////////////////////////////////////////////////////////////////////////////////
 TExogamSpectra::TExogamSpectra(){
+  SetName("Exogam");
   fnbinsRaw=16384;
   fbinRawMin=0;
   fbinRawMax=16384;
@@ -56,6 +57,7 @@ TExogamSpectra::TExogamSpectra(unsigned int NumberOfClover){
       << "TExogamSpectra : Initalising control spectra for " 
       << NumberOfClover << " Clover" << endl
       << "************************************************" << endl ;
+  SetName("Exogam");
   fNumberOfClover = NumberOfClover;
   fNumberOfSegments=4;
   fNumberOfCores=4;
diff --git a/NPLib/MUST2/TMust2Spectra.cxx b/NPLib/MUST2/TMust2Spectra.cxx
index 372a56f03..08f61511c 100644
--- a/NPLib/MUST2/TMust2Spectra.cxx
+++ b/NPLib/MUST2/TMust2Spectra.cxx
@@ -40,6 +40,7 @@ using namespace std;
 
 ////////////////////////////////////////////////////////////////////////////////
 TMust2Spectra::TMust2Spectra(){
+  SetName("Must2");
   fNumberOfTelescope = 0;
   fStripX=128;
   fStripY=128;
@@ -55,6 +56,7 @@ TMust2Spectra::TMust2Spectra(unsigned int NumberOfTelescope){
       << NumberOfTelescope << " Telescopes" << endl
       << "************************************************" << endl ;
 
+  SetName("Must2");
   fNumberOfTelescope = NumberOfTelescope;
   fStripX=128;
   fStripY=128;
diff --git a/NPLib/Sharc/TSharcSpectra.cxx b/NPLib/Sharc/TSharcSpectra.cxx
index 185b89b12..021084013 100644
--- a/NPLib/Sharc/TSharcSpectra.cxx
+++ b/NPLib/Sharc/TSharcSpectra.cxx
@@ -38,6 +38,7 @@ using namespace std;
 
 ////////////////////////////////////////////////////////////////////////////////
 TSharcSpectra::TSharcSpectra(){
+  SetName("Sharc");
   fNumberOfDetector = 0;
   fStripFront=24;
   fStripBack=48;
@@ -50,7 +51,7 @@ TSharcSpectra::TSharcSpectra(unsigned int NumberOfDetector){
       << "TSharcSpectra : Initalising control spectra for " 
       << NumberOfDetector << " Detectors" << endl
       << "************************************************" << endl ;
-
+  SetName("Sharc");
   fNumberOfDetector = NumberOfDetector;
   fStripFront=24;
   fStripBack=48;
diff --git a/NPLib/Tiara/TTiaraBarrelSpectra.cxx b/NPLib/Tiara/TTiaraBarrelSpectra.cxx
index 474356680..c3c7bcd95 100644
--- a/NPLib/Tiara/TTiaraBarrelSpectra.cxx
+++ b/NPLib/Tiara/TTiaraBarrelSpectra.cxx
@@ -40,6 +40,7 @@ using namespace NPUNITS;
 
 ////////////////////////////////////////////////////////////////////////////////
 TTiaraBarrelSpectra::TTiaraBarrelSpectra(){
+  SetName("TiaraBarrel");
   fNumberOfDetector= 0;
   fInnerBarrelStrip=4;
   fOuterBarrelStrip=4;
@@ -53,6 +54,7 @@ TTiaraBarrelSpectra::TTiaraBarrelSpectra(unsigned int NumberOfDetector){
       << NumberOfDetector << " Detectors" << endl
       << "************************************************" << endl ;
 
+  SetName("TiaraBarrel");
   fNumberOfDetector= NumberOfDetector;
   fInnerBarrelStrip=4;
   fOuterBarrelStrip=4;
diff --git a/NPLib/Tiara/TTiaraHyballSpectra.cxx b/NPLib/Tiara/TTiaraHyballSpectra.cxx
index 3a0ca4cf5..dc2288b9e 100644
--- a/NPLib/Tiara/TTiaraHyballSpectra.cxx
+++ b/NPLib/Tiara/TTiaraHyballSpectra.cxx
@@ -45,6 +45,7 @@ TTiaraHyballSpectra::TTiaraHyballSpectra(){
     cout << "************************************************" << endl;
   }
 
+  SetName("TiaraHyball");
   fRingsNumber   = 16;
   fSectorsNumber =  8;
   fWedgesNumber  =  6;
-- 
GitLab