Unused DAs removed.
[u/mrichter/AliRoot.git] / PHOS / AliPHOSCalibHistoProducer.cxx
index a439687..5c2a2b0 100644 (file)
 #include "AliLog.h"
 #include "AliPHOSCalibHistoProducer.h"
 #include "TH1.h"
+#include "TH2F.h"
 #include "TFile.h"
+#include "AliPHOSRawDecoder.h"
 #include "AliRawReader.h"
-#include "AliCaloRawStream.h"
 
 ClassImp(AliPHOSCalibHistoProducer)
 
 //-----------------------------------------------------------------------------
-AliPHOSCalibHistoProducer::AliPHOSCalibHistoProducer(AliRawReader* rawReader) : 
-  fRawReader(rawReader),fHistoFile(0),fUpdatingRate(100),fIsOldRCUFormat(kFALSE)
+AliPHOSCalibHistoProducer::AliPHOSCalibHistoProducer() : 
+  fRawDecoder(0),fHistoFile(0),fUpdatingRate(100),
+  fEvents(0),fNbins(100),fXlow(0.),fXup(1000.)
 {
-  // Constructor: initializes input data stream supplied by rawReader
+  // Constructor: initializes data members
   // Checks existence of histograms which might have been left
   // from the previous runs to continues their filling
 
   fHistoFile =  new TFile("calibHisto.root","update");
-
+  
   for(Int_t module=0; module<5; module++) {
     for(Int_t column=0; column<56; column++) {
       for(Int_t row=0; row<64; row++) {
@@ -52,117 +54,151 @@ AliPHOSCalibHistoProducer::AliPHOSCalibHistoProducer(AliRawReader* rawReader) :
        TH1F* hist = (TH1F*)fHistoFile->Get(hname);
        if(hist) 
          fAmpHisto[module][column][row]=hist;
-       else
-         fAmpHisto[module][column][row]=0;
+       else 
+         fAmpHisto[module][column][row] = 0;     
       }
     }
   }
 }
 
-//-----------------------------------------------------------------------------
-AliPHOSCalibHistoProducer::AliPHOSCalibHistoProducer() :
-  fRawReader(0),fHistoFile(0),fUpdatingRate(0),fIsOldRCUFormat(kFALSE)
+//-----------------------------------------------------------------------------            
+AliPHOSCalibHistoProducer::AliPHOSCalibHistoProducer(Int_t nbinsx, Double_t xlow, Double_t xup) :
+  fRawDecoder(0),fHistoFile(0),fUpdatingRate(100),
+  fEvents(0),fNbins(nbinsx),fXlow(xlow),fXup(xup)
 {
-  // Default constructor
+  // Constructor: initializes data members.
+  // Checks existence of histograms which might have been left
+  // from the previous runs to continues their filling.
+  // In addition sets number of bins, low and upper limits common for all histograms.
+
+  fHistoFile =  new TFile("calibHisto.root","update");
+
+  for(Int_t module=0; module<5; module++) {
+    for(Int_t column=0; column<56; column++) {
+      for(Int_t row=0; row<64; row++) {
+        char hname[128];
+        sprintf(hname,"mod%dcol%drow%d",module,column,row);
+        TH1F* hist = (TH1F*)fHistoFile->Get(hname);
+        if(hist)
+          fAmpHisto[module][column][row]=hist;
+        else
+          fAmpHisto[module][column][row] = 0;
+      }
+    }
+  }
 }
 
 //-----------------------------------------------------------------------------
 AliPHOSCalibHistoProducer::~AliPHOSCalibHistoProducer()
 {
   // Destructor
+  
+  UpdateHistoFile();
   if(fHistoFile) delete fHistoFile;
+
 }
 
 //-----------------------------------------------------------------------------
