LCOV - code coverage report
Current view: top level - TRD/TRDbase - AliTRDCalibPadStatus.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 303 0.3 %
Date: 2016-06-14 17:26:59 Functions: 1 31 3.2 %

          Line data    Source code
       1             : /**************************************************************************
       2             :  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
       3             :  *                                                                        *
       4             :  * Author: The ALICE Off-line Project.                                    *
       5             :  * Contributors are mentioned in the code where appropriate.              *
       6             :  *                                                                        *
       7             :  * Permission to use, copy, modify and distribute this software and its   *
       8             :  * documentation strictly for non-commercial purposes is hereby granted   *
       9             :  * without fee, provided that the above copyright notice appears in all   *
      10             :  * copies and that both the copyright notice and this permission notice   *
      11             :  * appear in the supporting documentation. The authors make no claims     *
      12             :  * about the suitability of this software for any purpose. It is          *
      13             :  * provided "as is" without express or implied warranty.                  *
      14             :  **************************************************************************/
      15             : 
      16             : /* $Id$ */
      17             : 
      18             : ////////////////////////////////////////////////////////////////////////////
      19             : //                                                                        //
      20             : // Example: fill pedestal with Gaussian noise                             //
      21             : //                                                                        //
      22             : //  AliTRDCalibPadStatus ped;                                             //
      23             : //  ped.TestEvent(numberofevent);                                         //
      24             : //                                                                        //
      25             : //  // Method without histo                                               //
      26             : //  ped.Analyse();                                                        //
      27             : //                                                                        //
      28             : //  // Create the histo of the AliTRDCalROC                               //
      29             : //  TH2F * histo2dm = ped.GetCalRocMean(0,kFALSE)->MakeHisto2D();         //
      30             : //  histo2dm->Scale(10.0);                                                //
      31             : //  TH1F * histo1dm = ped.GetCalRocMean(0,kFALSE)->MakeHisto1D();         //
      32             : //  histo1dm->Scale(10.0);                                                //
      33             : //  TH2F * histo2ds = ped.GetCalRocSquares(0,kFALSE)->MakeHisto2D();      //
      34             : //  histo2ds->Scale(10.0);                                                //
      35             : //  TH1F * histo1ds = ped.GetCalRocSquares(0,kFALSE)->MakeHisto1D();      //
      36             : //  histo1ds->Scale(10.0)                                                 //
      37             : //                                                                        //
      38             : //  // Draw output                                                        //
      39             : //  TCanvas* c1 = new TCanvas;                                            //
      40             : //  c1->Divide(2,2);                                                      //
      41             : //  c1->cd(1);                                                            //
      42             : //  histo2dm->Draw("colz");                                               //
      43             : //  c1->cd(2);                                                            //
      44             : //  histo1dm->Draw();                                                     //
      45             : //  c1->cd(3);                                                            //
      46             : //  histo2ds->Draw("colz");                                               //
      47             : //  c1->cd(4);                                                            //
      48             : //  histo1ds->Draw();                                                     //
      49             : //                                                                        //
      50             : //  // Method with histo                                                  //
      51             : //  ped.AnalyseHisto();                                                   //
      52             : //                                                                        //
      53             : //  // Take the histo                                                     //
      54             : //  TH1F *histo = ped.GetHisto(31);                                       //
      55             : //  histo->SetEntries(1);                                                 //
      56             : //  histo->Draw();                                                        //
      57             : //
      58             : // Authors:
      59             : //   R. Bailhache (R.Bailhache@gsi.de, rbailhache@ikf.uni-frankfurt.de)
      60             : //   J. Book (jbook@ikf.uni-frankfurt.de)
      61             : //                                                                                                    //
      62             : ////////////////////////////////////////////////////////////////////////////
      63             : 
      64             : 
      65             : //Root includes
      66             : #include <TObjArray.h>
      67             : #include <TH2F.h>
      68             : #include <TString.h>
      69             : #include <TMath.h>
      70             : #include <TRandom.h>
      71             : 
      72             : //#include <TRandom.h>
      73             : #include <TDirectory.h>
      74             : #include <TFile.h>
      75             : 
      76             : //AliRoot includes
      77             : #include <AliMathBase.h>
      78             : #include "AliRawReader.h"
      79             : #include "AliRawReaderRoot.h"
      80             : #include "AliRawReaderDate.h"
      81             : 
      82             : //header file
      83             : #include "AliLog.h"
      84             : #include "AliTRDCalibPadStatus.h"
      85             : #include "AliTRDgeometry.h"
      86             : #include "AliTRDCommonParam.h"
      87             : #include "AliTRDCalROC.h"
      88             : #include "AliTRDCalPadStatus.h"
      89             : #include "AliTRDCalDet.h"
      90             : #include "AliTRDCalPad.h"
      91             : #include "AliTRDCalSingleChamberStatus.h"
      92             : 
      93             : #include "AliTRDdigitsManager.h"
      94             : #include "AliTRDdigitsParam.h"
      95             : #include "AliTRDSignalIndex.h"
      96             : #include "AliTRDarraySignal.h"
      97             : #include "AliTRDarrayADC.h"
      98             : #include "AliTRDfeeParam.h"
      99             : 
     100             : #include "AliTRDrawStream.h"
     101             : 
     102             : #ifdef ALI_DATE
     103             : #include "event.h"
     104             : #endif
     105             : 
     106          48 : ClassImp(AliTRDCalibPadStatus) /*FOLD00*/
     107             : 
     108             : //_____________________________________________________________________
     109             : AliTRDCalibPadStatus::AliTRDCalibPadStatus() : /*FOLD00*/
     110           0 :   TObject(),
     111           0 :   fGeo(0),
     112           0 :   fAdcMin(0),
     113           0 :   fAdcMax(21),
     114           0 :   fDetector(-1),
     115           0 :   fNumberOfTimeBins(0),
     116           0 :   fCalRocArrayMean(540),
     117           0 :   fCalRocArrayRMS(540),
     118           0 :   fCalRocArrayMeand(540),
     119           0 :   fCalRocArrayRMSd(540),
     120           0 :   fHistoArray(540)
     121           0 : {
     122             :     //
     123             :     // default constructor
     124             :     //
     125             : 
     126           0 :   fGeo = new AliTRDgeometry();
     127             : 
     128           0 : }
     129             : 
     130             : //_____________________________________________________________________
     131             : AliTRDCalibPadStatus::AliTRDCalibPadStatus(const AliTRDCalibPadStatus &ped) : /*FOLD00*/
     132           0 :   TObject(ped),
     133           0 :   fGeo(0),
     134           0 :   fAdcMin(ped.GetAdcMin()),
     135           0 :   fAdcMax(ped.GetAdcMax()),
     136           0 :   fDetector(ped.fDetector),
     137           0 :   fNumberOfTimeBins(ped.fNumberOfTimeBins),
     138           0 :   fCalRocArrayMean(540),
     139           0 :   fCalRocArrayRMS(540),
     140           0 :   fCalRocArrayMeand(540),
     141           0 :   fCalRocArrayRMSd(540),
     142           0 :   fHistoArray(540)
     143           0 : {
     144             :     //
     145             :     // copy constructor
     146             :     //
     147           0 :     for (Int_t idet = 0; idet < 540; idet++){
     148           0 :         const AliTRDCalROC *calRocMean  = (AliTRDCalROC*)ped.fCalRocArrayMean.UncheckedAt(idet);
     149           0 :         const AliTRDCalROC *calRocRMS   = (AliTRDCalROC*)ped.fCalRocArrayRMS.UncheckedAt(idet);
     150           0 :         const AliTRDCalROC *calRocMeand = (AliTRDCalROC*)ped.fCalRocArrayMeand.UncheckedAt(idet);
     151           0 :         const AliTRDCalROC *calRocRMSd  = (AliTRDCalROC*)ped.fCalRocArrayRMSd.UncheckedAt(idet);
     152           0 :         const TH2F         *hped        = (TH2F*)ped.fHistoArray.UncheckedAt(idet);
     153             :     
     154           0 :         if ( calRocMean != 0x0 ) fCalRocArrayMean.AddAt(new AliTRDCalROC(*calRocMean), idet);
     155           0 :         if ( calRocRMS != 0x0 )  fCalRocArrayRMS.AddAt(new AliTRDCalROC(*calRocRMS), idet);
     156             : 
     157           0 :         if ( calRocMeand != 0x0 ) fCalRocArrayMeand.AddAt(new AliTRDCalROC(*calRocMeand), idet);
     158           0 :         if ( calRocRMSd != 0x0 )  fCalRocArrayRMSd.AddAt(new AliTRDCalROC(*calRocRMSd), idet);
     159             : 
     160           0 :         if ( hped != 0x0 ){
     161           0 :           TH2F *hNew = new TH2F(*hped);
     162           0 :           hNew->SetDirectory(0);
     163           0 :           fHistoArray.AddAt(hNew,idet);
     164           0 :         }
     165             :         
     166             :     }
     167           0 :     if (fGeo) {
     168           0 :       delete fGeo;
     169             :     }
     170           0 :     fGeo = new AliTRDgeometry();
     171           0 : }
     172             : 
     173             : //_____________________________________________________________________
     174             : AliTRDCalibPadStatus& AliTRDCalibPadStatus::operator = (const  AliTRDCalibPadStatus &source)
     175             : {
     176             :   //
     177             :   // assignment operator
     178             :   //
     179           0 :   if (&source == this) return *this;
     180           0 :   new (this) AliTRDCalibPadStatus(source);
     181             : 
     182           0 :   return *this;
     183           0 : }
     184             : //_____________________________________________________________________
     185             : AliTRDCalibPadStatus::~AliTRDCalibPadStatus() /*FOLD00*/
     186           0 : {
     187             :   //
     188             :   // destructor
     189             :   //
     190           0 :   fCalRocArrayMean.Delete();
     191           0 :   fCalRocArrayRMS.Delete();
     192           0 :   fCalRocArrayMeand.Delete();
     193           0 :   fCalRocArrayRMSd.Delete();
     194           0 :   fHistoArray.Delete();
     195           0 :   if (fGeo) {
     196           0 :     delete fGeo;
     197             :   }
     198           0 : }
     199             : //_____________________________________________________________________
     200             : void AliTRDCalibPadStatus::Destroy()
     201             : {
     202             :   //
     203             :   // Destroy
     204             :   //
     205           0 :   fCalRocArrayMean.Delete();
     206           0 :   fCalRocArrayRMS.Delete();
     207           0 :   fCalRocArrayMeand.Delete();
     208           0 :   fCalRocArrayRMSd.Delete();
     209           0 :   fHistoArray.Delete();
     210           0 : }
     211             : //_____________________________________________________________________
     212             : Int_t AliTRDCalibPadStatus::UpdateHisto(const Int_t icdet, /*FOLD00*/
     213             :                                          const Int_t icRow,
     214             :                                          const Int_t icCol,
     215             :                                          const Int_t csignal,
     216             :                                          const Int_t crowMax,
     217             :                                          const Int_t ccold,
     218             :                                          const Int_t icMcm,
     219             :                                          const Int_t icRob
     220             :                                          )
     221             : {
     222             :   //
     223             :   // Signal filling methode 
     224             :   //
     225           0 :   Int_t nbchannel = icRow+icCol*crowMax;
     226           0 :   Int_t mCm = icMcm%4;
     227           0 :   Int_t rOb = icRob%2;
     228             : 
     229             :   // now the case of double read channel
     230           0 :   if(ccold > 0){
     231           0 :     nbchannel = (((ccold-1)*8+ (mCm+rOb*4))*crowMax+icRow)+144*crowMax;
     232             :     //printf("nbchannel %d, ccold %d, icMcm %d, crowMax %d, icRow %d\n",nbchannel,ccold,icMcm,crowMax,icRow);
     233           0 :   }
     234             : 
     235             :   /*
     236             :   // fast filling methode.
     237             :   // Attention: the entry counter of the histogram is not increased
     238             :   //            this means that e.g. the colz draw option gives an empty plot
     239             :   
     240             :   Int_t bin = 0;
     241             :   
     242             :   if ( !(((Int_t)csignal>=fAdcMax ) || ((Int_t)csignal<fAdcMin)) )
     243             :     bin = (nbchannel+1)*(fAdcMax-fAdcMin+2)+((Int_t)csignal-fAdcMin+1);
     244             : 
     245             :     GetHisto(icdet,kTRUE)->GetArray()[bin]++;
     246             :   */
     247             :   // RS: don't use tricks, hist will be unmergable
     248           0 :   GetHisto(icdet,kTRUE)->Fill(csignal,nbchannel);
     249             : 
     250             : 
     251             :   
     252           0 :   return 0;
     253             : }
     254             : //_____________________________________________________________________
     255             : Int_t AliTRDCalibPadStatus::ProcessEvent(AliRawReader *rawReader)
     256             : {
     257             :   //
     258             :   // RawReader = AliTRDrawStream (Jochen Klein) 
     259             :   //
     260             :   // Event Processing loop - AliTRDRawStreamCosmic
     261             :   // 0 time bin problem or zero suppression
     262             :   // 1 no input
     263             :   // 2 input
     264             :   // Raw version number: 
     265             :   // [3,31] non zero suppressed
     266             :   // 2,4 and [32,63] zero suppressed 
     267             :   //
     268             :   
     269             :  
     270             : 
     271             :   Int_t withInput = 1;
     272             : 
     273           0 :   AliTRDdigitsManager *digitsManager = new AliTRDdigitsManager(kTRUE);
     274           0 :   digitsManager->CreateArrays();
     275             : 
     276           0 :   AliTRDrawStream *rawStream = new AliTRDrawStream(rawReader);
     277           0 :   rawStream->SetDigitsManager(digitsManager);
     278             :   //rawStream->SetNoErrorWarning();
     279             :   //rawStream->SetSharedPadReadout(kTRUE);
     280             :   
     281           0 :   AliTRDfeeParam *feeParam = AliTRDfeeParam::Instance();
     282             : 
     283             :   Int_t det    = 0;
     284           0 :   while ((det = rawStream->NextChamber(digitsManager, NULL, NULL)) >= 0) { //idetector
     285           0 :     if (digitsManager->GetIndexes(det)->HasEntry()) {//QA
     286             :       //      printf("there is ADC data on this chamber!\n");
     287             :       
     288           0 :        AliTRDarrayADC *digits = (AliTRDarrayADC *) digitsManager->GetDigits(det); //mod
     289           0 :       if (digits->HasData()) { //array
     290             :         
     291           0 :         AliTRDSignalIndex   *indexes = digitsManager->GetIndexes(det);
     292           0 :         if (indexes->IsAllocated() == kFALSE) {
     293           0 :           AliError("Indexes do not exist!");
     294           0 :           break;
     295             :         }
     296           0 :         Int_t iRow  = 0;
     297           0 :         Int_t iCol  = 0;
     298           0 :         indexes->ResetCounters();
     299             :         
     300           0 :         while (indexes->NextRCIndex(iRow, iCol)) { //column,row
     301             :         
     302           0 :           AliTRDdigitsParam *digitParam = (AliTRDdigitsParam *)digitsManager->GetDigitsParam();
     303             :           
     304             :           Int_t mcm          = 0;     // MCM from AliTRDfeeParam
     305             :           Int_t rob          = 0;     // ROB from AliTRDfeeParam
     306             :           Int_t extCol       = 0;     // extended column from AliTRDfeeParam  
     307           0 :           mcm = feeParam->GetMCMfromPad(iRow,iCol);
     308           0 :           rob = feeParam->GetROBfromPad(iRow,iCol);
     309             :           
     310             :           Int_t idetector  = det;                            //  current detector
     311             :           Int_t iRowMax    = 16;                              //  current rowmax
     312           0 :           if(GetStack(det) == 2) iRowMax = 12;
     313             :                   
     314           0 :           Int_t adc        = 20 - (iCol%18) -1;                 //  current adc
     315             :           Int_t col        = 0;                              //  col!=0 ->Shared Pad
     316           0 :           extCol = feeParam->GetExtendedPadColFromADC(rob,mcm,adc);
     317             :           //printf("  iCol %d  iRow %d  iRowMax %d  rob %d  mcm %d  adc %d  extCol %d\n",iCol,iRow,iRowMax,rob,mcm,adc,extCol);         
     318             :           
     319             :           // Signal for regular pads
     320           0 :           Int_t nbtimebin  = digitParam->GetNTimeBins(idetector);  //  number of time bins read from data      
     321           0 :           for(Int_t k = 0; k < nbtimebin; k++){
     322             :             Short_t signal = 0;
     323           0 :             signal = digits->GetData(iRow,iCol,k);
     324             : 
     325           0 :             if(signal>0) {
     326           0 :               UpdateHisto(idetector,iRow,iCol,signal,iRowMax,col,mcm,rob);
     327           0 :             }
     328             :           }
     329             :           
     330             :           
     331             :           
     332           0 :           if((adc==3-1 || adc==20-1 || adc==19-1) && (iCol > 1 && iCol <142)  ) { //SHARED PADS
     333             :             
     334           0 :             switch(adc) {
     335             :             case 2:  
     336             :               adc = 20;                                       //shared Pad adc 
     337           0 :               mcm = feeParam->GetMCMfromSharedPad(iRow,iCol); //shared Pad mcm 
     338             :               col =  1;
     339           0 :               break;
     340             :             case 19:  
     341             :               adc = 1;                                        //shared Pad adc  
     342           0 :               mcm = feeParam->GetMCMfromSharedPad(iRow,iCol); //shared Pad mcm  
     343             :               col =  2;
     344           0 :               break;
     345             :             case 18: 
     346             :               adc =  0;                                       //shared Pad adc  
     347           0 :               mcm = feeParam->GetMCMfromSharedPad(iRow,iCol); //shared Pad mcm 
     348             :               col =  3;
     349           0 :               break;
     350             :             }
     351           0 :             rob = feeParam->GetROBfromSharedPad(iRow,iCol);     //shared Pad rob 
     352             :             
     353             :             
     354           0 :             extCol = feeParam->GetExtendedPadColFromADC(rob,mcm,adc);     //extended pad col via the shared pad rob,mcm and adc
     355             :             
     356             :             //printf("SHARED PAD ---  iCol %d  iRow %d  rob %d  mcm %d  adc %d  extCol %d  col %d\n",iCol,iRow,rob,mcm,adc,extCol,col);
     357           0 :             for(Int_t k = 0; k < nbtimebin; k++){
     358             :               Short_t signal = 0;
     359           0 :               signal = digits->GetDataByAdcCol(iRow,extCol,k);
     360             :               
     361           0 :               if(signal>0) {
     362           0 :                 UpdateHisto(idetector,iRow,iCol,signal,iRowMax,col,mcm,rob);
     363           0 :               }
     364             :             }
     365           0 :           } //shared pads end
     366             :           
     367             :           
     368             :           withInput = 2;
     369             :         }//column,row
     370             : 
     371           0 :       }//array
     372           0 :     }//QA
     373           0 :     digitsManager->ClearArrays(det);
     374             :   }//idetector
     375           0 :   delete digitsManager;
     376           0 :   delete rawStream;
     377           0 :   return withInput;
     378             :   
     379           0 : }
     380             : 
     381             : //_____________________________________________________________________
     382             : TH2F* AliTRDCalibPadStatus::GetHisto(Int_t det, TObjArray *arr, /*FOLD00*/
     383             :                                   Int_t nbinsY, Float_t ymin, Float_t ymax,
     384             :                                   const Char_t *type, Bool_t force)
     385             : {
     386             :     //
     387             :     // return pointer to histogram
     388             :     // if force is true create a new histogram if it doesn't exist allready
     389             :     //
     390           0 :     if ( !force || arr->UncheckedAt(det) )
     391           0 :         return (TH2F*)arr->UncheckedAt(det);
     392             : 
     393             :     // if we are forced and histogram doesn't yes exist create it
     394           0 :     Char_t name[255], title[255];
     395             : 
     396           0 :     snprintf(name,255,"hCalib%s%.3d",type,det);
     397           0 :     snprintf(title,255,"%s calibration histogram detector %.2d;ADC channel;Channel (pad)",type,det);
     398             : 
     399             :    
     400           0 :     Int_t nbchannels = fGeo->GetRowMax(GetLayer(det),GetStack(det),GetSector(det))*fGeo->GetColMax(GetLayer(det));
     401             :     
     402             :     // we will add 3*8*rowMax channels at the end for the double counted
     403           0 :     nbchannels += 3*8*(fGeo->GetRowMax(GetLayer(det),GetStack(det),GetSector(det)));
     404             : 
     405             : 
     406             :     // new histogram with calib information. One value for each pad!
     407           0 :     TH2F* hist = new TH2F(name,title,
     408           0 :                           nbinsY, ymin, ymax,
     409           0 :                           nbchannels,0,nbchannels
     410             :                           );
     411           0 :     hist->SetDirectory(0);
     412           0 :     arr->AddAt(hist,det);
     413             :     return hist;
     414           0 : }
     415             : 
     416             : //_____________________________________________________________________
     417             : TH2F* AliTRDCalibPadStatus::GetHisto(Int_t det, Bool_t force) /*FOLD00*/
     418             : {
     419             :     //
     420             :     // return pointer to histogram
     421             :     // if force is true create a new histogram if it doesn't exist allready
     422             :     //
     423           0 :     TObjArray *arr = &fHistoArray;
     424           0 :     return GetHisto(det, arr, fAdcMax-fAdcMin, fAdcMin-0.5, fAdcMax-0.5, "Pedestal", force);
     425             : }
     426             : 
     427             : //_____________________________________________________________________
     428             : AliTRDCalROC* AliTRDCalibPadStatus::GetCalRoc(Int_t det, TObjArray* arr, Bool_t force) /*FOLD00*/
     429             : {
     430             :     //
     431             :     // return pointer to ROC Calibration
     432             :     // if force is true create a new AliTRDCalROC if it doesn't exist allready
     433             :     //
     434           0 :     if ( !force || arr->UncheckedAt(det) )
     435           0 :         return (AliTRDCalROC*)arr->UncheckedAt(det);
     436             : 
     437             :     // if we are forced and histogram doesn't yes exist create it
     438             : 
     439             :     // new AliTRDCalROC. One value for each pad!
     440           0 :     AliTRDCalROC *croc = new AliTRDCalROC(GetLayer(det),GetStack(det));
     441           0 :     arr->AddAt(croc,det);
     442             :     return croc;
     443           0 : }
     444             : //_____________________________________________________________________
     445             : AliTRDCalROC* AliTRDCalibPadStatus::GetCalRocMean(Int_t det, Bool_t force) /*FOLD00*/
     446             : {
     447             :     //
     448             :     // return pointer to Carge ROC Calibration
     449             :     // if force is true create a new histogram if it doesn't exist allready
     450             :     //
     451           0 :     TObjArray *arr = &fCalRocArrayMean;
     452           0 :     return GetCalRoc(det, arr, force);
     453             : }
     454             : 
     455             : //_____________________________________________________________________
     456             : AliTRDCalROC* AliTRDCalibPadStatus::GetCalRocRMS(Int_t det, Bool_t force) /*FOLD00*/
     457             : {
     458             :     //
     459             :     // return pointer to Carge ROC Calibration
     460             :     // if force is true create a new histogram if it doesn't exist allready
     461             :     //
     462           0 :     TObjArray *arr = &fCalRocArrayRMS;
     463           0 :     return GetCalRoc(det, arr, force);
     464             : }
     465             : //_____________________________________________________________________
     466             : AliTRDCalROC* AliTRDCalibPadStatus::GetCalRocMeand(Int_t det, Bool_t force) /*FOLD00*/
     467             : {
     468             :     //
     469             :     // return pointer to Carge ROC Calibration
     470             :     // if force is true create a new histogram if it doesn't exist allready
     471             :     //
     472           0 :     TObjArray *arr = &fCalRocArrayMeand;
     473           0 :     return GetCalRoc(det, arr, force);
     474             : }
     475             : 
     476             : //_____________________________________________________________________
     477             : AliTRDCalROC* AliTRDCalibPadStatus::GetCalRocRMSd(Int_t det, Bool_t force) /*FOLD00*/
     478             : {
     479             :     //
     480             :     // return pointer to Carge ROC Calibration
     481             :     // if force is true create a new histogram if it doesn't exist allready
     482             :     //
     483           0 :     TObjArray *arr = &fCalRocArrayRMSd;
     484           0 :     return GetCalRoc(det, arr, force);
     485             : }
     486             : 
     487             : //_____________________________________________________________________
     488             : void AliTRDCalibPadStatus::AnalyseHisto() /*FOLD00*/
     489             : {
     490             :     //
     491             :     //  Calculate calibration constants
     492             :     //
     493             : 
     494           0 :     Int_t nbinsAdc = fAdcMax-fAdcMin;
     495             : 
     496           0 :     TVectorD param(4);
     497           0 :     TMatrixD dummy(3,3);
     498             : 
     499             :     Float_t *arrayHP=0;
     500             : 
     501             : 
     502           0 :     for (Int_t idet=0; idet<540; idet++){
     503           0 :         TH2F *hP = GetHisto(idet);
     504           0 :         if ( !hP ) {
     505           0 :           continue;
     506             :         }
     507             : 
     508             :         //printf("Entries for %d\n",idet);
     509             : 
     510           0 :         AliTRDCalROC *rocMean     = GetCalRocMean(idet,kTRUE);
     511           0 :         AliTRDCalROC *rocRMS      = GetCalRocRMS(idet,kTRUE);
     512             : 
     513           0 :         arrayHP = hP->GetArray();
     514           0 :         Int_t nChannels = rocMean->GetNchannels();
     515             : 
     516           0 :         for (Int_t iChannel=0; iChannel<nChannels; iChannel++){
     517           0 :             Int_t offset = (nbinsAdc+2)*(iChannel+1)+1;
     518           0 :             Double_t ret = AliMathBase::FitGaus(arrayHP+offset,nbinsAdc,fAdcMin-0.5,fAdcMax-0.5,&param,&dummy);
     519             :             // if the fitting failed set noise and pedestal to 0
     520           0 :             if ((ret==-4) || (ret==-1) || (ret==-2)) {
     521           0 :                 param[1]=0.0;
     522           0 :                 param[2]=0.0;
     523           0 :             }
     524           0 :             if((param[1]/10.0) > 65534.0) param[1] = 0.0;
     525           0 :             if((param[2]/10.0) > 65534.0) param[2] = 0.0;
     526           0 :             rocMean->SetValue(iChannel,param[1]/10.0);
     527           0 :             rocRMS->SetValue(iChannel,param[2]/10.0);
     528             :         }
     529             : 
     530             :         // here we analyse doubled read channels
     531             :         
     532           0 :         AliTRDCalROC *rocMeand     = GetCalRocMeand(idet,kTRUE);
     533           0 :         AliTRDCalROC *rocRMSd      = GetCalRocRMSd(idet,kTRUE);
     534             : 
     535           0 :         Int_t nrows = rocMeand->GetNrows();
     536           0 :         Int_t shift = 144*nrows;
     537           0 :         Int_t total = shift+3*8*nrows; 
     538             : 
     539           0 :         for (Int_t iChannel=shift; iChannel<total; iChannel++){
     540           0 :             Int_t offset = (nbinsAdc+2)*(iChannel+1)+1;
     541           0 :             Double_t ret = AliMathBase::FitGaus(arrayHP+offset,nbinsAdc,fAdcMin-0.5,fAdcMax-0.5,&param,&dummy);
     542             :             // if the fitting failed set noise and pedestal to 0
     543           0 :             if ((ret==-4) || (ret==-1) || (ret==-2)) {
     544           0 :                 param[1]=0.0;
     545           0 :                 param[2]=0.0;
     546           0 :             }
     547           0 :             if((param[1]/10.0) > 65534.0) param[1] = 0.0;
     548           0 :             if((param[2]/10.0) > 65534.0) param[2] = 0.0;
     549             :             
     550             :             // here we have to recalculate backward
     551           0 :             Int_t nb   = iChannel-shift;
     552           0 :             Int_t row  = nb%nrows;
     553           0 :             Int_t j    = (Int_t)(nb/nrows);
     554           0 :             Int_t imcm = j%8;
     555           0 :             Int_t icol = (Int_t)(j/8);
     556             :             
     557           0 :             Int_t finalcol = 18*imcm;
     558           0 :             if(icol > 0) icol += 17;
     559             :             else icol = -1;
     560           0 :             finalcol += icol;
     561             : 
     562           0 :             Int_t channel = row+finalcol*nrows;
     563             : 
     564             :             //printf("iChannel %d, nrows %d, finalcol %d, row %d, channel %d\n",iChannel,nrows,finalcol,row,channel);
     565           0 :             if((finalcol < 0) || (finalcol >= 144)) continue;
     566             : 
     567           0 :             rocMeand->SetValue(channel,param[1]/10.0);
     568           0 :             rocRMSd->SetValue(channel,param[2]/10.0);
     569           0 :         }
     570             : 
     571           0 :     }
     572             :       
     573           0 : }
     574             : 
     575             : //_______________________________________________________________________________________
     576             : AliTRDCalPadStatus* AliTRDCalibPadStatus::CreateCalPadStatus()
     577             : {
     578             :   //
     579             :   // Create Pad Status out of Mean and RMS values
     580             :   // The chamber without data are masked, this is the corrected in the preprocessor
     581             :   //
     582             : 
     583           0 :   AliTRDCalPadStatus* obj = new AliTRDCalPadStatus("padstatus", "padstatus");
     584             :   
     585           0 :   for (Int_t idet=0; idet<540; ++idet)
     586             :     {
     587           0 :       AliTRDCalSingleChamberStatus *calROC = obj->GetCalROC(idet);
     588             : 
     589             : 
     590           0 :       if ( !GetCalRocMean(idet)) {
     591           0 :         for(Int_t k = 0; k < calROC->GetNchannels(); k++){
     592           0 :           calROC->SetStatus(k,AliTRDCalPadStatus::kNotConnected);
     593             :         }
     594           0 :         continue;
     595             :       }
     596             :       
     597             : 
     598             :       //Take the stuff
     599           0 :       AliTRDCalROC *calRocMean    = new AliTRDCalROC(*( (AliTRDCalROC *) GetCalRocMean(idet)));
     600           0 :       AliTRDCalROC *calRocRMS     = new AliTRDCalROC(*( (AliTRDCalROC *) GetCalRocRMS(idet)));
     601             : 
     602             :       //Take the stuff second chance
     603           0 :       AliTRDCalROC *calRocMeand    = new AliTRDCalROC(*( (AliTRDCalROC *) GetCalRocMeand(idet)));
     604           0 :       AliTRDCalROC *calRocRMSd     = new AliTRDCalROC(*( (AliTRDCalROC *) GetCalRocRMSd(idet)));
     605             : 
     606           0 :       calRocRMS->Unfold();
     607           0 :       calRocRMSd->Unfold();
     608             : 
     609             :      
     610             :       //Range
     611           0 :       Int_t row      = calROC->GetNrows();
     612           0 :       Int_t col      = calROC->GetNcols();
     613             :       
     614           0 :       Double_t rmsmean       = calRocMean->GetRMS()*10.0;
     615           0 :       Double_t meanmean      = calRocMean->GetMean()*10.0;
     616           0 :       Double_t meansquares   = calRocRMS->GetMean();
     617             : 
     618             :       
     619           0 :       for(Int_t irow = 0; irow < row; irow++){
     620             :         
     621             :         // for bridged pads
     622             :         Float_t meanprevious = 0.0;
     623             :         Float_t rmsprevious  = 0.0; 
     624             :         Float_t mean         = 0.0;
     625             :         Float_t rms          = 0.0;
     626             :         
     627           0 :         for(Int_t icol = 0; icol < col; icol++){
     628             :           
     629           0 :           mean     = calRocMean->GetValue(icol,irow)*10.0;
     630           0 :           rms      = calRocRMS->GetValue(icol,irow);
     631             : 
     632           0 :           if(icol > 0) {
     633           0 :             meanprevious     = calRocMean->GetValue((icol -1),irow)*10.0;
     634           0 :             rmsprevious      = calRocRMS->GetValue((icol - 1),irow);
     635           0 :           }
     636             :           
     637             :           Bool_t pb = kFALSE;
     638             :           // masked if two noisy
     639           0 :           if((rms <= 0.0001) || (TMath::Abs(mean-meanmean)>(5*rmsmean)) || (TMath::Abs(rms)>(5.0*TMath::Abs(meansquares)))) {
     640             :             
     641             :             pb = kTRUE;
     642             :             // look at second chance
     643           0 :             Float_t meand     = calRocMeand->GetValue(icol,irow)*10.0;
     644           0 :             Float_t rmsd      = calRocRMSd->GetValue(icol,irow);
     645             :             
     646           0 :             if((rmsd <= 0.0001) || (TMath::Abs(meand-meanmean)>(5*rmsmean)) || (TMath::Abs(rmsd)>(5.0*TMath::Abs(meansquares)))) {
     647           0 :               if((rmsd <= 0.0001) && (rms <= 0.0001)) {
     648           0 :                 calROC->SetStatus(icol,irow,AliTRDCalPadStatus::kNotConnected);
     649           0 :               }
     650             :               else {
     651           0 :                 calROC->SetStatus(icol, irow, AliTRDCalPadStatus::kMasked);
     652             :               }
     653             :             }
     654             :             else {
     655           0 :               calROC->SetStatus(icol, irow, AliTRDCalPadStatus::kReadSecond);
     656             :             }
     657           0 :           }
     658             : 
     659             : 
     660             :           // bridge if previous pad found something
     661           0 :           if(!pb) {
     662           0 :             if((TMath::Abs(meanprevious-mean)<0.000001) && (TMath::Abs(rmsprevious-rms)<0.000001) && (mean > 0.0001)) {
     663             :               //printf("mean previous %f, mean %f, rms %f, rmsprevious %f, col %d\n",meanprevious,mean,rms,rmsprevious,icol);
     664           0 :               calROC->SetStatus(icol -1 ,irow, AliTRDCalPadStatus::kPadBridgedRight);
     665           0 :               calROC->SetStatus(icol ,irow, AliTRDCalPadStatus::kPadBridgedLeft);
     666           0 :             }       
     667             :           }
     668             : 
     669             :         }
     670             :       }
     671             : 
     672           0 :       delete calRocMean;
     673           0 :       delete calRocRMS;
     674           0 :       delete calRocMeand;
     675           0 :       delete calRocRMSd;
     676             : 
     677             : 
     678           0 :     }
     679             :   
     680           0 :   return obj;
     681             :   
     682           0 : }
     683             : //_______________________________________________________________________________________
     684             : AliTRDCalPad* AliTRDCalibPadStatus::CreateCalPad()
     685             : {
     686             :   //
     687             :   // Create Pad Noise out of RMS values
     688             :   //
     689             : 
     690           0 :   AliTRDCalPad* obj = new AliTRDCalPad("PadNoise", "PadNoise");
     691             :   
     692             :   
     693           0 :   for (Int_t det=0; det<AliTRDgeometry::kNdet; ++det)  {
     694             :     
     695           0 :     AliTRDCalROC *calROC22 = obj->GetCalROC(det);
     696             : 
     697           0 :     AliTRDCalROC *calRocRMS     = ((AliTRDCalROC *)GetCalRocRMS(det,kTRUE));
     698             :    
     699           0 :     for(Int_t k = 0; k < calROC22->GetNchannels(); k++){
     700           0 :       calROC22->SetValue(k,calRocRMS->GetValue(k));
     701             :     }
     702             : 
     703             :   }
     704             :   
     705           0 :   return obj;
     706             :   
     707           0 : }
     708             : 
     709             : //_______________________________________________________________________________________
     710             : AliTRDCalDet* AliTRDCalibPadStatus::CreateCalDet() const
     711             : {
     712             :   //
     713             :   // Create Det Noise correction factor
     714             :   //
     715             : 
     716           0 :   AliTRDCalDet* obj = new AliTRDCalDet("DetNoise", "DetNoise (correction factor)");
     717             : 
     718           0 :   for(Int_t l = 0; l < 540; l++){
     719           0 :     obj->SetValue(l,10.0);
     720             :   }
     721             :   
     722           0 :   return obj;
     723             :   
     724           0 : }
     725             : 
     726             : //_____________________________________________________________________
     727             : void AliTRDCalibPadStatus::DumpToFile(const Char_t *filename, const Char_t *dir, Bool_t append) /*FOLD00*/
     728             : {
     729             :     //
     730             :     //  Write class to file
     731             :     //
     732             : 
     733           0 :     TString sDir(dir);
     734           0 :     TString option;
     735             : 
     736           0 :     if ( append )
     737           0 :         option = "update";
     738             :     else
     739           0 :         option = "recreate";
     740             : 
     741           0 :     TDirectory *backup = gDirectory;
     742           0 :     TFile f(filename,option.Data());
     743           0 :     f.cd();
     744           0 :     if ( !sDir.IsNull() ){
     745           0 :         f.mkdir(sDir.Data());
     746           0 :         f.cd(sDir);
     747             :     }
     748           0 :     this->Write();
     749           0 :     f.Close();
     750             : 
     751           0 :     if ( backup ) backup->cd();
     752           0 : }
     753             : 
     754             : //_____________________________________________________________________
     755             : void AliTRDCalibPadStatus::SetCalRocMean(AliTRDCalROC *mean, Int_t det) /*FOLD00*/
     756             : {
     757             :     //
     758             :     //  Put the AliTRDCalROC in the array fCalRocArrayMean
     759             :     //
     760             : 
     761             : 
     762           0 :   AliTRDCalROC *rocMean = GetCalRocMean(det,kTRUE);
     763             :   
     764           0 :   Int_t nChannels = rocMean->GetNchannels();
     765             :   
     766           0 :   for (Int_t iChannel=0; iChannel<nChannels; iChannel++){
     767             :     
     768           0 :     rocMean->SetValue(iChannel,mean->GetValue(iChannel));
     769             :     
     770             :   }
     771             :   
     772           0 : }
     773             : 
     774             : //_____________________________________________________________________
     775             : void AliTRDCalibPadStatus::SetCalRocRMS(AliTRDCalROC *rms, Int_t det) /*FOLD00*/
     776             : {
     777             :     //
     778             :     //  Put the AliTRDCalROC in the array fCalRocArrayRMS
     779             :     //
     780             : 
     781             : 
     782           0 :   AliTRDCalROC *rocRms = GetCalRocRMS(det,kTRUE);
     783             :   
     784           0 :   Int_t nChannels = rocRms->GetNchannels();
     785             :   
     786           0 :   for (Int_t iChannel=0; iChannel<nChannels; iChannel++){
     787             :     
     788           0 :     rocRms->SetValue(iChannel,rms->GetValue(iChannel));
     789             :     
     790             :   }
     791             :   
     792           0 : }
     793             : //_____________________________________________________________________
     794             : void AliTRDCalibPadStatus::SetCalRocMeand(AliTRDCalROC *mean, Int_t det) /*FOLD00*/
     795             : {
     796             :     //
     797             :     //  Put the AliTRDCalROC in the array fCalRocArrayMean
     798             :     //
     799             : 
     800             : 
     801           0 :   AliTRDCalROC *rocMean = GetCalRocMeand(det,kTRUE);
     802             :   
     803           0 :   Int_t nChannels = rocMean->GetNchannels();
     804             :   
     805           0 :   for (Int_t iChannel=0; iChannel<nChannels; iChannel++){
     806             :     
     807           0 :     rocMean->SetValue(iChannel,mean->GetValue(iChannel));
     808             :     
     809             :   }
     810             :   
     811           0 : }
     812             : 
     813             : //_____________________________________________________________________
     814             : void AliTRDCalibPadStatus::SetCalRocRMSd(AliTRDCalROC *rms, Int_t det) /*FOLD00*/
     815             : {
     816             :     //
     817             :     //  Put the AliTRDCalROC in the array fCalRocArrayRMS
     818             :     //
     819             : 
     820             : 
     821           0 :   AliTRDCalROC *rocRms = GetCalRocRMSd(det,kTRUE);
     822             :   
     823           0 :   Int_t nChannels = rocRms->GetNchannels();
     824             :   
     825           0 :   for (Int_t iChannel=0; iChannel<nChannels; iChannel++){
     826             :     
     827           0 :     rocRms->SetValue(iChannel,rms->GetValue(iChannel));
     828             :     
     829             :   }
     830             :   
     831           0 : }
     832             : //_____________________________________________________________________________
     833             : Int_t AliTRDCalibPadStatus::GetLayer(Int_t d) const
     834             : {
     835             :   //
     836             :   // Reconstruct the layer number from the detector number
     837             :   //
     838             : 
     839           0 :   return ((Int_t) (d % 6));
     840             : 
     841             : }
     842             : 
     843             : //_____________________________________________________________________________
     844             : Int_t AliTRDCalibPadStatus::GetStack(Int_t d) const
     845             : {
     846             :   //
     847             :   // Reconstruct the chamber number from the detector number
     848             :   //
     849             : 
     850           0 :   return ((Int_t) (d % 30) / 6);
     851             : 
     852             : }
     853             : 
     854             : //_____________________________________________________________________________
     855             : Int_t AliTRDCalibPadStatus::GetSector(Int_t d) const
     856             : {
     857             :   //
     858             :   // Reconstruct the sector number from the detector number
     859             :   //
     860             : 
     861           0 :   return ((Int_t) (d / 30));
     862             : 
     863             : }
     864             : 
     865             : 

Generated by: LCOV version 1.11