source: branches/MarsISDCBranchBasedOn17887/mtemp/mifae/library/MFHVNotNominal.cc

Last change on this file was 3999, checked in by jlopez, 21 years ago
*** empty log message ***
File size: 6.5 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of MARS, the MAGIC Analysis and Reconstruction
5! * Software. It is distributed to you in the hope that it can be a useful
6! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
7! * It is distributed WITHOUT ANY WARRANTY.
8! *
9! * Permission to use, copy, modify and distribute this software and its
10! * documentation for any purpose is hereby granted without fee,
11! * provided that the above copyright notice appear in all copies and
12! * that both that copyright notice and this permission notice appear
13! * in supporting documentation. It is provided "as is" without express
14! * or implied warranty.
15! *
16!
17!
18! Author(s): Javier Lopez 5/2004 <mailto:jlopez@ifae.es>
19!
20! Copyright: MAGIC Software Development, 2000-2004
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26//
27// MFHVNotNominal
28//
29// Filter to look if the HV monitored value is in agreement with the
30// expected nominal value. If this is not true it sets a flag in MBadPixelsCam
31// to not use this pixel in the analysis.
32// Moreover if more than a certain number of pixels (set by defauld to 230) is
33// deviated from the nominal value the event is rejected.
34//
35// Input Containers:
36// MCameraHV
37//
38// Output Containers:
39// MBadPixelsCam
40//
41//////////////////////////////////////////////////////////////////////////////
42#include "MFHVNotNominal.h"
43
44#include <fstream>
45#include <stdlib.h>
46
47#include <TMath.h>
48
49#include "MLog.h"
50#include "MLogManip.h"
51
52#include "MParList.h"
53
54#include "MCameraHV.h"
55
56#include "MBadPixelsPix.h"
57#include "MBadPixelsCam.h"
58
59ClassImp(MFHVNotNominal);
60
61using namespace std;
62// --------------------------------------------------------------------------
63//
64// Default constructor.
65//
66MFHVNotNominal::MFHVNotNominal(const char *name, const char *title)
67 : fHV(NULL), fBadPixels(NULL), fHVConfFile("NULL"), fMaxHVDeviation(0.03), fMaxNumPixelsDeviated(230)
68{
69 fName = name ? name : "MFHVNotNominal";
70 fTitle = title ? title : "Filter to reject events with too many pixels out of nominal HV";
71
72 fCut[0] = 0;
73 fCut[1] = 0;
74}
75
76// --------------------------------------------------------------------------
77//
78// The PreProcess searches for the following input containers:
79// - MCameraHV
80//
81// The following containers are searched and created if they were not found:
82// - MBadPixelsCam
83//
84Int_t MFHVNotNominal::PreProcess(MParList *pList)
85{
86 //
87 // Containers that have to be there.
88 //
89 fHV = (MCameraHV*)pList->FindObject("MCameraHV");
90 if (!fHV)
91 {
92 *fLog << err << "MCameraHV not found... aborting." << endl;
93 return kFALSE;
94 }
95
96 //
97 // Containers that are created in case that they are not there.
98 //
99 fBadPixels = (MBadPixelsCam*)pList->FindObject("MBadPixelsCam");
100 if (!fBadPixels)
101 {
102 *fLog << err << "Cannot find nor create MBadPixelsCam... aborting" << endl;
103 return kFALSE;
104 }
105
106 if (fHVConfFile != "NULL")
107 {
108
109 const UInt_t npix = 577;
110 fHVNominal.Set(npix);
111
112 // Here we get the nominal HV values directitly from a CC
113 // HV configuration file.
114 // Those files have the following structure:
115 // [HV]
116 // pixel_'hwnumber'='hvvalue'
117
118 ifstream fin(fHVConfFile);
119
120 TString str;
121
122 if(!fin)
123 {
124 *fLog << err << "Imposible to open CC HV configuration file " << fHVConfFile << endl;
125 return kFALSE;
126 }
127 else
128 *fLog << dbg << "Opened CC HV configuration file " << fHVConfFile << endl;
129
130
131 fin >> str;
132 if(str != "[HV]")
133 {
134 *fLog << err << fHVConfFile << " file is not a CC HV configuration file" << endl;
135 return kFALSE;
136 }
137 else
138 *fLog << dbg << fHVConfFile << " file is a good CC HV configuration file" << endl;
139
140 UInt_t npixinfile=0;
141 while(1)
142 {
143 fin >> str;
144 if (fin.eof())
145 break;
146
147 UInt_t equalpos = str.Index("=");
148 UInt_t underpos = str.Index("_");
149 UInt_t length = str.Length();
150
151 TString tmp = str(underpos+1,equalpos-(underpos+1));
152 UInt_t hwpix = atoi((const char*)tmp);
153 tmp = str(equalpos+1,length-(equalpos+1));
154 Double_t value = atof((const char*)tmp);
155
156 fHVNominal[hwpix-1]=value;
157 npixinfile++;
158 }
159
160 fin.close();
161
162 if (npixinfile!=npix)
163 {
164 *fLog << err << fHVConfFile << " CC HV configuration file contain " << npixinfile << " pixels while the camera have " << npix << " pixels." << endl;
165 return kFALSE;
166 }
167 }
168
169 return kTRUE;
170}
171
172
173// ---------------------------------------------------------
174//
175// HVNotNominal rejection:
176//
177// Requiring less than fMaxHVDeviation deviation of HV monitored values
178// from nominal ones.
179//
180// fMaxNumPixelsDeviated is set to 230 by default which is slightly higher
181// than the number of outer pixels in MAGIC (for the case that
182// the outer pixels have some defect).
183//
184Bool_t MFHVNotNominal::HVNotNominalRejection()
185{
186 UInt_t npix = fHVNominal.GetSize();
187
188 UInt_t notnominalpix = 0;
189
190 for (UInt_t idx=1; idx<npix; idx++)
191 {
192 Double_t hv = (*fHV)[idx];
193 Double_t nominal = fHVNominal[idx];
194 Double_t dev = 2.*TMath::Abs(nominal-hv)/(nominal+hv);
195
196 if (dev > fMaxHVDeviation)
197 {
198 MBadPixelsPix &bad = (*fBadPixels)[idx];
199 bad.SetUnsuitable(MBadPixelsPix::kUnsuitableEvt);
200 bad.SetHardware(MBadPixelsPix::kHVNotNominal);
201 notnominalpix++;
202 }
203 }
204
205 if (notnominalpix!=0)
206 fCut[0]++;
207
208 //
209 // If the camera contains more than fMaxNumPixelsDeviated
210 // pixels with deviated HV, then the event is discarted.
211 //
212
213 return notnominalpix > fMaxNumPixelsDeviated;
214}
215
216// -----------------------------------------------------------
217//
218// Compare the HV monitored valued with the HV nominal ones.
219//
220Int_t MFHVNotNominal::Process()
221{
222 fResult = HVNotNominalRejection();
223
224 if (fResult)
225 fCut[1]++;
226
227 return kTRUE;
228}
229
230Int_t MFHVNotNominal::PostProcess()
231{
232 if (GetNumExecutions()==0)
233 return kTRUE;
234
235 *fLog << inf << endl;
236 *fLog << GetDescriptor() << " execution statistics:" << endl;
237 *fLog << dec << setfill(' ');
238
239 *fLog << " " << setw(7) << fCut[0] << " (" << setw(3) ;
240 *fLog << (Int_t)(fCut[0]*100/GetNumExecutions()) ;
241 *fLog << "%) 'some not nominal pixel' events" << endl;
242
243 *fLog << " " << setw(7) << fCut[1] << " (" << setw(3) ;
244 *fLog << (Int_t)(fCut[1]*100/GetNumExecutions()) ;
245 *fLog << "%) rejected events" ;
246 *fLog << " (with fMaxNumPixelsDeviated = " << fMaxNumPixelsDeviated << ")" << endl;
247
248 return kTRUE;
249}
250
Note: See TracBrowser for help on using the repository browser.