]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - FMD/AliFMDGainDA.cxx
a macro with TPC,ITS, ITSSPD vertex, global vertex and v0's
[u/mrichter/AliRoot.git] / FMD / AliFMDGainDA.cxx
index d92b32f2e588bd45f1765eb26632a40d3182668b..f24161e2a2005796cafb5b98714d72a769c7a252 100644 (file)
@@ -37,6 +37,7 @@
 #include "TMath.h"
 #include "TGraphErrors.h"
 #include "AliFMDParameters.h"
+#include "AliFMDAltroMapping.h"
 
 //_____________________________________________________________________
 ClassImp(AliFMDGainDA)
@@ -48,13 +49,13 @@ ClassImp(AliFMDGainDA)
 AliFMDGainDA::AliFMDGainDA() 
   : AliFMDBaseDA(),
     fGainArray(),
-    //fPulseSize(32),
     fHighPulse(256), 
-    //fPulseLength(100),
-    fEventsPerChannel(16),
-    fCurrentPulse(16),
-    fCurrentChannel(16),
-    fNumberOfStripsPerChip(128)
+    fEventsPerChannel(10),
+    fCurrentPulse(10),
+    fCurrentChannel(10),
+    fNumberOfStripsPerChip(128),
+    fSummaryGains("GainsSummary","Summary of gains",51200,0,51200),
+    fCurrentSummaryStrip(1)
 {
   fCurrentPulse.Reset(0);
   fCurrentChannel.Reset(0);
@@ -66,13 +67,13 @@ AliFMDGainDA::AliFMDGainDA()
 AliFMDGainDA::AliFMDGainDA(const AliFMDGainDA & gainDA) 
   :  AliFMDBaseDA(gainDA),
      fGainArray(gainDA.fGainArray),
-     //fPulseSize(gainDA.fPulseSize),
      fHighPulse(gainDA.fHighPulse),
-     //fPulseLength(gainDA.fPulseLength),
      fEventsPerChannel(gainDA.fEventsPerChannel),
      fCurrentPulse(gainDA.fCurrentPulse),
      fCurrentChannel(gainDA.fCurrentChannel),
-     fNumberOfStripsPerChip(gainDA.fNumberOfStripsPerChip)
+     fNumberOfStripsPerChip(gainDA.fNumberOfStripsPerChip),
+     fSummaryGains(gainDA.fSummaryGains),
+     fCurrentSummaryStrip(gainDA.fCurrentSummaryStrip)
 {  
   fCurrentPulse.Reset(0);
   fCurrentChannel.Reset(0);
@@ -89,19 +90,31 @@ void AliFMDGainDA::Init()
   
  
   Int_t nEventsRequired = 0;
-  for(Int_t i=0;i<fEventsPerChannel.GetSize();i++)
+  
+  //for(UShort_t det=1; det<=3;det++) {
+  //  UShort_t firstring = (det == 1 ? 1 : 0);
+  //  for(UShort_t iring = firstring; iring <=1;iring++) {
+  //    Char_t ring = (iring == 1 ? 'I' : 'O');
+  //    for(UShort_t board =0 ; board <=1; board++) {
+  //   Int_t idx = GetHalfringIndex(det,ring,board);
+  for(Int_t idx = 0;idx<fEventsPerChannel.GetSize();idx++)
     {
-      Int_t nEvents = (fPulseLength.At(i)*fHighPulse) / fPulseSize.At(i);
-      fEventsPerChannel.AddAt(nEvents,i);
+      
+      Int_t nEvents = 0;
+      if(fPulseSize.At(idx))
+       nEvents = (fPulseLength.At(idx)*fHighPulse) / fPulseSize.At(idx);
+      fEventsPerChannel.AddAt(nEvents,idx);
       if(nEvents>nEventsRequired) nEventsRequired = nEvents * fNumberOfStripsPerChip;
       
     }
+  //}
+  // }
   
-  std::cout<<nEventsRequired<<std::endl;
   //8 pulser values * 128 strips * 100 samples
   
   
   SetRequiredEvents(nEventsRequired); 
+  
   TObjArray* detArray;
   TObjArray* ringArray;
   TObjArray* sectorArray;
@@ -155,8 +168,12 @@ void AliFMDGainDA::FillChannels(AliFMDDigit* digit) {
   UShort_t sec   = digit->Sector();
   UShort_t strip = digit->Strip();
   
+  //Strip is always seen as the first in a VA chip. All other strips are junk.
+  //Strips are counted from zero on even sectors and from 511 on odd sectors...
+   
+  if((sec%2)     && ((strip+1) % fNumberOfStripsPerChip)) return;
+  if(((sec+1)%2) && (strip % fNumberOfStripsPerChip)) return;
   
-  if(strip % fNumberOfStripsPerChip) return;
   Int_t vaChip   = strip / fNumberOfStripsPerChip; 
   TH1S* hChannel = GetChannelHistogram(det, ring, sec, vaChip);
   hChannel->Fill(digit->Counts());
@@ -170,27 +187,40 @@ void AliFMDGainDA::Analyse(UShort_t det,
                           UShort_t strip) {
   TGraphErrors* grChannel = GetChannel(det,ring,sec,strip);
   if(!grChannel->GetN()) {
-    // AliWarning(Form("No entries for FMD%d%c, sector %d, strip %d",
-    //                 det, ring , sec, strip));
+    AliWarning(Form("No entries for FMD%d%c, sector %d, strip %d",
+                     det, ring , sec, strip));
     return;
   }
   TF1 fitFunc("fitFunc","pol1",-10,280); 
   fitFunc.SetParameters(100,3);
   grChannel->Fit("fitFunc","Q0+","",0,fHighPulse);
      
-  Float_t chi2ndf = 0;
-  if(fitFunc.GetNDF())
-    chi2ndf = fitFunc.GetChisquare() / fitFunc.GetNDF();
-   
+  Float_t gain    = -1;
+  Float_t error   = -1; 
+  Float_t chi2ndf = -1;
+  if((fitFunc.GetParameter(1)) == (fitFunc.GetParameter(1))) {
+    gain    = fitFunc.GetParameter(1);
+    error   = fitFunc.GetParError(1);
+    if(fitFunc.GetNDF())
+      chi2ndf = fitFunc.GetChisquare() / fitFunc.GetNDF();
+  }
+  
   fOutputFile << det                         << ','
              << ring                        << ','
              << sec                         << ','
              << strip                       << ','
-             << fitFunc.GetParameter(1)     << ','
-             << fitFunc.GetParError(1)      << ','
+             << gain                        << ','
+             << error                       << ','
              << chi2ndf                     <<"\n";
   
+  //due to RCU trouble, first strips on VAs are excluded
+  // if(strip%128 != 0) {
+    
+  fSummaryGains.SetBinContent(fCurrentSummaryStrip,fitFunc.GetParameter(1));
+  fSummaryGains.SetBinError(fCurrentSummaryStrip,fitFunc.GetParError(1));
   
+  fCurrentSummaryStrip++;
+    // }
   if(fSaveHistograms) {
     gDirectory->cd(GetSectorPath(det,ring, sec, kTRUE));
     
@@ -215,6 +245,15 @@ void AliFMDGainDA::Analyse(UShort_t det,
   }  
 }
 
+//_____________________________________________________________________
+void AliFMDGainDA::Terminate(TFile* diagFile)
+{
+  if(diagFile) {
+    diagFile->cd();
+    fSummaryGains.Write();
+  }
+}
+
 //_____________________________________________________________________
 void AliFMDGainDA::WriteHeaderToFile() 
 {
@@ -273,13 +312,21 @@ void AliFMDGainDA::UpdatePulseAndADC(UShort_t det,
 {
   
   AliFMDParameters* pars = AliFMDParameters::Instance();
-  UInt_t ddl, board,chip,ch;
-  pars->Detector2Hardware(det,ring,sec,strip,ddl,board,chip,ch);
-  Int_t halfring = GetHalfringIndex(det,ring,board%16);
+  // UInt_t ddl, board,chip,ch;
+  UShort_t board = pars->GetAltroMap()->Sector2Board(ring, sec);
+  // pars->Detector2Hardware(det,ring,sec,strip,ddl,board,chip,ch);
+  /// pars->GetAltroMap()->Strip2Channel(
+  Int_t halfring = GetHalfringIndex(det,ring,board/16);
+  
   if(GetCurrentEvent()> (fNumberOfStripsPerChip*fEventsPerChannel.At(halfring)))
-    return
-  if(strip % fNumberOfStripsPerChip) return;
-  if(((GetCurrentEvent()) % fPulseLength.At(halfring)) && GetCurrentEvent() > 0) return;
+    return;
+  
+  if((sec%2)     && ((strip+1) % fNumberOfStripsPerChip)) return;
+  
+  if(((sec+1)%2) && (strip % fNumberOfStripsPerChip)) return;
+  
+  if(((GetCurrentEvent()) % fPulseLength.At(halfring)) 
+     && GetCurrentEvent() > 0) return;
      
   Int_t vaChip = strip/fNumberOfStripsPerChip; 
   TH1S* hChannel = GetChannelHistogram(det,ring,sec,vaChip);
@@ -291,7 +338,8 @@ void AliFMDGainDA::UpdatePulseAndADC(UShort_t det,
   }
   Double_t mean      = hChannel->GetMean();
   Double_t rms       = hChannel->GetRMS();
-  Double_t pulse     = Double_t(fCurrentPulse.At(halfring)) * fPulseSize.At(halfring);
+  Double_t pulse     = (Double_t(fCurrentPulse.At(halfring)) 
+                       * fPulseSize.At(halfring));
   Int_t    firstBin  = hChannel->GetXaxis()->GetFirst();
   Int_t    lastBin   = hChannel->GetXaxis()->GetLast();
   hChannel->GetXaxis()->SetRangeUser(mean-4*rms,mean+4*rms);
@@ -301,7 +349,15 @@ void AliFMDGainDA::UpdatePulseAndADC(UShort_t det,
   
   hChannel->GetXaxis()->SetRange(firstBin,lastBin);
   
-  Int_t channelNumber = strip + (GetCurrentEvent()-1)/((fPulseLength.At(halfring)*fHighPulse)/fPulseSize.At(halfring)); 
+  Int_t    channelNumber      = (strip + 
+                                (GetCurrentEvent()-1)
+                                / ((fPulseLength.At(halfring)*fHighPulse)
+                                   / fPulseSize.At(halfring))); 
+  if(sec%2)
+    channelNumber      = (strip - 
+                         (GetCurrentEvent()-1)
+                         / ((fPulseLength.At(halfring)*fHighPulse)
+                            / fPulseSize.At(halfring))); 
   
   TGraphErrors* channel = GetChannel(det,ring,sec,channelNumber);
   
@@ -313,10 +369,7 @@ void AliFMDGainDA::UpdatePulseAndADC(UShort_t det,
     hChannel->Write(Form("%s_pulse_%03d",hChannel->GetName(),(Int_t)pulse));
     
   }
-  
-  
-  
-  
+    
   hChannel->Reset();
   
 }
@@ -324,19 +377,28 @@ void AliFMDGainDA::UpdatePulseAndADC(UShort_t det,
 //_____________________________________________________________________
 void AliFMDGainDA::ResetPulseAndUpdateChannel() 
 {  
-  //for(Int_t i=0; i<fCurrentPulse.GetSize();i++)
   fCurrentPulse.Reset(0); 
 }
 
 //_____________________________________________________________________
 void AliFMDGainDA::FinishEvent() 
 {
-  for(Int_t i = 0; i<fPulseLength.GetSize();i++) {
-    if(GetCurrentEvent()>0 && (GetCurrentEvent() % fPulseLength.At(i) == 0))
-      fCurrentPulse.AddAt(fCurrentPulse.At(i)+1,i);
-    
-    if(GetCurrentEvent()>0 && (GetCurrentEvent()) % fEventsPerChannel.At(i) == 0)
-      fCurrentPulse.AddAt(0,i);
+  for(UShort_t det=1; det<=3;det++) {
+    UShort_t firstring = (det == 1 ? 1 : 0);
+    for(UShort_t iring = firstring; iring <=1;iring++) {
+      Char_t ring = (iring == 1 ? 'I' : 'O');
+      for(UShort_t board =0 ; board <=1; board++) {
+       Int_t idx = GetHalfringIndex(det,ring,board);
+       
+       if( !fPulseLength.At(idx) || !fEventsPerChannel.At(idx))
+         continue;
+       if(GetCurrentEvent()>0 && ((GetCurrentEvent() % fPulseLength.At(idx)) == 0))
+         fCurrentPulse.AddAt(fCurrentPulse.At(idx)+1,idx);
+       
+       if(GetCurrentEvent()>0 && ((GetCurrentEvent()) % fEventsPerChannel.At(idx)) == 0)
+         fCurrentPulse.AddAt(0,idx);
+      }
+    }
   }
 }
 //_____________________________________________________________________