LCOV - code coverage report
Current view: top level - FMD/FMDbase - AliFMDPreprocessor.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 200 0.5 %
Date: 2016-06-14 17:26:59 Functions: 1 10 10.0 %

          Line data    Source code
       1             : /**************************************************************************
       2             :  * Copyright(c) 2004, 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             : /* $Id$ */
      16             : /** @file    AliFMDPreprocessor.cxx
      17             :     @author  Hans Hjersing Dalsgaard <canute@nbi.dk>
      18             :     @date    Mon Mar 27 12:39:09 2006
      19             :     @brief   Shuttle "preprocessor" for the FMD
      20             : */
      21             : //___________________________________________________________________
      22             : //
      23             : // The class processes data points from DCS (via Amanada), and DAQ DA
      24             : // files (via FXS) to make calibration data for the FMD. 
      25             : //
      26             : // Data points: 
      27             : //    *  Nothing yet. 
      28             : //
      29             : // DAQ FXS file:
      30             : //    * pedestals - a (ASCII) Comma Separated Values files with the
      31             : //                  fields 
      32             : //                       rcu     DDL number 
      33             : //                       board   FEC board number 
      34             : //                       chip    ALTRO chip number on FEC
      35             : //                       channel ALTRO channel number
      36             : //                       strip   VA1 strip number
      37             : //                       sample  Sample number
      38             : //                       ped     Mean of ADC spectra
      39             : //                       noise   Spread of ADC spectra
      40             : //                       mu      Mean of Gaussian fit to ADC spectra
      41             : //                       sigma   Variance of Gaussian fit to ADC spectra
      42             : //                       chi2    Chi^2 per degrees of freedom of fit
      43             : //    * Gains     - a (ASCII) Comma Separated Values files with the
      44             : //                  fields 
      45             : //                       rcu     DDL number 
      46             : //                       board   FEC board number 
      47             : //                       chip    ALTRO chip number on FEC
      48             : //                       channel ALTRO channel number
      49             : //                       strip   VA1 strip number
      50             : //                       gain    Slope of gain
      51             : //                       error   Error on gain
      52             : //                       chi2    Chi^2 per degrees of freedom of fit
      53             : //                  
      54             : // See also 
      55             : //
      56             : //   http://aliceinfo.cern.ch/Offline/Activities/Shuttle.html
      57             : //
      58             : // Latest changes by Christian Holm Christensen
      59             : //
      60             : 
      61             :  #include <iostream>
      62             : 
      63             : #include <fstream>
      64             : #include "AliFMDPreprocessor.h"
      65             : #include "AliFMDCalibPedestal.h"
      66             : #include "AliFMDCalibGain.h"
      67             : #include "AliFMDCalibStripRange.h"
      68             : #include "AliFMDCalibSampleRate.h"
      69             : #include "AliFMDParameters.h"
      70             : #include "AliCDBMetaData.h"
      71             : #include "AliCDBManager.h"
      72             : // #include "AliDCSValue.h"
      73             : #include "AliLog.h"
      74             : #include <TTimeStamp.h>
      75             : // #include <TFile.h>
      76             : #include <TObjString.h>
      77             : #include <TString.h>
      78             : #include <TNamed.h>
      79             : 
      80             : 
      81          12 : ClassImp(AliFMDPreprocessor)
      82             : #if 0 // Do not remove - here to make Emacs happy
      83             : ;
      84             : #endif 
      85             : 
      86             : 
      87             : //____________________________________________________
      88             : AliFMDPreprocessor::AliFMDPreprocessor(AliShuttleInterface* shuttle)
      89           0 :   : AliPreprocessor("FMD", shuttle)
      90           0 : {
      91           0 :   AddRunType("PHYSICS");
      92           0 :   AddRunType("STANDALONE");
      93           0 :   AddRunType("PEDESTAL");
      94           0 :   AddRunType("GAIN");
      95           0 : }
      96             : 
      97             : 
      98             : //____________________________________________________
      99             : Bool_t AliFMDPreprocessor::GetAndCheckFileSources(TList*&     list,
     100             :                                                   Int_t       system, 
     101             :                                                   const char* id) 
     102             : {
     103             :   // Convinience function 
     104             :   // Parameters: 
     105             :   //   list     On return, list of files. 
     106             :   //   system   Alice system (DAQ, DCS, ...)
     107             :   //   id       File id
     108             :   // Return:
     109             :   //   kTRUE on success. 
     110           0 :   list = GetFileSources(system, id);
     111           0 :   if (!list) { 
     112           0 :     TString sys;
     113           0 :     switch (system) { 
     114           0 :     case kDAQ: sys = "DAQ";     break;
     115           0 :     case kDCS: sys = "DCS";     break;
     116           0 :     default:   sys = "unknown"; break;
     117             :     }
     118           0 :     Log(Form("Failed to get file sources for %s/%d", sys.Data(), system));
     119             :     return kFALSE;
     120           0 :   }
     121           0 :   return kTRUE;
     122           0 : }
     123             : 
     124             : //____________________________________________________
     125             : AliCDBEntry* 
     126             : AliFMDPreprocessor::GetFromCDB(const char* second, const char* third)
     127             : {
     128           0 :   return GetFromOCDB(second, third);
     129             : }
     130             : 
     131             : 
     132             : //____________________________________________________
     133             : UInt_t AliFMDPreprocessor::Process(TMap* /* dcsAliasMap */)
     134             : {
     135             :   // Main member function. 
     136             :   // Parameters: 
     137             :   //    dcsAliassMap   Map of DCS data point aliases.
     138             :   // Return 
     139             :   //    0 on success, >0 otherwise 
     140             :   Bool_t resultPed   = kTRUE;
     141             :   Bool_t resultGain  = kTRUE;
     142             :   Bool_t resultRange = kTRUE;
     143             :   Bool_t resultRate  = kTRUE;
     144             :   Bool_t resultZero  = kTRUE;
     145             :   Bool_t infoCalib   = kTRUE;
     146             :   Bool_t resultDead  = kTRUE;
     147             :   // Do we need this ?
     148             :   // if(!dcsAliasMap) return 1;
     149             :   // 
     150             :   // Invoking the cdb manager and the FMD parameters class
     151             :   // AliCDBManager* cdb   = AliCDBManager::Instance();
     152             :   // cdb->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
     153             :   // cdb->SetRun(0);
     154             :   
     155             :   // Get the run type 
     156           0 :   TString runType(GetRunType()); 
     157             :   
     158           0 :   AliFMDParameters* pars = AliFMDParameters::Instance();
     159           0 :   if(runType.Contains("PEDESTAL", TString::kIgnoreCase))
     160           0 :     pars->Init(this, false, AliFMDParameters::kAltroMap|AliFMDParameters::kPulseGain);
     161           0 :   else if(runType.Contains("GAIN", TString::kIgnoreCase))
     162           0 :     pars->Init(this, false, AliFMDParameters::kAltroMap|AliFMDParameters::kPedestal);
     163             :   else
     164           0 :     pars->Init(this, false, AliFMDParameters::kAltroMap);
     165             :   
     166             :   // This is if the SOR contains Fee parameters, and we run a DA to
     167             :   // extract these parameters.   The same code could work if we get
     168             :   // the information from DCS via the FXS 
     169           0 :   TList* files = 0;
     170           0 :   AliFMDCalibSampleRate*      calibRate  = 0;
     171           0 :   AliFMDCalibStripRange*      calibRange = 0;
     172           0 :   AliFMDCalibZeroSuppression* calibZero  = 0;
     173             : 
     174           0 :   if (GetAndCheckFileSources(files, kDAQ,pars->GetConditionsShuttleID()))
     175           0 :     infoCalib = GetInfoCalibration(files, calibRate, calibRange, calibZero);
     176             :  
     177           0 :   resultRate  = (!calibRate  ? kFALSE : kTRUE);
     178           0 :   resultRange = (!calibRange ? kFALSE : kTRUE);
     179           0 :   resultZero  = (!calibZero  ? kFALSE : kTRUE);
     180             :   
     181             : 
     182             :   
     183             :   //Creating calibration objects
     184             :   AliFMDCalibPedestal* calibPed  = 0;
     185             :   AliFMDCalibGain*     calibGain = 0;
     186             :   AliFMDCalibDeadMap*  calibDead = 0;
     187           0 :   if (runType.Contains("PEDESTAL", TString::kIgnoreCase)) { 
     188           0 :     if (GetAndCheckFileSources(files, kDAQ, pars->GetPedestalShuttleID())) {
     189           0 :       if(files->GetSize())
     190           0 :         calibPed = GetPedestalCalibration(files);
     191             :     }
     192           0 :     resultPed = (calibPed ? kTRUE : kFALSE);
     193           0 :   }
     194           0 :   if (runType.Contains("GAIN", TString::kIgnoreCase)) {
     195           0 :     if (GetAndCheckFileSources(files, kDAQ, pars->GetGainShuttleID())) {
     196           0 :       if(files->GetSize())
     197           0 :         calibGain = GetGainCalibration(files);
     198             :     }
     199           0 :     resultGain = (calibGain ? kTRUE : kFALSE);
     200           0 :   }
     201           0 :   if(runType.Contains("PEDESTAL", TString::kIgnoreCase) || runType.Contains("GAIN", TString::kIgnoreCase))
     202           0 :     calibDead = GetDeadChannelMap(calibPed,calibGain);
     203             :   
     204             :   //Storing Calibration objects  
     205           0 :   AliCDBMetaData metaData;
     206           0 :   metaData.SetBeamPeriod(0);
     207           0 :   metaData.SetResponsible("Hans H. Dalsgaard");
     208           0 :   metaData.SetComment("Preprocessor stores pedestals and gains for the FMD.");
     209             :   
     210           0 :   if(calibPed)  { 
     211           0 :     resultPed  = Store("Calib","Pedestal", calibPed, &metaData, 0, kTRUE);
     212           0 :     delete calibPed;
     213             :   }
     214           0 :   if(calibGain) { 
     215           0 :     resultGain = Store("Calib","PulseGain", calibGain, &metaData, 0, kTRUE);
     216           0 :     delete calibGain;
     217             :   }
     218           0 :   if(calibRange) { 
     219           0 :     resultRange = Store("Calib","StripRange", calibRange, &metaData, 0, kTRUE);
     220           0 :     delete calibRange;
     221             :   }
     222           0 :   if(calibRate) { 
     223           0 :     resultRate = Store("Calib","SampleRate", calibRate, &metaData, 0, kTRUE);
     224           0 :     delete calibRate;
     225             :   }
     226           0 :   if(calibZero) { 
     227           0 :     resultZero = Store("Calib","ZeroSuppression", calibZero,&metaData,0,kTRUE);
     228           0 :     delete calibZero;
     229             :   }
     230           0 :   if(calibDead) { 
     231           0 :     resultDead = Store("Calib","Dead", calibDead,&metaData,0,kTRUE);
     232           0 :     delete calibDead;
     233             :   }
     234             : 
     235           0 :   Bool_t success = (resultPed && resultGain  && resultRange && 
     236           0 :                     resultRate  && resultZero && resultDead && infoCalib);
     237             :   
     238           0 :   Log(Form("FMD preprocessor was %s", (success ? "successful" : "failed")));
     239           0 :   return (success ? 0 : 1);
     240           0 : }
     241             : 
     242             : //____________________________________________________________________
     243             : Bool_t
     244             : AliFMDPreprocessor::GetInfoCalibration(TList* files, 
     245             :                                        AliFMDCalibSampleRate*&      s,
     246             :                                        AliFMDCalibStripRange*&      r, 
     247             :                                        AliFMDCalibZeroSuppression*& z)
     248             : {
     249             :   // Get info calibrations. 
     250             :   // Parameters:
     251             :   //     files List of files. 
     252             :   //     s     On return, newly allocated object 
     253             :   //     r     On return, newly allocated object 
     254             :   //     z     On return, newly allocated object 
     255             :   // Return: 
     256             :   //     kTRUE on success
     257           0 :   if (!files) return kFALSE; // Should really be false
     258           0 :   if (files->GetEntries() <= 0) return kFALSE;
     259             :   
     260           0 :   s = new AliFMDCalibSampleRate();
     261           0 :   r = new AliFMDCalibStripRange();
     262           0 :   z = new AliFMDCalibZeroSuppression();
     263             :   
     264           0 :   AliFMDParameters*    pars     = AliFMDParameters::Instance();
     265           0 :   TIter                iter(files);
     266             :   TObjString*          fileSource;
     267             : 
     268           0 :   while((fileSource = dynamic_cast<TObjString*>(iter.Next()))) {
     269           0 :     const Char_t* filename = GetFile(kDAQ, pars->GetConditionsShuttleID(), fileSource->GetName());
     270           0 :     std::ifstream in(filename);
     271           0 :     if(!in) {
     272           0 :       Log(Form("File %s not found!", filename));
     273           0 :       continue;
     274             :     }
     275           0 :     s->ReadFromFile(in);
     276           0 :     r->ReadFromFile(in);
     277           0 :   }
     278             :   return kTRUE;
     279           0 : }
     280             : 
     281             :   
     282             : //____________________________________________________________________
     283             : AliFMDCalibPedestal* 
     284             : AliFMDPreprocessor::GetPedestalCalibration(const TList* pedFiles)
     285             : {
     286             :   // Read DAQ DA produced CSV files of pedestals, and return a
     287             :   // calibration object. 
     288             :   // Parameters:
     289             :   //   pedFiles     List of pedestal files 
     290             :   // Return 
     291             :   //   A pointer to a newly allocated AliFMDCalibPedestal object, or
     292             :   //   null in case of errors. 
     293           0 :   if(!pedFiles) return 0;
     294             : 
     295           0 :   AliFMDCalibPedestal* calibPed = new AliFMDCalibPedestal();
     296           0 :   AliFMDParameters*    pars     = AliFMDParameters::Instance();
     297           0 :   TIter                iter(pedFiles);
     298             :   TObjString*          fileSource;
     299             :   
     300           0 :   while((fileSource = dynamic_cast<TObjString*>(iter.Next()))) {
     301           0 :     const Char_t* filename = GetFile(kDAQ, pars->GetPedestalShuttleID(), 
     302           0 :                                      fileSource->GetName());
     303           0 :     std::ifstream in(filename);
     304           0 :     if(!in) {
     305           0 :       Log(Form("File %s not found!", filename));
     306           0 :       continue;
     307             :     }
     308             :     // Loop until EOF
     309             :     int lineno = 0;
     310             :     char cc;
     311           0 :     while((cc = in.peek())!=EOF) {
     312           0 :       if(in.bad()) { 
     313           0 :         Log(Form("Bad read at line %d in %s", lineno, filename));
     314             :         break;
     315             :       }
     316           0 :       if (cc == '#') { 
     317           0 :         TString line;
     318           0 :         line.ReadLine(in);
     319           0 :         lineno++;
     320           0 :         if (lineno == 1) {
     321           0 :           line.ToLower();
     322           0 :           if(!line.Contains(pars->GetPedestalShuttleID())) {
     323           0 :             Log(Form("File header is not from pedestal!: %s", line.Data()));
     324           0 :             break;
     325             :           }
     326           0 :           Log("File contains data from pedestals");
     327             :         }
     328           0 :         continue;
     329           0 :       }
     330           0 :       UShort_t det, sec, strip;
     331           0 :       Char_t ring;
     332           0 :       Float_t ped, noise, mu, sigma, chi2ndf;
     333           0 :       Char_t c[8];
     334             :           
     335           0 :       in >> det      >> c[0] 
     336           0 :          >> ring     >> c[1]
     337           0 :          >> sec      >> c[2]
     338           0 :          >> strip    >> c[3]
     339           0 :          >> ped      >> c[4]
     340           0 :          >> noise    >> c[5]
     341           0 :          >> mu       >> c[6]
     342           0 :          >> sigma    >> c[7]
     343           0 :          >> chi2ndf;
     344           0 :       lineno++;
     345             :       
     346             :       // Ignore trailing garbage 
     347             :       // if (strip > 127) continue;
     348             :       
     349             :       //Setting DDL to comply with the FMD in DAQ
     350             :       // UInt_t FmdDDLBase = 3072; 
     351             :       // ddl = ddl - FmdDDLBase;
     352             :       //Setting the pedestals via the hardware address
     353             :       
     354             :       
     355             :       // pars->Hardware2Detector(ddl,board,chip,channel,det,ring,sec,str);
     356             :       // strip += str;
     357             :      
     358           0 :       calibPed->Set(det,ring,sec,strip,ped,noise);
     359             :      
     360           0 :     }
     361           0 :   }
     362             :   return calibPed;
     363           0 : }       
     364             : 
     365             : //____________________________________________________________________
     366             : AliFMDCalibGain* 
     367             : AliFMDPreprocessor::GetGainCalibration(const TList* gainFiles)
     368             : {
     369             :   // Read DAQ DA produced CSV files of pedestals, and return a
     370             :   // calibration object. 
     371             :   // Parameters:
     372             :   //   pedFiles     List of pedestal files 
     373             :   // Return 
     374             :   //   A pointer to a newly allocated AliFMDCalibPedestal object, or
     375             :   //   null in case of errors. 
     376           0 :   if(!gainFiles) return 0;
     377             :   
     378           0 :   AliFMDCalibGain*  calibGain  = new AliFMDCalibGain();
     379           0 :   AliFMDParameters* pars       = AliFMDParameters::Instance();
     380           0 :   TIter             iter(gainFiles);
     381             :   TObjString*       fileSource;
     382           0 :   while((fileSource = dynamic_cast<TObjString *>(iter.Next()))) {
     383           0 :     const Char_t* filename = GetFile(kDAQ, pars->GetGainShuttleID(), 
     384           0 :                                      fileSource->GetName());
     385           0 :     std::ifstream in(filename);
     386           0 :     if(!in) {
     387           0 :       Log(Form("File %s not found!", filename));
     388           0 :       continue;
     389             :     }
     390             :     // Loop until EOF                                                                                                                                   
     391             :     int lineno = 0;
     392             :     char cc;
     393           0 :     while((cc = in.peek())!=EOF) {
     394           0 :       if(in.bad()) {
     395           0 :         Log(Form("Bad read at line %d in %s", lineno, filename));
     396             :         break;
     397             :       }
     398           0 :       if (cc == '#') {
     399           0 :         TString line;
     400           0 :         line.ReadLine(in);
     401           0 :         lineno++;
     402           0 :         if (lineno == 1) {
     403           0 :           line.ToLower();
     404           0 :           if(!line.Contains(pars->GetGainShuttleID())) {
     405           0 :             Log(Form("File header is not from gains!: %s", line.Data()));
     406           0 :             break;
     407             :           }
     408           0 :           Log("File contains data from gains");
     409             :         }
     410           0 :         continue;
     411           0 :       }
     412           0 :       UShort_t det, sec, strip;
     413           0 :       Char_t ring;
     414             :       
     415           0 :       Float_t gain,error,  chi2ndf;
     416           0 :       Char_t c[6];
     417             :       
     418           0 :       in >> det      >> c[0] 
     419           0 :          >> ring     >> c[1]
     420           0 :          >> sec      >> c[2]
     421           0 :          >> strip    >> c[3]
     422           0 :          >> gain     >> c[4]
     423           0 :          >> error    >> c[5]
     424           0 :          >> chi2ndf;
     425           0 :       lineno++;
     426             :       // Ignore trailing garbage
     427             :       //if(strip > 127) continue;
     428             :       
     429             :       //Setting DDL to comply with the FMD in DAQ
     430             :       // UInt_t FmdDDLBase = 3072; 
     431             :       // ddl = ddl - FmdDDLBase;
     432             :       //Setting the pedestals via the hardware address
     433             :       //   pars->Hardware2Detector(ddl,board,chip,channel,det,ring,sec,str);
     434             : 
     435             :       // strip += str;
     436           0 :       calibGain->Set(det,ring,sec,strip,gain);
     437           0 :     }
     438           0 :   }
     439             :   return calibGain;
     440           0 : }
     441             : //____________________________________________________________________
     442             : AliFMDCalibDeadMap*    
     443             : AliFMDPreprocessor::GetDeadChannelMap(AliFMDCalibPedestal* pedcalib,
     444             :                                       AliFMDCalibGain*     gaincalib) {
     445             :   //creating dead channel map. '0' means 51200 entries
     446           0 :   AliFMDCalibDeadMap* deadmap = new AliFMDCalibDeadMap(0);
     447             :   //deadmap->Reset(kTRUE);
     448             :   Float_t noise = 0;
     449             :   Float_t gain  = 0;
     450             :   
     451           0 :   AliFMDParameters* pars = AliFMDParameters::Instance();
     452             :   //Looping over the channels.
     453           0 :   for(UShort_t det=1;det<=3;det++) {
     454           0 :     Int_t nRings = (det==1 ? 1 : 2);
     455           0 :     for (UShort_t ir = 0; ir < nRings; ir++) {
     456           0 :       Char_t   ring = (ir == 0 ? 'I' : 'O');
     457           0 :       UShort_t nsec = (ir == 0 ? 20  : 40);
     458           0 :       UShort_t nstr = (ir == 0 ? 512 : 256);
     459             :       
     460           0 :       for(UShort_t sec =0; sec < nsec;  sec++) {
     461             :         
     462           0 :         for(UShort_t strip = 0; strip < nstr; strip++) {
     463             :           
     464             :           Bool_t isDead = kFALSE;
     465           0 :           if(pedcalib)
     466           0 :             noise = pedcalib->Width(det, ring, sec, strip);
     467             :           else 
     468           0 :             noise = pars->GetPedestalWidth(det, ring, sec, strip);
     469             :        
     470           0 :           if(gaincalib)
     471           0 :             gain  = gaincalib->Value(det, ring, sec, strip);
     472             :           else 
     473           0 :             gain  = pars->GetPulseGain(det, ring, sec, strip);
     474             :           
     475             :           //marking these channels dead.
     476           0 :           if (gain < 0.5 || gain > 5 || noise > 10 || noise == 0) isDead = kTRUE;
     477             :           
     478           0 :           deadmap->operator()(det, ring, sec, strip) = isDead;
     479             :         }
     480             :       }
     481             :     }
     482             :   }
     483             : 
     484           0 :   return deadmap;
     485           0 : }
     486             : //____________________________________________________________________
     487             : //
     488             : // EOF
     489             : //

Generated by: LCOV version 1.11