read magnetic field from local GRP
[u/mrichter/AliRoot.git] / HLT / TRD / AliHLTTRDCalibrationComponent.cxx
CommitLineData
95259bbb 1// $Id$
2
3/**************************************************************************
4 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5 * *
6 * Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
7 * Timm Steinbeck <timm@kip.uni-heidelberg.de> *
8 * for The ALICE Off-line Project. *
9 * *
10 * Permission to use, copy, modify and distribute this software and its *
11 * documentation strictly for non-commercial purposes is hereby granted *
12 * without fee, provided that the above copyright notice appears in all *
13 * copies and that both the copyright notice and this permission notice *
14 * appear in the supporting documentation. The authors make no claims *
15 * about the suitability of this software for any purpose. It is *
16 * provided "as is" without express or implied warranty. *
17 **************************************************************************/
18
19/** @file AliHLTTRDCalibrationComponent.cxx
20 @author Timm Steinbeck, Matthias Richter
dc2e6604 21 @date
95259bbb 22 @brief A TRDCalibration processing component for the HLT. */
23
24#if __GNUC__ >= 3
775f67d7 25using namespace std;
95259bbb 26#endif
27
28#include "TTree.h"
29#include "TFile.h"
30#include "TBranch.h"
31
32#include "AliHLTTRDCalibrationComponent.h"
33#include "AliHLTTRDDefinitions.h"
dc2e6604 34#include "AliHLTTRDUtils.h"
95259bbb 35
36#include "AliCDBManager.h"
775f67d7 37#include "AliCDBStorage.h"
95259bbb 38#include "AliRawReaderMemory.h"
9aea5deb 39#include "AliTRDCalibraFillHisto.h"
dc2e6604 40#include "AliTRDtrackV1.h"
95259bbb 41
42#include <cstdlib>
43#include <cerrno>
44#include <string>
45
46// this is a global object used for automatic component registration, do not use this
47AliHLTTRDCalibrationComponent gAliHLTTRDCalibrationComponent;
48
49ClassImp(AliHLTTRDCalibrationComponent);
dc2e6604 50
d679dd6c 51AliHLTTRDCalibrationComponent::AliHLTTRDCalibrationComponent():
775f67d7 52 AliHLTCalibrationProcessor(),
53 fTRDCalibraFillHisto(NULL),
54 fOutputPercentage(100) // By default we copy to the output exactly what we got as input
95259bbb 55{
775f67d7 56 // Default constructor
95259bbb 57}
58
59AliHLTTRDCalibrationComponent::~AliHLTTRDCalibrationComponent()
60{
775f67d7 61 // Destructor
62 ;
95259bbb 63}
64
65const char* AliHLTTRDCalibrationComponent::GetComponentID()
66{
775f67d7 67 // Return the component ID const char *
68 return "TRDCalibration"; // The ID of this component
95259bbb 69}
70
71void AliHLTTRDCalibrationComponent::GetInputDataTypes( vector<AliHLTComponent_DataType>& list)
72{
775f67d7 73 // Get the list of input data
74 list.clear(); // We do not have any requirements for our input data type(s).
75 list.push_back( AliHLTTRDDefinitions::fgkTRDSATracksDataType );
95259bbb 76}
77
78AliHLTComponent_DataType AliHLTTRDCalibrationComponent::GetOutputDataType()
79{
775f67d7 80 // Get the output data type
81 return AliHLTTRDDefinitions::fgkCalibrationDataType;
95259bbb 82}
83
84void AliHLTTRDCalibrationComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
85{
775f67d7 86 // Get the output data size
87 constBase = 0;
88 inputMultiplier = ((double)fOutputPercentage)/100.0;
95259bbb 89}
90
91AliHLTComponent* AliHLTTRDCalibrationComponent::Spawn()
92{
775f67d7 93 // Spawn function, return new instance of this class
94 return new AliHLTTRDCalibrationComponent;
95259bbb 95};
96
97Int_t AliHLTTRDCalibrationComponent::ScanArgument( int argc, const char** argv )
98{
775f67d7 99 // perform initialization. We check whether our relative output size is specified in the arguments.
100 int i = 0;
101 char* cpErr;
102 while ( i < argc )
103 {
104 HLTDebug("argv[%d] == %s", i, argv[i] );
105 if ( !strcmp( argv[i], "output_percentage" ) )
dc2e6604 106 {
775f67d7 107 if ( i+1>=argc )
108 {
109 HLTError("Missing output_percentage parameter");
110 return ENOTSUP;
dc2e6604 111 }
775f67d7 112 HLTDebug("argv[%d+1] == %s", i, argv[i+1] );
113 fOutputPercentage = strtoul( argv[i+1], &cpErr, 0 );
114 if ( *cpErr )
115 {
116 HLTError("Cannot convert output_percentage parameter '%s'", argv[i+1] );
117 return EINVAL;
118 }
119 HLTInfo("Output percentage set to %lu %%", fOutputPercentage );
120 i += 2;
121 continue;
dc2e6604 122 }
775f67d7 123 else {
124 HLTError("Unknown option '%s'", argv[i] );
125 return EINVAL;
126 }
127 }
128 return 0;
95259bbb 129}
130
131Int_t AliHLTTRDCalibrationComponent::InitCalibration()
132{
775f67d7 133 if(!AliCDBManager::Instance()->IsDefaultStorageSet()){
134 HLTError("DefaultStorage is not Set in CDBManager");
135 return -1;
136 }
137 if(AliCDBManager::Instance()->GetRun()<0){
138 AliCDBManager *cdb = AliCDBManager::Instance();
139 if (cdb)
140 {
141 cdb->SetRun(0);
142 HLTWarning("Setting CDB Runnumber to 0. CDB instance 0x%x", cdb);
143 }
dc2e6604 144 else
775f67d7 145 {
146 HLTError("Could not get CDB instance", "cdb 0x%x", cdb);
147 return -1;
148 }
149 }
150 HLTInfo("CDB default storage: %s; RunNo: %i", (AliCDBManager::Instance()->GetDefaultStorage()->GetBaseFolder()).Data(), AliCDBManager::Instance()->GetRun());
151
152
153 fTRDCalibraFillHisto = AliTRDCalibraFillHisto::Instance();
154 fTRDCalibraFillHisto->SetHisto2d(); // choose to use histograms
155 fTRDCalibraFillHisto->SetCH2dOn(); // choose to calibrate the gain
156 fTRDCalibraFillHisto->SetPH2dOn(); // choose to calibrate the drift velocity
157 fTRDCalibraFillHisto->SetPRF2dOn(); // choose to look at the PRF
158 fTRDCalibraFillHisto->Init2Dhistos(); // initialise the histos
159 return 0;
95259bbb 160}
161
162Int_t AliHLTTRDCalibrationComponent::DeinitCalibration()
163{
775f67d7 164 HLTDebug("DeinitCalibration");
dc2e6604 165
775f67d7 166 // Deinitialization of the component
dc2e6604 167
775f67d7 168 return 0;
95259bbb 169}
170
d679dd6c 171Int_t AliHLTTRDCalibrationComponent::ProcessCalibration(const AliHLTComponent_EventData& evtData,
dc2e6604 172 const AliHLTComponent_BlockData* blocks,
173 AliHLTComponent_TriggerData& /*trigData*/,
174 AliHLTUInt8_t* /*outputPtr*/,
175 AliHLTUInt32_t& /*size*/,
176 vector<AliHLTComponent_BlockData>& /*outputBlocks*/)
95259bbb 177{
775f67d7 178 HLTDebug("NofBlocks %lu", evtData.fBlockCnt );
179 // Process an event
180
181 // Loop over all input blocks in the event
182 vector<AliHLTComponent_DataType> expectedDataTypes;
183 GetInputDataTypes(expectedDataTypes);
184 for ( unsigned long iBlock = 0; iBlock < evtData.fBlockCnt; iBlock++ )
185 {
186 const AliHLTComponentBlockData &block = blocks[iBlock];
187 AliHLTComponentDataType inputDataType = block.fDataType;
188 Bool_t correctDataType = kFALSE;
189
190 for(UInt_t i = 0; i < expectedDataTypes.size(); i++)
191 if( expectedDataTypes.at(i) == inputDataType)
192 correctDataType = kTRUE;
193 if (!correctDataType) {
194 HLTDebug( "Block # %i/%i; Event 0x%08LX (%Lu) Wrong received datatype: %s - Skipping",
195 iBlock, evtData.fBlockCnt,
196 evtData.fEventID, evtData.fEventID,
197 DataType2Text(inputDataType).c_str());
198 continue;
199 }
200 else {
201 HLTDebug("We get the right data type: Block # %i/%i; Event 0x%08LX (%Lu) Received datatype: %s",
202 iBlock, evtData.fBlockCnt-1,
203 evtData.fEventID, evtData.fEventID,
204 DataType2Text(inputDataType).c_str());
205 }
206
207 TClonesArray* tracksArray = NULL;
208 tracksArray = new TClonesArray("AliTRDtrackV1");
209 HLTDebug("BLOCK fPtr 0x%x, fOffset %i, fSize %i, fSpec 0x%x, fDataType %s", block.fPtr, block.fOffset, block.fSize, block.fSpecification, DataType2Text(block.fDataType).c_str());
210 AliHLTTRDUtils::ReadTracks(tracksArray, block.fPtr, block.fSize);
211
212 if (tracksArray) {
213 Int_t nbEntries = tracksArray->GetEntries();
214 HLTDebug(" %i TRDtracks in tracksArray", nbEntries);
215 AliTRDtrackV1* trdTrack = 0x0;
216 for (Int_t i = 0; i < nbEntries; i++){
217 HLTDebug("%i/%i: ", i+1, nbEntries);
218 trdTrack = (AliTRDtrackV1*)tracksArray->At(i);
219 trdTrack->Print();
220 fTRDCalibraFillHisto->UpdateHistogramsV1(trdTrack);
221 }
222 }
dc2e6604 223
224
775f67d7 225 TObjArray *outArray = FormOutput();
226 if (outArray) {
227 PushBack(outArray, AliHLTTRDDefinitions::fgkCalibrationDataType);
228 delete outArray;
229 }
dc2e6604 230
775f67d7 231 }
232 return 0;
dc2e6604 233
95259bbb 234}
235
dc2e6604 236
d679dd6c 237/**
dc2e6604 238 * Form output array of histrograms
d679dd6c 239 */
240//============================================================================
dc2e6604 241TObjArray* AliHLTTRDCalibrationComponent::FormOutput()
d679dd6c 242{
775f67d7 243 TObjArray *outArray=new TObjArray(3);
d679dd6c 244
775f67d7 245 // gain histo
246 TH2I *hCH2d = fTRDCalibraFillHisto->GetCH2d();
247 outArray->Add(hCH2d);
d679dd6c 248
775f67d7 249 // drift velocity histo
250 TProfile2D *hPH2d = fTRDCalibraFillHisto->GetPH2d();
251 outArray->Add(hPH2d);
d679dd6c 252
775f67d7 253 // PRF histo
254 TProfile2D *hPRF2d = fTRDCalibraFillHisto->GetPRF2d();
255 outArray->Add(hPRF2d);
dc2e6604 256
775f67d7 257 HLTDebug("GetCH2d = 0x%x; NEntries = %i; size = %i", hCH2d, hCH2d->GetEntries(), sizeof(hCH2d));
258 hCH2d->Print();
259 HLTDebug("GetPH2d = 0x%x; NEntries = %i; size = %i", hPH2d, hPH2d->GetEntries(), sizeof(hPH2d));
260 hPH2d->Print();
261 HLTDebug("GetPRF2d = 0x%x; NEntries = %i; size = %i", hPRF2d, hPRF2d->GetEntries(), sizeof(hPRF2d));
262 hPRF2d->Print();
263 HLTDebug("output Array: pointer = 0x%x; NEntries = %i; size = %i", outArray, outArray->GetEntries(), sizeof(outArray));
dc2e6604 264
265
266
775f67d7 267 return outArray;
d679dd6c 268
d679dd6c 269}
270