]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/global/physics/AliHLTCaloHistoComponent.cxx
8c095cdc358f6176a538effb8586e88fe35f3d07
[u/mrichter/AliRoot.git] / HLT / global / physics / AliHLTCaloHistoComponent.cxx
1 //-*- Mode: C++ -*-
2  /**************************************************************************
3  * This file is property of and copyright by the ALICE HLT Project        *
4  * All rights reserved.                                                   *
5  *                                                                        *
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  **************************************************************************/
15
16 /** 
17  * @file   AliHLTCaloHistoComponent.cxx
18  * @author Svein Lindal
19  * @date   
20  * @brief  A physics histogram producer component for Calo HLT
21 */
22
23 #if __GNUC__>= 3
24 using namespace std;
25 #endif
26
27
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"
38
39 // see below for class documentation
40 // or
41 // refer to README to build package
42 // or
43 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
44
45
46 AliHLTCaloHistoComponent gAliHLTCaloHistoComponent;
47
48 ClassImp(AliHLTCaloHistoComponent);
49
50 AliHLTCaloHistoComponent::AliHLTCaloHistoComponent() :
51   AliHLTProcessor(),
52   fClusterReader(NULL),
53   fEmcalClustersArray(NULL),
54   fPhosClustersArray(NULL),
55   fPhosHistogramArray(NULL),
56   fEmcalHistogramArray(NULL),
57   fDoEmcal(kFALSE),
58   fDoPhos(kFALSE)
59 {
60   //see header file for documentation
61 }
62
63 AliHLTCaloHistoComponent::~AliHLTCaloHistoComponent() 
64 {
65   //see header file for documentation
66   //Deinit();
67 }
68
69 Int_t AliHLTCaloHistoComponent::DoInit(int argc, const char** argv ) {
70   //see header file for documentation
71   
72   
73   fEmcalHistogramArray = new TObjArray();
74   fEmcalHistogramArray->SetOwner(kTRUE);
75   fPhosHistogramArray = new TObjArray();
76   fPhosHistogramArray->SetOwner(kTRUE);
77   
78   bool doPhos = true;
79   bool doEmcal = true;
80
81   
82   for(int i = 0; i < argc; i++) {
83     
84     if(!strcmp("-phos", argv[i])) {
85       fDoPhos = kTRUE;
86       doPhos = true;
87       doEmcal = false;
88     }
89     if(!strcmp("-emcal", argv[i])) {
90       fDoEmcal = kTRUE;
91       doEmcal = true;
92       doPhos = false;
93     }
94     if(!strcmp("-both", argv[i])) {
95       fDoEmcal = kTRUE;
96       fDoPhos = kTRUE;
97       doEmcal = true;
98       doPhos = true;
99     }
100     
101     if(!strcmp("-clusterenergy", argv[i])){
102       if(doEmcal){
103         AliHLTCaloHistoClusterEnergy * histo = new AliHLTCaloHistoClusterEnergy("EMCAL");
104         fEmcalHistogramArray->AddLast(dynamic_cast<TObject*>(histo));
105         HLTInfo("Adding EMCAL cluster energy histogram");
106       } 
107       if(doPhos){
108         AliHLTCaloHistoClusterEnergy * histo = new AliHLTCaloHistoClusterEnergy("PHOS");
109         fPhosHistogramArray->AddLast(dynamic_cast<TObject*>(histo));
110         HLTInfo("Adding PHOS cluster energy histogram");
111       }
112     } 
113
114     if(!strcmp("-invariantmass", argv[i])){
115       if(doEmcal){
116         AliHLTCaloHistoInvMass * histo = new AliHLTCaloHistoInvMass("EMCAL");
117         fEmcalHistogramArray->AddLast(dynamic_cast<TObject*>(histo));
118         HLTInfo("Adding EMCAL invariant mass histogram");
119       } 
120       if(doPhos){
121         AliHLTCaloHistoInvMass * histo = new AliHLTCaloHistoInvMass("PHOS");
122         fPhosHistogramArray->AddLast(dynamic_cast<TObject*>(histo));
123         HLTInfo("Adding PHOS invariant mass histogram");
124       }
125     } 
126    
127     if(!strcmp("-matchedtracks", argv[i])) {
128       if(doEmcal){
129         AliHLTCaloHistoMatchedTracks * histo = new AliHLTCaloHistoMatchedTracks("EMCAL");
130         fEmcalHistogramArray->AddLast(dynamic_cast<TObject*>(histo));
131         HLTInfo("Adding EMCAL track-matching histograms");
132       } 
133       if(doPhos){
134         AliHLTCaloHistoMatchedTracks * histo = new AliHLTCaloHistoMatchedTracks("PHOS");
135         fPhosHistogramArray->AddLast(dynamic_cast<TObject*>(histo));
136         HLTInfo("Adding PHOS track-matching histograms");
137       }
138     }
139   }
140     
141   if(fDoPhos)
142     fPhosClustersArray = new TRefArray();
143   if(fDoEmcal)
144     fEmcalClustersArray = new TRefArray();
145   
146   fClusterReader = new AliHLTCaloClusterReader();
147   
148   return 0;
149 }
150
151
152 Int_t AliHLTCaloHistoComponent::DoDeinit()
153
154   //see header file for documentation
155
156   if(fEmcalClustersArray)
157     delete fEmcalClustersArray;
158   fEmcalClustersArray = NULL;
159
160   if(fPhosClustersArray)
161     delete fPhosClustersArray;
162   fPhosClustersArray = NULL;
163
164   //Deleting these should also destroy histograms!!?
165   if(fEmcalHistogramArray)
166     delete fEmcalHistogramArray;
167   fEmcalHistogramArray = NULL;
168  
169  if(fPhosHistogramArray)
170     delete fPhosHistogramArray;
171   fPhosHistogramArray = NULL;
172  
173   return 0;
174 }
175
176 const char* AliHLTCaloHistoComponent::GetComponentID()
177 {
178   //see header file for documentation
179   return "CaloPhysicsHistos";
180 }
181
182
183 void
184 AliHLTCaloHistoComponent::GetInputDataTypes(vector<AliHLTComponentDataType>& list)
185
186   //see header file for documentation
187   list.clear();
188   list.push_back( kAliHLTDataTypeESDObject | kAliHLTDataOriginOut );
189   list.push_back( kAliHLTDataTypeCaloCluster | kAliHLTDataOriginEMCAL );
190   list.push_back( kAliHLTDataTypeCaloCluster | kAliHLTDataOriginPHOS );
191
192   //   list.push_back(AliHLTPHOSDefinitions::fgkClusterDataType);
193   //   list.push_back(AliHLTPHOSDefinitions::fgkESDCaloClusterDataType);
194   //   list.push_back(AliHLTPHOSDefinitions::fgkESDCaloCellsDataType);
195
196 }
197
198 AliHLTComponentDataType AliHLTCaloHistoComponent::GetOutputDataType()
199 {
200   //see header file for documentation
201   return kAliHLTDataTypeHistogram  | kAliHLTDataOriginAny ;
202 }
203
204
205 void AliHLTCaloHistoComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
206 {
207   //see header file for documentation
208   constBase = 30;
209   inputMultiplier = 5;
210 }
211
212 AliHLTComponent* AliHLTCaloHistoComponent::Spawn() {
213   //see header file for documentation
214   return new AliHLTCaloHistoComponent();
215 }
216
217 Int_t AliHLTCaloHistoComponent::DoEvent(const AliHLTComponentEventData& /*evtData*/, AliHLTComponentTriggerData& /*trigData*/) {
218
219   //see header file for documentation
220   Int_t iResult = 0;
221
222
223   if ( GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR ) )
224     return 0;
225
226   
227   if (fDoEmcal) {
228     //    HLTInfo("Processing EMCAL blocks");
229     for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock( kAliHLTDataTypeCaloCluster | kAliHLTDataOriginEMCAL ); pBlock!=NULL; pBlock=GetNextInputBlock()) {
230       ProcessBlocks(pBlock, fEmcalHistogramArray);
231     }
232   }
233
234   if (fDoPhos) {
235     //HLTInfo("Processing PHOS blocks");
236     for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock( kAliHLTDataTypeCaloCluster | kAliHLTDataOriginPHOS ); pBlock!=NULL; pBlock=GetNextInputBlock()) {
237       ProcessBlocks(pBlock, fPhosHistogramArray);
238     }
239   }
240
241   //Push histos
242   for(int ih = 0; ih < fPhosHistogramArray->GetEntriesFast(); ih++) {
243     //HLTInfo("Pushing PHOS histograms");
244     PushBack(static_cast<AliHLTCaloHistoProducer*>(fPhosHistogramArray->At(ih))->GetHistograms(), kAliHLTDataTypeHistogram | kAliHLTDataOriginPHOS );
245   }
246   for(int ih = 0; ih < fEmcalHistogramArray->GetEntriesFast(); ih++) {
247     //HLTInfo("Pushing EMCAL histograms");
248     PushBack(static_cast<AliHLTCaloHistoProducer*>(fEmcalHistogramArray->At(ih))->GetHistograms(), kAliHLTDataTypeHistogram | kAliHLTDataOriginEMCAL );
249   }
250
251   return iResult;
252
253 }
254
255
256 Int_t AliHLTCaloHistoComponent::ProcessBlocks(const AliHLTComponentBlockData * pBlock, TObjArray * histoArray) {
257
258   Int_t iResult = 0;
259
260   AliHLTCaloClusterDataStruct * clusterStruct;
261   vector<AliHLTCaloClusterDataStruct*> clustersVector;
262   
263   AliHLTCaloClusterHeaderStruct *clusterHeader = reinterpret_cast<AliHLTCaloClusterHeaderStruct*>(pBlock->fPtr);
264   fClusterReader->SetMemory(clusterHeader);
265      
266   if ( (clusterHeader->fNClusters) < 0) {
267     HLTError("Event has negative number of clusters: %d! Very bad for vector resizing", (Int_t) (clusterHeader->fNClusters));
268     return -1;
269   }
270   
271   clustersVector.resize((int) (clusterHeader->fNClusters)); 
272   Int_t nClusters = 0;
273   
274   while( (clusterStruct = fClusterReader->NextCluster()) != 0) {
275     clustersVector[nClusters++] = clusterStruct;  
276   }
277   
278   nClusters = clusterHeader->fNClusters;
279   
280   for(int ih = 0; ih < histoArray->GetEntriesFast(); ih++) {
281     iResult = static_cast<AliHLTCaloHistoProducer*>(histoArray->At(ih))->FillHistograms(nClusters, clustersVector);
282   }
283   
284   return iResult;
285 }