"Bad Channels Finder" Detector Algorithm introduced.
[u/mrichter/AliRoot.git] / PHOS / AliPHOSDA2.cxx
CommitLineData
6a34dadb 1#include "AliPHOSDA2.h"
2#include "TString.h"
3
4ClassImp(AliPHOSDA2)
5
6//----------------------------------------------------------------
7AliPHOSDA2::AliPHOSDA2(int module) : TNamed(),
8 fHistoFile(0),fMod(module)
9
10{
11 // Create AliPHOSDA2 ("Bad channels finder") object.
12 // module is the PHOS module number (0..4).
13 // Quality histogram names: module_iX_iZ_gain.
14 // Root file name: PHOS_ModuleX_BCM.root, where X - module number.
15
16 char name[128];
17 sprintf(name,"PHOS_Module%d_BCM",fMod);
18 SetName(name);
19
20 SetTitle("Detector Algorithm to check for PHOS channels quality");
21
22 char rootname[128];
23 sprintf(rootname,"%s.root",GetName());
24
25 fHistoFile = new TFile(rootname,"recreate"); // new file!
26
27 for(Int_t iX=0; iX<64; iX++) {
28 for(Int_t iZ=0; iZ<56; iZ++) {
29 for(Int_t iGain=0; iGain<2; iGain++) {
30 fHQuality[iX][iZ][iGain] = 0;
31 }
32 }
33 }
34
35 fMaps[0]=0;
36 fMaps[1]=0;
37
38}
39
40//-------------------------------------------------------------------
41AliPHOSDA2::AliPHOSDA2(const AliPHOSDA2& da) : TNamed(da),
42 fHistoFile(0),fMod(da.fMod)
43{
44 // Copy constructor.
45
46 char hname[128];
47 TH1F* hist1=0;
48
49 for(Int_t iX=0; iX<64; iX++) {
50 for(Int_t iZ=0; iZ<56; iZ++) {
51 for(Int_t iGain=0; iGain<2; iGain++) {
52
53 sprintf(hname,"%d_%d_%d_%d",fMod,iX,iZ,iGain);
54 hist1 = (TH1F*)da.fHistoFile->Get(hname);
55 if(hist1) fHQuality[iX][iZ][iGain] = new TH1F(*hist1);
56 else
57 fHQuality[iX][iZ][iGain] = 0;
58 }
59 }
60 }
61
62 if(da.fMaps[0])
63 fMaps[0] = new TH2F(*da.fMaps[0]);
64 else
65 fMaps[0] = 0;
66
67 if(da.fMaps[1])
68 fMaps[1] = new TH2F(*da.fMaps[1]);
69 else
70 fMaps[1] = 0;
71
72 fHistoFile = new TFile(da.GetName(),"recreate");
73
74}
75
76//-------------------------------------------------------------------
77AliPHOSDA2& AliPHOSDA2::operator= (const AliPHOSDA2& da)
78{
79 //Assignment operator.
80
81 if(this != &da) {
82
83 TString oldname(fHistoFile->GetName());
84 TString newname(da.fHistoFile->GetName());
85
86 if(oldname != newname) {
87 delete fHistoFile;
88 fHistoFile = new TFile(da.fHistoFile->GetName(),"update");
89 }
90
91 fMod = da.fMod;
92
93 SetName(da.GetName());
94 SetTitle(da.GetTitle());
95
96 for(Int_t iX=0; iX<64; iX++) {
97 for(Int_t iZ=0; iZ<56; iZ++) {
98 for(Int_t iGain=0; iGain<2; iGain++) {
99 if (fHQuality[iX][iZ][iGain]) delete fHQuality[iX][iZ][iGain];
100 fHQuality[iX][iZ][iGain] = da.fHQuality[iX][iZ][iGain];
101 }
102 }
103 }
104
105 if(fMaps[0]) {
106 delete fMaps[0];
107 fMaps[0] = da.fMaps[0];
108 }
109
110 if(fMaps[1]) {
111 delete fMaps[1];
112 fMaps[1] = da.fMaps[1];
113 }
114
115 }
116
117 return *this;
118}
119
120
121//-------------------------------------------------------------------
122AliPHOSDA2::~AliPHOSDA2()
123{
124 // Destructor
125
126 UpdateHistoFile();
127 if(fHistoFile) delete fHistoFile;
128
129}
130
131//-------------------------------------------------------------------
132void AliPHOSDA2::FillQualityHistograms(Float_t quality[64][56][2])
133{
134 // Fills quality histograms.
135 // _By definition_, qood quality is 0<quality<1,
136 // all outside that is a bad quality.
137 // If no quality value read for particular channel,
138 // the correspondent array entry should be filled by zero.
139 // WARNING: this function should be called once per event!
140
141 char hname[128];
142 char htitl[128];
143
144 for(Int_t iX=0; iX<64; iX++) {
145 for (Int_t iZ=0; iZ<56; iZ++) {
146
147 for(Int_t iGain=0; iGain<2; iGain++) {
148 if(!quality[iX][iZ][iGain]) continue;
149
150 if(fHQuality[iX][iZ][iGain])
151 fHQuality[iX][iZ][iGain]->Fill(quality[iX][iZ][iGain]);
152 else {
153 sprintf(hname,"%d_%d_%d_%d",fMod,iX,iZ,iGain);
154 sprintf(htitl,"Quality for crystal %d_%d_%d and gain %d",fMod,iX,iZ,iGain);
155 fHQuality[iX][iZ][iGain] = new TH1F(hname,htitl,100,1.e-6,10.);
156 fHQuality[iX][iZ][iGain]->Fill(quality[iX][iZ][iGain]);
157 }
158 }
159
160 }
161 }
162
163}
164
165//-------------------------------------------------------------------
166void AliPHOSDA2::UpdateHistoFile()
167{
168 // Write histograms to file
169
170 if(!fHistoFile) return;
171 if(!fHistoFile->IsOpen()) return;
172
173 char titl[128];
174
175 if(fMaps[0])
176 fMaps[0]->Reset();
177 else {
178 sprintf(titl,"Quality map for Low gain");
179 fMaps[0] = new TH2F("gmaplow", titl, 64,0.,64.,56,0.,56.);
180 }
181
182 if(fMaps[1])
183 fMaps[1]->Reset();
184 else {
185 sprintf(titl,"Quality map for High gain");
186 fMaps[1] = new TH2F("gmaphigh", titl, 64,0.,64.,56,0.,56.);
187 }
188
189 TH1F* hist1=0;
190
191 for(Int_t iX=0; iX<64; iX++) {
192 for(Int_t iZ=0; iZ<56; iZ++) {
193
194 for(Int_t iGain=0; iGain<2; iGain++) {
195 hist1 = fHQuality[iX][iZ][iGain];
196 if(hist1) {
197 hist1->Write(hist1->GetName(),TObject::kWriteDelete);
198 Double_t mean = hist1->GetMean();
199 fMaps[iGain]->Fill(iX,iZ,mean);
200 }
201 }
202
203 }
204 }
205
206 fMaps[0]->Write(fMaps[0]->GetName(),TObject::kWriteDelete);
207 fMaps[1]->Write(fMaps[1]->GetName(),TObject::kWriteDelete);
208
209}
210