First shuttle code, online calibration histograms producer, EMCAL preprocessor
authorgustavo <gustavo@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 7 Dec 2006 16:32:16 +0000 (16:32 +0000)
committergustavo <gustavo@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 7 Dec 2006 16:32:16 +0000 (16:32 +0000)
EMCAL/AliEMCALCalibHistoProducer.cxx [new file with mode: 0644]
EMCAL/AliEMCALCalibHistoProducer.h [new file with mode: 0644]
EMCAL/AliEMCALPreprocessor.cxx [new file with mode: 0644]
EMCAL/AliEMCALPreprocessor.h [new file with mode: 0644]
EMCAL/EMCALLinkDefshuttle.h [new file with mode: 0644]
EMCAL/libEMCALshuttle.pkg [new file with mode: 0644]

diff --git a/EMCAL/AliEMCALCalibHistoProducer.cxx b/EMCAL/AliEMCALCalibHistoProducer.cxx
new file mode 100644 (file)
index 0000000..43add41
--- /dev/null
@@ -0,0 +1,211 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+/* $Id$ */
+/* History of cvs commits:
+ *
+ * $Log$ 
+ *
+*/
+///////////////////////////////////////////////////////////////////////////////
+// Class AliEMCALCalibHistoProducer accumulating histograms
+// with amplitudes per EMCAL channel
+// It is intended to run at DAQ computers (LDC, GDC, HLT or MOOD)
+// and it fills the histograms with amplitudes per channel.
+// Usage example see in EMCAL/macros/Shuttle/AliEMCALCalibHistoProducer.C
+//
+// Author: Boris Polichtchouk, 4 October 2006
+// Adapted for EMCAL by Gustavo Conesa Balbastre, October 2006
+///////////////////////////////////////////////////////////////////////////////
+
+#include "AliLog.h"
+#include "AliEMCALCalibHistoProducer.h"
+#include "TH1.h"
+#include "TFile.h"
+#include "TProfile.h"
+#include "AliRawReader.h"
+#include "AliCaloRawStream.h"
+
+ClassImp(AliEMCALCalibHistoProducer)
+
+//-----------------------------------------------------------------------------
+AliEMCALCalibHistoProducer::AliEMCALCalibHistoProducer(AliRawReader* rawReader) : 
+  fRawReader(rawReader),fHistoFile(0),fHistoFileName("calibHisto.root"),
+  fUpdatingRate(100),fIsOldRCUFormat(kFALSE), fNSuperModules(12),  fNCellsEta (48),   
+  fNCellsPhi(24),  fNCellsPhiHalfSM(12)
+{
+  // Constructor
+
+  for(Int_t ism=0; ism<fNSuperModules; ism++) {
+    fAmpProf[ism] = 0;
+    fSMInstalled[ism]=kTRUE;
+    for(Int_t icol=0; icol<fNCellsEta; icol++) 
+      for(Int_t irow=0; irow<fNCellsPhi; irow++) 
+         fAmpHisto[ism][icol][irow]=0;
+  }
+
+}
+
+//-----------------------------------------------------------------------------
+AliEMCALCalibHistoProducer::AliEMCALCalibHistoProducer() :
+  fRawReader(0),fHistoFile(0),fUpdatingRate(0),fIsOldRCUFormat(kFALSE),
+  fNSuperModules(12), fNCellsEta (48), fNCellsPhi(24), fNCellsPhiHalfSM(12)
+{
+  // Default constructor
+}
+
+//-----------------------------------------------------------------------------
+AliEMCALCalibHistoProducer::~AliEMCALCalibHistoProducer()
+{
+  // Destructor
+  if(fHistoFile) {
+    fHistoFile->Close();
+    delete fHistoFile;
+  }
+}
+//-----------------------------------------------------------------------------
+void AliEMCALCalibHistoProducer::Init()
+{
+  // initializes input data stream supplied by rawReader
+  // Checks existence of histograms which might have been left
+  // from the previous runs to continue their filling
+  fHistoFile =  new TFile(fHistoFileName,"update");
+  char hname[128];
+  Int_t nRow =  fNCellsPhi ;
+
+  for(Int_t supermodule=0; supermodule<fNSuperModules; supermodule++) {
+    //Check installed supermodules
+    if(fSMInstalled[supermodule]==kFALSE) continue;
+    //Check created profiles
+    sprintf(hname,"mod%d",supermodule);
+    TProfile* prof = (TProfile*)fHistoFile->Get(hname);
+    if(prof)
+      fAmpProf[supermodule]=prof;
+    
+    //Check created histograms
+    if(supermodule > 10) nRow = fNCellsPhiHalfSM ; //Supermodules 11 and 12 are half supermodules
+    for(Int_t column=0; column<fNCellsEta; column++) {
+      for(Int_t row=0; row<nRow; row++) {
+       sprintf(hname,"mod%dcol%drow%d",supermodule,column,row);
+       TH1F* hist = (TH1F*)fHistoFile->Get(hname);
+       if(hist) 
+         fAmpHisto[supermodule][column][row]=hist;
+      }
+    }
+  }
+  
+}
+//-----------------------------------------------------------------------------
+void AliEMCALCalibHistoProducer::Run()
+{
+  // Reads raw data stream and fills amplitude histograms
+  // The histograms are written to file every fUpdatingRate events
+  //Also fills profiles to study the stability of supermodules during runs.
+
+  Init();
+  
+//   TH1F* gHighGain = 0;
+//   TH1F* gLowGain = 0;
+  Int_t iBin = 0;
+  Int_t iEvent = 0;
+  Int_t runNum = 0;
+  Int_t nProfFreq = 1000; //Number of events with which a bin of the TProfile if filled
+  Int_t nEvtBins = 1000; //Total number of the profile survey bins.
+
+  AliCaloRawStream in(fRawReader,"EMCAL");
+  if(fIsOldRCUFormat)
+    in.SetOldRCUFormat(kTRUE);
+
+  // Read raw data event by event
+
+  while (fRawReader->NextEvent()) {
+    runNum = fRawReader->GetRunNumber();
+    Float_t energy = 0;
+     while ( in.Next() ) { 
+
+      if(fSMInstalled[in.GetModule()]==kFALSE) continue;
+       
+      if (in.GetSignal() > energy) {
+       energy = (Double_t) in.GetSignal();
+      }    
+
+      iBin++;
+
+      if(iBin==in.GetTimeLength()) {
+       iBin=0;
+           
+       Int_t mod = in.GetModule();
+       Int_t col = in.GetColumn();
+       Int_t row = in.GetRow();
+       Int_t evtbin = iEvent/nProfFreq;
+       char hname[128];
+
+       //Check if histogram/profile already exist, if not create it.
+       if(!fAmpHisto[mod][col][row]) {
+         sprintf(hname,"mod%dcol%drow%d",mod,col,row);
+         fAmpHisto[mod][col][row] = new TH1F(hname,hname,1024,-0.5,1023.);
+       }
+       if(!fAmpProf[mod]) {
+         sprintf(hname,"mod%d",mod);
+         fAmpProf[mod] = new TProfile(hname,hname,nEvtBins,0.,nEvtBins);
+       }
+       //Fill histogram/profile 
+       Bool_t lowGainFlag = in.IsLowGain();
+       if(!lowGainFlag) {
+         fAmpHisto[mod][col][row]->Fill(energy);
+         fAmpProf[mod]->Fill(evtbin, energy);
+       }
+      }
+    }
+
+    // update histograms in local file every 100th event
+    if(iEvent%fUpdatingRate == 0) {
+      AliInfo(Form("Updating histo file, event %d, run %d\n",iEvent,runNum));
+      UpdateHistoFile();
+    } 
+    iEvent++;
+  }
+
+  UpdateHistoFile(); 
+  AliInfo(Form("%d events of run %d processed.",iEvent,runNum));
+}
+
+//-----------------------------------------------------------------------------
+void AliEMCALCalibHistoProducer::UpdateHistoFile()
+{
+  // Write histograms to file
+
+  if(!fHistoFile) return;
+  if(!fHistoFile->IsOpen()) return;
+
+  TH1F* hist=0;
+  TProfile* prof =0;
+  Int_t nRow =  fNCellsPhi ;
+  for(Int_t supermodule=0; supermodule<fNSuperModules; supermodule++) {
+    
+    prof = fAmpProf[supermodule]; 
+    if(prof) prof->Write(prof->GetName(),TObject::kWriteDelete);
+    
+    if(supermodule > 10)  nRow = fNCellsPhiHalfSM ; //Supermodules 11 and 12 are half supermodules
+    for(Int_t column=0; column<fNCellsEta; column++) {
+      for(Int_t row=0; row<nRow; row++) {
+       hist = fAmpHisto[supermodule][column][row]; 
+       if(hist) hist->Write(hist->GetName(),TObject::kWriteDelete);
+      }
+    }
+  }
+  
+}
diff --git a/EMCAL/AliEMCALCalibHistoProducer.h b/EMCAL/AliEMCALCalibHistoProducer.h
new file mode 100644 (file)
index 0000000..1c80b02
--- /dev/null
@@ -0,0 +1,62 @@
+#ifndef ALIEMCALCALIBHISTOPRODUCER_H
+#define ALIEMCALCALIBHISTOPRODUCER_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/* $Id$ */
+
+/* History of cvs commits:
+ *
+ * $Log$ 
+ *
+*/
+
+///////////////////////////////////////////////////////////////////////////////
+// Class AliEMCALCalibHistoProducer accumulating histograms
+// with amplitudes per EMCAL channel
+///////////////////////////////////////////////////////////////////////////////
+
+#include "TObject.h"
+
+class TProfile;
+class TString;
+class TH1F;
+class TFile;
+class AliRawReader;
+
+class AliEMCALCalibHistoProducer : public TObject {
+public:
+
+  AliEMCALCalibHistoProducer();
+  AliEMCALCalibHistoProducer(AliRawReader* rawReader);
+  AliEMCALCalibHistoProducer(const AliEMCALCalibHistoProducer &histoproducer);
+  AliEMCALCalibHistoProducer& operator= (const AliEMCALCalibHistoProducer &histoproducer);
+  virtual ~AliEMCALCalibHistoProducer();
+
+  void Init();
+  void Run();
+  void UpdateHistoFile();
+  void SetUpdatingRate(const Int_t rate) {fUpdatingRate = rate;}
+  void SetOldRCUFormat(Bool_t isOldRCUFormat) { fIsOldRCUFormat = isOldRCUFormat; }
+  void SetCalibHistoFileName(const Int_t name) {fHistoFileName = name;}
+  void SetSMInstalled(const Int_t nsm, Bool_t bsm) {fSMInstalled[nsm] = bsm;}
+
+protected:
+
+  TH1F* fAmpHisto[12][48][24]; // amplitudes in [module][column][row].
+  TProfile *fAmpProf[12]; // one per SuperModule
+  AliRawReader* fRawReader;   // raw data reader.
+  TFile* fHistoFile;          // root file to store histograms in
+  TString fHistoFileName;          // name of root file to store histograms in
+  Int_t fUpdatingRate;        // update rate
+  Bool_t fIsOldRCUFormat;     // Old RCU format flag.
+  Int_t fNSuperModules;          //Number of SuperModules;
+  Int_t fNCellsEta;                  //Number of Cells in Eta in a SuperModule;
+  Int_t fNCellsPhi;                   //Number of Cells in Phi in a SuperModule;
+  Int_t fNCellsPhiHalfSM;      //Number of Cells in Phi in a Half SuperModule;
+  Bool_t fSMInstalled[12];  //Check which detectors are on.
+  ClassDef(AliEMCALCalibHistoProducer,1)
+
+};
+
+#endif
diff --git a/EMCAL/AliEMCALPreprocessor.cxx b/EMCAL/AliEMCALPreprocessor.cxx
new file mode 100644 (file)
index 0000000..ec25117
--- /dev/null
@@ -0,0 +1,128 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+/* $Id$ */
+/* History of cvs commits:
+ *
+ * $Log$ 
+ *
+*/
+///////////////////////////////////////////////////////////////////////////////
+// EMCAL Preprocessor class. It runs by Shuttle at the end of the run,
+// calculates calibration coefficients and dead/bad channels
+// to be posted in OCDB
+//
+// Author: Boris Polichtchouk, 4 October 2006
+// Adapted for EMCAL by Gustavo Conesa Balbastre, October 2006
+///////////////////////////////////////////////////////////////////////////////
+
+#include "AliEMCALPreprocessor.h"
+#include "AliLog.h"
+#include "AliCDBMetaData.h"
+#include "AliEMCALCalibData.h"
+#include "TFile.h"
+#include "TH1.h"
+#include "TMap.h"
+#include "TRandom.h"
+
+ClassImp(AliEMCALPreprocessor)
+
+//_______________________________________________________________________________________
+AliEMCALPreprocessor::AliEMCALPreprocessor() :
+AliPreprocessor("EMCAL",0)
+{
+  //default constructor
+}
+
+//_______________________________________________________________________________________
+AliEMCALPreprocessor::AliEMCALPreprocessor(const char* detector, AliShuttleInterface* shuttle):
+AliPreprocessor(detector,shuttle)
+{
+  // Constructor
+}
+
+//_______________________________________________________________________________________
+UInt_t AliEMCALPreprocessor::Process(TMap* /*valueSet*/)
+{
+  // process data retrieved by the Shuttle
+
+  // The fileName with the histograms which have been produced by
+  // AliEMCALCalibHistoProducer.
+  // It is a responsibility of the SHUTTLE framework to form the fileName
+
+  const char* fileName = GetFile(kDAQ, "AMPLITUDES", "GDC");
+  AliInfo(Form("Got filename: %s",fileName));
+
+  TFile f(fileName);
+
+  if(!f.IsOpen()) {
+    AliInfo(Form("File %s is not opened, something goes wrong!",fileName));
+    return 0;
+  }
+
+  const Int_t nMod=12; // 1:5 modules
+  const Int_t nCol=48; //1:56 columns in each module
+  Int_t nRow=24; //1:64 rows in each module
+  const Int_t nRowHalfSM = 12; //Supermodules 11 and 12 are half supermodules
+
+  Double_t coeff;
+  char hnam[80];
+  TH1F* histo=0;
+
+  // Generate name of the reference histogram
+  TString refHistoName = "mod";
+  refHistoName += gRandom->Integer(nMod)+1;
+  refHistoName += "col";
+  refHistoName += gRandom->Integer(nCol)+1;
+  refHistoName += "row";
+  refHistoName += gRandom->Integer(nRow)+1;
+  TH1F* hRef = (TH1F*)f.Get(refHistoName);
+
+  // If the reference histogram does not exist or has too little statistics,
+  // it is better to give up preprocessing
+  if(!hRef || hRef->GetEntries()<2) {
+    AliInfo(Form("Cannot get reference histogram %s",refHistoName.Data()));
+    return 0;
+  }
+
+  AliEMCALCalibData calibData;
+  Double_t refMean=hRef->GetMean();
+  // Calculates relative calibration coefficients for all non-zero channels
+
+  for(Int_t mod=0; mod<nMod; mod++) {
+   if(mod > 10) nRow = nRowHalfSM ;
+    for(Int_t col=0; col<nCol; col++) {
+      for(Int_t row=0; row<nRow; row++) {
+        sprintf(hnam,"mod%dcol%drow%d",mod,col,row);
+        histo = (TH1F*)f.Get(hnam);
+       //TODO: dead channels exclusion!
+        if(histo) {
+          coeff = histo->GetMean()/refMean;
+         calibData.SetADCchannel(mod+1,col+1,row+1,1./coeff);
+         AliInfo(Form("mod %d col %d row %d  coeff %f\n",mod,col,row,coeff));
+       }
+        else
+          calibData.SetADCchannel(mod+1,col+1,row+1,-111); 
+      }
+    }
+  }
+
+  AliCDBMetaData metaData;
+  Int_t result = Store("Calib", "Data", &calibData, &metaData);
+
+  f.Close();
+  return result;
+
+}
diff --git a/EMCAL/AliEMCALPreprocessor.h b/EMCAL/AliEMCALPreprocessor.h
new file mode 100644 (file)
index 0000000..a133b4a
--- /dev/null
@@ -0,0 +1,33 @@
+#ifndef ALIEMCALPREPROCESSOR_H
+#define ALIEMCALPREPROCESSOR_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/* $Id$ */
+/* History of cvs commits:
+ *
+ * $Log$
+ *
+ */
+///////////////////////////////////////////////////////////////////////////////
+// Class AliEMCALPreprocessor
+///////////////////////////////////////////////////////////////////////////////
+
+
+#include "AliPreprocessor.h"
+
+class AliEMCALPreprocessor : public AliPreprocessor {
+public:
+
+  AliEMCALPreprocessor();
+  AliEMCALPreprocessor(const char* detector, AliShuttleInterface* shuttle);
+
+protected:
+
+  virtual UInt_t Process(TMap* valueSet);
+
+  ClassDef(AliEMCALPreprocessor,0);
+
+};
+
+#endif
diff --git a/EMCAL/EMCALLinkDefshuttle.h b/EMCAL/EMCALLinkDefshuttle.h
new file mode 100644 (file)
index 0000000..33ec171
--- /dev/null
@@ -0,0 +1,10 @@
+#ifdef __CINT__
+#pragma link off all globals;
+#pragma link off all classes;
+#pragma link off all functions;
+
+#pragma link C++ class AliEMCALCalibHistoProducer+;
+#pragma link C++ class AliEMCALPreprocessor+;
+
+#endif
diff --git a/EMCAL/libEMCALshuttle.pkg b/EMCAL/libEMCALshuttle.pkg
new file mode 100644 (file)
index 0000000..7330c4c
--- /dev/null
@@ -0,0 +1,8 @@
+SRCS          =  AliEMCALCalibHistoProducer.cxx \
+                 AliEMCALPreprocessor.cxx
+
+HDRS:= $(SRCS:.cxx=.h) 
+
+DHDR= EMCALLinkDefshuttle.h
+
+EINCLUDE:=RAW