2 /**************************************************************************
3 * This file is property of and copyright by the ALICE HLT Project *
4 * All rights reserved. *
6 * Primary Authors: Svein Lindal, Oeystein Djuvsland *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
17 * @file AliHLTCaloHistoComponent.cxx
18 * @author Svein Lindal
20 * @brief A physics histogram producer component for Calo HLT
28 #include "AliHLTCaloHistoComponent.h"
29 #include "AliHLTCaloHistoCellEnergy.h"
30 #include "AliHLTCaloHistoClusterEnergy.h"
31 #include "AliHLTCaloHistoInvMass.h"
32 #include "AliHLTCaloHistoMatchedTracks.h"
33 #include "AliESDEvent.h"
34 #include "TRefArray.h"
35 #include "AliHLTCaloClusterDataStruct.h"
36 #include "AliHLTCaloClusterReader.h"
37 #include "TObjArray.h"
39 // see below for class documentation
41 // refer to README to build package
43 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
46 AliHLTCaloHistoComponent gAliHLTCaloHistoComponent;
48 ClassImp(AliHLTCaloHistoComponent);
50 AliHLTCaloHistoComponent::AliHLTCaloHistoComponent() :
53 fEmcalClustersArray(NULL),
54 fPhosClustersArray(NULL),
55 fPhosProducerArray(NULL),
56 fEmcalProducerArray(NULL),
57 fPhosHistogramArray(NULL),
58 fEmcalHistogramArray(NULL),
61 fCutOnCentrality(kFALSE),
63 fCentralityCutEnergy(0.5)
65 //see header file for documentation
68 AliHLTCaloHistoComponent::~AliHLTCaloHistoComponent()
70 //see header file for documentation
74 Int_t AliHLTCaloHistoComponent::DoInit(int argc, const char** argv ) {
75 //see header file for documentation
79 for ( int i = 0; i < argc; i++ ) {
80 if ( !allArgs.IsNull() ) allArgs += " ";
84 HLTImportant("Configuring with string \"%s\"", allArgs.Data());
87 fEmcalProducerArray = new TObjArray();
88 fEmcalProducerArray->SetOwner(kTRUE);
89 fPhosProducerArray = new TObjArray();
90 fPhosProducerArray->SetOwner(kTRUE);
93 fEmcalHistogramArray = new TObjArray();
94 fEmcalHistogramArray->SetOwner(kFALSE);
95 fPhosHistogramArray = new TObjArray();
96 fPhosHistogramArray->SetOwner(kFALSE);
99 //Configure the component
104 for(int i = 0; i < argc; i++) {
106 if(!strcmp("-phos", argv[i])) {
112 else if(!strcmp("-emcal", argv[i])) {
118 else if(!strcmp("-both", argv[i])) {
125 else if(!strcmp("-clusterenergy", argv[i])){
127 AliHLTCaloHistoClusterEnergy * histo = new AliHLTCaloHistoClusterEnergy("EMCAL");
128 fEmcalProducerArray->AddLast(dynamic_cast<TObject*>(histo));
129 HLTImportant("Adding EMCAL cluster energy histogram");
132 AliHLTCaloHistoClusterEnergy * histo = new AliHLTCaloHistoClusterEnergy("PHOS");
133 fPhosProducerArray->AddLast(dynamic_cast<TObject*>(histo));
134 HLTImportant("Adding PHOS cluster energy histogram");
138 else if(!strcmp("-invariantmass", argv[i])){
140 AliHLTCaloHistoInvMass * histo = new AliHLTCaloHistoInvMass("EMCAL");
141 fEmcalProducerArray->AddLast(dynamic_cast<TObject*>(histo));
142 HLTImportant("Adding EMCAL invariant mass histogram");
145 AliHLTCaloHistoInvMass * histo = new AliHLTCaloHistoInvMass("PHOS");
146 fPhosProducerArray->AddLast(dynamic_cast<TObject*>(histo));
147 HLTImportant("Adding PHOS invariant mass histogram");
151 else if(!strcmp("-matchedtracks", argv[i])) {
153 AliHLTCaloHistoMatchedTracks * histo = new AliHLTCaloHistoMatchedTracks("EMCAL");
154 fEmcalProducerArray->AddLast(dynamic_cast<TObject*>(histo));
155 HLTImportant("Adding EMCAL track-matching histograms");
158 AliHLTCaloHistoMatchedTracks * histo = new AliHLTCaloHistoMatchedTracks("PHOS");
159 fPhosProducerArray->AddLast(dynamic_cast<TObject*>(histo));
160 HLTImportant("Adding PHOS track-matching histograms");
164 else if(!strcmp("-cutoncentrality", argv[i])) {
165 fCutOnCentrality = kTRUE;
166 HLTImportant("Cutting on centrality");
168 else if(!strcmp("-centralityenergycut", argv[i])) {
169 fCentralityCutEnergy = atof(argv[i+1]);
170 HLTImportant("Cutting on centrality for clusters with energy > %f", fCentralityCutEnergy);
172 else if(!strcmp("-centralitycut", argv[i])) {
173 fCentralityCut = atof(argv[i+1]);
174 HLTImportant("Cutting on centrality > %f");
178 HLTError("Unknown argument \"%s\"", argv[i]);
185 fPhosClustersArray = new TRefArray();
187 fEmcalClustersArray = new TRefArray();
189 fClusterReader = new AliHLTCaloClusterReader();
195 Int_t AliHLTCaloHistoComponent::DoDeinit()
197 //see header file for documentation
199 if(fEmcalClustersArray)
200 delete fEmcalClustersArray;
201 fEmcalClustersArray = NULL;
203 if(fPhosClustersArray)
204 delete fPhosClustersArray;
205 fPhosClustersArray = NULL;
207 //Deleting these should also destroy histogram producers!!?
208 if(fEmcalProducerArray)
209 delete fEmcalProducerArray;
210 fEmcalProducerArray = NULL;
212 if(fPhosProducerArray)
213 delete fPhosProducerArray;
214 fPhosProducerArray = NULL;
217 if(fEmcalHistogramArray)
218 delete fEmcalHistogramArray;
219 fEmcalHistogramArray = NULL;
221 if(fPhosHistogramArray)
222 delete fPhosHistogramArray;
223 fPhosHistogramArray = NULL;
228 const char* AliHLTCaloHistoComponent::GetComponentID()
230 //see header file for documentation
231 return "CaloPhysicsHistos";
236 AliHLTCaloHistoComponent::GetInputDataTypes(vector<AliHLTComponentDataType>& list)
238 //see header file for documentation
240 list.push_back( kAliHLTDataTypeESDObject | kAliHLTDataOriginOut );
241 list.push_back( kAliHLTDataTypeCaloCluster | kAliHLTDataOriginEMCAL );
242 list.push_back( kAliHLTDataTypeCaloCluster | kAliHLTDataOriginPHOS );
244 // list.push_back(AliHLTPHOSDefinitions::fgkClusterDataType);
245 // list.push_back(AliHLTPHOSDefinitions::fgkESDCaloClusterDataType);
246 // list.push_back(AliHLTPHOSDefinitions::fgkESDCaloCellsDataType);
250 AliHLTComponentDataType AliHLTCaloHistoComponent::GetOutputDataType()
252 //see header file for documentation
253 return kAliHLTDataTypeHistogram | kAliHLTDataOriginAny ;
257 void AliHLTCaloHistoComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
259 //see header file for documentation
264 AliHLTComponent* AliHLTCaloHistoComponent::Spawn() {
265 //see header file for documentation
266 return new AliHLTCaloHistoComponent();
269 Int_t AliHLTCaloHistoComponent::DoEvent(const AliHLTComponentEventData& /*evtData*/, AliHLTComponentTriggerData& /*trigData*/) {
271 fPhosHistogramArray->Clear();
272 fEmcalHistogramArray->Clear();
275 //see header file for documentation
279 if ( GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR ) )
284 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock( kAliHLTDataTypeCaloCluster | kAliHLTDataOriginEMCAL ); pBlock!=NULL; pBlock=GetNextInputBlock()) {
285 ProcessBlocks(pBlock, fEmcalProducerArray);
290 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock( kAliHLTDataTypeCaloCluster | kAliHLTDataOriginPHOS ); pBlock!=NULL; pBlock=GetNextInputBlock()) {
291 ProcessBlocks(pBlock, fPhosProducerArray);
295 //Get histograms from all producers and push back in one block
296 for(int ih = 0; ih < fPhosProducerArray->GetEntriesFast(); ih++) {
297 fPhosHistogramArray->AddAll(static_cast<AliHLTCaloHistoProducer*>(fPhosProducerArray->At(ih))->GetHistograms());
298 // PushBack(static_cast<AliHLTCaloHistoProducer*>(fPhosProducerArray->At(ih))->GetHistograms(), kAliHLTDataTypeHistogram | kAliHLTDataOriginPHOS );
301 PushBack(fPhosHistogramArray, kAliHLTDataTypeHistogram | kAliHLTDataOriginPHOS );
303 for(int ih = 0; ih < fEmcalProducerArray->GetEntriesFast(); ih++) {
304 fEmcalHistogramArray->AddAll(static_cast<AliHLTCaloHistoProducer*>(fEmcalProducerArray->At(ih))->GetHistograms() );
305 // PushBack(static_cast<AliHLTCaloHistoProducer*>(fEmcalProducerArray->At(ih))->GetHistograms(), kAliHLTDataTypeHistogram | kAliHLTDataOriginEMCAL );
307 PushBack(fEmcalHistogramArray, kAliHLTDataTypeHistogram | kAliHLTDataOriginEMCAL );
314 Int_t AliHLTCaloHistoComponent::ProcessBlocks(const AliHLTComponentBlockData * pBlock, TObjArray * histoArray) {
318 AliHLTCaloClusterDataStruct * clusterStruct;
319 vector<AliHLTCaloClusterDataStruct*> clustersVector;
321 AliHLTCaloClusterHeaderStruct *clusterHeader = reinterpret_cast<AliHLTCaloClusterHeaderStruct*>(pBlock->fPtr);
322 fClusterReader->SetMemory(clusterHeader);
324 if ( (clusterHeader->fNClusters) < 0) {
325 HLTError("Event has negative number of clusters: %d! Very bad for vector resizing", (Int_t) (clusterHeader->fNClusters));
329 clustersVector.reserve((int) (clusterHeader->fNClusters));
333 Bool_t cutCluster = false;
334 while( (clusterStruct = fClusterReader->NextCluster()) != 0) {
336 if(fCutOnCentrality){
337 if(clusterStruct->fEnergy > fCentralityCutEnergy) {
338 for(UInt_t i = 0; i < clusterStruct->fNCells; i++) {
339 fClusterReader->GetCell(clusterStruct, cellId, ampFrac, i);
340 if(ampFrac > fCentralityCut) {
349 clustersVector.push_back(clusterStruct);
353 nClusters = clustersVector.size();
355 for(int ih = 0; ih < histoArray->GetEntriesFast(); ih++) {
356 iResult = static_cast<AliHLTCaloHistoProducer*>(histoArray->At(ih))->FillHistograms(nClusters, clustersVector);