splitting the functionality of the TRD calibration components, old component kept...
authorrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 27 Apr 2010 13:53:55 +0000 (13:53 +0000)
committerrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 27 Apr 2010 13:53:55 +0000 (13:53 +0000)
HLT/AliHLTTRDLinkDef.h
HLT/TRD/AliHLTTRDAgent.cxx
HLT/TRD/AliHLTTRDCalibFitComponent.cxx [new file with mode: 0644]
HLT/TRD/AliHLTTRDCalibFitComponent.h [new file with mode: 0644]
HLT/TRD/AliHLTTRDCalibHistoComponent.cxx [new file with mode: 0644]
HLT/TRD/AliHLTTRDCalibHistoComponent.h [new file with mode: 0644]
HLT/libAliHLTTRD.pkg

index 6738f66ac4fd5f87ce3c107f04fe5620d9792e83..a2a00e62c9d8bf3f915af3fb3dfb1e12ac7d1525 100644 (file)
@@ -10,6 +10,8 @@
 #pragma link C++ class AliHLTTRDDefinitions;
 #pragma link C++ class AliHLTTRDEsdWriterComponent;
 #pragma link C++ class AliHLTTRDCalibrationComponent;
+#pragma link C++ class AliHLTTRDCalibFitComponent;
+#pragma link C++ class AliHLTTRDCalibHistoComponent;
 #pragma link C++ class AliHLTTRDUtils;
 #pragma link C++ class AliHLTTRDClusterHistoComponent;
 #pragma link C++ class AliHLTTRDTrackHistoComponent;
index 5f890f7fd9f147085a5b0d5c139c5ed49b5b5139..e04d4abd10db2439817ffbf5c6bb66ed0a1c8968 100644 (file)
@@ -35,6 +35,8 @@ AliHLTTRDAgent gAliHLTTRDAgent;
 #include "AliHLTTRDClusterizerComponent.h"
 #include "AliHLTTRDTrackerV1Component.h"
 #include "AliHLTTRDCalibrationComponent.h"
+#include "AliHLTTRDCalibFitComponent.h"
+#include "AliHLTTRDCalibHistoComponent.h"
 #include "AliHLTTRDEsdWriterComponent.h"
 #include "AliHLTTRDClusterHistoComponent.h"
 #include "AliHLTTRDTrackHistoComponent.h"
@@ -91,6 +93,8 @@ int AliHLTTRDAgent::RegisterComponents(AliHLTComponentHandler* pHandler) const
   pHandler->AddComponent(new AliHLTTRDClusterizerComponent);
   pHandler->AddComponent(new AliHLTTRDTrackerV1Component);
   pHandler->AddComponent(new AliHLTTRDCalibrationComponent);
+  pHandler->AddComponent(new AliHLTTRDCalibFitComponent);
+  pHandler->AddComponent(new AliHLTTRDCalibHistoComponent);
   pHandler->AddComponent(new AliHLTTRDEsdWriterComponent);
   pHandler->AddComponent(new AliHLTTRDClusterHistoComponent);
   pHandler->AddComponent(new AliHLTTRDTrackHistoComponent);
