LCOV - code coverage report
Current view: top level - HLT/TRD - AliHLTTRDCalibFitComponent.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 14 144 9.7 %
Date: 2016-06-14 17:26:59 Functions: 7 17 41.2 %

          Line data    Source code
       1             : // $Id: AliHLTTRDCalibFitComponent.cxx 40282 2010-04-09 13:29:10Z richterm $
       2             : 
       3             : /**************************************************************************
       4             :  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
       5             :  *                                                                        *
       6             :  * Authors:                                                               *
       7             :  *          for The ALICE HLT Project.                                    *
       8             :  *                                                                        *
       9             :  * Permission to use, copy, modify and distribute this software and its   *
      10             :  * documentation strictly for non-commercial purposes is hereby granted   *
      11             :  * without fee, provided that the above copyright notice appears in all   *
      12             :  * copies and that both the copyright notice and this permission notice   *
      13             :  * appear in the supporting documentation. The authors make no claims     *
      14             :  * about the suitability of this software for any purpose. It is          *
      15             :  * provided "as is" without express or implied warranty.                  *
      16             :  **************************************************************************/
      17             : 
      18             : //  @file   AliHLTTRDCalibFitComponent.cxx
      19             : //  @author Theodor Rascanu
      20             : //  @date   25.04.2010
      21             : //  @brief  A TRDCalibration fitting component for the HLT. 
      22             : // 
      23             : 
      24             : #include "TTree.h"
      25             : #include "TFile.h"
      26             : #include "TBranch.h"
      27             : #include "TH2I.h"
      28             : #include "TH2.h"
      29             : #include "TProfile2D.h"
      30             : 
      31             : #include "AliHLTReadoutList.h"
      32             : 
      33             : #include "AliHLTTRDCalibFitComponent.h"
      34             : #include "AliHLTTRDDefinitions.h"
      35             : #include "AliHLTTRDUtils.h"
      36             : 
      37             : #include "AliRawReaderMemory.h"
      38             : 
      39             : #include "AliTRDCalPad.h"
      40             : #include "AliTRDCalDet.h"
      41             : 
      42             : #include "AliTRDCalibraFillHisto.h"
      43             : #include "AliTRDtrackV1.h"
      44             : 
      45             : #include "AliTRDCalibraFit.h"
      46             : #include "AliTRDCalibraMode.h"
      47             : #include "AliTRDCalibraVector.h"
      48             : #include "AliTRDCalibraVdriftLinearFit.h"
      49             : #include "AliTRDReconstructor.h"
      50             : #include "AliTRDrecoParam.h"
      51             : 
      52             : #include <cstdlib>
      53             : #include <cerrno>
      54             : #include <string>
      55             : 
      56             : using namespace std;
      57             : 
      58           6 : ClassImp(AliHLTTRDCalibFitComponent);
      59             : 
      60             : AliHLTTRDCalibFitComponent::AliHLTTRDCalibFitComponent()
      61           3 :   : AliHLTCalibrationProcessor(),
      62           3 :     fOutputSize(500000),
      63           3 :     fOutArray(NULL),
      64           3 :     fAfterRunArray(NULL),
      65           3 :     fNoOfSM(0),
      66           3 :     fNoOfIncSM(0)
      67          15 : {
      68             :   // Default constructor
      69             : 
      70         114 :   for(int i=0; i<18; i++)
      71          54 :     fIncSM[i]=kFALSE;
      72             : 
      73           6 : }
      74             : 
      75             : AliHLTTRDCalibFitComponent::~AliHLTTRDCalibFitComponent()
      76          12 : {
      77             :   // Destructor
      78          12 : }
      79             : 
      80             : const char* AliHLTTRDCalibFitComponent::GetComponentID()
      81             : {
      82             :   // Return the component ID const char *
      83         144 :   return "TRDCalibFit"; // The ID of this component
      84             : }
      85             : 
      86             : void AliHLTTRDCalibFitComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
      87             : {
      88             :   // Get the list of input data
      89           0 :   list.clear(); // We do not have any requirements for our input data type(s).
      90           0 :   list.push_back(AliHLTTRDDefinitions::fgkCalibrationDataType);
      91           0 : }
      92             : 
      93             : AliHLTComponentDataType AliHLTTRDCalibFitComponent::GetOutputDataType()
      94             : {
      95             :   // Get the output data type
      96           0 :   return kAliHLTMultipleDataType;
      97             :   //  return AliHLTTRDDefinitions::fgkCalibrationDataType;
      98             :  
      99             : }
     100             : 
     101             : int AliHLTTRDCalibFitComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList)
     102             : {
     103             :   // Get the output data type
     104           0 :   tgtList.clear();
     105           0 :   tgtList.push_back(AliHLTTRDDefinitions::fgkCalibrationDataType);
     106           0 :   tgtList.push_back(AliHLTTRDDefinitions::fgkEORCalibrationDataType);
     107           0 :   return tgtList.size();
     108             : }
     109             : 
     110             : void AliHLTTRDCalibFitComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
     111             : {
     112             :   // Get the output data size
     113           0 :   constBase = fOutputSize;
     114           0 :   inputMultiplier = 0;
     115           0 : }
     116             : 
     117             : AliHLTComponent* AliHLTTRDCalibFitComponent::Spawn()
     118             : {
     119             :   // Spawn function, return new instance of this class
     120           0 :   return new AliHLTTRDCalibFitComponent;
     121           0 : };
     122             : 
     123             : Int_t AliHLTTRDCalibFitComponent::InitCalibration()
     124             : {
     125           0 :   for(int i=0; i<18; i++)
     126           0 :     fIncSM[i]=kFALSE;
     127             : 
     128           0 :   fOutArray = new TObjArray(4);
     129           0 :   fAfterRunArray=new TObjArray(5);
     130             : 
     131           0 :   return 0;
     132           0 : }
     133             : 
     134             : Int_t AliHLTTRDCalibFitComponent::DeinitCalibration()
     135             : {
     136             :   
     137             :   // Deinitialization of the component
     138             :   
     139             :   HLTDebug("DeinitCalibration");
     140             :   //fOutArray->Delete();
     141           0 :   delete fOutArray; fOutArray=0;
     142           0 :   fAfterRunArray->Delete();
     143           0 :   delete fAfterRunArray; fAfterRunArray=0;
     144           0 :   return 0;
     145             : }
     146             : 
     147             : Int_t AliHLTTRDCalibFitComponent::ProcessCalibration(const AliHLTComponent_EventData& /*evtData*/,
     148             :                                                         const AliHLTComponent_BlockData* /*blocks*/,
     149             :                                                         AliHLTComponent_TriggerData& /*trigData*/,
     150             :                                                         AliHLTUInt8_t* /*outputPtr*/,
     151             :                                                         AliHLTUInt32_t& /*size*/,
     152             :                                                         vector<AliHLTComponent_BlockData>& /*outputBlocks*/)
     153             : {
     154             :   // Process an event
     155             : 
     156           0 :   if(!IsDataEvent())return 0;
     157             : 
     158             :   int lastSM = -1;
     159             : 
     160           0 :   for(const TObject* iter = GetFirstInputObject(AliHLTTRDDefinitions::fgkCalibrationDataType);
     161           0 :       iter != NULL; iter = GetNextInputObject() ) {
     162             : 
     163           0 :     if(!dynamic_cast<const TObjArray*>(iter))
     164             :       continue;
     165             : 
     166           0 :     AliHLTUInt32_t spec = GetSpecification(iter);
     167           0 :     int SM = AliHLTTRDUtils::GetSM(spec);
     168             : 
     169           0 :     HLTInfo("Got Data from SM %i", SM);
     170             : 
     171           0 :     if(SM!=lastSM){
     172           0 :       if(fIncSM[SM]){
     173           0 :         if(fNoOfIncSM<fNoOfSM)
     174           0 :           return 0;
     175           0 :         fNoOfSM=fNoOfIncSM;
     176           0 :         PushBack(fOutArray, AliHLTTRDDefinitions::fgkCalibrationDataType);
     177           0 :         fOutArray->Delete();
     178           0 :         delete fOutArray;
     179           0 :         fOutArray = NULL;
     180           0 :         for(int i=0; i<18; i++)
     181           0 :           fIncSM[i]=kFALSE;
     182           0 :         fNoOfIncSM=0;
     183           0 :       }
     184             :       lastSM = SM;
     185           0 :       fIncSM[SM]=kTRUE;
     186           0 :       fNoOfIncSM++;
     187           0 :     }
     188             : 
     189           0 :     if(!fOutArray) fOutArray = (TObjArray*)iter->Clone();
     190             :     else{
     191           0 :       TObjArray* inArr = (TObjArray*)iter;
     192           0 :       for(int i = inArr->GetEntriesFast(); i--;){
     193           0 :         const TH1* histo = dynamic_cast<const TH1*>(inArr->At(i));
     194           0 :         if(histo){
     195           0 :           if(fOutArray->At(i)){
     196           0 :             ((TH1*)fOutArray->At(i))->Add(histo);
     197           0 :           }else{
     198           0 :             fOutArray->AddAt(histo->Clone(), i);
     199             :           }
     200           0 :           continue;
     201             :         }
     202           0 :         AliTRDCalibraVdriftLinearFit* obj = dynamic_cast<AliTRDCalibraVdriftLinearFit*>(inArr->At(i));
     203           0 :         if(obj){
     204           0 :           if(fOutArray->At(i)){
     205           0 :             ((AliTRDCalibraVdriftLinearFit*)fOutArray->At(i))->Add(obj);
     206           0 :           }else{
     207           0 :             fOutArray->AddAt(new AliTRDCalibraVdriftLinearFit(*obj), i);
     208             :           }
     209             :         }
     210           0 :       }
     211             :     }
     212             : 
     213           0 :   }
     214             : 
     215           0 :   return 0;
     216           0 : }
     217             : 
     218             : Int_t AliHLTTRDCalibFitComponent::ShipDataToFXS(const AliHLTComponentEventData& /*evtData*/, AliHLTComponentTriggerData& /*trigData*/)
     219             : {
     220           0 :   AliHLTReadoutList rdList(AliHLTReadoutList::kTRD);
     221             : 
     222           0 :   EORCalibration();
     223             :   
     224           0 :   fOutArray->Remove(fOutArray->FindObject("AliTRDCalibraVdriftLinearFit"));
     225             :   //fOutArray->Remove(fOutArray->FindObject("PRF2d"));
     226             :   //fOutArray->Remove(fOutArray->FindObject("PH2d"));
     227             :   //fOutArray->Remove(fOutArray->FindObject("CH2d"));
     228             : 
     229           0 :   if(!(fOutArray->FindObject("CH2d"))) {
     230           0 :     TH2I * ch2d = new TH2I("CH2d","Nz0Nrphi0",100,0.0,300.0,540,0,540);
     231           0 :     fOutArray->Add(ch2d);
     232           0 :   }
     233             : 
     234           0 :   if(!(fOutArray->FindObject("PH2d"))) {
     235           0 :     TProfile2D * ph2d = new TProfile2D("PH2d","Nz0Nrphi0",30,-0.05,2.95,540,0,540);
     236           0 :     fOutArray->Add(ph2d);
     237           0 :   }
     238             : 
     239           0 :   if(!(fOutArray->FindObject("PRF2d"))) {
     240           0 :     TProfile2D * prf2d = new TProfile2D("PRF2d","Nz0Nrphi0Ngp3",60,-9.0,9.0,540,0,540);
     241           0 :     fOutArray->Add(prf2d);
     242           0 :   }
     243             : 
     244             :   HLTDebug("Size of the fOutArray is %d\n",fOutArray->GetEntriesFast());
     245             : 
     246           0 :   PushToFXS((TObject*)fOutArray, "TRD", "GAINDRIFTPRF", &rdList );
     247             :   //PushToFXS((TObject*)fOutArray->FindObject("CH2d"), "TRD", "GAINDRIFTPRF", rdList.Buffer() );
     248             : 
     249             :   return 0;
     250           0 : }
     251             : 
     252             : Int_t AliHLTTRDCalibFitComponent::EORCalibration()
     253             : {
     254             :   //Also Fill histograms for the online display
     255           0 :   TH2I *hCH2d=(TH2I*)fOutArray->FindObject("CH2d");
     256           0 :   TProfile2D *hPH2d=(TProfile2D*)fOutArray->FindObject("PH2d");
     257           0 :   TProfile2D *hPRF2d= (TProfile2D*)fOutArray->FindObject("PRF2d");
     258           0 :   AliTRDCalibraVdriftLinearFit* hVdriftLinearFit = (AliTRDCalibraVdriftLinearFit*)fOutArray->FindObject("AliTRDCalibraVdriftLinearFit");
     259             :  
     260             : 
     261           0 :   if(!hCH2d || !hPH2d || !hPRF2d || !hVdriftLinearFit) return 0; 
     262             : 
     263             :   //Fit
     264           0 :   AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
     265             : 
     266             :   //Gain
     267           0 :   calibra->SetMinEntries(100);
     268           0 :   calibra->AnalyseCH(hCH2d);
     269             :   //Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(0))
     270             :   //  + 6*  18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(0));
     271             :   //Int_t nbfit       = calibra->GetNumberFit();
     272             :   //Int_t nbE         = calibra->GetNumberEnt();
     273             :   TH1F *coefgain = 0x0;
     274             :   // enough statistics
     275             :   //if ((nbtg >                  0) && 
     276             :   //   (nbfit        >= 0.2*nbE)) {
     277             :   // create the cal objects
     278             :   //calibra->PutMeanValueOtherVectorFit(1,kTRUE);
     279           0 :   TObjArray object           = calibra->GetVectorFit();
     280           0 :   AliTRDCalDet *objgaindet   = calibra->CreateDetObjectGain(&object,kFALSE);
     281           0 :   coefgain                   = objgaindet->MakeHisto1DAsFunctionOfDet();
     282             :   //}
     283           0 :   calibra->ResetVectorFit();
     284             : 
     285             :   // vdrift second method
     286           0 :   calibra->SetMinEntries(100); // If there is less than 100
     287           0 :   hVdriftLinearFit->FillPEArray();
     288           0 :   calibra->AnalyseLinearFitters(hVdriftLinearFit);
     289             :   //nbtg = 540;
     290             :   //nbfit = calibra->GetNumberFit();
     291             :   //nbE   = calibra->GetNumberEnt();
     292             :   TH1F *coefdriftsecond = 0x0;
     293             :   // enough statistics
     294             :   //if ((nbtg >                  0) && 
     295             :   // (nbfit        >= 0.1*nbE)) {
     296             :   // create the cal objects
     297             :   //calibra->PutMeanValueOtherVectorFit(1,kTRUE);
     298           0 :   object  = calibra->GetVectorFit();
     299           0 :   AliTRDCalDet *objdriftvelocitydetsecond = calibra->CreateDetObjectVdrift(&object,kTRUE);
     300           0 :   objdriftvelocitydetsecond->SetTitle("secondmethodvdrift");
     301           0 :   coefdriftsecond  = objdriftvelocitydetsecond->MakeHisto1DAsFunctionOfDet();
     302             :   //}
     303           0 :   calibra->ResetVectorFit();
     304             :   
     305             :   // vdrift first method
     306           0 :   calibra->SetMinEntries(100*20); // If there is less than 20000
     307           0 :   calibra->AnalysePH(hPH2d);
     308             :   //nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(1))
     309             :   //  + 6*  18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(1));
     310             :   //nbfit        = calibra->GetNumberFit();
     311             :   //nbE          = calibra->GetNumberEnt();
     312             :   TH1F *coefdrift = 0x0;
     313             :   TH1F *coeft0 = 0x0;
     314             :   // enough statistics
     315             :   //if ((nbtg >                  0) && 
     316             :   // (nbfit        >= 0.2*nbE)) {
     317             :   // create the cal objects
     318             :   //calibra->PutMeanValueOtherVectorFit(1,kTRUE);
     319             :   //calibra->PutMeanValueOtherVectorFit2(1,kTRUE);
     320           0 :   object  = calibra->GetVectorFit();
     321           0 :   AliTRDCalDet *objdriftvelocitydet = calibra->CreateDetObjectVdrift(&object,kTRUE);
     322           0 :   coefdrift        = objdriftvelocitydet->MakeHisto1DAsFunctionOfDet();
     323           0 :   object              = calibra->GetVectorFit2();
     324           0 :   AliTRDCalDet *objtime0det  = calibra->CreateDetObjectT0(&object,kTRUE);
     325           0 :   coeft0        = objtime0det->MakeHisto1DAsFunctionOfDet();
     326             :   //}
     327           0 :   calibra->ResetVectorFit();
     328             :            
     329             : 
     330             :   //PRF
     331           0 :   calibra->SetMinEntries(200); 
     332           0 :   calibra->AnalysePRFMarianFit(hPRF2d);
     333             :   //nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(2))
     334             :   //  + 6*  18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(2));
     335             :   //nbfit        = calibra->GetNumberFit();
     336             :   //nbE          = calibra->GetNumberEnt();
     337             :   TH1F *coefprf = 0x0;
     338             :   // enough statistics
     339             :   //if ((nbtg >                  0) && 
     340             :   //  (nbfit        >= 0.95*nbE)) {
     341             :   // create cal pad objects 
     342           0 :   object            = calibra->GetVectorFit();
     343           0 :   TObject *objPRFpad          = calibra->CreatePadObjectPRF(&object);
     344           0 :   coefprf                     = ((AliTRDCalPad *) objPRFpad)->MakeHisto1D();
     345             :   //}
     346           0 :   calibra->ResetVectorFit();
     347             : 
     348             : 
     349           0 :   coefgain->SetName("coefgain");
     350           0 :   coefprf->SetName("coefprf");
     351           0 :   coefdrift->SetName("coefdrift");
     352           0 :   coefdriftsecond->SetName("coefdriftsecond");
     353           0 :   coeft0->SetName("coeft0");
     354           0 :   fAfterRunArray->Add(coefgain);
     355           0 :   fAfterRunArray->Add(coefprf);
     356           0 :   fAfterRunArray->Add(coefdrift);
     357           0 :   fAfterRunArray->Add(coefdriftsecond);
     358           0 :   fAfterRunArray->Add(coeft0);
     359             :   
     360           0 :   PushBack(fAfterRunArray, AliHLTTRDDefinitions::fgkEORCalibrationDataType);
     361             : 
     362             :   // TString fileName="/tmp/CalibHistoDump_run";
     363             :   // fileName+=AliCDBManager::Instance()->GetRun();
     364             :   // fileName+=".root";
     365             :   // HLTInfo("Dumping Histogram file to %s",fileName.Data());
     366             :   // TFile* file = TFile::Open(fileName, "RECREATE");
     367             :   // fAfterRunArray->Write();
     368             :   // fOutArray->Write();
     369             :   // file->Close();
     370             :   // HLTInfo("Histogram file dumped");
     371             : 
     372             :   return 0;
     373           0 : }       
     374             : 

Generated by: LCOV version 1.11