]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/global/AliHLTGlobalHistoComponent.cxx
- coverity fix 14329
[u/mrichter/AliRoot.git] / HLT / global / AliHLTGlobalHistoComponent.cxx
CommitLineData
a4c1f5dd 1// $Id$
2
3//**************************************************************************
4//* This file is property of and copyright by the ALICE HLT Project *
5//* ALICE Experiment at CERN, All rights reserved. *
6//* *
7//* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8//* for The ALICE HLT 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 AliHLTGlobalHistoComponent.cxx
20/// @author Matthias Richter
21/// @date 2010-09-16
22/// @brief A histogramming component for global ESD properties based
23/// on the AliHLTTTreeProcessor
24
25#include "AliHLTGlobalHistoComponent.h"
26#include "AliESDEvent.h"
7a37a034 27#include "AliESDv0.h"
28#include "AliKFParticle.h"
29#include "AliKFVertex.h"
30
a4c1f5dd 31#include "TTree.h"
32#include "TString.h"
a4c1f5dd 33#include <cassert>
34
35/** ROOT macro for the implementation of ROOT specific class methods */
36ClassImp(AliHLTGlobalHistoComponent)
37
38AliHLTGlobalHistoComponent::AliHLTGlobalHistoComponent()
39 : AliHLTTTreeProcessor()
40 , fEvent(0)
41 , fNofTracks(0)
a0cfb01c 42 , fNofV0s(0)
1b89b93a 43 , fNofContributors(0)
54da0d34 44 , fVertexX(-99)
45 , fVertexY(-99)
46 , fVertexZ(-99)
1b89b93a 47 , fVertexStatus(kFALSE)
b77cb0b8 48 , fMaxTrackCount(20000)
a0cfb01c 49 , fMaxV0Count(1000)
50 , fFillV0(kFALSE)
a4c1f5dd 51 , fTrackVariables()
e7f3baeb 52 , fTrackVariablesInt()
a0cfb01c 53 , fV0Variables()
a4c1f5dd 54{
55 // see header file for class documentation
56 // or
57 // refer to README to build package
58 // or
59 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
a4c1f5dd 60}
61
b77cb0b8 62AliHLTGlobalHistoComponent::~AliHLTGlobalHistoComponent(){
a4c1f5dd 63 // see header file for class documentation
64 fTrackVariables.Reset();
e7f3baeb 65 fTrackVariablesInt.Reset();
a0cfb01c 66 fV0Variables.Reset();
a4c1f5dd 67}
68
7a37a034 69void AliHLTGlobalHistoComponent::GetInputDataTypes(AliHLTComponentDataTypeList& list){
a4c1f5dd 70 // see header file for class documentation
71 list.push_back(kAliHLTAllDataTypes);
72}
73
7a37a034 74AliHLTComponentDataType AliHLTGlobalHistoComponent::GetOutputDataType(){
af747e4b 75 // see header file for class documentation
76 return kAliHLTDataTypeHistogram|kAliHLTDataOriginOut;
77}
78
7a37a034 79TTree* AliHLTGlobalHistoComponent::CreateTree(int /*argc*/, const char** /*argv*/){
b77cb0b8 80// create the tree and branches
81
a4c1f5dd 82 int iResult=0;
b77cb0b8 83 TTree* pTree = new TTree("ESDproperties", "HLT ESD properties");
a4c1f5dd 84 if (!pTree) return NULL;
85
86 const char* trackVariableNames = {
e7f3baeb 87 // Note the black at the end of each name!
a4c1f5dd 88 "Track_pt "
89 "Track_phi "
90 "Track_eta "
54da0d34 91 "Track_p "
92 "Track_theta "
e43650fb 93 "Track_TPCclus "
94 "Track_ITSclus "
97491309 95 "Track_status "
54da0d34 96 "Track_charge "
97491309 97 "Track_DCAr "
98 "Track_DCAz "
99 "Track_dEdx "
a4c1f5dd 100 };
54da0d34 101
e7f3baeb 102 const char* trackIntVariableNames = {
103 // Note the black at the end of each name!
104 "Track_status "
105 };
a0cfb01c 106
107 const char* V0VariableNames = {
108 // Note the black at the end of each name!
109 "V0_AP "
110 "V0_pt "
111 "clust1 "
112 "clust2 "
113 "dev1 "
114 "dev2 "
115 "devPrim "
116 "length "
117 "sigmaLength "
118 "r "
119 };
8a79a0a9 120
a0cfb01c 121 if((iResult=fTrackVariables.Init(fMaxTrackCount, trackVariableNames))<0){
e7f3baeb 122 HLTError("failed to initialize internal structure for track properties (float)");
123 }
a0cfb01c 124 if((iResult=fTrackVariablesInt.Init(fMaxTrackCount, trackIntVariableNames))<0){
e7f3baeb 125 HLTError("failed to initialize internal structure for track properties (int)");
a4c1f5dd 126 }
a0cfb01c 127 if((iResult=fV0Variables.Init(fMaxV0Count, V0VariableNames))<0){
128 HLTError("failed to initialize internal structure for V0 properties (float)");
129 }
a4c1f5dd 130
a0cfb01c 131 if(iResult>=0){
132 pTree->Branch("event", &fEvent, "event/I");
133 pTree->Branch("trackcount", &fNofTracks, "trackcount/I");
134 pTree->Branch("vertexX", &fVertexX, "vertexX/F");
135 pTree->Branch("vertexY", &fVertexY, "vertexY/F");
136 pTree->Branch("vertexZ", &fVertexZ, "vertexZ/F");
137 pTree->Branch("nContributors",&fNofContributors, "nContributors/I");
138 pTree->Branch("vertexStatus", &fVertexStatus, "vertexStatus/I");
139 if(fFillV0==kTRUE) pTree->Branch("V0", &fNofV0s, "V0/I");
140
141 int i=0;
142 // FIXME: this is a bit ugly since type 'f' and 'i' are specified
143 // explicitely. Would be better to use a function like
144 // AliHLTGlobalHistoVariables::GetType but could not get this working
145
146 for(i=0; i<fTrackVariables.Variables(); i++){
147 TString specifier=fTrackVariables.GetKey(i);
148 float* pArray=fTrackVariables.GetArray(specifier);
149 specifier+="[trackcount]/f";
150 pTree->Branch(fTrackVariables.GetKey(i), pArray, specifier.Data());
151 }
152 for(i=0; i<fTrackVariablesInt.Variables(); i++){
153 TString specifier=fTrackVariablesInt.GetKey(i);
154 int* pArray=fTrackVariablesInt.GetArray(specifier);
155 specifier+="[trackcount]/i";
156 pTree->Branch(fTrackVariablesInt.GetKey(i), pArray, specifier.Data());
157 }
158 if(fFillV0==kTRUE){
159 for(i=0; i<fV0Variables.Variables(); i++){
160 TString specifier=fV0Variables.GetKey(i);
161 float* pArray=fV0Variables.GetArray(specifier);
162 specifier+="[V0]/f";
163 pTree->Branch(fV0Variables.GetKey(i), pArray, specifier.Data());
164 }
165 }
a4c1f5dd 166 } else {
167 delete pTree;
a0cfb01c 168 pTree = NULL;
a4c1f5dd 169 }
7a37a034 170
a4c1f5dd 171 return pTree;
172}
173
7a37a034 174void AliHLTGlobalHistoComponent::FillHistogramDefinitions(){
a4c1f5dd 175 /// default histogram definitions
176}
177
7a37a034 178int AliHLTGlobalHistoComponent::FillTree(TTree* pTree, const AliHLTComponentEventData& /*evtData*/, AliHLTComponentTriggerData& /*trigData*/ ){
179
a4c1f5dd 180 /// fill the tree from the ESD
181 int iResult=0;
182 if (!IsDataEvent()) return 0;
183
184 ResetVariables();
185
186 // fetch ESD from input stream
e43650fb 187 const TObject *obj = GetFirstInputObject(kAliHLTAllDataTypes, "AliESDEvent");
188 AliESDEvent *esd = dynamic_cast<AliESDEvent*>(const_cast<TObject*>(obj));
a4c1f5dd 189 esd->GetStdContent();
190
191 // fill track variables
1b89b93a 192 fNofTracks = esd->GetNumberOfTracks();
193 fVertexX = esd->GetPrimaryVertexTracks()->GetX();
194 fVertexY = esd->GetPrimaryVertexTracks()->GetY();
195 fVertexZ = esd->GetPrimaryVertexTracks()->GetZ();
1b89b93a 196 fNofContributors = esd->GetPrimaryVertexTracks()->GetNContributors();
197 fVertexStatus = esd->GetPrimaryVertexTracks()->GetStatus();
e43650fb 198 fNofV0s = esd->GetNumberOfV0s();
54da0d34 199
e43650fb 200 if(fFillV0==kTRUE && (fNofV0s > fMaxV0Count)){
a0cfb01c 201 HLTWarning("Found V0s are %d, while component argument is %d, the respective TTree branch is not filled properly. Need to reconfigure.\n", fNofV0s, fMaxV0Count);
7a37a034 202 }
7a37a034 203
a0cfb01c 204 for(int i=0; i<fNofTracks; i++){
205 AliESDtrack *esdTrack = esd->GetTrack(i);
206 if (!esdTrack) continue;
207
208 Float_t DCAr, DCAz = -99;
209 esdTrack->GetImpactParametersTPC(DCAr, DCAz);
210
211 fTrackVariables.Fill("Track_pt" , esdTrack->Pt() );
212 fTrackVariables.Fill("Track_phi" , esdTrack->Phi()*TMath::RadToDeg() );
e43650fb 213 fTrackVariables.Fill("Track_eta" , esdTrack->Eta() );
a0cfb01c 214 fTrackVariables.Fill("Track_p" , esdTrack->P() );
215 fTrackVariables.Fill("Track_theta" , esdTrack->Theta()*TMath::RadToDeg() );
e43650fb 216 fTrackVariables.Fill("Track_TPCclus" , esdTrack->GetTPCNcls() );
217 fTrackVariables.Fill("Track_ITSclus" , esdTrack->GetNcls(0) );
a0cfb01c 218 fTrackVariables.Fill("Track_status" , esdTrack->GetStatus() );
219 fTrackVariables.Fill("Track_charge" , esdTrack->Charge() );
220 fTrackVariables.Fill("Track_DCAr" , DCAr );
221 fTrackVariables.Fill("Track_DCAz" , DCAz );
222 fTrackVariables.Fill("Track_dEdx" , esdTrack->GetTPCsignal() );
223 fTrackVariablesInt.Fill("Track_status" , esdTrack->GetStatus() );
224 }
7a37a034 225
a0cfb01c 226 if(fFillV0==kTRUE){
e43650fb 227 for(int i=0; i<fNofV0s; i++){
a0cfb01c 228 AliESDv0 *esdV0 = esd->GetV0(i);
229 if(!esdV0) continue;
a0cfb01c 230
231 //fV0Variables.Fill("V0_AP", ap);
232 //fV0Variables.Fill("V0_pt", pt);
233 //fV0Variables.Fill("clust1", t1->GetTPCNcls());
234 //fV0Variables.Fill("clust2", t2->GetTPCNcls());
235 //fV0Variables.Fill("dev1", dev1);
236 //fV0Variables.Fill("dev2", dev2);
237 //fV0Variables.Fill("devPrim", devPrim);
238 //fV0Variables.Fill("length", length);
239 //fV0Variables.Fill("sigmaLength", sigmaLength);
240 //fV0Variables.Fill("r", r);
241
242 } // end of loop over V0s
243 }
7a37a034 244
a0cfb01c 245 if(iResult<0){
a4c1f5dd 246 // fill an empty event
247 ResetVariables();
248 }
a0cfb01c 249
a4c1f5dd 250 fEvent++;
a4c1f5dd 251 pTree->Fill();
252 return iResult;
253}
254
b77cb0b8 255int AliHLTGlobalHistoComponent::ResetVariables(){
256/// reset all filling variables
a4c1f5dd 257 fNofTracks=0;
a0cfb01c 258 fNofV0s=0;
a4c1f5dd 259 fTrackVariables.ResetCount();
e7f3baeb 260 fTrackVariablesInt.ResetCount();
a0cfb01c 261 fV0Variables.ResetCount();
a4c1f5dd 262 return 0;
263}
264
b77cb0b8 265AliHLTComponentDataType AliHLTGlobalHistoComponent::GetOriginDataType() const{
266// get the origin of the output data
4bb46850 267 return kAliHLTDataTypeHistogram|kAliHLTDataOriginHLT;
a4c1f5dd 268}
b77cb0b8 269
270int AliHLTGlobalHistoComponent::ScanConfigurationArgument(int argc, const char** argv){
271/// inherited from AliHLTComponent, scan argument
272
273 if (argv==NULL || argc<1) return 0;
274
275 int i=0;
a0cfb01c 276 TString argument = argv[i];
277
278 // -max-track-count
279 if(argument.CompareTo("-max-track-count")==0){
280 if (++i>=argc) return -EPROTO; // missing parameter
281 argument = argv[i];
282 fMaxTrackCount = argument.Atoi();
283 HLTInfo("got %s with parameter %s", argument.Data(), argv[i]);
284 return ++i;
285 }
286
287 // -max-V0-count
288 if(argument.CompareTo("-max-V0-count")==0){
289 if (++i>=argc) return -EPROTO; // missing parameter
290 argument = argv[i];
291 fMaxV0Count = argument.Atoi();
292 HLTInfo("got %s with parameter %s", argument.Data(), argv[i]);
293 return ++i;
294 }
295
296 // -fill-V0
297 if(argument.CompareTo("-fill-V0")==0){
298 fFillV0 = kTRUE;
299 HLTInfo("got %s", argument.Data());
300 return ++i;
b77cb0b8 301 }
b77cb0b8 302 // no recognized argument, forward to base class
303 return AliHLTTTreeProcessor::ScanConfigurationArgument(argc, argv);
304}
305
306int AliHLTGlobalHistoComponent::Reconfigure(const char* cdbEntry, const char* /*chainId*/){
307// see header file for class documentation
308
309 TString cdbPath;
310 if (cdbEntry) {
311 cdbPath=cdbEntry;
312 } else {
313 cdbPath="HLT/ConfigHLT/";
314 cdbPath+=GetComponentID();
315 }
316
317 return ConfigureFromCDBTObjString(cdbPath.Data());
318}
319
320