-void AliPHOSCalibHistoProducer::Run()
+AliPHOSCalibHistoProducer::AliPHOSCalibHistoProducer(const AliPHOSCalibHistoProducer &histoproducer) :
+  TObject(histoproducer),fRawDecoder(histoproducer.fRawDecoder),fHistoFile(histoproducer.fHistoFile),
+  fUpdatingRate(histoproducer.fUpdatingRate),
+  fEvents(histoproducer.fEvents),fNbins(histoproducer.fNbins),fXlow(histoproducer.fXlow),fXup(histoproducer.fXup)
 {
-  // Reads raw data stream and fills amplitude histograms
-  // The histograms are written to file every fUpdatingRate events
+  //Copy constructor.
 
-  TH1F* gHighGain = 0;
-  TH1F* gLowGain = 0;
-  Int_t iBin = 0;
-  Int_t iEvent = 0;
-  Int_t runNum = 0;
-
-  AliCaloRawStream in(fRawReader,"PHOS");
-  if(fIsOldRCUFormat)
-    in.SetOldRCUFormat(kTRUE);
-
-  // Read raw data event by event
-
-  while (fRawReader->NextEvent()) {
-    runNum = fRawReader->GetRunNumber();
-
-    while ( in.Next() ) { 
-       
-      if(!gHighGain) gHighGain = new TH1F("gHighGain","High gain",
-                                         in.GetTimeLength(),0,in.GetTimeLength());
-      else
-       if(gHighGain->GetNbinsX() != in.GetTimeLength()) {
-         delete gHighGain;
-         gHighGain = new TH1F("gHighGain","High gain",in.GetTimeLength(),0,in.GetTimeLength());
-       }
+  for(Int_t module=0; module<5; module++) {
+    for(Int_t column=0; column<56; column++) {
+      for(Int_t row=0; row<64; row++) {
+       char hname[128];
+       sprintf(hname,"mod%dcol%drow%d",module,column,row);
+       TH1F* hist = (TH1F*)histoproducer.fHistoFile->Get(hname);
+       if(hist) 
+         fAmpHisto[module][column][row]= new TH1F(*hist);
+       else
+         fAmpHisto[module][column][row]=0;
+      }
+    }
+  }
+}
 
-      if(!gLowGain)  gLowGain = new TH1F("gLowGain","Low gain",
-                                        in.GetTimeLength(),0,in.GetTimeLength());
-      else
-       if(gLowGain->GetNbinsX() != in.GetTimeLength()) {
-         delete gLowGain;
-         gLowGain = new TH1F("gLowGain","Low gain",in.GetTimeLength(),0,in.GetTimeLength());
+//-----------------------------------------------------------------------------
+AliPHOSCalibHistoProducer& AliPHOSCalibHistoProducer::operator= 
+(const AliPHOSCalibHistoProducer &histoproducer)
+{
+  //Assignment operator.
+
+  if(this != &histoproducer) {
+
+    fRawDecoder = histoproducer.fRawDecoder;
+    fHistoFile = histoproducer.fHistoFile;
+    fUpdatingRate = histoproducer.fUpdatingRate;
+    fEvents = histoproducer.fEvents;
+    fEvents = histoproducer.fEvents;
+    fNbins = histoproducer.fNbins;
+    fXlow = histoproducer.fXlow;
+    fXup = histoproducer.fXup;   
+    
+    for(Int_t module=0; module<5; module++) {
+      for(Int_t column=0; column<56; column++) {
+       for(Int_t row=0; row<64; row++) {
+         if(fAmpHisto[module][column][row]){
+           delete fAmpHisto[module][column][row];
+           fAmpHisto[module][column][row] = histoproducer.fAmpHisto[module][column][row];
+         }
+         else
+         fAmpHisto[module][column][row] = histoproducer.fAmpHisto[module][column][row];
        }
-
-      Bool_t lowGainFlag = in.IsLowGain();
-      
-      if(lowGainFlag) 
-       gLowGain->SetBinContent(in.GetTimeLength()-iBin-1,in.GetSignal());
-      else {
-       gHighGain->SetBinContent(in.GetTimeLength()-iBin-1,in.GetSignal());
       }
+    }
 
-      iBin++;
-
-      if(iBin==in.GetTimeLength()) {
-       iBin=0;
-
-       Double_t energy;
 
-       if(!lowGainFlag) {
-         energy = gHighGain->GetMaximum(); // no pedestal subtraction!
-       }
-       else {
-         energy = gLowGain->GetMaximum(); // no pedestal subtraction!
-       }
-           
-       Int_t mod = in.GetModule();
-       Int_t col = in.GetColumn();
-       Int_t row = in.GetRow();
-
-       if(fAmpHisto[mod][col][row]) {
-         if(!lowGainFlag) {
-           fAmpHisto[mod][col][row]->Fill(energy);
-         }
-       }
-       else {
-         char hname[128];
-         sprintf(hname,"mod%dcol%drow%d",mod,col,row);
-         fAmpHisto[mod][col][row] = new TH1F(hname,hname,100,0.,1000.);
-       }
+  }
 
+  return *this;
+}
+//-----------------------------------------------------------------------------
+void AliPHOSCalibHistoProducer::Run()
+{
+  // Reads raw data of current event and fills amplitude histograms
+  // The histograms are written to file every fUpdatingRate events
 
-      }
+  if(!fRawDecoder) AliFatal("Raw decoder not set!");
+  
+  Double_t energy;
+  Int_t mod,col,row;
+  
+  while(fRawDecoder->NextDigit()) {
+    
+    if(fRawDecoder->IsLowGain()) continue; 
+
+    energy = fRawDecoder->GetEnergy();
+    
+    mod = fRawDecoder->GetModule()-1;
+    col = fRawDecoder->GetColumn()-1;
+    row = fRawDecoder->GetRow()-1;
+    
+    if(fAmpHisto[mod][col][row]) {
+      fAmpHisto[mod][col][row]->Fill(energy);
     }
-
+    else {
+      char hname[128];
+      sprintf(hname,"mod%dcol%drow%d",mod,col,row);
+      fAmpHisto[mod][col][row] = new TH1F(hname,hname,fNbins,fXlow,fXup);
+      fAmpHisto[mod][col][row]->Fill(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));
+    if(fEvents != 0 && fEvents%fUpdatingRate == 0) {
+      AliInfo(Form("Updating histo file, event %d, run %d\n",
+                  fEvents,fRawDecoder->GetRawReader()->GetRunNumber()));
       UpdateHistoFile();
-    } 
-    iEvent++;
-  }
-
-  UpdateHistoFile(); 
-  AliInfo(Form("%d events of run %d processed.",iEvent,runNum));
+    }
+    
+    //   UpdateHistoFile();
+    //   AliInfo(Form("%d events of run %d processed.",iEvent,runNum));
+  
+  fEvents++;
+  
 }
 
 //-----------------------------------------------------------------------------
@@ -174,14 +210,22 @@ void AliPHOSCalibHistoProducer::UpdateHistoFile()
   if(!fHistoFile->IsOpen()) return;
 
   TH1F* hist=0;
+  char hname[128];
+  char htitle[128];
 
   for(Int_t module=0; module<5; module++) {
+    sprintf(hname,"hMeanE%d",module);
+    sprintf(htitle,"Mean energies in module %d",module);
+    TH2F hMeanE(hname,htitle,56,0.,56.,64,0.,64);
+
     for(Int_t column=0; column<56; column++) {
       for(Int_t row=0; row<64; row++) {
        hist = fAmpHisto[module][column][row]; 
        if(hist) hist->Write(hist->GetName(),TObject::kWriteDelete);
+       if(hist) hMeanE.SetBinContent(column,row,hist->GetMean());
       }
     }
+    hMeanE.Write(hMeanE.GetName(),TObject::kWriteDelete);
   }
 
 }