]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - FMD/AliFMDPedestalDA.cxx
Fixed the DA so it picks up the pedestals from the right sample
[u/mrichter/AliRoot.git] / FMD / AliFMDPedestalDA.cxx
index a6b6e2cb7db098d72a28daba978ecab0a89c2451..bb84b771e5b1fcd4cf9779fa9c80ccd10196ce17 100644 (file)
     @brief   Derived class for the pedestal detector algorithm.
 */
 //
-// This class implements the virtual functions of the AliFMDBaseDA class.
-// The most important of these functions, FillChannels(..) and Analyse(...) collect 
-// and analyse the data of each channel. The resulting pedestal and noise values are
-// written to a comma separated values (csv) file on the go. The csv files produced 
-// in this way are the basic input to the AliFMDPreprocessor.
+// This class implements the virtual functions of the AliFMDBaseDA
+// class.  The most important of these functions, FillChannels(..) and
+// Analyse(...) collect and analyse the data of each channel. The
+// resulting pedestal and noise values are written to a comma
+// separated values (csv) file on the go. The csv files produced in
+// this way are the basic input to the AliFMDPreprocessor.
 //
 
 #include "AliFMDPedestalDA.h"
 #include "fstream"
 #include "AliLog.h"
 #include "TF1.h"
+#include "TObject.h"
+#include "TMath.h"
 
 //_____________________________________________________________________
 ClassImp(AliFMDPedestalDA)
 
 //_____________________________________________________________________
-AliFMDPedestalDA::AliFMDPedestalDA() : AliFMDBaseDA()
+AliFMDPedestalDA::AliFMDPedestalDA() : AliFMDBaseDA(),
+  fCurrentChannel(1),
+  fPedSummary("PedestalSummary","pedestals",51200,0,51200),
+  fNoiseSummary("NoiseSummary","noise",51200,0,51200),
+  fZSfileFMD1(),
+  fZSfileFMD2(),
+  fZSfileFMD3()
 {
   fOutputFile.open("peds.csv");
-  
+  fZSfileFMD1.open("ddl3072.csv");
+  fZSfileFMD2.open("ddl3073.csv");
+  fZSfileFMD3.open("ddl3074.csv");  
 }
 
 //_____________________________________________________________________
 AliFMDPedestalDA::AliFMDPedestalDA(const AliFMDPedestalDA & pedDA) : 
-  AliFMDBaseDA(pedDA)
+  AliFMDBaseDA(pedDA),
+  fCurrentChannel(1),
+  fPedSummary("PedestalSummary","pedestals",51200,0,51200),
+  fNoiseSummary("NoiseSummary","noise",51200,0,51200),
+  fZSfileFMD1(),
+  fZSfileFMD2(),
+  fZSfileFMD3()
 {
   
 }
 
 //_____________________________________________________________________