diff --git a/HLT/TRD/AliHLTTRDCalibFitComponent.cxx b/HLT/TRD/AliHLTTRDCalibFitComponent.cxx
new file mode 100644 (file)
index 0000000..942e8b1
--- /dev/null
@@ -0,0 +1,375 @@
+// $Id: AliHLTTRDCalibFitComponent.cxx 40282 2010-04-09 13:29:10Z richterm $
+
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Authors:                                                               *
+ *          for The ALICE HLT Project.                                    *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+//  @file   AliHLTTRDCalibFitComponent.cxx
+//  @author Theodor Rascanu
+//  @date   25.04.2010
+//  @brief  A TRDCalibration fitting component for the HLT. 
+// 
+
+#if __GNUC__ >= 3
+using namespace std;
+#endif
+
+#include "TTree.h"
+#include "TFile.h"
+#include "TBranch.h"
+#include "TH2I.h"
+#include "TH2.h"
+#include "TProfile2D.h"
+
+#include "AliHLTReadoutList.h"
+
+#include "AliHLTTRDCalibFitComponent.h"
+#include "AliHLTTRDDefinitions.h"
+#include "AliHLTTRDUtils.h"
+
+#include "AliRawReaderMemory.h"
+
+#include "AliTRDCalPad.h"
+#include "AliTRDCalDet.h"
+
+#include "AliTRDCalibraFillHisto.h"
+#include "AliTRDtrackV1.h"
+
+#include "AliTRDCalibraFit.h"
+#include "AliTRDCalibraMode.h"
+#include "AliTRDCalibraVector.h"
+#include "AliTRDCalibraVdriftLinearFit.h"
+#include "AliTRDReconstructor.h"
+#include "AliTRDrecoParam.h"
+
+#include <cstdlib>
+#include <cerrno>
+#include <string>
+
+ClassImp(AliHLTTRDCalibFitComponent);
+
+AliHLTTRDCalibFitComponent::AliHLTTRDCalibFitComponent()
+  : AliHLTCalibrationProcessor(),
+    fOutputSize(500000),
+    fOutArray(NULL),
+    fTempArray(NULL),
+    fAfterRunArray(NULL)
+{
+  // Default constructor
+}
+
+AliHLTTRDCalibFitComponent::~AliHLTTRDCalibFitComponent()
+{
+  // Destructor
+}
+
+const char* AliHLTTRDCalibFitComponent::GetComponentID()
+{
+  // Return the component ID const char *
+  return "TRDCalibFit"; // The ID of this component
+}
+
+void AliHLTTRDCalibFitComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
+{
+  // Get the list of input data
+  list.clear(); // We do not have any requirements for our input data type(s).
+  list.push_back(AliHLTTRDDefinitions::fgkCalibrationDataType);
+}
+
+AliHLTComponentDataType AliHLTTRDCalibFitComponent::GetOutputDataType()
+{
+  // Get the output data type
+  return kAliHLTMultipleDataType;
+  //  return AliHLTTRDDefinitions::fgkCalibrationDataType;
+}
+
+int AliHLTTRDCalibFitComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList)
+{
+  // Get the output data type
+  tgtList.clear();
+  tgtList.push_back(AliHLTTRDDefinitions::fgkCalibrationDataType);
+  tgtList.push_back(AliHLTTRDDefinitions::fgkEORCalibrationDataType);
+  return tgtList.size();
+}
+
+void AliHLTTRDCalibFitComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
+{
+  // Get the output data size
+  constBase = fOutputSize;
+  inputMultiplier = 0;
+}
+
+AliHLTComponent* AliHLTTRDCalibFitComponent::Spawn()
+{
+  // Spawn function, return new instance of this class
+  return new AliHLTTRDCalibFitComponent;
+};
+
+Int_t AliHLTTRDCalibFitComponent::InitCalibration()
+{
+  for(int i=0; i<18; i++)
+    fIncSM[i]=kFALSE;
+
+  fOutArray = new TObjArray(4);
+  fAfterRunArray=new TObjArray(5);
+
+  return 0;
+}
+
+Int_t AliHLTTRDCalibFitComponent::DeinitCalibration()
+{
+  
+  // Deinitialization of the component
+  
+  HLTDebug("DeinitCalibration");
+  //fOutArray->Delete();
+  if(fTempArray){
+    delete fTempArray; fTempArray=0;
+  }
+  delete fOutArray; fOutArray=0;
+  fAfterRunArray->Delete();
+  delete fAfterRunArray; fAfterRunArray=0;
+  return 0;
+}
+
+Int_t AliHLTTRDCalibFitComponent::ProcessCalibration(const AliHLTComponent_EventData& /*evtData*/,
+                                                        const AliHLTComponent_BlockData* /*blocks*/,
+                                                        AliHLTComponent_TriggerData& /*trigData*/,
+                                                        AliHLTUInt8_t* /*outputPtr*/,
+                                                        AliHLTUInt32_t& /*size*/,
+                                                        vector<AliHLTComponent_BlockData>& /*outputBlocks*/)
+{
+  // Process an event
+
+  if(!IsDataEvent())return 0;
+
+  int lastSM = -1;
+
+  for(const TObject* iter = GetFirstInputObject(AliHLTTRDDefinitions::fgkCalibrationDataType);
+      iter != NULL; iter = GetNextInputObject() ) {
+
+    if(!dynamic_cast<const TObjArray*>(iter))
+      continue;
+
+    AliHLTUInt32_t spec = GetSpecification(iter);
+    int SM = AliHLTTRDUtils::GetSM(spec);
+
+    HLTInfo("Got Data from SM %i", SM);
+
+    if(SM!=lastSM){
+      if(fIncSM[SM]){
+       PushBack(fTempArray, AliHLTTRDDefinitions::fgkCalibrationDataType);
+       fOutArray->Delete();
+       delete fOutArray;
+       fOutArray = fTempArray;
+       fTempArray = NULL;
+       for(int i=0; i<18; i++)
+         fIncSM[i]=kFALSE;
+      }
+      lastSM = SM;
+      fIncSM[SM]=kTRUE;
+    }
+
+    if(!fTempArray) fTempArray = (TObjArray*)iter->Clone();
+    else{
+      TObjArray* inArr = (TObjArray*)iter;
+      for(int i = inArr->GetEntriesFast(); i--;){
+       const TH1* histo = dynamic_cast<const TH1*>(inArr->At(i));
+       if(histo){
+         if(fTempArray->At(i)){
+           ((TH1*)fTempArray->At(i))->Add(histo);
+         }else{
+           fTempArray->AddAt(histo->Clone(), i);
+         }
+         continue;
+       }
+       AliTRDCalibraVdriftLinearFit* obj = dynamic_cast<AliTRDCalibraVdriftLinearFit*>(inArr->At(i));
+       if(obj){
+         if(fTempArray->At(i)){
+           ((AliTRDCalibraVdriftLinearFit*)fTempArray->At(i))->Add(obj);
+         }else{
+           fTempArray->AddAt(new AliTRDCalibraVdriftLinearFit(*obj), i);
+         }
+       }
+      }
+    }
+
+  }
+
+  return 0;
+}
+
+Int_t AliHLTTRDCalibFitComponent::ShipDataToFXS(const AliHLTComponentEventData& /*evtData*/, AliHLTComponentTriggerData& /*trigData*/)
+{
+  //fTRDCalibraFillHisto->DestroyDebugStreamer();
+
+  AliHLTReadoutList rdList(AliHLTReadoutList::kTRD);
+
+  EORCalibration();
+  
+  fOutArray->Remove(fOutArray->FindObject("AliTRDCalibraVdriftLinearFit"));
+  //fOutArray->Remove(fOutArray->FindObject("PRF2d"));
+  //fOutArray->Remove(fOutArray->FindObject("PH2d"));
+  //fOutArray->Remove(fOutArray->FindObject("CH2d"));
+
+  if(!(fOutArray->FindObject("CH2d"))) {
+    TH2I * ch2d = new TH2I("CH2d","Nz0Nrphi0",100,0.0,300.0,540,0,540);
+    fOutArray->Add(ch2d);
+  }
+
+  if(!(fOutArray->FindObject("PH2d"))) {
+    TProfile2D * ph2d = new TProfile2D("PH2d","Nz0Nrphi0",30,-0.05,2.95,540,0,540);
+    fOutArray->Add(ph2d);
+  }
+
+  if(!(fOutArray->FindObject("PRF2d"))) {
+    TProfile2D * prf2d = new TProfile2D("PRF2d","Nz0Nrphi0Ngp3",60,-9.0,9.0,540,0,540);
+    fOutArray->Add(prf2d);
+  }
+
+  HLTDebug("Size of the fOutArray is %d\n",fOutArray->GetEntriesFast());
+
+  PushToFXS((TObject*)fOutArray, "TRD", "GAINDRIFTPRF", rdList.Buffer() );
+  //PushToFXS((TObject*)fOutArray->FindObject("CH2d"), "TRD", "GAINDRIFTPRF", rdList.Buffer() );
+
+  return 0;
+}
+
+Int_t AliHLTTRDCalibFitComponent::EORCalibration()
+{
+  //Also Fill histograms for the online display
+  TH2I *hCH2d=(TH2I*)fOutArray->FindObject("CH2d");
+  TProfile2D *hPH2d=(TProfile2D*)fOutArray->FindObject("PH2d");
+  TProfile2D *hPRF2d= (TProfile2D*)fOutArray->FindObject("PRF2d");
+  AliTRDCalibraVdriftLinearFit* hVdriftLinearFit = (AliTRDCalibraVdriftLinearFit*)fOutArray->FindObject("AliTRDCalibraVdriftLinearFit");
+
+  if(!hCH2d || !hPH2d || !hPRF2d || !hVdriftLinearFit) return 0; 
+
+  //Fit
+  AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
+
+  //Gain
+  calibra->SetMinEntries(100);
+  calibra->AnalyseCH(hCH2d);
+  Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(0))
+    + 6*  18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(0));
+  Int_t nbfit       = calibra->GetNumberFit();
+  Int_t nbE         = calibra->GetNumberEnt();
+  TH1F *coefgain = 0x0;
+  // enough statistics
+  //if ((nbtg >                  0) && 
+  //   (nbfit        >= 0.2*nbE)) {
+  // create the cal objects
+  //calibra->PutMeanValueOtherVectorFit(1,kTRUE);
+  TObjArray object           = calibra->GetVectorFit();
+  AliTRDCalDet *objgaindet   = calibra->CreateDetObjectGain(&object,kFALSE);
+  coefgain                   = objgaindet->MakeHisto1DAsFunctionOfDet();
+  //}
+  calibra->ResetVectorFit();
+
+  // vdrift second method
+  calibra->SetMinEntries(100); // If there is less than 100
+  hVdriftLinearFit->FillPEArray();
+  calibra->AnalyseLinearFitters(hVdriftLinearFit);
+  nbtg = 540;
+  nbfit = calibra->GetNumberFit();
+  nbE   = calibra->GetNumberEnt();
+  TH1F *coefdriftsecond = 0x0;
+  // enough statistics
+  //if ((nbtg >                  0) && 
+  // (nbfit        >= 0.1*nbE)) {
+  // create the cal objects
+  //calibra->PutMeanValueOtherVectorFit(1,kTRUE);
+  object  = calibra->GetVectorFit();
+  AliTRDCalDet *objdriftvelocitydetsecond = calibra->CreateDetObjectVdrift(&object,kTRUE);
+  objdriftvelocitydetsecond->SetTitle("secondmethodvdrift");
+  coefdriftsecond  = objdriftvelocitydetsecond->MakeHisto1DAsFunctionOfDet();
+  //}
+  calibra->ResetVectorFit();
+  
+  // vdrift first method
+  calibra->SetMinEntries(100*20); // If there is less than 20000
+  calibra->AnalysePH(hPH2d);
+  nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(1))
+    + 6*  18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(1));
+  nbfit        = calibra->GetNumberFit();
+  nbE          = calibra->GetNumberEnt();
+  TH1F *coefdrift = 0x0;
+  TH1F *coeft0 = 0x0;
+  // enough statistics
+  //if ((nbtg >                  0) && 
+  // (nbfit        >= 0.2*nbE)) {
+  // create the cal objects
+  //calibra->PutMeanValueOtherVectorFit(1,kTRUE);
+  //calibra->PutMeanValueOtherVectorFit2(1,kTRUE);
+  object  = calibra->GetVectorFit();
+  AliTRDCalDet *objdriftvelocitydet = calibra->CreateDetObjectVdrift(&object,kTRUE);
+  coefdrift        = objdriftvelocitydet->MakeHisto1DAsFunctionOfDet();
+  object              = calibra->GetVectorFit2();
+  AliTRDCalDet *objtime0det  = calibra->CreateDetObjectT0(&object,kTRUE);
+  coeft0        = objtime0det->MakeHisto1DAsFunctionOfDet();
+  //}
+  calibra->ResetVectorFit();
+           
+
+  //PRF
+  calibra->SetMinEntries(200); 
+  calibra->AnalysePRFMarianFit(hPRF2d);
+  nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(2))
+    + 6*  18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(2));
+  nbfit        = calibra->GetNumberFit();
+  nbE          = calibra->GetNumberEnt();
+  TH1F *coefprf = 0x0;
+  // enough statistics
+  //if ((nbtg >                  0) && 
+  //  (nbfit        >= 0.95*nbE)) {
+  // create cal pad objects 
+  object            = calibra->GetVectorFit();
+  TObject *objPRFpad          = calibra->CreatePadObjectPRF(&object);
+  coefprf                     = ((AliTRDCalPad *) objPRFpad)->MakeHisto1D();
+  //}
+  calibra->ResetVectorFit();
+
+
+  coefgain->SetName("coefgain");
+  coefprf->SetName("coefprf");
+  coefdrift->SetName("coefdrift");
+  coefdriftsecond->SetName("coefdriftsecond");
+  coeft0->SetName("coeft0");
+  if(coefgain) fAfterRunArray->Add(coefgain);
+  if(coefprf) fAfterRunArray->Add(coefprf);
+  if(coefdrift) fAfterRunArray->Add(coefdrift);
+  if(coefdriftsecond) fAfterRunArray->Add(coefdriftsecond);
+  if(coeft0) fAfterRunArray->Add(coeft0);
+  
+
+  if(coefgain||coefprf||coefdrift||coeft0||coefdriftsecond) {
+    PushBack(fAfterRunArray, AliHLTTRDDefinitions::fgkEORCalibrationDataType);
+  }
+
+  // TString fileName="/tmp/CalibHistoDump_run";
+  // fileName+=AliCDBManager::Instance()->GetRun();
+  // fileName+=".root";
+  // HLTInfo("Dumping Histogram file to %s",fileName.Data());
+  // TFile* file = TFile::Open(fileName, "RECREATE");
+  // fAfterRunArray->Write();
+  // fOutArray->Write();
+  // file->Close();
+  // HLTInfo("Histogram file dumped");
+
+  return 0;
+}      
+
diff --git a/HLT/TRD/AliHLTTRDCalibFitComponent.h b/HLT/TRD/AliHLTTRDCalibFitComponent.h
new file mode 100644 (file)
index 0000000..37928a0
--- /dev/null
@@ -0,0 +1,90 @@
+//-*- Mode: C++ -*-
+// $Id: AliHLTTRDCalibFitComponent.h 40269 2010-04-08 22:08:53Z richterm $
+
+#ifndef ALIHLTTRDCALIBFITCOMPONENT_H
+#define ALIHLTTRDCALIBFITCOMPONENT_H
+//* This file is property of and copyright by the ALICE HLT Project        * 
+//* ALICE Experiment at CERN, All rights reserved.                         *
+//* See cxx source for full Copyright notice                               *
+
+//  @file   AliHLTTRDCalibFitComponent.h
+//  @author 
+//  @date   
+//  @brief  Declaration of a TRDCalibration component. 
+// 
+
+
+#include "AliHLTCalibrationProcessor.h"
+class AliCDBManager;
+class AliTRDCalibraFillHisto;
+class TClonesArray;
+
+/**
+ * @class AliHLTTRDCalibFitComponent
+ * @brief A TRDCalibration HLT processing component. 
+ *
+ * - @ref InitCalibration (optional)
+ * - @ref ScanArgument (optional)
+ * - @ref DeinitCalibration (optional)
+ * - @ref ProcessCalibration
+ * - @ref ShipDataToFXS
+ * - @ref GetComponentID
+ * - @ref GetInputDataTypes
+ * - @ref GetOutputDataType
+ * - @ref GetOutputDataSize
+ * - @ref Spawn
+ * @ingroup alihlt_tutorial
+ */
+class AliHLTTRDCalibFitComponent : public AliHLTCalibrationProcessor
+{
+public:
+  AliHLTTRDCalibFitComponent();
+  virtual ~AliHLTTRDCalibFitComponent();
+
+  // Public functions to implement AliHLTComponent's interface.
+  // These functions are required for the registration process
+
+  const char* GetComponentID();
+  void GetInputDataTypes( vector<AliHLTComponentDataType>& list);
+  AliHLTComponentDataType GetOutputDataType();
+  int GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList);
+  virtual void GetOutputDataSize( unsigned long& constBase, double& inputMultiplier );
+  AliHLTComponent* Spawn();
+       
+protected:
+       
+  // Protected functions to implement AliHLTComponent's interface.
+  // These functions provide initialization as well as the actual processing
+  // capabilities of the component. 
+       
+  virtual Int_t InitCalibration();
+  virtual Int_t DeinitCalibration();
+  virtual Int_t ProcessCalibration(const AliHLTComponent_EventData& evtData,
+                                  const AliHLTComponent_BlockData* blocks,
+                                  AliHLTComponent_TriggerData& trigData, AliHLTUInt8_t* outputPtr,
+                                  AliHLTUInt32_t& size,
+                                  vector<AliHLTComponent_BlockData>& outputBlocks);
+  /*   virtual Int_t ProcessCalibration( const AliHLTComponentEventData& evtData, AliHLTComponentTriggerData& trigData); */
+  virtual Int_t ShipDataToFXS(const AliHLTComponentEventData& evtData, AliHLTComponentTriggerData& trigData);
+  virtual Int_t  EORCalibration();
+       
+  using AliHLTCalibrationProcessor::ProcessCalibration;
+  //using AliHLTCalibrationProcessor::ShipDataToFXS;
+
+private:
+  /** copy constructor prohibited */
+  AliHLTTRDCalibFitComponent(const AliHLTTRDCalibFitComponent&);
+  /** assignment operator prohibited */
+  AliHLTTRDCalibFitComponent& operator=(const AliHLTTRDCalibFitComponent&);
+
+  AliHLTUInt32_t fOutputSize;    // output size
+  TObjArray* fOutArray;          // array containing the output
+  TObjArray* fTempArray;          // array containing the output
+  TObjArray* fAfterRunArray;     // array with after run processing output 
+  Bool_t fIncSM[18];            // array for telling which super module was already added
+  
+  ClassDef(AliHLTTRDCalibFitComponent, 2)
+
+};
+#endif
+
diff --git a/HLT/TRD/AliHLTTRDCalibHistoComponent.cxx b/HLT/TRD/AliHLTTRDCalibHistoComponent.cxx
new file mode 100644 (file)
index 0000000..3910b6f
--- /dev/null
@@ -0,0 +1,444 @@
+// $Id: AliHLTTRDCalibHistoComponent.cxx 40282 2010-04-09 13:29:10Z richterm $
+
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Authors:                                                               *
+ *          for The ALICE HLT Project.                                    *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+//  @file   AliHLTTRDCalibHistoComponent.cxx
+//  @author Theodor Rascanu
+//  @date   25.04.2010
+//  @brief  A TRDCalibration histogramming component for the HLT. 
+// 
+
+#if __GNUC__ >= 3
+using namespace std;
+#endif
+
+#include "TTree.h"
+#include "TFile.h"
+#include "TBranch.h"
+#include "TH2I.h"
+#include "TH2.h"
+#include "TProfile2D.h"
+
+#include "AliHLTReadoutList.h"
+
+#include "AliHLTTRDCalibHistoComponent.h"
+#include "AliHLTTRDDefinitions.h"
+#include "AliHLTTRDUtils.h"
+
+#include "AliCDBManager.h"
+#include "AliCDBStorage.h"
+#include "AliCDBEntry.h"
+#include "AliRawReaderMemory.h"
+
+#include "AliTRDCalPad.h"
+#include "AliTRDCalDet.h"
+
+#include "AliTRDCalibraFillHisto.h"
+#include "AliTRDtrackV1.h"
+
+#include "AliTRDCalibraFit.h"
+#include "AliTRDCalibraMode.h"
+#include "AliTRDCalibraVector.h"
+#include "AliTRDCalibraVdriftLinearFit.h"
+#include "AliTRDReconstructor.h"
+#include "AliTRDrecoParam.h"
+
+#include <cstdlib>
+#include <cerrno>
+#include <string>
+
+ClassImp(AliHLTTRDCalibHistoComponent);
+
+AliHLTTRDCalibHistoComponent::AliHLTTRDCalibHistoComponent()
+  : AliHLTProcessor(),
+    fOutputSize(500000),
+    fSpec(0),
+    fTracksArray(NULL),
+    fOutArray(NULL),
+    fTRDCalibraFillHisto(NULL),
+    fSavedTimeBins(kFALSE),
+    fTrgStrings(NULL),
+    fAccRejTrg(0),
+    fMinClusters(0),
+    fMinTracklets(0),
+    fTakeAllEvents(kFALSE)
+{
+  // Default constructor
+}
+
+AliHLTTRDCalibHistoComponent::~AliHLTTRDCalibHistoComponent()
+{
+  // Destructor
+}
+
+const char* AliHLTTRDCalibHistoComponent::GetComponentID()
+{
+  // Return the component ID const char *
+  return "TRDCalibHisto"; // The ID of this component
+}
+
+void AliHLTTRDCalibHistoComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
+{
+  // Get the list of input data
+  list.clear(); // We do not have any requirements for our input data type(s).
+  list.push_back(AliHLTTRDDefinitions::fgkTracksDataType);
+}
+
+AliHLTComponentDataType AliHLTTRDCalibHistoComponent::GetOutputDataType()
+{
+  // Get the output data type
+  return kAliHLTMultipleDataType;
+  //  return AliHLTTRDDefinitions::fgkCalibrationDataType;
+}
+
+int AliHLTTRDCalibHistoComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList)
+{
+  // Get the output data type
+  tgtList.clear();
+  tgtList.push_back(AliHLTTRDDefinitions::fgkCalibrationDataType);
+  return tgtList.size();
+}
+
+void AliHLTTRDCalibHistoComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
+{
+  // Get the output data size
+  constBase = fOutputSize;
+  inputMultiplier = 0;
+}
+
+AliHLTComponent* AliHLTTRDCalibHistoComponent::Spawn()
+{
+  // Spawn function, return new instance of this class
+  return new AliHLTTRDCalibHistoComponent;
+};
+
+int AliHLTTRDCalibHistoComponent::DoInit( int argc, const char** argv )
+{
+  int iResult=0;
+  if(fTrgStrings)
+    delete fTrgStrings;
+  fTrgStrings = new TObjArray();
+  
+  TString configuration="";
+  TString argument="";
+  for (int i=0; i<argc && iResult>=0; i++) {
+    argument=argv[i];
+    if (!configuration.IsNull()) configuration+=" ";
+    configuration+=argument;
+  }
+
+  if (!configuration.IsNull()) {
+    iResult=Configure(configuration.Data());
+  } else {
+    iResult=Reconfigure(NULL, NULL);
+  }
+  if(iResult>=0){
+    iResult=SetParams();
+  }
+  return iResult;
+}
+
+int AliHLTTRDCalibHistoComponent::Configure(const char* arguments){
+  int iResult=0;
+  if (!arguments) return iResult;
+  
+  TString allArgs=arguments;
+  TString argument;
+  int bMissingParam=0;
+
+  TObjArray* pTokens=allArgs.Tokenize(" ");
+  if (pTokens) {
+    for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
+      argument=((TObjString*)pTokens->At(i))->GetString();
+      if (argument.IsNull()) continue;
+      
+      if (argument.CompareTo("output_size")==0) {
+       if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
+       HLTInfo("Setting output size to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
+       fOutputSize=((TObjString*)pTokens->At(i))->GetString().Atoi();
+       continue;
+      } 
+      else if (argument.CompareTo("-minClusters")==0) {
+       if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
+       HLTInfo("Setting minCusters to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
+       fMinClusters=((TObjString*)pTokens->At(i))->GetString().Atoi();
+       continue;
+      } 
+      else if (argument.CompareTo("-minTracklets")==0) {
+       if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
+       HLTInfo("Setting minTracklets to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
+       fMinTracklets=((TObjString*)pTokens->At(i))->GetString().Atoi();
+       continue;
+      } 
+      else if (argument.CompareTo("-TrgStr")==0) {
+       if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
+       HLTInfo("Select TrgStr: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
+       fTrgStrings->Add(new TObjString(((TObjString*)pTokens->At(i))->GetString().Data()));
+       continue;
+      } 
+      else if (argument.CompareTo("-acceptTrgStr")==0) {
+       fAccRejTrg=1;
+       HLTInfo("Accept selected Trigger Strings only");
+       continue;
+      }
+      else if (argument.CompareTo("-rejectTrgStr")==0) {
+       fAccRejTrg=-1;
+       HLTInfo("Reject all selected Trigger Strings");
+       continue;
+      }
+      else if (argument.CompareTo("-takeAllEvents")==0) {
+       fAccRejTrg=0;
+       fTakeAllEvents = kTRUE;
+       HLTInfo("Take all events independently of the trigger strings");
+       continue;
+      }
+      
+      else {
+       HLTError("unknown argument: %s", argument.Data());
+       iResult=-EINVAL;
+       break;
+      }
+    }
+    delete pTokens;
+  }
+  if (bMissingParam) {
+    HLTError("missing parameter for argument %s", argument.Data());
+    iResult=-EINVAL;
+  }
+  return iResult;
+}
+
+int AliHLTTRDCalibHistoComponent::SetParams()
+{
+
+  if(!fTrgStrings)
+    fTrgStrings = new TObjArray();
+
+  if(!AliCDBManager::Instance()->IsDefaultStorageSet()){
+    HLTError("DefaultStorage is not set in CDBManager");
+    return -EINVAL;
+  }
+  if(AliCDBManager::Instance()->GetRun()<0){
+    HLTError("Run Number is not set in CDBManager");
+    return -EINVAL;
+  }
+  HLTInfo("CDB default storage: %s; RunNo: %i", (AliCDBManager::Instance()->GetDefaultStorage()->GetBaseFolder()).Data(), AliCDBManager::Instance()->GetRun());
+
+  if(fTrgStrings->GetEntriesFast()>0 && !fAccRejTrg){
+    HLTError("Trigger string(s) given, but acceptTrgStr or rejectTrgStr not selected");
+    return -EINVAL;
+  }
+
+  fTRDCalibraFillHisto = AliTRDCalibraFillHisto::Instance();
+  fTRDCalibraFillHisto->SetIsHLT(kTRUE);
+  fTRDCalibraFillHisto->SetHisto2d(); // choose to use histograms
+  fTRDCalibraFillHisto->SetCH2dOn();  // choose to calibrate the gain
+  fTRDCalibraFillHisto->SetPH2dOn();  // choose to calibrate the drift velocity
+  fTRDCalibraFillHisto->SetPRF2dOn(); // choose to look at the PRF
+  fTRDCalibraFillHisto->SetIsHLT(); // per detector
+  //fTRDCalibraFillHisto->SetDebugLevel(1);// debug
+  fTRDCalibraFillHisto->SetFillWithZero(kTRUE);
+  fTRDCalibraFillHisto->SetLinearFitterOn(kTRUE);
+  fTRDCalibraFillHisto->SetNumberBinCharge(100);
+  
+  if(!fTracksArray) fTracksArray = new TClonesArray("AliTRDtrackV1");
+  if(!fOutArray)fOutArray = new TObjArray(4);
+
+  HLTDebug("run SetupCTPData");
+  SetupCTPData();
+
+  return 0;
+}
+
+int AliHLTTRDCalibHistoComponent::DoDeinit()
+{
+  
+  // Deinitialization of the component
+  
+  HLTDebug("DeinitCalibration");
+  delete fTracksArray; fTracksArray=0;
+  //fTRDCalibraFillHisto->Destroy();
+  //fOutArray->Delete();
+  delete fOutArray; fOutArray=0;
+  fTrgStrings->Delete();
+  delete fTrgStrings; fTrgStrings=0;
+  return 0;
+}
+
+Int_t AliHLTTRDCalibHistoComponent::DoEvent(const AliHLTComponent_EventData& /*evtData*/,
+                                           const AliHLTComponent_BlockData* /*blocks*/,
+                                           AliHLTComponent_TriggerData& /*trigData*/,
+                                           AliHLTUInt8_t* /*outputPtr*/,
+                                           AliHLTUInt32_t& /*size*/,
+                                           vector<AliHLTComponent_BlockData>& /*outputBlocks*/)
+{
+  // Process an event
+  TClonesArray* TCAarray[18] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
+  Int_t usedEntries = 0;
+  Int_t blockOrObject = 0;
+  Int_t nTimeBins = -1;
+
+  for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(AliHLTTRDDefinitions::fgkTracksDataType); pBlock; pBlock=GetNextInputBlock()) 
+    {
+      TCAarray[0] = fTracksArray;
+      AliHLTTRDUtils::ReadTracks(TCAarray[0], pBlock->fPtr, pBlock->fSize, &nTimeBins);
+      fSpec |= pBlock->fSpecification;
+      usedEntries = 1;
+      blockOrObject = -1;
+    }  
+
+  for(const TObject *iter = GetFirstInputObject(AliHLTTRDDefinitions::fgkHiLvlTracksDataType); iter; iter = GetNextInputObject()) 
+    {
+      if(blockOrObject<0){
+       HLTError("You may not mix high level and low level!");
+       return -1;
+      }
+
+      TCAarray[usedEntries] = dynamic_cast<TClonesArray*>(const_cast<TObject*>(iter));
+      if(TCAarray[usedEntries])continue;
+      TObjString* strg = dynamic_cast<TObjString*>(const_cast<TObject*>(GetNextInputObject()));
+      if(!strg)continue;
+
+      nTimeBins = strg->String().Atoi();
+      fSpec |= GetSpecification(iter);
+      usedEntries++;
+      blockOrObject = 1;
+    }
+
+  if(!blockOrObject)
+    return 0;
+
+  if(!fSavedTimeBins){
+    if(nTimeBins<0){
+      HLTFatal("Number of timebins is negative!");
+      return -1;
+    }
+    HLTDebug("Saving number of time bins which was read from input block. Value is: %d", nTimeBins);
+    fTRDCalibraFillHisto->Init2Dhistos(nTimeBins); // initialise the histos
+    fTRDCalibraFillHisto->SetNumberClusters(fMinClusters); // At least fMinClusters clusters
+    fTRDCalibraFillHisto->SetNumberClustersf(nTimeBins); // Not more than %d  clusters
+    fSavedTimeBins=kTRUE;
+  }
+
+  Bool_t bTriggerPassed = fTakeAllEvents;
+
+  if(fAccRejTrg){
+    if(fAccRejTrg>0){
+      bTriggerPassed=kFALSE;
+      for(int i = 0; i < fTrgStrings->GetEntriesFast(); i++){
+       const TObjString *const obString=(TObjString*)fTrgStrings->At(i);
+       const TString tString=obString->GetString();
+       if(CheckCTPTrigger(tString.Data())>0){bTriggerPassed=kTRUE; break;}
+      }
+    }
+    else{
+      bTriggerPassed=kTRUE;
+      for(int i = 0; i < fTrgStrings->GetEntriesFast(); i++){
+       const TObjString *const obString=(TObjString*)fTrgStrings->At(i);
+       const TString tString=obString->GetString();
+       if(CheckCTPTrigger(tString.Data())>0){bTriggerPassed=kFALSE; break;}
+      }
+    }
+  }
+  
+  fTRDCalibraFillHisto->SetCH2dOn(bTriggerPassed);
+  fTRDCalibraFillHisto->SetPH2dOn(bTriggerPassed);
+  for(int i=0; i<usedEntries; i++){
+    const TClonesArray *const inArr = TCAarray[i];
+    Int_t nbEntries = inArr->GetEntries();
+    HLTDebug(" %i TRDtracks in tracksArray", nbEntries);
+    AliTRDtrackV1* trdTrack = 0x0;
+    for (Int_t ii = 0; ii < nbEntries; ii++){
+      HLTDebug("%i/%i: ", ii+1, nbEntries);
+      trdTrack = (AliTRDtrackV1*)inArr->At(ii);
+      if(trdTrack->GetNumberOfTracklets()<fMinTracklets)continue;
+      fTRDCalibraFillHisto->UpdateHistogramsV1(trdTrack);
+      // for(int i3=0; i3<7; i3++)
+      //   if(trdTrack->GetTracklet(i3))trdTrack->GetTracklet(i3)->Bootstrap(fReconstructor);
+    }
+  }
+
+  if(!fOutArray->At(0))FormOutput();
+  PushBack(fOutArray, AliHLTTRDDefinitions::fgkCalibrationDataType, fSpec);
+
+  return 0;
+}
+
+/**
+ * Form output array of histrograms
+ */
+//============================================================================
+void AliHLTTRDCalibHistoComponent::FormOutput()
+{
+  // gain histo
+  TH2I *hCH2d = fTRDCalibraFillHisto->GetCH2d();
+  fOutArray->Add(hCH2d);
+  
+  // drift velocity histo
+  TProfile2D *hPH2d = fTRDCalibraFillHisto->GetPH2d();
+  fOutArray->Add(hPH2d);
+  
+  // PRF histo
+  TProfile2D *hPRF2d = fTRDCalibraFillHisto->GetPRF2d();
+  fOutArray->Add(hPRF2d);
+  
+  // Vdrift Linear Fit
+  AliTRDCalibraVdriftLinearFit *hVdriftLinearFitOne=(AliTRDCalibraVdriftLinearFit *)fTRDCalibraFillHisto->GetVdriftLinearFit();
+  fOutArray->Add(hVdriftLinearFitOne);
+  
+  HLTDebug("GetCH2d = 0x%x; NEntries = %i; size = %i", hCH2d, hCH2d->GetEntries(), sizeof(*hCH2d));
+  hCH2d->Print();
+  HLTDebug("GetPH2d = 0x%x; NEntries = %i; size = %i", hPH2d, hPH2d->GetEntries(), sizeof(*hPH2d));
+  hPH2d->Print();
+  HLTDebug("GetPRF2d = 0x%x; NEntries = %i; size = %i", hPRF2d, hPRF2d->GetEntries(), sizeof(*hPRF2d));
+  hPRF2d->Print();
+  HLTDebug("GetVdriftLinearFit = 0x%x; size = %i", hVdriftLinearFitOne, sizeof(hVdriftLinearFitOne)); 
+  
+  HLTDebug("output Array: pointer = 0x%x; NEntries = %i; size = %i", fOutArray, fOutArray->GetEntries(), sizeof(fOutArray));
+   
+}
+
+int AliHLTTRDCalibHistoComponent::Reconfigure(const char* cdbEntry, const char* chainId)
+{
+  // see header file for class documentation
+
+  int iResult=0;
+  const char* path="HLT/ConfigTRD/CalibHistoComponent";
+  const char* defaultNotify="";
+  if (cdbEntry) {
+    path=cdbEntry;
+    defaultNotify=" (default)";
+  }
+  if (path) {
+    HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
+    AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
+    if (pEntry) {
+      TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
+      if (pString) {
+       HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
+       iResult=Configure(pString->GetString().Data());
+      } else {
+       HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
+      }
+    } else {
+      HLTError("cannot fetch object \"%s\" from CDB", path);
+    }
+  }
+
+  return iResult;
+}
diff --git a/HLT/TRD/AliHLTTRDCalibHistoComponent.h b/HLT/TRD/AliHLTTRDCalibHistoComponent.h
new file mode 100644 (file)
index 0000000..f5715c4
--- /dev/null
@@ -0,0 +1,80 @@
+//-*- Mode: C++ -*-
+// $Id: AliHLTTRDCalibHistoComponent.h 40269 2010-04-08 22:08:53Z richterm $
+
+#ifndef ALIHLTTRDCALIBHISTOCOMPONENT_H
+#define ALIHLTTRDCALIBHISTOCOMPONENT_H
+//* This file is property of and copyright by the ALICE HLT Project        * 
+//* ALICE Experiment at CERN, All rights reserved.                         *
+//* See cxx source for full Copyright notice                               *
+
+//  @file   AliHLTTRDCalibHistoComponent.h
+//  @author 
+//  @date   
+//  @brief  Declaration of a TRDCalibration component. 
+// 
+
+
+#include "AliHLTProcessor.h"
+class AliCDBManager;
+class AliTRDCalibraFillHisto;
+class TClonesArray;
+
+class AliHLTTRDCalibHistoComponent : public AliHLTProcessor
+{
+public:
+  AliHLTTRDCalibHistoComponent();
+  virtual ~AliHLTTRDCalibHistoComponent();
+
+  // Public functions to implement AliHLTComponent's interface.
+  // These functions are required for the registration process
+
+  const char* GetComponentID();
+  void GetInputDataTypes( vector<AliHLTComponentDataType>& list);
+  AliHLTComponentDataType GetOutputDataType();
+  int GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList);
+  virtual void GetOutputDataSize( unsigned long& constBase, double& inputMultiplier );
+  AliHLTComponent* Spawn();
+       
+protected:
+       
+  // Protected functions to implement AliHLTComponent's interface.
+  // These functions provide initialization as well as the actual processing
+  // capabilities of the component. 
+       
+  int DoInit( int argc, const char** argv );
+  int DoDeinit();
+  int DoEvent( const AliHLTComponent_EventData& evtData, const AliHLTComponent_BlockData* blocks, 
+              AliHLTComponent_TriggerData& trigData, AliHLTUInt8_t* outputPtr, 
+              AliHLTUInt32_t& size, vector<AliHLTComponent_BlockData>& outputBlocks );
+  int Reconfigure(const char* cdbEntry, const char* chainId);
+
+  using AliHLTProcessor::DoEvent;
+
+  int Configure(const char* arguments);
+  int SetParams();
+  int TakeHistos(Int_t nTimeBins);
+
+private:
+  /** copy constructor prohibited */
+  AliHLTTRDCalibHistoComponent(const AliHLTTRDCalibHistoComponent&);
+  /** assignment operator prohibited */
+  AliHLTTRDCalibHistoComponent& operator=(const AliHLTTRDCalibHistoComponent&);
+  void FormOutput();
+
+  AliHLTUInt32_t fOutputSize;    // output size
+  AliHLTUInt32_t fSpec;         // accumulated specification
+  TClonesArray* fTracksArray;    // array containing the input
+  TObjArray* fOutArray;          // array containing the output
+  AliTRDCalibraFillHisto *fTRDCalibraFillHisto;  // TRD calibration object     
+  Bool_t fSavedTimeBins;         // already saved the number of time bins?
+  TObjArray *fTrgStrings;        // name of trigger classes to accept or reject
+  Int_t  fAccRejTrg;             // do we actually accept or reject the trigger strings?
+  Int_t fMinClusters;           // minimal number of clusters/tracklet accepted to fill histos
+  Int_t fMinTracklets;          // minimal number of tracklets/track accepted to fill histos
+  Bool_t fTakeAllEvents;         // take all events, disregarding the triggers
+  
+  ClassDef(AliHLTTRDCalibHistoComponent, 2)
+
+};
+#endif
+
index e9bcc024b317065c679bce7b88ad30a9426fd6db..dab31496c830874e8b5796654d9fec2645899b47 100644 (file)
@@ -11,6 +11,8 @@ CLASS_HDRS:= \
        AliHLTTRDClusterizer.h \
        AliHLTTRDEsdWriterComponent.h \
        AliHLTTRDCalibrationComponent.h \
+        AliHLTTRDCalibFitComponent.h \
+        AliHLTTRDCalibHistoComponent.h \
        AliHLTTRDCluster.h \
        AliHLTTRDTracklet.h \
        AliHLTTRDTrack.h \