]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/global/physics/AliHLTCaloHistoComponent.cxx
adding PrimaryVertexFinder and V0Finder component to registration, to be consolidated...
[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   fPhosProducerArray(NULL),
56   fEmcalProducerArray(NULL),
57   fPhosHistogramArray(NULL),
58   fEmcalHistogramArray(NULL),
59   fDoEmcal(kFALSE),
60   fDoPhos(kFALSE),
61   fCutOnCentrality(kFALSE),
62   fCentralityCut(0.9),
63   fCentralityCutEnergy(0.5)
64 {
65   //see header file for documentation
66 }
67
68 AliHLTCaloHistoComponent::~AliHLTCaloHistoComponent() 
69 {
70   //see header file for documentation
71   //Deinit();
72 }
73
74 Int_t AliHLTCaloHistoComponent::DoInit(int argc, const char** argv ) {
75   //see header file for documentation
76   
77   TString allArgs = "";
78   
79   for ( int i = 0; i < argc; i++ ) {
80     if ( !allArgs.IsNull() ) allArgs += " ";
81     allArgs += argv[i];
82   }
83
84   HLTImportant("Configuring with string \"%s\"", allArgs.Data());
85
86   
87   fEmcalProducerArray = new TObjArray();
88   fEmcalProducerArray->SetOwner(kTRUE);
89   fPhosProducerArray = new TObjArray();
90   fPhosProducerArray->SetOwner(kTRUE);
91
92
93   fEmcalHistogramArray = new TObjArray();
94   fEmcalHistogramArray->SetOwner(kFALSE);
95   fPhosHistogramArray = new TObjArray();
96   fPhosHistogramArray->SetOwner(kFALSE);
97
98
99   //Configure the component
100   bool doPhos = true;
101   bool doEmcal = true;
102
103   
104   for(int i = 0; i < argc; i++) {
105     
106     if(!strcmp("-phos", argv[i])) {
107       fDoPhos = kTRUE;
108       doPhos = true;
109       doEmcal = false;
110     }
111
112     else if(!strcmp("-emcal", argv[i])) {
113       fDoEmcal = kTRUE;
114       doEmcal = true;
115       doPhos = false;
116     }
117
118     else if(!strcmp("-both", argv[i])) {
119       fDoEmcal = kTRUE;
120       fDoPhos = kTRUE;
121       doEmcal = true;
122       doPhos = true;
123     }
124     
125     else if(!strcmp("-clusterenergy", argv[i])){
126       if(doEmcal){
127         AliHLTCaloHistoClusterEnergy * histo = new AliHLTCaloHistoClusterEnergy("EMCAL");
128         fEmcalProducerArray->AddLast(dynamic_cast<TObject*>(histo));
129         HLTImportant("Adding EMCAL cluster energy histogram");
130       } 
131       if(doPhos){
132         AliHLTCaloHistoClusterEnergy * histo = new AliHLTCaloHistoClusterEnergy("PHOS");
133         fPhosProducerArray->AddLast(dynamic_cast<TObject*>(histo));
134         HLTImportant("Adding PHOS cluster energy histogram");
135       }
136     } 
137
138     else if(!strcmp("-invariantmass", argv[i])){
139       if(doEmcal){
140         AliHLTCaloHistoInvMass * histo = new AliHLTCaloHistoInvMass("EMCAL");
141         fEmcalProducerArray->AddLast(dynamic_cast<TObject*>(histo));
142         HLTImportant("Adding EMCAL invariant mass histogram");
143       } 
144       if(doPhos){
145         AliHLTCaloHistoInvMass * histo = new AliHLTCaloHistoInvMass("PHOS");
146         fPhosProducerArray->AddLast(dynamic_cast<TObject*>(histo));
147         HLTImportant("Adding PHOS invariant mass histogram");
148       }
149     } 
150    
151     else if(!strcmp("-matchedtracks", argv[i])) {
152       if(doEmcal){
153         AliHLTCaloHistoMatchedTracks * histo = new AliHLTCaloHistoMatchedTracks("EMCAL");
154         fEmcalProducerArray->AddLast(dynamic_cast<TObject*>(histo));
155         HLTImportant("Adding EMCAL track-matching histograms");
156       } 
157       if(doPhos){
158         AliHLTCaloHistoMatchedTracks * histo = new AliHLTCaloHistoMatchedTracks("PHOS");
159         fPhosProducerArray->AddLast(dynamic_cast<TObject*>(histo));
160         HLTImportant("Adding PHOS track-matching histograms");
161       }
162     } 
163     
164       else if(!strcmp("-cutoncentrality", argv[i])) {
165          fCutOnCentrality = kTRUE;
166          HLTImportant("Cutting on centrality");
167       }
168       else if(!strcmp("-centralityenergycut", argv[i])) {
169          fCentralityCutEnergy = atof(argv[i+1]);
170          HLTImportant("Cutting on centrality for clusters with energy > %f", fCentralityCutEnergy);
171       }
172       else if(!strcmp("-centralitycut", argv[i])) {
173          fCentralityCut = atof(argv[i+1]);
174          HLTImportant("Cutting on centrality > %f");
175       }
176      
177     else {
178       HLTError("Unknown argument \"%s\"", argv[i]);
179     }
180
181
182   }
183     
184   if(fDoPhos)
185     fPhosClustersArray = new TRefArray();
186   if(fDoEmcal)
187     fEmcalClustersArray = new TRefArray();
188   
189   fClusterReader = new AliHLTCaloClusterReader();
190   
191   return 0;
192 }
193
194
195 Int_t AliHLTCaloHistoComponent::DoDeinit()
196
197   //see header file for documentation
198
199   if(fEmcalClustersArray)
200     delete fEmcalClustersArray;
201   fEmcalClustersArray = NULL;
202
203   if(fPhosClustersArray)
204     delete fPhosClustersArray;
205   fPhosClustersArray = NULL;
206
207   //Deleting these should also destroy histogram producers!!?
208   if(fEmcalProducerArray)
209     delete fEmcalProducerArray;
210   fEmcalProducerArray = NULL;
211  
212  if(fPhosProducerArray)
213     delete fPhosProducerArray;
214   fPhosProducerArray = NULL;
215  
216
217   if(fEmcalHistogramArray)
218     delete fEmcalHistogramArray;
219   fEmcalHistogramArray = NULL;
220   
221   if(fPhosHistogramArray)
222     delete fPhosHistogramArray;
223   fPhosHistogramArray = NULL;
224  
225   return 0;
226 }
227
228 const char* AliHLTCaloHistoComponent::GetComponentID()
229 {
230   //see header file for documentation
231   return "CaloPhysicsHistos";
232 }
233
234
235 void
236 AliHLTCaloHistoComponent::GetInputDataTypes(vector<AliHLTComponentDataType>& list)
237
238   //see header file for documentation
239   list.clear();
240   list.push_back( kAliHLTDataTypeESDObject | kAliHLTDataOriginOut );
241   list.push_back( kAliHLTDataTypeCaloCluster | kAliHLTDataOriginEMCAL );
242   list.push_back( kAliHLTDataTypeCaloCluster | kAliHLTDataOriginPHOS );
243
244   //   list.push_back(AliHLTPHOSDefinitions::fgkClusterDataType);
245   //   list.push_back(AliHLTPHOSDefinitions::fgkESDCaloClusterDataType);
246   //   list.push_back(AliHLTPHOSDefinitions::fgkESDCaloCellsDataType);
247
248 }
249
250 AliHLTComponentDataType AliHLTCaloHistoComponent::GetOutputDataType()
251 {
252   //see header file for documentation
253   return kAliHLTDataTypeHistogram  | kAliHLTDataOriginAny ;
254 }
255
256
257 void AliHLTCaloHistoComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
258 {
259   //see header file for documentation
260   constBase = 30;
261   inputMultiplier = 5;
262 }
263
264 AliHLTComponent* AliHLTCaloHistoComponent::Spawn() {
265   //see header file for documentation
266   return new AliHLTCaloHistoComponent();
267 }
268
269 Int_t AliHLTCaloHistoComponent::DoEvent(const AliHLTComponentEventData& /*evtData*/, AliHLTComponentTriggerData& /*trigData*/) {
270
271   fPhosHistogramArray->Clear();
272   fEmcalHistogramArray->Clear();
273
274
275   //see header file for documentation
276   Int_t iResult = 0;
277
278
279   if ( GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR ) )
280     return 0;
281
282   
283   if (fDoEmcal) {
284     for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock( kAliHLTDataTypeCaloCluster | kAliHLTDataOriginEMCAL ); pBlock!=NULL; pBlock=GetNextInputBlock()) {
285       ProcessBlocks(pBlock, fEmcalProducerArray);
286     }
287   }
288
289   if (fDoPhos) {
290     for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock( kAliHLTDataTypeCaloCluster | kAliHLTDataOriginPHOS ); pBlock!=NULL; pBlock=GetNextInputBlock()) {
291       ProcessBlocks(pBlock, fPhosProducerArray);
292     }
293   }
294
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 );
299     
300   }
301   PushBack(fPhosHistogramArray, kAliHLTDataTypeHistogram | kAliHLTDataOriginPHOS );
302
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 );
306   }
307   PushBack(fEmcalHistogramArray, kAliHLTDataTypeHistogram | kAliHLTDataOriginEMCAL );
308
309   return iResult;
310
311 }
312
313
314 Int_t AliHLTCaloHistoComponent::ProcessBlocks(const AliHLTComponentBlockData * pBlock, TObjArray * histoArray) {
315
316   Int_t iResult = 0;
317
318   AliHLTCaloClusterDataStruct * clusterStruct;
319   vector<AliHLTCaloClusterDataStruct*> clustersVector;
320   
321   AliHLTCaloClusterHeaderStruct *clusterHeader = reinterpret_cast<AliHLTCaloClusterHeaderStruct*>(pBlock->fPtr);
322   fClusterReader->SetMemory(clusterHeader);
323      
324   if ( (clusterHeader->fNClusters) < 0) {
325     HLTError("Event has negative number of clusters: %d! Very bad for vector resizing", (Int_t) (clusterHeader->fNClusters));
326     return -1;
327   }
328   
329   clustersVector.reserve((int) (clusterHeader->fNClusters)); 
330   Int_t nClusters = 0;
331   Double_t ampFrac;
332   UShort_t cellId;
333   Bool_t cutCluster = false;
334   while( (clusterStruct = fClusterReader->NextCluster()) != 0) {
335     cutCluster = false;
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) {
341                   cutCluster = true;
342                   break;
343                }
344             }
345          }
346       }
347     
348     if(!cutCluster) {
349       clustersVector.push_back(clusterStruct);  
350     }
351   }
352   
353   nClusters = clustersVector.size();
354   
355   for(int ih = 0; ih < histoArray->GetEntriesFast(); ih++) {
356     iResult = static_cast<AliHLTCaloHistoProducer*>(histoArray->At(ih))->FillHistograms(nClusters, clustersVector);
357   }
358   
359   return iResult;
360 }