]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/PHOS/AliHLTPHOSNoiseMapperComponent.cxx
67c82f674952bb5b6c8ea946debe24a0af6c0cd9
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTPHOSNoiseMapperComponent.cxx
1 //insert copyright
2
3 #include "AliHLTPHOSNoiseMapperComponent.h"
4 #include "AliHLTPHOSNoiseMapper.h"
5 #include "AliHLTPHOSDigitDataStruct.h"
6 #include "AliHLTPHOSBaseline.h"
7 #include "AliHLTPHOSProcessor.h"
8 #include "TH2I.h"
9 #include "TFile.h" 
10 //#include <direct.h>
11 #include <sys/stat.h>
12 #include <sys/types.h>
13
14 const AliHLTComponentDataType AliHLTPHOSNoiseMapperComponent::fgkInputDataTypes[]={kAliHLTVoidDataType,{0,"",""}};
15
16 AliHLTPHOSNoiseMapperComponent gAliHLTPHOSNoiseMapperComponent;
17
18 AliHLTPHOSNoiseMapperComponent::AliHLTPHOSNoiseMapperComponent() :
19   AliHLTPHOSProcessor(),
20   fNoiseMapperPtr(0),
21   fWriteInterval(100),
22   fFilename(0),
23   fDirectory(0),
24   fRunNb(0),
25   fRateThreshold(10)     
26 {
27   
28 }
29
30 AliHLTPHOSNoiseMapperComponent::~AliHLTPHOSNoiseMapperComponent()
31 {
32 }
33
34 int 
35 AliHLTPHOSNoiseMapperComponent::Deinit()
36 {
37  
38   char filename [50];
39   sprintf(filename, "%s/run%d_noisemap.root", fDirectory, fRunNb);
40       
41   FillHistograms();
42       
43   cout << "Writing file...";
44   TFile *outfile = new TFile(filename,"recreate");
45   fNoiseCountLowGainHistPtr->Write();
46   fNoiseCountHighGainHistPtr->Write();
47   fNoiseMapLowGainHistPtr->Write();     
48   fNoiseMapHighGainHistPtr->Write();
49   delete outfile;
50   outfile = 0;
51   cout << "Done!\n";
52   
53   if(fNoiseMapperPtr)
54     {
55       delete fNoiseMapperPtr;
56       fNoiseMapperPtr = 0;
57     }
58   if(fFilename)
59     {
60       delete fFilename;
61       fFilename = 0;
62     }
63 }
64
65 const char*
66 AliHLTPHOSNoiseMapperComponent::GetComponentID()
67 {
68   return "PhosNoiseMapper";
69 }
70
71 void
72
73 AliHLTPHOSNoiseMapperComponent::GetInputDataTypes(vector<AliHLTComponentDataType>& list)
74
75  //Get datatypes for input
76   const AliHLTComponentDataType* pType=fgkInputDataTypes;
77   while (pType->fID!=0) {
78     list.push_back(*pType); 
79     pType++;
80   }
81 }
82
83 AliHLTComponentDataType 
84 AliHLTPHOSNoiseMapperComponent::GetOutputDataType()
85 {
86   return AliHLTPHOSDefinitions::fgkAliHLTNoiseMapDataType;
87 }
88
89
90 void 
91 AliHLTPHOSNoiseMapperComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
92 {
93   constBase = 30;
94   inputMultiplier = 1;
95 }
96
97 int 
98 AliHLTPHOSNoiseMapperComponent::DoEvent(const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
99                                         AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size,
100                                         std::vector<AliHLTComponentBlockData>& outputBlocks)
101 {
102    //Do event
103      
104   UInt_t tSize            = 0;
105   UInt_t offset           = 0; 
106   UInt_t mysize           = 0;
107   Int_t nRecPoints        = 0;
108   Int_t index             = 0;
109   
110   Int_t fileCount = 0;
111   Int_t digitCount = 0;
112   char filename [50];
113
114
115   AliHLTUInt8_t* outBPtr;
116   outBPtr = outputPtr;
117   const AliHLTComponentBlockData* iter = 0; 
118   unsigned long ndx; 
119
120   for( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
121     {
122       iter = blocks+ndx;
123       
124       if(iter->fDataType != AliHLTPHOSDefinitions::fgkCellEnergyDataType)
125         {
126           //      cout << "Warning: data type is not fgkCellEnergyDataType " << endl;
127           continue;
128
129         }
130       fNoiseMapperPtr->MapNoisyChannels(reinterpret_cast<AliHLTPHOSDigitContainerDataStruct*>(iter->fPtr));
131     }
132   
133   fEventCount++;
134
135   //PushBack(fDigitArrayPtr, kAliHLTAnyDataType, (AliHLTUInt32_t)0);
136   
137    if(fEventCount % 10 == 0)
138     {
139       cout << "Event #: " << fEventCount << endl;
140     }
141
142   if(fEventCount % fWriteInterval == 0)
143     {
144       char filename [50];
145       sprintf(filename, "%s/run%d_noisemap.root", fDirectory, fRunNb);
146       
147       FillHistograms();
148       
149       cout << "Writing file...";
150       TFile *outfile = new TFile(filename,"recreate");
151       fNoiseCountLowGainHistPtr->Write();
152       fNoiseCountLowGainHistPtr->Write();
153       fNoiseMapLowGainHistPtr->Write(); 
154       fNoiseMapHighGainHistPtr->Write();
155       delete outfile;
156       outfile = 0;
157       cout << "Done!\n";          
158     }
159   
160   return 0;
161 }
162
163
164 int
165 AliHLTPHOSNoiseMapperComponent::DoInit(int argc, const char** argv )
166 {
167   
168   Bool_t pathSet = false;
169   Bool_t nSamplesSet = false;
170   
171   fDirectory = new char[50];
172
173   fNoiseMapperPtr = new AliHLTPHOSNoiseMapper();
174   
175   fNoiseCountLowGainHistPtr = new TH2I("noiseCountLowGain", "Noise count for low gain channels", 64, 0, 63, 56, 0, 55);
176   fNoiseCountHighGainHistPtr = new TH2I("noiseCountHighGain", "Noise count for high gain channels", 64, 0, 63, 56, 0, 55);
177   fNoiseMapLowGainHistPtr = new TH2I("noiseMapLowGain", "Noise map for low gain channels", 64, 0, 63, 56, 0, 55);
178   fNoiseMapHighGainHistPtr = new TH2I("noiseMapHighGain", "Noise map for high gain channels", 64, 0, 63, 56, 0, 55);
179   
180   for(int i = 0; i < argc; i++)
181     {
182       if(!strcmp("-path", argv[i]))
183         {
184           strcpy(fDirectory, argv[i+1]);
185           pathSet = true;
186         }
187       if(!strcmp("-noisethreshold", argv[i]))
188         {
189           fNoiseMapperPtr->SetNoiseThreshold(atof(argv[i+1]));
190         }
191     }
192         
193   
194   fWriteInterval = 100;
195
196   return 0;
197 }
198
199 AliHLTComponent*
200 AliHLTPHOSNoiseMapperComponent::Spawn()
201 {
202   return new AliHLTPHOSNoiseMapperComponent();
203 }
204
205 void 
206 AliHLTPHOSNoiseMapperComponent::FillHistograms()
207 {
208   Int_t channelArray[N_XCOLUMNS_MOD][N_ZROWS_MOD][N_GAINS];
209   fNoiseMapperPtr->GetChannelArray(channelArray);
210   for(Int_t x = 0; x < N_XCOLUMNS_MOD; x++)
211     {
212       for(Int_t z = 0; z < N_ZROWS_MOD; z++)
213         {
214           fNoiseCountLowGainHistPtr->SetBinContent(x, z, channelArray[x][z][0]);
215           fNoiseCountHighGainHistPtr->SetBinContent(x, z, channelArray[x][z][1]);
216           if((channelArray[x][z][0]/fEventCount) > fRateThreshold)
217           {
218             fNoiseMapLowGainHistPtr->SetBinContent(x, z, 10);
219           }
220           if((channelArray[x][z][1]/fEventCount) > fRateThreshold)
221           {
222             fNoiseMapHighGainHistPtr->SetBinContent(x, z, 10);
223           }
224         }
225     }
226 }