-AliFMDPedestalDA::~AliFMDPedestalDA() {
+AliFMDPedestalDA::~AliFMDPedestalDA() 
+{ 
 }
 
 //_____________________________________________________________________
-void AliFMDPedestalDA::Init() {
+void AliFMDPedestalDA::Init() 
+{ 
   SetRequiredEvents(1000);
+  
 }
 
 //_____________________________________________________________________
 void AliFMDPedestalDA::AddChannelContainer(TObjArray* sectorArray, 
                                           UShort_t det, 
-                                          Char_t ring, 
+                                          Char_t   ring, 
                                           UShort_t sec, 
-                                          UShort_t strip) {
-
-  TH1S* hChannel = new TH1S(Form("hFMD%d%c_%d_%d",det,ring,sec,strip),
-                           Form("hFMD%d%c_%d_%d",det,ring,sec,strip),
-                           1024,0,1023);
+                                          UShort_t strip) 
+{
+  AliFMDParameters* pars        = AliFMDParameters::Instance();
+  UInt_t             samples     = pars->GetSampleRate(det, ring, sec, strip);
+  TObjArray*        sampleArray = new TObjArray(samples);
+  sampleArray->SetOwner();
+  for (UInt_t sample = 0; sample < samples; sample++) {
+    TH1S* hSample = new TH1S(Form("FMD%d%c[%02d,03%d]_%d",
+                                 det,ring,sec,strip,sample),
+                            Form("FMD%d%c[%02d,%03%d]_%d",
+                                 det,ring,sec,strip),
+                            1024,-.5,1023.5);
+    hSample->SetXTitle("ADC");
+    hSample->SetYTitle("Events");
+    hSample->SetDirectory(0);
+    sampleArray->AddAt(hSample, sample);
+  }
+  sectorArray->AddAtAndExpand(sampleArray, strip);
   
-  hChannel->SetDirectory(0);
-  sectorArray->AddAtAndExpand(hChannel,strip);
+
 }
 
 //_____________________________________________________________________
-void AliFMDPedestalDA::FillChannels(AliFMDDigit* digit) {
+void AliFMDPedestalDA::FillChannels(AliFMDDigit* digit) 
+{
   UShort_t det   = digit->Detector();
   Char_t   ring  = digit->Ring();
   UShort_t sec   = digit->Sector();
   UShort_t strip = digit->Strip();
-    
-  TH1S* hChannel       = GetChannel(det, ring, sec, strip);
-  hChannel->Fill(digit->Counts());
+  
+  AliFMDParameters* pars     = AliFMDParameters::Instance();
+  UInt_t             samples  = pars->GetSampleRate(det, ring, sec, strip);
+  for (UInt_t sample = 0; sample < samples; sample++) {
+    TH1S* hSample = GetChannel(det, ring, sec, strip, sample);
+    hSample->Fill(digit->Count(sample));
+  }
   
 }
 
 //_____________________________________________________________________
 void AliFMDPedestalDA::Analyse(UShort_t det, 
-                              Char_t ring, 
+                              Char_t   ring, 
                               UShort_t sec, 
                               UShort_t strip) {
-
-  TH1S* hChannel       = GetChannel(det, ring, sec, strip);
-  if(hChannel->GetEntries() == 0) {
-    //  AliWarning(Form("No entries for FMD%d%c, sector %d, strip %d",det,ring,sec,strip));
-    return;
-  }
-  
-  //std::cout<<"Fitting Channel #"<<Form("FMD%d%c_%d_%d",det,ring,sec,strip)<<" with "<<hChannel->GetEntries()<<" entries     \r"<<std::flush;
-  
-  Float_t mean = hChannel->GetMean();
-  Float_t rms  = hChannel->GetRMS();
-  
-  hChannel->GetXaxis()->SetRangeUser(mean-4*rms,mean+4*rms);
   
-  mean = hChannel->GetMean();
-  rms  = hChannel->GetRMS();
+  AliFMDParameters* pars     = AliFMDParameters::Instance();
+  UInt_t             samples  = pars->GetSampleRate(det, ring, sec, strip);
+  for (UShort_t sample = 0; sample < samples; sample++) {
   
-  hChannel->Fit("gaus","QO","QO",mean-5*rms,mean+5*rms);
-  TF1* fitFunc = hChannel->GetFunction("gaus");
+    TH1S* hChannel       = GetChannel(det, ring, sec, strip,sample);
+    if(hChannel->GetEntries() == 0) {
+      //AliWarning(Form("No entries for FMD%d%c, sector %d, strip %d",
+      //           det,ring,sec,strip));
+      return;
+    }
     
-  UInt_t ddl, board, chip, channel;
-  
-  UShort_t relStrip = strip%128;
-  AliFMDParameters* pars = AliFMDParameters::Instance();
-  pars->Detector2Hardware(det,ring,sec,strip,ddl,board,chip,channel);
-  Float_t chi2ndf = 0;
-  if(fitFunc->GetNDF())
-    chi2ndf = fitFunc->GetChisquare() / fitFunc->GetNDF();
-  ddl = ddl + kBaseDDL;
-  
-  fOutputFile << ddl                         << ','
-             << board                       << ','
-             << chip                        << ','
-             << channel                     << ','
-             << relStrip                    << ','
-             << 0                           << ','
-             << 0                           << ','
-             << mean                        << ','
-             << rms                         << ','
-             << fitFunc->GetParameter(1)    << ','
-             << fitFunc->GetParameter(2)    << ','
-             << chi2ndf                     <<"\n";
+    AliDebug(50, Form("Fitting FMD%d%c_%d_%d with %d entries",det,ring,sec,strip,
+                     hChannel->GetEntries()));
+    TF1 fitFunc("fitFunc","gausn",0,300);
+    fitFunc.SetParameters(100,100,1);
+    hChannel->Fit("fitFunc","Q0+","",10,200);
+    
+    Float_t mean = hChannel->GetMean();
+    Float_t rms  = hChannel->GetRMS();
+    
+    
+    
+    hChannel->GetXaxis()->SetRangeUser(mean-5*rms,mean+5*rms);
+    
+    mean = hChannel->GetMean();
+    rms  = hChannel->GetRMS();
   
+    
+    UShort_t ddl, board, altro, channel;
+    UShort_t timebin;
+    
+    pars->Detector2Hardware(det,ring,sec,strip,sample,ddl,board,altro,channel,timebin);
+    
+    switch(det) {
+    case 1:
+      fZSfileFMD1 << board << ',' << altro << ',' << channel << ',' << timebin << ','
+                 << mean  << ',' << rms << "\n"; break;
+    case 2:
+      fZSfileFMD2 << board << ',' << altro << ',' << channel << ',' << timebin << ','
+                 << mean  << ',' << rms << "\n"; break;
+    case 3:
+      fZSfileFMD3 << board << ',' << altro << ',' << channel << ',' << timebin << ','
+                 << mean  << ',' << rms << "\n"; break;
+    default:
+      AliWarning("Unknown sample!"); break;
+      
+    }
+    
+    Float_t chi2ndf = 0;
+    
+    
+    if(fitFunc.GetNDF())
+      chi2ndf = fitFunc.GetChisquare() / fitFunc.GetNDF();
+    
+    Int_t sampleToWrite = 2;
+    
+    if(pars->GetSampleRate(det,ring,sec,strip)==2)
+      sampleToWrite = 1;
+    
+    if(pars->GetSampleRate(det,ring,sec,strip)<2)
+      sampleToWrite = 0;
+    
+    if(sample==sampleToWrite) {
+    
+      fOutputFile << det                         << ','
+                 << ring                        << ','
+                 << sec                         << ','
+                 << strip                       << ','
+                 << mean                        << ','
+                 << rms                         << ','
+                 << fitFunc.GetParameter(1)     << ','
+                 << fitFunc.GetParameter(2)     << ','
+                 << chi2ndf                     <<"\n";
+      
+      if(fSaveHistograms  ) {
+       gDirectory->cd(GetSectorPath(det, ring, sec, kTRUE));
+       TH1F* sumPed   = dynamic_cast<TH1F*>(gDirectory->Get("Pedestals"));
+       TH1F* sumNoise = dynamic_cast<TH1F*>(gDirectory->Get("Noise"));
+       Int_t nStr = (ring == 'I' ? 512 : 256);
+       if (!sumPed) {
+         sumPed = new TH1F("Pedestals", 
+                           Form("Summary of pedestals in FMD%d%c[%02d]", 
+                                det, ring, sec), 
+                           nStr, -.5, nStr-.5);
+         sumPed->SetXTitle("Strip");
+         sumPed->SetYTitle("Pedestal [ADC]");
+         sumPed->SetDirectory(gDirectory);
+       }
+       if (!sumNoise) { 
+         sumNoise = new TH1F("Noise", 
+                             Form("Summary of noise in FMD%d%c[%02d]", 
+                                  det, ring, sec), 
+                             nStr, -.5, nStr-.5);
+         sumNoise->SetXTitle("Strip");
+         sumNoise->SetYTitle("Noise [ADC]");
+         
+         sumNoise->SetDirectory(gDirectory);
+       }
+       sumPed->SetBinContent(strip+1, mean);
+       sumPed->SetBinError(strip+1, rms);
+       sumNoise->SetBinContent(strip+1, rms);
+      
+       if(sumNoise->GetEntries() == nStr)
+         sumNoise->Write(sumNoise->GetName(),TObject::kOverwrite);
+       if(sumPed->GetEntries() == nStr)
+         sumPed->Write(sumPed->GetName(),TObject::kOverwrite);
+       
+       fPedSummary.SetBinContent(fCurrentChannel,mean);
+       
+       fNoiseSummary.SetBinContent(fCurrentChannel,rms);
+       fCurrentChannel++;
+       
+       gDirectory->cd(GetStripPath(det, ring, sec, strip, kTRUE));
+       hChannel->GetXaxis()->SetRange(1,1024);
+       
+       hChannel->Write();
+      }
+    }
+  }
+}
+
+//_____________________________________________________________________
+void AliFMDPedestalDA::Terminate(TFile* diagFile) 
+{
   if(fSaveHistograms) {
-    gDirectory->cd(Form("%s:FMD%d%c/sector_%d/strip_%d",fDiagnosticsFilename.Data(),det,ring,sec,strip));
-    hChannel->GetXaxis()->SetRange(0,1023);
-    hChannel->Write();
+    diagFile->cd();
     
+    fPedSummary.Write();
+    fNoiseSummary.Write();
   }
   
+  if(fZSfileFMD1.is_open()) { 
+    fZSfileFMD1.write("# EOF\n",6);
+    fZSfileFMD1.close();  }
+  if(fZSfileFMD2.is_open()) {
+    fZSfileFMD2.write("# EOF\n",6);
+    fZSfileFMD2.close(); }
+  if(fZSfileFMD3.is_open()) {
+    fZSfileFMD3.write("# EOF\n",6);
+    fZSfileFMD3.close(); }
+  
 }
 
 //_____________________________________________________________________
-void AliFMDPedestalDA::WriteHeaderToFile() {
+void AliFMDPedestalDA::WriteHeaderToFile() 
+{
   AliFMDParameters* pars       = AliFMDParameters::Instance();
   fOutputFile.write(Form("# %s \n",pars->GetPedestalShuttleID()),13);
-  fOutputFile.write("# Rcu, Board, Chip, Channel, Strip, Sample, TimeBin, Pedestal, Noise, Mu, Sigma, Chi2/NDF \n",91);
+  fOutputFile.write("# Detector, "
+                   "Ring, "
+                   "Sector, "
+                   "Strip, "
+                   "Pedestal, "
+                   "Noise, "
+                   "Mu, "
+                   "Sigma, "
+                   "Chi2/NDF \n", 71);
+  fZSfileFMD1.write("# FMD 1 pedestals \n",19);
+  fZSfileFMD1.write("# board, "
+                   "altro, "
+                   "channel, "
+                   "timebin, "
+                   "pedestal, "
+                   "noise \n", 51);
+  fZSfileFMD2.write("# FMD 2 pedestals \n",19);
+  fZSfileFMD2.write("# board, "
+                   "altro, "
+                   "channel, "
+                   "timebin, "
+                   "pedestal, "
+                   "noise \n", 51);
+  fZSfileFMD3.write("# FMD 3 pedestals \n",19);
+  fZSfileFMD3.write("# board, "
+                   "altro, "
+                   "channel, "
+                   "timebin, "
+                   "pedestal, "
+                   "noise \n", 51);
   
 }
 
 //_____________________________________________________________________
-TH1S* AliFMDPedestalDA::GetChannel(UShort_t det, Char_t ring, UShort_t sec, UShort_t strip) {
-  
-  UShort_t  Ring = 1;
-  if(ring == 'O')
-    Ring = 0;
-  
-  
+TH1S* AliFMDPedestalDA::GetChannel(UShort_t det, 
+                                  Char_t   ring, 
+                                  UShort_t sec, 
+                                  UShort_t strip,
+                                  UInt_t    sample) 
+{
+  UShort_t   iring     = (ring == 'O' ? 0 : 1);
   TObjArray* detArray  = static_cast<TObjArray*>(fDetectorArray.At(det));
-  TObjArray* ringArray = static_cast<TObjArray*>(detArray->At(Ring));
+  TObjArray* ringArray = static_cast<TObjArray*>(detArray->At(iring));
   TObjArray* secArray  = static_cast<TObjArray*>(ringArray->At(sec));
-  TH1S* hChannel       = static_cast<TH1S*>(secArray->At(strip));
+  TObjArray*        sampleArray = static_cast<TObjArray*>(secArray->At(strip));
+  TH1S*      hSample = static_cast<TH1S*>(sampleArray->At(sample));
+  return hSample;
   
-  return hChannel;
 }
+
 //_____________________________________________________________________
 //
 //EOF