]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/PHOS/AliHLTPHOSPhysicsAnalyzerSpectrumComponent.cxx
Components for selective readout of the DDL blocks
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTPHOSPhysicsAnalyzerSpectrumComponent.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Authors: Oystein Djuvsland <oysteind@ift.uib.no>                       *
5  *                                                                        *
6  * Permission to use, copy, modify and distribute this software and its   *
7  * documentation strictly for non-commercial purposes is hereby granted   *
8  * without fee, provided that the above copyright notice appears in all   *
9  * copies and that both the copyright notice and this permission notice   *
10  * appear in the supporting documentation. The authors make no claims     *
11  * about the suitability of this software for any purpose. It is          *
12  * provided "as is" without express or implied warranty.                  *
13  **************************************************************************/
14
15 #include "AliHLTPHOSPhysicsAnalyzerSpectrumComponent.h"
16 #include "AliHLTPHOSPhysicsAnalyzerPeakFitter.h"
17 //#include "AliHLTPHOSPhysicsDefinitions.h"
18 #include "AliHLTPHOSDefinitions.h" 
19 #include "AliHLTPHOSPhysicsAnalyzerSpectrum.h"
20 #include "AliHLTPHOSPhysicsAnalyzerSpectrumComponent.h"
21 #include "AliHLTPHOSRecPointDataStruct.h"
22 //#include "Rtypes.h"
23
24 /** @file   AliHLTPHOSPhysicsAnalyzerSpectrumComponent.cxx
25     @author Oystein Djuvsland
26     @date   
27     @brief  An invariant mass spectrum component for PHOS HLT
28 */
29
30 // see header file for class documentation
31 // or
32 // refer to README to build package
33 // or
34 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
35
36 //class AliHLTPHOSDefinitions;
37
38 const AliHLTComponentDataType AliHLTPHOSPhysicsAnalyzerSpectrumComponent::fgkInputDataTypes[]={kAliHLTVoidDataType,{0,"",""}};
39 UInt_t AliHLTPHOSPhysicsAnalyzerSpectrumComponent::fgCount = 0; 
40
41 AliHLTPHOSPhysicsAnalyzerSpectrumComponent gAliHLTPHOSPhysicsAnalyzerSpectrumComponent;
42
43 // removed by PTH AliHLTPHOSPhysicsAnalyzerSpectrumComponent::AliHLTPHOSPhysicsAnalyzerSpectrumComponent():AliHLTPHOSBase(), AliHLTProcessor(), fAnalyzerPtr(0), 
44 //                                                                                       fPeakFitter(0), fRootHistPtr(0),
45 //                                                                                       fWriteInterval(0)
46                                                          
47 AliHLTPHOSPhysicsAnalyzerSpectrumComponent::AliHLTPHOSPhysicsAnalyzerSpectrumComponent():AliHLTPHOSProcessor(), fAnalyzerPtr(0), // added by PTH 
48                                                                                          fPeakFitter(0), fRootHistPtr(0),
49                                                                                          fWriteInterval(0)
50 {
51   //Constructor
52 }
53
54 AliHLTPHOSPhysicsAnalyzerSpectrumComponent::~AliHLTPHOSPhysicsAnalyzerSpectrumComponent()
55 {
56   //Destructor
57   if(fPeakFitter)
58     {
59       delete fPeakFitter;
60       fPeakFitter = 0;
61     }
62
63   if(fAnalyzerPtr)
64     {
65       delete fAnalyzerPtr;
66       fAnalyzerPtr = 0;
67     }
68   
69   if(fRootHistPtr)
70     {
71       delete fRootHistPtr;
72       fRootHistPtr = 0;
73     }
74       
75 }
76
77 // PTH AliHLTPHOSPhysicsAnalyzerSpectrumComponent::AliHLTPHOSPhysicsAnalyzerSpectrumComponent(const AliHLTPHOSPhysicsAnalyzerSpectrumComponent &):AliHLTProcessor(), fAnalyzerPtr(0), 
78 //                                                                                                                                         fPeakFitter(0), fRootHistPtr(0), 
79 //                                                                                                                                         fWriteInterval(0)
80 //{
81   //Copy constructor not implemented 
82 //}
83
84 Int_t
85 AliHLTPHOSPhysicsAnalyzerSpectrumComponent::Deinit()
86 {
87   //Deinitialize the component
88   if(fPeakFitter)
89     {
90       fPeakFitter->SetHistogram(fRootHistPtr);
91       fPeakFitter->FitGaussian();
92       delete fPeakFitter;
93       fPeakFitter = 0;
94     }
95
96   if(fAnalyzerPtr)
97     {
98       fAnalyzerPtr->WriteHistogram("~/hist_fin.root");
99       delete fAnalyzerPtr;
100       fAnalyzerPtr = 0;
101     }
102   
103   if(fRootHistPtr)
104     {
105       delete fRootHistPtr;
106       fRootHistPtr = 0;
107     }
108       
109   return 0;
110 }
111
112 const Char_t* 
113 AliHLTPHOSPhysicsAnalyzerSpectrumComponent::GetComponentID()
114 {
115   return "AliHltPhosPhysicsAnalyzerSpectrum";
116 }
117
118 void
119 AliHLTPHOSPhysicsAnalyzerSpectrumComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
120 {
121   //Get the input data types
122   const AliHLTComponentDataType* pType=fgkInputDataTypes;
123   while (pType->fID!=0) {
124     list.push_back(*pType);
125     pType++;
126   }
127 }
128
129 AliHLTComponentDataType 
130 AliHLTPHOSPhysicsAnalyzerSpectrumComponent::GetOutputDataType()
131 {
132   //  return AliHLTPHOSPhysicsDefinitions::fgkAliHLTSpectrumDataType;
133   return AliHLTPHOSDefinitions::fgkAliHLTSpectrumDataType;
134 }
135
136 void
137 AliHLTPHOSPhysicsAnalyzerSpectrumComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier )
138   
139 {
140   //Get the data size of the output
141   constBase = 30;
142   inputMultiplier = 2;
143 }
144
145
146 Int_t 
147 AliHLTPHOSPhysicsAnalyzerSpectrumComponent::DoEvent(const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
148                                                     AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& /*size*/,
149                                                     std::vector<AliHLTComponentBlockData>& /*outputBlocks*/)
150 {
151   //Do event
152
153   const AliHLTComponentBlockData* iter = NULL; 
154   unsigned long ndx; 
155   
156   for( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
157     {
158       iter = blocks+ndx;
159       
160       if(iter->fDataType != AliHLTPHOSDefinitions::fgkAliHLTRecPointDataType)
161         {
162           cout << "Warning: data type is not fgkAliHLTClusterDataType " << endl;
163           continue;
164         }
165       
166       fRecPointArrayPtr[ndx] = reinterpret_cast<AliHLTPHOSRecPointDataStruct*>(iter->fPtr);
167       
168     } 
169   
170   //fAnalyzerPtr->Analyze(fRecPointArrayPtr, ndx);
171
172   if(fgCount%fWriteInterval == 0 && fgCount != 0)
173     {
174       //    PushBack(fRootHistPtr, kAliHLTAnyDataType, (AliHLTUInt32_t)0);
175       fAnalyzerPtr->WriteHistogram("~/hist.root");
176     }
177
178   fgCount++; 
179
180   if(fgCount%100==0) 
181   {
182     cout << "fgCount: " << fgCount << endl;
183   }
184   
185   return 0;
186   
187 }
188
189
190 //int 
191 //AliHLTPHOSPhysicsAnalyzerSpectrumComponent::DoEvent(const AliHLTComponentEventData &/*evtData*/, AliHLTComponentTriggerData &/*trigData*/)    
192 /*
193 {
194   const AliHLTComponentBlockData* iter = NULL; 
195   int ndx = 0;
196   //int nBlocks = GetNumberOfInputBlocks();
197
198   // PTH  if((iter = GetFirstInputBlock(AliHLTPHOSPhysicsDefinitions::fgkAliHLTClusterDataType)))
199   if((iter = GetFirstInputBlock(AliHLTPHOSDefinitions::fgkAliHLTClusterDataType)))
200     {
201     fClusterArrayPtr[ndx] = reinterpret_cast<AliHLTPHOSClusterDataStruct*>(iter->fPtr);
202     }
203
204   while((iter = GetNextInputBlock()))
205     {
206       ndx++;
207       fClusterArrayPtr[ndx] = reinterpret_cast<AliHLTPHOSClusterDataStruct*>(iter->fPtr);
208     }
209   
210   fAnalyzerPtr->Analyze(fClusterArrayPtr, ndx);
211   
212   if(fgCount%fWriteInterval == 0 && fgCount != 0)
213     {
214       PushBack(fRootHistPtr, kAliHLTAnyDataType, (AliHLTUInt32_t)0);
215     }
216   
217   fgCount++; 
218
219   if(fgCount%100==0) 
220     {
221       //printf("fgCount: %d\n\n", fgCount);
222       cout << "fgCount: " << fgCount << endl;
223     }
224   
225   return 0;
226 }
227 */
228
229
230 Int_t
231 AliHLTPHOSPhysicsAnalyzerSpectrumComponent::DoInit(int argc, const char** argv )
232 {
233   //Initialize the component
234   Float_t firstThreshold = atof(argv[0]);
235   Float_t secondThreshold = atof(argv[1]);
236   fWriteInterval = atoi(argv[2]);
237   Int_t nBins = atoi(argv[3]);
238   Float_t lowLimit  = atof(argv[4]);
239   Float_t highLimit = atof(argv[5]);
240
241   fPeakFitter = new AliHLTPHOSPhysicsAnalyzerPeakFitter();
242   fRootHistPtr = new TH1F("hist", "hist", nBins, lowLimit, highLimit);
243   fAnalyzerPtr = new AliHLTPHOSPhysicsAnalyzerSpectrum();
244   fAnalyzerPtr->SetThreshold(firstThreshold,secondThreshold);
245   fAnalyzerPtr->SetHistogram(fRootHistPtr);
246
247   if (argc==0 && argv==NULL) {
248     // this is currently just to get rid of the warning "unused parameter"
249   }
250   
251   return 0;
252 }
253
254 AliHLTComponent*
255 AliHLTPHOSPhysicsAnalyzerSpectrumComponent::Spawn()
256 {
257   //Spawn a new AliHLTPHOSPhysicsAnalyzerSpectrumComponent, for the HLT framework
258   return new AliHLTPHOSPhysicsAnalyzerSpectrumComponent();
259 }