Make SetChi2 method public
[u/mrichter/AliRoot.git] / HLT / global / AliHLTGlobalVertexerHistoComponent.cxx
CommitLineData
de0257eb 1//**************************************************************************
2//* This file is property of and copyright by the ALICE HLT Project *
3//* ALICE Experiment at CERN, All rights reserved. *
4//* *
5//* Primary Authors: Timur.Pocheptsov@cern.ch *
6//* for The ALICE HLT Project. *
7//* *
8//* Permission to use, copy, modify and distribute this software and its *
9//* documentation strictly for non-commercial purposes is hereby granted *
10//* without fee, provided that the above copyright notice appears in all *
11//* copies and that both the copyright notice and this permission notice *
12//* appear in the supporting documentation. The authors make no claims *
13//* about the suitability of this software for any purpose. It is *
14//* provided "as is" without express or implied warranty. *
15//**************************************************************************
16
17/** @file AliHLTGlobalVertexerComponent.h
18 @author Timur Pocheptsov
19 @brief Component for monitor primary vertex
20*/
21
22#include "AliESDVertex.h"
23#include "AliESDEvent.h"
e419c1ae 24#include "TTimeStamp.h"
25#include "TSystem.h"
de0257eb 26
27#include "AliHLTGlobalVertexerHistoComponent.h"
28
29ClassImp(AliHLTGlobalVertexerHistoComponent)
30
31AliHLTGlobalVertexerHistoComponent::AliHLTGlobalVertexerHistoComponent()
32 :
e419c1ae 33 fUID(0),
ac0d701f 34 fRefreshPeriod(1000),
35 fFillSecond(0),
36 fFillSecondSPD(0)
de0257eb 37{
38 //Default ctor.
ac0d701f 39 for( int i=0; i<2; i++ ){
40 fPrimaryXY[i].SetName("primVertexXY");
41 fPrimaryXY[i].SetTitle("HLT: Primary vertex distribution in XY");
42 fPrimaryXY[i].SetMarkerStyle(8);
43 fPrimaryXY[i].SetMarkerSize(0.4);
44 fPrimaryXY[i].SetYTitle("Y [cm]");
45 fPrimaryXY[i].SetXTitle("X [cm]");
46 //fPrimaryXY[i].SetStats(0);
47 //fPrimaryXY[i].SetBit(TH1::kCanRebin);
48
49 fPrimaryX[i].SetName("primVertexX");
50 fPrimaryX[i].SetTitle("HLT: Primary vertex distribution in X");
51 fPrimaryX[i].SetMarkerStyle(8);
52 fPrimaryX[i].SetMarkerSize(0.4);
53 fPrimaryX[i].SetXTitle("X [cm]");
54 //fPrimaryX[i].SetStats(0);
55 //fPrimaryX[i].SetBit(TH1::kCanRebin);
56
57 fPrimaryY[i].SetName("primVertexY");
58 fPrimaryY[i].SetTitle("HLT: Primary vertex distribution in Y");
59 fPrimaryY[i].SetMarkerStyle(8);
60 fPrimaryY[i].SetMarkerSize(0.4);
61 fPrimaryY[i].SetXTitle("Y [cm]");
62 //fPrimaryY[i].SetStats(0);
63 //fPrimaryX[i].SetBit(TH1::kCanRebin);
64
65 fPrimaryZ[i].SetName("primVertexZ");
66 fPrimaryZ[i].SetTitle("HLT: Primary vertex distribution in Z");
67 fPrimaryZ[i].SetMarkerStyle(8);
68 fPrimaryZ[i].SetMarkerSize(0.4);
69 fPrimaryZ[i].SetXTitle("Z [cm]");
70 //fPrimaryZ[i].SetStats(0);
71 //fPrimaryX[i].SetBit(TH1::kCanRebin);
72
73
74 fSPDVertexXY[i].SetName("spdVertexXY");
75 fSPDVertexXY[i].SetTitle("HLT: SPD vertex distribution in XY");
76 fSPDVertexXY[i].SetMarkerStyle(8);
77 fSPDVertexXY[i].SetMarkerSize(0.4);
78 fSPDVertexXY[i].SetYTitle("Y [cm]");
79 fSPDVertexXY[i].SetXTitle("X [cm]");
e419c1ae 80 //fSPDVertexXY[i].SetStats(0);
ac0d701f 81 //fSPDVertexXY[i].SetBit(TH1::kCanRebin);
82
83 fSPDVertexX[i].SetName("spdVertexX");
84 fSPDVertexX[i].SetTitle("HLT: SPD vertex distribution in X");
85 fSPDVertexX[i].SetMarkerStyle(8);
86 fSPDVertexX[i].SetMarkerSize(0.4);
87 fSPDVertexX[i].SetXTitle("X [cm]");
88 //fSPDVertexX[i].SetStats(0);
89 //fSPDVertexX[i].SetBit(TH1::kCanRebin);
90
91 fSPDVertexY[i].SetName("spdVertexY");
92 fSPDVertexY[i].SetTitle("HLT: SPD vertex distribution in Y");
93 fSPDVertexY[i].SetMarkerStyle(8);
94 fSPDVertexY[i].SetMarkerSize(0.4);
95 fSPDVertexY[i].SetXTitle("Y [cm]");
96 //fSPDVertexY[i].SetStats(0);
97 //fSPDVertexY[i].SetBit(TH1::kCanRebin);
98
99 fSPDVertexZ[i].SetName("spdVertexZ");
100 fSPDVertexZ[i].SetTitle("HLT: SPD vertex distribution in Z");
101 fSPDVertexZ[i].SetMarkerStyle(8);
102 fSPDVertexZ[i].SetMarkerSize(0.4);
103 fSPDVertexZ[i].SetXTitle("Z [cm]");
104 //fSPDVertexZ[i].SetStats(0);
105 //fSPDVertexZ[i].SetBit(TH1::kCanRebin);
106 }
de0257eb 107}
108
109const char* AliHLTGlobalVertexerHistoComponent::GetComponentID()
110{
111 //Unique component id.
112 return "GlobalVertexerHisto";
113}
114
115void AliHLTGlobalVertexerHistoComponent::GetInputDataTypes(AliHLTComponentDataTypeList& list)
116{
117 //
118 list.clear();
de0257eb 119 list.push_back(kAliHLTDataTypeESDVertex|kAliHLTDataOriginITS );
d9386025 120 list.push_back(kAliHLTDataTypeESDVertex|kAliHLTDataOriginOut );
121 list.push_back(kAliHLTDataTypeESDObject|kAliHLTDataOriginOut);
de0257eb 122}
123
124
d2831d6a 125
de0257eb 126AliHLTComponentDataType AliHLTGlobalVertexerHistoComponent::GetOutputDataType()
127{
d2831d6a 128 // see header file for class documentation
129 return kAliHLTMultipleDataType;
de0257eb 130}
131
d2831d6a 132int AliHLTGlobalVertexerHistoComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList)
133
134{
135 // see header file for class documentation
136 tgtList.clear();
137 tgtList.push_back(kAliHLTDataTypeHistogram|kAliHLTDataOriginOut);
138 tgtList.push_back(kAliHLTDataTypeHistogram|kAliHLTDataOriginITSSPD);
139 return tgtList.size();
140}
141
142
de0257eb 143void AliHLTGlobalVertexerHistoComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
144{
145 //8000 is a temporary number. Find the way to
146 //estimate 3 serialized TH2F.
147 constBase = GetOutputDataSize();
148 inputMultiplier = 1.;
149}
150
151AliHLTComponent* AliHLTGlobalVertexerHistoComponent::Spawn()
152{
153 //Should be const, I think, but it's not.
154 return new AliHLTGlobalVertexerHistoComponent;
155}
156
ac0d701f 157void AliHLTGlobalVertexerHistoComponent::SetDefaultConfiguration()
158{
159 // Set default configuration for the CA tracker component
160 // Some parameters can be later overwritten from the OCDB
161
162 fRefreshPeriod = 1000;
163}
164
165int AliHLTGlobalVertexerHistoComponent::ReadConfigurationString( const char* arguments )
166{
167 // Set configuration parameters for the CA tracker component from the string
168
169 int iResult = 0;
170 if ( !arguments ) return iResult;
171
172 TString allArgs = arguments;
173 TString argument;
174 int bMissingParam = 0;
175
176 TObjArray* pTokens = allArgs.Tokenize( " " );
177
178 int nArgs = pTokens ? pTokens->GetEntries() : 0;
179
180 for ( int i = 0; i < nArgs; i++ ) {
181 argument = ( ( TObjString* )pTokens->At( i ) )->GetString();
182 if ( argument.IsNull() ) continue;
183
184 if ( argument.CompareTo( "-refresh" ) == 0 ) {
185 if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
186 fRefreshPeriod = ( ( TObjString* )pTokens->At( i ) )->GetString().Atoi();
187 HLTInfo( "N events for refresh of the run vertex is set to: %d", fRefreshPeriod );
188 continue;
189 }
190
191
192 HLTError( "Unknown option \"%s\"", argument.Data() );
193 iResult = -EINVAL;
194 }
195 delete pTokens;
196
197 if ( bMissingParam ) {
198 HLTError( "Specifier missed for parameter \"%s\"", argument.Data() );
199 iResult = -EINVAL;
200 }
201
202 return iResult;
203}
204
205
206int AliHLTGlobalVertexerHistoComponent::DoInit(int argc, const char** argv)
de0257eb 207{
208 //Clear all bin contents and statistics.
de0257eb 209
ac0d701f 210 SetDefaultConfiguration();
211
212
213 TString arguments = "";
214 for ( int i = 0; i < argc; i++ ) {
215 if ( !arguments.IsNull() ) arguments += " ";
216 arguments += argv[i];
217 }
218
219 int ret = ReadConfigurationString( arguments.Data() );
220 for( int i=0; i<2; i++ ){
221 fPrimaryXY[i].Reset();
222 fPrimaryX[i].Reset();
223 fPrimaryY[i].Reset();
224 fPrimaryZ[i].Reset();
225 fSPDVertexXY[i].Reset();
226 fSPDVertexX[i].Reset();
227 fSPDVertexY[i].Reset();
228 fSPDVertexZ[i].Reset();
229 //Set bin numbers and axis ranges[i].
230 fPrimaryXY[i].SetBins(1000, -1., 1., 1000, -1., 1.);
231 fPrimaryX[i].SetBins( 1000, -1., 1.);
232 fPrimaryY[i].SetBins( 1000, -1., 1.);
233 fPrimaryZ[i].SetBins( 1000, -30., 30.);
234 fSPDVertexXY[i].SetBins(1000, -1., 1., 1000, -1., 1.);
235 fSPDVertexX[i].SetBins(1000, -1., 1.);
236 fSPDVertexY[i].SetBins(1000, -1., 1.);
237 fSPDVertexZ[i].SetBins(1000, -30., 30.);
238 }
239 fFillSecond = 0;
240 fFillSecondSPD = 0;
e419c1ae 241 fUID = 0;
ac0d701f 242 return ret;
de0257eb 243}
244
245int AliHLTGlobalVertexerHistoComponent::DoDeinit()
246{
247 //Nothing to delete or "do de init" yet.
e419c1ae 248 fUID = 0;
de0257eb 249 return 0;
250}
251
e419c1ae 252int AliHLTGlobalVertexerHistoComponent::DoEvent(const AliHLTComponentEventData& evtData,
de0257eb 253 const AliHLTComponentBlockData* /*blocks*/,
254 AliHLTComponentTriggerData& /*trigData*/,
255 AliHLTUInt8_t* /*outputPtr*/,
256 AliHLTUInt32_t& size,
257 AliHLTComponentBlockDataList& /*outputBlocks*/)
258{
259 //Fill histogramms.
260 if (GetFirstInputBlock(kAliHLTDataTypeSOR) || GetFirstInputBlock(kAliHLTDataTypeEOR))
261 return 0;
262
e419c1ae 263 if( fUID == 0 ){
264 TTimeStamp t;
265 fUID = ( gSystem->GetPid() + t.GetNanoSec())*10 + evtData.fEventID;
266 //cout<<"\nSet id to "<<fUID<<endl;
267 }
268
de0257eb 269 if (GetOutputDataSize() > size) {
270 Logging(kHLTLogFatal, "HLT::AliHLTGlobalVertexerHistoComponent::DoEvent", "Too much data",
271 "Data written over allowed buffer. Amount written: %lu, allowed amount: %lu.",
272 GetOutputDataSize(), size);
273 return -ENOSPC;
274 }
275
ac0d701f 276 if( fRefreshPeriod>0 ){
277 if( fPrimaryXY[0].GetEntries()+1>=fRefreshPeriod/2 ) fFillSecond = 1;
278 if( fSPDVertexXY[0].GetEntries()+1>=fRefreshPeriod/2 ) fFillSecondSPD = 1;
279 }
de0257eb 280
ac0d701f 281 int iResult = 0;
d9386025 282
283 const AliESDVertex *vertexITS = 0;
284 const AliESDVertex *vertexGlobal = 0;
285
286
cda9e128 287 {
288 const TObject *iter = GetFirstInputObject(kAliHLTDataTypeESDVertex|kAliHLTDataOriginITS);
289 if( iter != NULL ) {
290 if( !( vertexITS = dynamic_cast<AliESDVertex*>(const_cast<TObject*>( iter ) ) ) ){
291 HLTError("ITS SPD vertex object is corrupted");
292 iResult = -EINVAL;
293 }
de0257eb 294 }
d9386025 295 }
296
cda9e128 297 {
298 const TObject *iter = GetFirstInputObject(kAliHLTDataTypeESDVertex|kAliHLTDataOriginOut);
299 if( iter != NULL ){
300 if( !( vertexGlobal = dynamic_cast<AliESDVertex*>(const_cast<TObject*>( iter ) ) ) ){
301 HLTError("Global vertex object is corrupted");
302 iResult = -EINVAL;
303 }
d9386025 304 }
de0257eb 305 }
306
d9386025 307 if( !vertexITS || !vertexGlobal ){
308
309 for (const TObject* iter = GetFirstInputObject(kAliHLTDataTypeESDObject|kAliHLTDataOriginOut); iter; iter = GetNextInputObject() ) {
310 if ( AliESDEvent* event = dynamic_cast<AliESDEvent*>((TObject*)iter) ) {
311 event->GetStdContent();
312 if( !vertexGlobal ) vertexGlobal = event->GetPrimaryVertexTracks();
313 if( !vertexITS ) vertexITS = event->GetPrimaryVertexSPD();
314 } else {
315 HLTError("ESD event object is corrupted");
316 iResult = -EINVAL;
317 }
318 }
319 }
320
321 if (vertexGlobal && vertexGlobal->GetNContributors() >= 5) {
322 for( int i=0; i<=fFillSecond; i++ ){
323 if( fRefreshPeriod>0 && fPrimaryXY[i].GetEntries()>=fRefreshPeriod ){
324 fPrimaryXY[i].Reset();
325 fPrimaryX[i].Reset();
326 fPrimaryY[i].Reset();
327 fPrimaryZ[i].Reset();
de0257eb 328 }
d9386025 329 fPrimaryXY[i].Fill(vertexGlobal->GetX(), vertexGlobal->GetY());
330 fPrimaryX[i].Fill(vertexGlobal->GetX());
331 fPrimaryY[i].Fill(vertexGlobal->GetY());
332 fPrimaryZ[i].Fill(vertexGlobal->GetZ());
333 }
334 }
335
336 if( vertexITS && vertexITS->GetNContributors() >= 5 ){
337 for( int i=0; i<=fFillSecondSPD; i++ ){
338 if( fRefreshPeriod>0 && fSPDVertexXY[i].GetEntries()>=fRefreshPeriod ){
339 fSPDVertexXY[i].Reset();
340 fSPDVertexX[i].Reset();
341 fSPDVertexY[i].Reset();
342 fSPDVertexZ[i].Reset();
de0257eb 343 }
d9386025 344 fSPDVertexXY[i].Fill(vertexITS->GetX(), vertexITS->GetY());
345 fSPDVertexX[i].Fill(vertexITS->GetX() );
346 fSPDVertexY[i].Fill(vertexITS->GetY() );
347 fSPDVertexZ[i].Fill(vertexITS->GetZ() );
de0257eb 348 }
349 }
ac0d701f 350
351 int i = ( fPrimaryXY[1].GetEntries() > fPrimaryXY[0].GetEntries() );
352
e419c1ae 353 PushBack(&fPrimaryXY[i], kAliHLTDataTypeHistogram | kAliHLTDataOriginOut, fUID);
354 PushBack(&fPrimaryZ[i], kAliHLTDataTypeHistogram | kAliHLTDataOriginOut, fUID);
355 PushBack(&fPrimaryX[i], kAliHLTDataTypeHistogram | kAliHLTDataOriginOut, fUID);
356 PushBack(&fPrimaryY[i], kAliHLTDataTypeHistogram | kAliHLTDataOriginOut, fUID);
ac0d701f 357
358 i = ( fSPDVertexXY[1].GetEntries() > fSPDVertexXY[0].GetEntries() );
359
360 //cout<<"bla NEntr = "<<fPrimaryXY[0].GetEntries()<<" / "<<fPrimaryXY[1].GetEntries()<<endl;
361 //cout<<"bla NEntr SPD = "<<fSPDVertexXY[0].GetEntries()<<" / "<<fSPDVertexXY[1].GetEntries()<<endl;
362
e419c1ae 363 PushBack(&fSPDVertexXY[i], kAliHLTDataTypeHistogram | kAliHLTDataOriginITSSPD, fUID);
364 PushBack(&fSPDVertexZ[i], kAliHLTDataTypeHistogram | kAliHLTDataOriginITSSPD, fUID);
365 PushBack(&fSPDVertexX[i], kAliHLTDataTypeHistogram | kAliHLTDataOriginITSSPD, fUID);
366 PushBack(&fSPDVertexY[i], kAliHLTDataTypeHistogram | kAliHLTDataOriginITSSPD, fUID);
de0257eb 367
368 return iResult;
369}
370
371int AliHLTGlobalVertexerHistoComponent::Reconfigure(const char* cdbEntry, const char* chainId)
372{
373 //Do nothing at the moment, but at least log (base class version).
374 return AliHLTComponent::Reconfigure(cdbEntry, chainId);
375}
376
377unsigned long AliHLTGlobalVertexerHistoComponent::GetOutputDataSize()const
378{
379 //8000 is a temporary number. Find the way to
380 //estimate serialized TH2F.
381 return 20000;
382}