Added PHOS/macros/Trigger/raw and contained code.
authorhqvigsta <hqvigsta@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 4 Feb 2013 13:22:06 +0000 (13:22 +0000)
committerhqvigsta <hqvigsta@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 4 Feb 2013 13:22:06 +0000 (13:22 +0000)
PHOS/macros/Trigger/raw/AliTRUPedestalAnalysis.cxx [new file with mode: 0644]
PHOS/macros/Trigger/raw/AliTRUPedestalAnalysis.h [new file with mode: 0644]
PHOS/macros/Trigger/raw/AliTRUPedestalOutput.cxx [new file with mode: 0644]
PHOS/macros/Trigger/raw/AliTRUPedestalOutput.h [new file with mode: 0644]
PHOS/macros/Trigger/raw/README [new file with mode: 0644]
PHOS/macros/Trigger/raw/alien_163759.txt [new file with mode: 0644]
PHOS/macros/Trigger/raw/runTRUPedestalAnalysis.C [new file with mode: 0644]
PHOS/macros/Trigger/raw/truPedestalAnalysis.C [new file with mode: 0644]

diff --git a/PHOS/macros/Trigger/raw/AliTRUPedestalAnalysis.cxx b/PHOS/macros/Trigger/raw/AliTRUPedestalAnalysis.cxx
new file mode 100644 (file)
index 0000000..485a241
--- /dev/null
@@ -0,0 +1,77 @@
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+// Author: Henrik Qvigstad <henrik.qvigstad@cern.ch>
+/* $Id$ */
+
+#include "AliCaloRawStreamV3.h"
+#include "AliTRUPedestalOutput.h"
+#include "AliPHOSTriggerRawReader.h"
+#include "AliPHOSTRURawReader.h"
+#include "TH1I.h"
+
+#include "AliTRUPedestalAnalysis.h"
+#include <TRandom.h>
+
+AliTRUPedestalAnalysis::AliTRUPedestalAnalysis()
+: fOutput(new AliTRUPedestalOutput),
+  fTriggerReader(new AliPHOSTriggerRawReader)
+{
+}
+
+AliTRUPedestalAnalysis::~AliTRUPedestalAnalysis()
+{
+  delete fOutput;
+}
+
+void AliTRUPedestalAnalysis::ProcessEvent ( AliCaloRawStreamV3* phosStream )
+{
+  fTriggerReader->Reset();
+
+  phosStream->Reset();
+  while (phosStream->NextDDL()) {
+    while (phosStream->NextChannel()) {
+      if (phosStream->IsTRUData()) {
+       fTriggerReader->ReadFromStream(phosStream);
+      }// IsTRUData
+    }// NextChannel
+  }//NextDDL
+
+  bool data_in_event = false;
+  for (unsigned int mod=0; mod<kNMods; ++mod) {
+    for (unsigned int row=0; row<kNTRURows; ++row) {
+      for (unsigned int branch=0; branch<kNBranches; ++branch) {
+       // if there is tru data in this branch, for this event.
+       if( fTriggerReader->GetTRU(mod, row, branch)->IsActive() ) {
+         data_in_event = true;
+         for (unsigned int xrow=0; xrow<kN2x2XPrTRURow; ++xrow) {
+           for (unsigned int zcol=0; zcol<kN2x2ZPrBranch; ++zcol) {
+             // if there is tru data for this timebin, for this branch.
+             for (unsigned int timeBin=0; timeBin < kNTRUTimeBins; ++timeBin) {
+               if( fTriggerReader->GetTRU(mod, row, branch)->IsActive(timeBin) ){
+                 double signal = fTriggerReader->GetTRU(mod, row, branch)->GetTriggerSignal(xrow, zcol, timeBin);
+                 fOutput->GetTRUSignals(mod, row, branch, xrow, zcol)->Fill(signal);
+               } // if timebin is active
+             } // timeBin
+           } // zcol
+         } // xrow
+       } // if branch is active
+      } // branch
+    } // row
+  } // mod
+
+  if( data_in_event )
+    fOutput->EventAdded();
+}
+
+
+UInt_t AliTRUPedestalAnalysis::Get2x2Max ( AliPHOSTriggerRawReader* reader, int mod, int row, int branch, int x, int z )
+{
+  UInt_t max = 0;
+  for(UInt_t timeBin = 0; timeBin < kNTRUTimeBins; ++timeBin) {
+    const UInt_t signal = reader->GetTRU(mod, row, branch)->GetTriggerSignal(x, z, timeBin);
+    if( max < signal )
+      max = signal;
+  }
+  return max;
+}
diff --git a/PHOS/macros/Trigger/raw/AliTRUPedestalAnalysis.h b/PHOS/macros/Trigger/raw/AliTRUPedestalAnalysis.h
new file mode 100644 (file)
index 0000000..45236bd
--- /dev/null
@@ -0,0 +1,47 @@
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+// Author: Henrik Qvigstad <henrik.qvigstad@cern.ch>
+/* $Id$ */
+
+
+#ifndef ALITRUPEDESTALANALYSIS_H
+#define ALITRUPEDESTALANALYSIS_H
+
+#include <Rtypes.h>
+
+class AliCaloRawStreamV3;
+class AliTRUPedestalOutput;
+class AliPHOSTriggerRawReader;
+
+class AliTRUPedestalAnalysis
+{
+public:
+  AliTRUPedestalAnalysis();
+  virtual ~AliTRUPedestalAnalysis();
+
+  void ProcessEvent(AliCaloRawStreamV3* );
+  AliTRUPedestalOutput* GetOutput() { return fOutput; }
+
+  static UInt_t Get2x2Max(AliPHOSTriggerRawReader* reader, int mod, int row, int branch, int x, int z);
+
+  // Constants
+  const static UInt_t kNMods         = 5;
+  const static UInt_t kNTRURows      = 4;
+  const static UInt_t kNBranches     = 2;
+  const static UInt_t kN2x2X         = 64/2;
+  const static UInt_t kN2x2Z         = 56/2;
+  const static UInt_t kN2x2XPrTRURow = kN2x2X / kNTRURows;
+  const static UInt_t kN2x2ZPrBranch = kN2x2Z / kNBranches;
+  const static UInt_t kNTRUTimeBins  = 128;
+  const static UInt_t kNEMCTimeBins  = 62;
+
+private:
+  AliTRUPedestalAnalysis ( const AliTRUPedestalAnalysis& other ); // not impl.
+  AliTRUPedestalAnalysis& operator= ( const AliTRUPedestalAnalysis& other ); // not impl.
+
+  AliTRUPedestalOutput* fOutput;
+  AliPHOSTriggerRawReader* fTriggerReader;
+};
+
+#endif // ALITRUPEDESTALANALYSIS_H
diff --git a/PHOS/macros/Trigger/raw/AliTRUPedestalOutput.cxx b/PHOS/macros/Trigger/raw/AliTRUPedestalOutput.cxx
new file mode 100644 (file)
index 0000000..79e486c
--- /dev/null
@@ -0,0 +1,374 @@
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+// Author: Henrik Qvigstad <henrik.qvigstad@cern.ch>
+/* $Id$ */
+
+
+#include "AliTRUPedestalOutput.h"
+
+ClassImp(AliTRUPedestalOutput)
+
+#include "TMath.h"
+#include <TH1I.h>
+#include <TH1F.h>
+#include <TH2F.h>
+#include <TString.h>
+#include "TCanvas.h"
+
+#include <iostream>
+using namespace std;
+
+AliTRUPedestalOutput::AliTRUPedestalOutput()
+: fRun(-1),
+  fNEvents(0),
+  fPedestals(0),
+  fPedestalRMS(0),
+  fPedestalSamples(0),
+  fPedestals2d({0}),
+  fPedestalRMS2d({0}),
+  fPedestalsId(0),
+  fPedestals_branch({{{0}}}),
+  fTRUSignals({{{{{0}}}}})
+{
+
+}
+
+AliTRUPedestalOutput::~AliTRUPedestalOutput()
+{
+  // All the class contains is Histograms, they are owned by current ROOT folder.
+  // new TCanvas;
+  // fTRUSignals[2][0][1][0][1]->DrawCopy();
+}
+
+void AliTRUPedestalOutput::SetRun ( Int_t run )
+{
+  if( fRun >= 0 ) // fRun is initilized to -1
+    Error("SetRun", "Only one run allowed, i.e. run should not be set, then set to something different.");
+  fRun = run;
+}
+
+void AliTRUPedestalOutput::EventAdded()
+{
+  fNEvents++;
+}
+
+TH1F* AliTRUPedestalOutput::GetPedestals()
+{
+  // Delete Histogram if exists
+  if( fPedestals )
+    fPedestals->Delete();
+  fPedestals = 0;
+
+  // Create Histogram
+  fPedestals = new TH1F("fPedestals", "TRU Pedestals", 10*1024, 0, 1024);
+  fPedestals->GetXaxis()->SetTitle("Pedestals, <signal>_c");
+  fPedestals->GetYaxis()->SetTitle("Count");
+
+  // Fill Histogram
+  for (unsigned int mod=0; mod<kNMods; ++mod) {
+    for (unsigned int row=0; row<kNTRURows; ++row) {
+      for (unsigned int branch=0; branch<kNBranches; ++branch) {
+       for (unsigned int xrow=0; xrow<kN2x2XPrTRURow; ++xrow) {
+         for (unsigned int zcol=0; zcol<kN2x2ZPrBranch; ++zcol) {
+           if( ! fTRUSignals[mod][row][branch][xrow][zcol] )
+             continue;
+
+           double pedestal = GetPedestal(mod, row, branch, xrow, zcol);
+           fPedestals->Fill(pedestal);
+         }
+       }
+      }
+    }
+  }
+
+  return fPedestals;
+}
+
+TH1F* AliTRUPedestalOutput::GetPedestalRMS()
+{
+  // Delete Histogram if exists
+  if( fPedestalRMS )
+    fPedestalRMS->Delete();
+  fPedestalRMS = 0;
+
+  fPedestalRMS = new TH1F("fPedestalRMS", "TRU Pedestal RMS", 1020, 0, 102);
+  fPedestalRMS->GetXaxis()->SetTitle("RMS");
+  fPedestalRMS->GetYaxis()->SetTitle("Count");
+
+  for (unsigned int mod=0; mod<kNMods; ++mod) {
+    for (unsigned int row=0; row<kNTRURows; ++row) {
+      for (unsigned int branch=0; branch<kNBranches; ++branch) {
+       for (unsigned int xrow=0; xrow<kN2x2XPrTRURow; ++xrow) {
+         for (unsigned int zcol=0; zcol<kN2x2ZPrBranch; ++zcol) {
+           if( ! fTRUSignals[mod][row][branch][xrow][zcol] )
+             continue;
+
+           double rms = GetRMS(mod, row, branch, xrow, zcol);
+           fPedestalRMS->Fill(rms);
+           if ( 2 < rms )
+             printf("AliTRUPedestalOutput::GetPedestalRMS: ped. RMS:%f, mod:%d row:%d branch:%d x:%02d z:%02d\n", rms, mod, row, branch, xrow, zcol);
+
+         }
+       }
+      }
+    }
+  }
+
+  return fPedestalRMS;
+}
+
+TH1I* AliTRUPedestalOutput::GetPedestalSamples()
+{
+  if( fPedestalSamples )
+    fPedestalSamples->Delete();
+  fPedestalSamples = 0;
+
+  fPedestalSamples = new TH1I("fPedestalSamples", "TRU Pedestal Samples", 1000, 0, kNTRUTimeBins*fNEvents);
+  fPedestalSamples->GetXaxis()->SetTitle("Samples");
+  fPedestalSamples->GetYaxis()->SetTitle("Count");
+
+  int smallThreshold = 2600;
+  for (unsigned int mod=0; mod<kNMods; ++mod) {
+    for (unsigned int row=0; row<kNTRURows; ++row) {
+      for (unsigned int branch=0; branch<kNBranches; ++branch) {
+       int smallCount = 0;
+       for (unsigned int xrow=0; xrow<kN2x2XPrTRURow; ++xrow) {
+         for (unsigned int zcol=0; zcol<kN2x2ZPrBranch; ++zcol) {
+           if( ! fTRUSignals[mod][row][branch][xrow][zcol] )
+             continue;
+
+           double entries = GetSamples(mod, row, branch, xrow, zcol);
+           fPedestalSamples->Fill(entries);
+           if ( entries < smallThreshold )
+             ++smallCount;
+         } // z
+       } // x 
+       if(smallCount)
+         printf("AliTRUPedestalOutput::GetPedestalSamples: Small Sample! %d cells in TRU: mod:%d row:%d branch:%d\n", smallCount, mod, row, branch);
+      } // branch 
+    } // row
+  } // mod
+
+  return fPedestalSamples;
+}
+
+TH2F* AliTRUPedestalOutput::GetPedestals2d(UInt_t mod)
+{
+  if( fPedestals2d[mod] )
+    fPedestals2d[mod]->Delete();
+  fPedestals2d[mod] = 0;
+
+  const int nhr = kN2x2X +kNTRURows -1; // number of histogram rows, x
+  const int nhc = kN2x2Z +kNBranches -1; // number of histogram columns, z
+  TString name("fPedestals2d_mod:"); name += mod;
+  TString title("fPedestals, Mod: "); title += mod;
+  fPedestals2d[mod] = new TH2F(name, title, nhr, 0, nhr,   nhc, 0, nhc);
+  fPedestals2d[mod]->GetXaxis()->SetTitle("x = x_tru + 9*tru");
+  fPedestals2d[mod]->GetYaxis()->SetTitle("z = z_tru + 15*branch");
+  fPedestals2d[mod]->SetStats(0);
+
+  for (unsigned int row=0; row<kNTRURows; ++row) {
+      for (unsigned int branch=0; branch<kNBranches; ++branch) {
+       for (unsigned int xrow=0; xrow<kN2x2XPrTRURow; ++xrow) {
+         for (unsigned int zcol=0; zcol<kN2x2ZPrBranch; ++zcol) {
+           if( ! fTRUSignals[mod][row][branch][xrow][zcol] )
+             continue;
+
+           int xindex = xrow + kN2x2XPrTRURow*row +row;
+           int zindex = zcol + kN2x2ZPrBranch*branch +branch;
+           double pedestal = GetPedestal(mod, row, branch, xrow, zcol);
+
+           fPedestals2d[mod]->SetBinContent(xindex+1, zindex+1, pedestal);
+         } // z col
+       } // x row
+      } // branch, tru
+    } // row, tru
+  fPedestals2d[mod]->SetDrawOption("colz");
+  return fPedestals2d[mod];
+}
+
+TH2F* AliTRUPedestalOutput::GetPedestalRMS2d(UInt_t mod)
+{
+  if( fPedestalRMS2d[mod] )
+    fPedestalRMS2d[mod]->Delete();
+  fPedestalRMS2d[mod] = 0;
+
+  const int nhr = kN2x2X +kNTRURows -1; // number of histogram rows, x
+  const int nhc = kN2x2Z +kNBranches -1; // number of histogram columns, z
+  TString name("fPedestalRMS2d_mod:"); name += mod;
+  TString title("RMS, Mod: "); title += mod;
+  fPedestalRMS2d[mod] = new TH2F(name, title, nhr, 0, nhr,   nhc, 0, nhc);
+  fPedestalRMS2d[mod]->GetXaxis()->SetTitle("x = x_tru + 9*tru");
+  fPedestalRMS2d[mod]->GetYaxis()->SetTitle("z = z_tru + 15*branch");
+  fPedestalRMS2d[mod]->SetStats(0);
+
+  for (unsigned int row=0; row<kNTRURows; ++row) {
+      for (unsigned int branch=0; branch<kNBranches; ++branch) {
+       for (unsigned int xrow=0; xrow<kN2x2XPrTRURow; ++xrow) {
+         for (unsigned int zcol=0; zcol<kN2x2ZPrBranch; ++zcol) {
+           if( ! fTRUSignals[mod][row][branch][xrow][zcol] )
+             continue;
+
+           int xindex = xrow + kN2x2XPrTRURow*row +row;
+           int zindex = zcol + kN2x2ZPrBranch*branch +branch;
+           double rms = GetRMS(mod, row, branch, xrow, zcol);
+
+           fPedestalRMS2d[mod]->SetBinContent(xindex+1, zindex+1, rms);
+         } // z col
+       } // x row
+      } // branch, tru
+    } // row, tru
+  fPedestalRMS2d[mod]->SetDrawOption("colz");
+  return fPedestalRMS2d[mod];
+}
+
+TH1F* AliTRUPedestalOutput::GetPedestalsId()
+{
+  if( fPedestalsId )
+    fPedestalsId->Delete();
+  fPedestalsId = 0;
+
+  // else Initilize
+  int nhc = kNMods*kNTRURows*kNBranches*kN2x2XPrTRURow*kN2x2ZPrBranch;
+  TString title("Id v Pedestal");
+  fPedestalsId = new TH1F("fPedestalsId", title.Data(), nhc, 0, nhc);
+  fPedestalsId->GetXaxis()->SetTitle("Id ([mod][row][branch][x][z], Row-major order)");
+  fPedestalsId->GetYaxis()->SetTitle("Pedestal");
+  fPedestalsId->SetStats(0);
+
+  for (unsigned int mod=0; mod<kNMods; ++mod) {
+    for (unsigned int row=0; row<kNTRURows; ++row) {
+      for (unsigned int branch=0; branch<kNBranches; ++branch) {
+       for (unsigned int xrow=0; xrow<kN2x2XPrTRURow; ++xrow) {
+         for (unsigned int zcol=0; zcol<kN2x2ZPrBranch; ++zcol) {
+           if( ! fTRUSignals[mod][row][branch][xrow][zcol] )
+             continue;
+
+           int index =
+             mod*kNTRURows*kNBranches*kN2x2XPrTRURow*kN2x2ZPrBranch
+           + row*kNBranches*kN2x2XPrTRURow*kN2x2ZPrBranch
+           + branch*kN2x2XPrTRURow*kN2x2ZPrBranch
+           + xrow*kN2x2ZPrBranch
+           + zcol;
+           double pedestal = GetPedestal(mod, row, branch, xrow, zcol);
+           double pederror = GetPedestalError(mod, row, branch, xrow, zcol);
+           fPedestalsId->SetBinContent(index+1, pedestal);
+           fPedestalsId->SetBinError(index+1, pederror);
+         }
+       }
+      }
+    }
+  }
+  fPedestalsId->SetDrawOption("E");
+  return fPedestalsId;
+}
+
+TH1F* AliTRUPedestalOutput::GetPedestals_branch ( UInt_t mod, UInt_t row, UInt_t branch )
+{
+  if( fPedestals_branch[mod][row][branch] )
+    fPedestals_branch[mod][row][branch]->Delete();
+  fPedestals_branch[mod][row][branch] = 0;
+  
+  TH1F* hist = new TH1F("fPedestals", "Pedestals", 10*1024, 0, 1024);
+  hist->GetXaxis()->SetTitle("Pedestals, <signal>");
+  hist->GetYaxis()->SetTitle("Count");
+
+  for (unsigned int xrow=0; xrow<kN2x2XPrTRURow; ++xrow) {
+    for (unsigned int zcol=0; zcol<kN2x2ZPrBranch; ++zcol) {
+      if( ! fTRUSignals[mod][row][branch][xrow][zcol] )
+       continue;
+      double pedestal = GetPedestal(mod, row, branch, xrow, zcol);
+      hist->Fill(pedestal);
+    }
+  }
+
+  return fPedestals_branch[mod][row][branch] = hist;
+}
+
+TH1I* AliTRUPedestalOutput::GetTRUSignals ( UInt_t mod, UInt_t row, UInt_t branch, UInt_t x, UInt_t z )
+{
+  if( fTRUSignals[mod][row][branch][x][z] )
+    return fTRUSignals[mod][row][branch][x][z];
+  else
+  {
+    // else Initilize
+    char name[256];
+    sprintf(name, "fTRUSignals_m:%d_r:%d_b:%d_x:%02d_z:%02d", mod, row, branch, x, z);
+    char title[256];
+    sprintf(title, "TRU Signal mod:%d row:%d branch:%d x:%02d z:%02d", mod, row, branch, x, z);
+  
+    TH1I* hist = new TH1I(name, title, 1024, 0, 1024);
+    hist->GetXaxis()->SetTitle("Bin");
+    hist->GetYaxis()->SetTitle("Count");
+    return fTRUSignals[mod][row][branch][x][z] = hist;
+  }
+}
+
+Double_t AliTRUPedestalOutput::GetPedestal ( UInt_t mod, UInt_t row, UInt_t branch, UInt_t x, UInt_t z )
+{
+  
+  if( fTRUSignals[mod][row][branch][x][z] )
+    return fTRUSignals[mod][row][branch][x][z]->GetMean();
+  else
+    return -1;
+}
+
+Double_t AliTRUPedestalOutput::GetPedestalError ( UInt_t mod, UInt_t row, UInt_t branch, UInt_t x, UInt_t z )
+{
+  if( fTRUSignals[mod][row][branch][x][z] )
+    return fTRUSignals[mod][row][branch][x][z]->GetMeanError();
+  else
+    return -1;
+
+}
+
+Double_t AliTRUPedestalOutput::GetRMS ( UInt_t mod, UInt_t row, UInt_t branch, UInt_t x, UInt_t z )
+{
+  if( fTRUSignals[mod][row][branch][x][z] )
+    return fTRUSignals[mod][row][branch][x][z]->GetRMS();
+  else
+    return -1;
+}
+
+Double_t AliTRUPedestalOutput::GetSamples(UInt_t mod, UInt_t row, UInt_t branch, UInt_t x, UInt_t z)
+{
+  if( fTRUSignals[mod][row][branch][x][z] )
+    return fTRUSignals[mod][row][branch][x][z]->GetEntries();
+  else
+    return -1;
+}
+
+// TH2F* AliTRUPedestalOutput::GetPedestalRMS2d_old(UInt_t mod)
+// {
+//   if( fPedestalRMS2d[mod] )
+//     fPedestalRMS2d[mod]->Delete();
+//   fPedestalRMS2d[mod] = 0;
+//
+//   const int nhr = 2*kN2x2X +2*kNTRURows; // number of histogram rows, x
+//   const int nhc = 2*kN2x2Z +2*kNBranches; // number of histogram columns, z
+//   TString name("fPedestalRMS2d_mod:"); name += mod;
+//   TString title("RMS, Mod: "); title += mod;
+//   fPedestalRMS2d[mod] = new TH2F(name, title, nhr, 0, nhr,   nhc, 0, nhc);
+//   fPedestalRMS2d[mod]->GetXaxis()->SetTitle("x");
+//   fPedestalRMS2d[mod]->GetYaxis()->SetTitle("z");
+//
+//   for (unsigned int row=0; row<kNTRURows; ++row) {
+//       for (unsigned int branch=0; branch<kNBranches; ++branch) {
+//     for (unsigned int xrow=0; xrow<kN2x2XPrTRURow; ++xrow) {
+//       for (unsigned int zcol=0; zcol<kN2x2ZPrBranch; ++zcol) {
+//         if( ! fTRUSignals[mod][row][branch][xrow][zcol] )
+//           continue;
+//
+//         int xindex = 2*xrow + 2*kN2x2XPrTRURow*row +2*row;
+//         int zindex = 2*zcol + 2*kN2x2ZPrBranch*branch +2*branch;
+//         double rms = GetRMS(mod, row, branch, xrow, zcol);
+//
+//                 fPedestalRMS2d[mod]->SetBinContent(xindex+1, zindex+1, rms);
+//       } // z col
+//     } // x row
+//       } // branch, tru
+//     } // row, tru
+//   fPedestalRMS2d[mod]->SetDrawOption("colz");
+//   return fPedestalRMS2d[mod];
+// }
diff --git a/PHOS/macros/Trigger/raw/AliTRUPedestalOutput.h b/PHOS/macros/Trigger/raw/AliTRUPedestalOutput.h
new file mode 100644 (file)
index 0000000..4662361
--- /dev/null
@@ -0,0 +1,82 @@
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+// Author: Henrik Qvigstad <henrik.qvigstad@cern.ch>
+/* $Id$ */
+
+
+#ifndef ALITRUPEDESTALOUTPUT_H
+#define ALITRUPEDESTALOUTPUT_H
+
+#include <TObject.h>
+#include <Rtypes.h>
+
+class TH1I;
+class TH1F;
+class TH2F;
+
+class AliTRUPedestalOutput : public TObject
+{
+
+public:
+  AliTRUPedestalOutput();
+  virtual ~AliTRUPedestalOutput();
+
+  void SetRun(Int_t run);
+  void EventAdded();
+
+  UInt_t GetEventsAdded() { return fNEvents; }
+
+  // Histograms Getters:
+  TH1F* GetPedestals();
+  TH1F* GetPedestalRMS();
+  TH1I* GetPedestalSamples();
+  TH2F* GetPedestals2d(UInt_t mod);
+  TH2F* GetPedestalRMS2d(UInt_t mod);
+  TH1F* GetPedestalsId();
+  TH1F* GetPedestals_branch(UInt_t mod, UInt_t row, UInt_t branch);
+
+  TH1I* GetTRUSignals(UInt_t mod, UInt_t row, UInt_t branch, UInt_t x, UInt_t z);
+
+  // Other Getters:
+  Double_t GetPedestal(UInt_t mod, UInt_t row, UInt_t branch, UInt_t x, UInt_t z);
+  Double_t GetPedestalError(UInt_t mod, UInt_t row, UInt_t branch, UInt_t x, UInt_t z);
+  Double_t GetRMS(UInt_t mod, UInt_t row, UInt_t branch, UInt_t x, UInt_t z);
+  Double_t GetSamples(UInt_t mod, UInt_t row, UInt_t branch, UInt_t x, UInt_t z);
+  
+  // Constants
+  const static UInt_t kNMods         = 5;
+  const static UInt_t kNTRURows      = 4;
+  const static UInt_t kNBranches     = 2;
+  const static UInt_t kN2x2X         = 64/2;
+  const static UInt_t kN2x2Z         = 56/2;
+  const static UInt_t kN2x2XPrTRURow = kN2x2X / kNTRURows;
+  const static UInt_t kN2x2ZPrBranch = kN2x2Z / kNBranches;
+  const static UInt_t kNTRUTimeBins  = 128;
+  const static UInt_t kNEMCTimeBins  = 62;
+
+private:
+  AliTRUPedestalOutput ( const AliTRUPedestalOutput& other ); // not impl.
+  AliTRUPedestalOutput& operator= ( const AliTRUPedestalOutput& other ); // not impl.
+  
+  Int_t fRun;
+  UInt_t fNEvents;
+  
+  // Event Global Histograms:
+  TH1F* fPedestals;   //! Pedestals
+  TH1F* fPedestalRMS; //!
+  TH1I* fPedestalSamples; //!
+  TH2F* fPedestals2d[kNMods]; //!
+  TH2F* fPedestalRMS2d[kNMods]; //!
+  TH1F* fPedestalsId; //! Pedestals v Id
+  TH1F* fPedestals_branch[kNMods][kNTRURows][kNBranches]; //! Pedestals, pr mod
+  // TH2F* fPedestalsId_branch[kNMods][kNTRURows][kNBranches]; //! Pedestals v Id, pr mod
+
+  // Regular Histograms
+  TH1I* fTRUSignals[kNMods][kNTRURows][kNBranches][kN2x2XPrTRURow][kN2x2ZPrBranch]; //->
+
+  
+  ClassDef(AliTRUPedestalOutput, 0)
+};
+
+#endif // ALITRUPEDESTALOUTPUT_H
diff --git a/PHOS/macros/Trigger/raw/README b/PHOS/macros/Trigger/raw/README
new file mode 100644 (file)
index 0000000..bb45c6e
--- /dev/null
@@ -0,0 +1,11 @@
+This folder: 
+/opt/alice/aliroot/trunk/PHOS/macros/Trigger/raw 
+contains code for analyzing the raw TRU data from an raw data stream.
+
+truPedestalAnalysis.C - contains functions which takes a list of raw files and produces some histograms.
+
+runTRUPedestalAnalysis.C - shows how to use this analysis.
+
+It is a required that you provide a file containing a list of raw .root files, files.txt by default.
+Assuming you have such a files.txt file, you should be a ble to run the analysis as is by the following command:
+$ aliroot runTRUPedestalAnalysis.C
diff --git a/PHOS/macros/Trigger/raw/alien_163759.txt b/PHOS/macros/Trigger/raw/alien_163759.txt
new file mode 100644 (file)
index 0000000..d73f155
--- /dev/null
@@ -0,0 +1,12 @@
+alien:///alice/data/2011/LHC11f_PHOS/000163759/raw/11000163759003.10.root
+alien:///alice/data/2011/LHC11f_PHOS/000163759/raw/11000163759003.11.root
+alien:///alice/data/2011/LHC11f_PHOS/000163759/raw/11000163759003.12.root
+alien:///alice/data/2011/LHC11f_PHOS/000163759/raw/11000163759003.13.root
+alien:///alice/data/2011/LHC11f_PHOS/000163759/raw/11000163759003.14.root
+alien:///alice/data/2011/LHC11f_PHOS/000163759/raw/11000163759003.15.root
+alien:///alice/data/2011/LHC11f_PHOS/000163759/raw/11000163759003.20.root
+alien:///alice/data/2011/LHC11f_PHOS/000163759/raw/11000163759003.21.root
+alien:///alice/data/2011/LHC11f_PHOS/000163759/raw/11000163759003.22.root
+alien:///alice/data/2011/LHC11f_PHOS/000163759/raw/11000163759003.23.root
+alien:///alice/data/2011/LHC11f_PHOS/000163759/raw/11000163759003.24.root
+alien:///alice/data/2011/LHC11f_PHOS/000163759/raw/11000163759003.25.root
diff --git a/PHOS/macros/Trigger/raw/runTRUPedestalAnalysis.C b/PHOS/macros/Trigger/raw/runTRUPedestalAnalysis.C
new file mode 100644 (file)
index 0000000..0cd8b27
--- /dev/null
@@ -0,0 +1,22 @@
+#include <TSystem.h>
+#include <TROOT.h>
+
+void runTRUPedestalAnalysis(char* filesList = "files.txt")
+{
+  gSystem->AddIncludePath("-I$ALICE_ROOT/include");
+  gSystem->AddIncludePath("-I$ALICE_ROOT/PHOS");
+  gSystem->AddIncludePath("-I$ALICE_ROOT/RAW");
+
+  gSystem->Load("libPHOSrec");
+  
+  gROOT->LoadMacro("AliTRUPedestalOutput.cxx+g");
+  gROOT->LoadMacro("AliTRUPedestalAnalysis.cxx+g");
+
+  gROOT->LoadMacro("truPedestalAnalysis.C+g");
+  
+  // for if the files are on alien, use responsibly!
+  // TGrid::Connect("alien://");
+  // AliCDBManager::Instance()->SetDefaultStorage("raw://");
+
+  truPedestalAnalysis(filesList);
+}
diff --git a/PHOS/macros/Trigger/raw/truPedestalAnalysis.C b/PHOS/macros/Trigger/raw/truPedestalAnalysis.C
new file mode 100644 (file)
index 0000000..f3e1c33
--- /dev/null
@@ -0,0 +1,155 @@
+#include "TROOT.h"
+#include "TChain.h"
+#include "TString.h"
+#include "TCanvas.h"
+#include "TH1F.h"
+#include "TH2F.h"
+#include "AliRawReaderChain.h"
+#include "AliCaloRawStreamV3.h"
+#include "AliCDBManager.h"
+
+#include <fstream>
+#include <iostream>
+
+#include "AliTRUPedestalAnalysis.h"
+#include "AliTRUPedestalOutput.h"
+#include <TStyle.h>
+
+void addFilesToChain(const TString rawFileList, TChain* chain);
+void printHists(AliTRUPedestalOutput* output);
+void saveResults(AliTRUPedestalOutput* output, TString saveToFile);
+
+
+
+void truPedestalAnalysis(TString rawFileList = "files.txt", TString saveToFile = "truOutput.root")
+{
+  // Raw Chain Initialization
+  TChain *chain = new TChain("RAW");
+  addFilesToChain(rawFileList, chain );
+  AliRawReaderChain* rawChain = new AliRawReaderChain(chain);
+  rawChain->Reset();
+
+  // PHOS Raw Stream Initialization
+  AliCaloRawStreamV3* phosRawStream = new AliCaloRawStreamV3(rawChain,"PHOS");
+
+  // Analysis object Initialization
+  AliTRUPedestalAnalysis* anaObj = new AliTRUPedestalAnalysis();
+
+  // Loop over events in Chain
+  UInt_t runNumber = -1;
+  Int_t event_count = 0;
+  while (rawChain->NextEvent())
+  { // Print out event number:
+    std::cout << "\r" << "event: " << ++event_count
+             << "/"<< rawChain->GetNumberOfEvents() << " " << std::flush;
+    if( rawChain->GetRunNumber() != runNumber ){
+      // if new event number, update OCDB
+      runNumber = rawChain->GetRunNumber();
+      AliCDBManager::Instance()->SetRun(runNumber);
+      Printf("New run number, current run number is: %d", runNumber);
+    }
+
+    // Process Event using analysis Object
+    anaObj->ProcessEvent(phosRawStream);
+  }
+
+  // Save output to file, in form of single entry in tree
+  saveResults(anaObj->GetOutput(), saveToFile);
+
+  printHists(anaObj->GetOutput());
+
+
+  // plotting
+  //anaObj->GetOutput()->SaveAs("test.root");
+  // cleanup
+  //delete anaObj;
+
+  //delete phosRawStream;
+  //delete rawChain;
+  //delete chain;
+}
+
+void addFilesToChain(const TString rawFileList, TChain* chain)
+{
+  // Open rawFileList and add files contained to chain
+  std::ifstream inList;
+  inList.open( rawFileList.Data() );
+  std::string line;
+  while( std::getline(inList, line ) ) {
+    printf("Add file %s to chain\n", line.c_str());
+    chain->Add(line.c_str());
+ }
+  inList.close();
+}
+
+void printHists(AliTRUPedestalOutput* output){
+  gROOT->SetStyle("Plain");
+  gStyle->SetPadRightMargin(0.11);
+  
+  TCanvas* canvas =  new TCanvas;
+  TH1F* pedhist = output->GetPedestals();
+  pedhist->GetXaxis()->SetRangeUser(512-10, 512+10);
+  canvas->SetLogy();
+  pedhist->DrawCopy();
+
+  canvas =  new TCanvas;
+  TH1F* rmshist = output->GetPedestalRMS();
+  rmshist->GetXaxis()->SetRangeUser(0, 5);
+  canvas->SetLogy();
+  rmshist->DrawCopy();
+
+  canvas = new TCanvas;
+  TH1F* pedId  = output->GetPedestalsId();
+  pedId->DrawCopy();
+
+  canvas = new TCanvas;
+  TH1I* samples = output->GetPedestalSamples();
+  samples->DrawCopy();
+  
+  canvas = new TCanvas;
+  canvas->Divide(3, 2);
+  canvas->cd(1);
+  TH2F* ped2d_2 = output->GetPedestals2d(2);
+  ped2d_2->GetZaxis()->SetRangeUser(512-10, 512+10);
+  ped2d_2->DrawCopy("colz");
+
+  canvas->cd(2);
+  TH2F* ped2d_3 = output->GetPedestals2d(3);
+  ped2d_3->GetZaxis()->SetRangeUser(512-10, 512+10);
+  ped2d_3->DrawCopy("colz");
+
+  canvas->cd(3);
+  TH2F* ped2d_4 = output->GetPedestals2d(4);
+  ped2d_4->GetZaxis()->SetRangeUser(512-10, 512+10);
+  ped2d_4->DrawCopy("colz");
+
+  canvas->cd(4);
+  TH2F* rms2d_2 = output->GetPedestalRMS2d(2);
+  //rms2d_2->GetZaxis()->SetRangeUser(0, 5);
+  rms2d_2->DrawCopy("colz");
+
+  canvas->cd(5);
+  TH2F* rms2d_3 = output->GetPedestalRMS2d(3);
+  //rms2d_3->GetZaxis()->SetRangeUser(0, 5);
+  rms2d_3->DrawCopy("colz");
+
+  canvas->cd(6);
+  TH2F* rms2d_4 = output->GetPedestalRMS2d(4);
+  //rms2d_4->GetZaxis()->SetRangeUser(0, 5);
+  rms2d_4->DrawCopy("colz");
+}
+
+void saveResults(AliTRUPedestalOutput* output, TString saveToFile)
+{
+  if( ! output )
+    gROOT->Error("truPedestalAnalysis.C::saveResults: no ouput", "no msgfmt");
+
+  TTree* tree = new TTree("pedestalTree", "Pedestal Analysis Tree");
+  TBranch* branch = tree->Branch("pedOutput", &output);
+
+  Printf("Filling:");
+  branch->Print();;
+  tree->Fill();
+
+  tree->SaveAs(saveToFile);
+}