]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/PHOS/AliHLTPHOSPhysicsAnalyzerSpectrumComponent.cxx
Selectiv readout and writing to FXS (oystein)
[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 AliHLTPHOSPhysicsAnalyzerSpectrumComponent::AliHLTPHOSPhysicsAnalyzerSpectrumComponent(const AliHLTPHOSPhysicsAnalyzerSpectrumComponent &) :
78   AliHLTPHOSProcessor(),
79   fAnalyzerPtr(0),
80   fPeakFitter(0), 
81   fRootHistPtr(0)
82   //fWriteInterval(0)
83 {
84   //Copy constructor not implemented 
85 }
86
87 Int_t
88 AliHLTPHOSPhysicsAnalyzerSpectrumComponent::Deinit()
89 {
90   //Deinitialize the component
91   if(fPeakFitter)
92     {
93       fPeakFitter->SetHistogram(fRootHistPtr);
94       fPeakFitter->FitGaussian();
95       delete fPeakFitter;
96       fPeakFitter = 0;
97     }
98
99   if(fAnalyzerPtr)
100     {
101       fAnalyzerPtr->WriteHistogram("~/hist_fin.root");
102       delete fAnalyzerPtr;
103       fAnalyzerPtr = 0;
104     }
105   
106   if(fRootHistPtr)
107     {
108       delete fRootHistPtr;
109       fRootHistPtr = 0;
110     }
111       
112   return 0;
113 }
114
115 const Char_t* 
116 AliHLTPHOSPhysicsAnalyzerSpectrumComponent::GetComponentID()
117 {
118   return "AliHltPhosPhysicsAnalyzerSpectrum";
119 }
120
121 void
122 AliHLTPHOSPhysicsAnalyzerSpectrumComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
123 {
124   //Get the input data types
125   const AliHLTComponentDataType* pType=fgkInputDataTypes;
126   while (pType->fID!=0) {
127     list.push_back(*pType);
128     pType++;
129   }
130 }
131
132 AliHLTComponentDataType 
133 AliHLTPHOSPhysicsAnalyzerSpectrumComponent::GetOutputDataType()
134 {
135   //  return AliHLTPHOSPhysicsDefinitions::fgkAliHLTSpectrumDataType;
136   return AliHLTPHOSDefinitions::fgkSpectrumDataType;
137 }
138
139 void
140 AliHLTPHOSPhysicsAnalyzerSpectrumComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier )
141   
142 {
143   //Get the data size of the output
144   constBase = 30;
145   inputMultiplier = 2;
146 }
147
148
149 Int_t 
150 AliHLTPHOSPhysicsAnalyzerSpectrumComponent::DoEvent(const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
151                                                     AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* /*outputPtr*/, AliHLTUInt32_t& /*size*/,
152                                                     std::vector<AliHLTComponentBlockData>& /*outputBlocks*/)
153 {
154   //Do event
155
156   const AliHLTComponentBlockData* iter = NULL; 
157   unsigned long ndx; 
158   
159   for( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
160     {
161       iter = blocks+ndx;
162       
163       if(iter->fDataType != AliHLTPHOSDefinitions::fgkRecPointDataType)
164         {
165           cout << "Warning: data type is not fgkRecPointDataType " << endl;
166           continue;
167         }
168       
169       fRecPointArrayPtr[ndx] = reinterpret_cast<AliHLTPHOSRecPointDataStruct*>(iter->fPtr);
170       
171     } 
172   
173   //fAnalyzerPtr->Analyze(fRecPointArrayPtr, ndx);
174
175   if(fgCount%fWriteInterval == 0 && fgCount != 0)
176     {
177       //    PushBack(fRootHistPtr, kAliHLTAnyDataType, (AliHLTUInt32_t)0);
178       fAnalyzerPtr->WriteHistogram("~/hist.root");
179     }
180
181   fgCount++; 
182
183   if(fgCount%100==0) 
184   {
185     cout << "fgCount: " << fgCount << endl;
186   }
187   
188   return 0;
189   
190 }
191
192
193 //int 
194 //AliHLTPHOSPhysicsAnalyzerSpectrumComponent::DoEvent(const AliHLTComponentEventData &/*evtData*/, AliHLTComponentTriggerData &/*trigData*/)    
195 /*
196 {
197   const AliHLTComponentBlockData* iter = NULL; 
198   int ndx = 0;
199   //int nBlocks = GetNumberOfInputBlocks();
200
201   // PTH  if((iter = GetFirstInputBlock(AliHLTPHOSPhysicsDefinitions::fgkAliHLTClusterDataType)))
202   if((iter = GetFirstInputBlock(AliHLTPHOSDefinitions::fgkAliHLTClusterDataType)))
203     {
204     fClusterArrayPtr[ndx] = reinterpret_cast<AliHLTPHOSClusterDataStruct*>(iter->fPtr);
205     }
206
207   while((iter = GetNextInputBlock()))
208     {
209       ndx++;
210       fClusterArrayPtr[ndx] = reinterpret_cast<AliHLTPHOSClusterDataStruct*>(iter->fPtr);
211     }
212   
213   fAnalyzerPtr->Analyze(fClusterArrayPtr, ndx);
214   
215   if(fgCount%fWriteInterval == 0 && fgCount != 0)
216     {
217       PushBack(fRootHistPtr, kAliHLTAnyDataType, (AliHLTUInt32_t)0);
218     }
219   
220   fgCount++; 
221
222   if(fgCount%100==0) 
223     {
224       //printf("fgCount: %d\n\n", fgCount);
225       cout << "fgCount: " << fgCount << endl;
226     }
227   
228   return 0;
229 }
230 */
231
232
233 Int_t
234 AliHLTPHOSPhysicsAnalyzerSpectrumComponent::DoInit(int argc, const char** argv )
235 {
236   //Initialize the component
237   Float_t firstThreshold = atof(argv[0]);
238   Float_t secondThreshold = atof(argv[1]);
239   fWriteInterval = atoi(argv[2]);
240   Int_t nBins = atoi(argv[3]);
241   Float_t lowLimit  = atof(argv[4]);
242   Float_t highLimit = atof(argv[5]);
243
244   fPeakFitter = new AliHLTPHOSPhysicsAnalyzerPeakFitter();
245   fRootHistPtr = new TH1F("hist", "hist", nBins, lowLimit, highLimit);
246   fAnalyzerPtr = new AliHLTPHOSPhysicsAnalyzerSpectrum();
247   fAnalyzerPtr->SetThreshold(firstThreshold,secondThreshold);
248   fAnalyzerPtr->SetHistogram(fRootHistPtr);
249
250   if (argc==0 && argv==NULL) {
251     // this is currently just to get rid of the warning "unused parameter"
252   }
253   
254   return 0;
255 }
256
257 AliHLTComponent*
258 AliHLTPHOSPhysicsAnalyzerSpectrumComponent::Spawn()
259 {
260   //Spawn a new AliHLTPHOSPhysicsAnalyzerSpectrumComponent, for the HLT framework
261   return new AliHLTPHOSPhysicsAnalyzerSpectrumComponent();
262 }