GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CubicFilter.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2004-2006 by Olivier Stezowski & Christian Finck *
3  * stezow(AT)ipnl.in2p3.fr, cfinck(AT)ires.in2p3.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
20 
22 #include <fstream>
23 
24 #ifndef ROOT_TList
25 #include "TList.h"
26 #endif
27 
28 #ifndef Gw_CubicFilter
29 #include "CubicFilter.h"
30 #endif
31 
32 #ifndef Gw_Link
33 #include "Link.h"
34 #endif
35 
36 #ifndef Gw_Peak1D
37 #include "Peak1D.h"
38 #endif
39 
40 using namespace Gw;
41 
42 //
44 
45 
46 //__________________________________________________________
48  : CSFilter("CubicFilter", "Cubic Gating"),
49  fGateList(new TList()),
50  IsPeak(true)
51 {
52  // default constructor
53  fLog.GetProcessName() = "CubicFilter";
54  fGateList->SetOwner(true);
55  for (Int_t i = 0; i < 4; ++i) {
56  fGateList->Add(new Gate());
57  }
58 }
59 
60 
61 //__________________________________________________________
63 {
64  // default destructor
65  delete fGateList;
66 }
67 
68 //__________________________________________________________
70 {
72  ResetGates();
73 }
74 
75 //__________________________________________________________
76 Bool_t CubicFilter::IsListFilled(Int_t idx)
77 {
78  Gate* gate = static_cast<Gate*> (fGateList->At(idx));
79 
80  if (gate)
81  if (gate->GetNofGates() > 0) return true;
82 
83  return false;
84 }
85 
86 //__________________________________________________________
87 void CubicFilter::ImportGates(const Char_t* name, Option_t* opt)
88 {
89 
90  Gate* gate = static_cast<Gate*> (fGateList->At(0));
91 
92  IsPeak = false;
93  std::ifstream filein(name);
94  Double_t gateInf;
95  Double_t gateSup;
96 
97  while ( filein.good() ) {
98  filein >> gateInf >> gateSup;
99  gate->AddGate(gateInf, gateSup, opt);
100  }
101 
102  filein.close();
103 }
104 
105 //__________________________________________________________
106 void CubicFilter::AddGate(Double_t gateInf, Double_t gateSup, Int_t axis, Option_t* opt)
107 {
108 
109  if (axis < fGateList->GetEntries()) {
110  Gate* gate = static_cast<Gate*> (fGateList->At(axis));
111  gate->AddGate(gateInf, gateSup, opt);
112  } else {
113  fLog.SetProcessMethod("AddGate(Double_t, Double_t, Int_t, Option_t* )");
114  fLog << error << "axis not defined" << dolog;
115  }
116 }
117 
118 //__________________________________________________________
119 void CubicFilter::MakeGates(Option_t* opt)
120 {
121  TString tmp(opt);
122  tmp.ToLower();
123 
124  if (IsPeak) {
125  ResetGates();
126  if (tmp.Contains("peak"))
127  FillGates();
128  else
129  FillBkgGates();
130  IsPeak = true;
131  }
132 }
133 
134 //__________________________________________________________
136 {
137  Int_t nList = 0;
138  for (Int_t iGate = 0; iGate < fGateList->GetEntries(); ++iGate) {
139 
140  Gate* gate = static_cast<Gate*> ( fGateList->At(iGate) );
141  if (gate->GetNofGates() > 0) nList++;
142  }
143 
144  return (nList > 1);
145 }
146 
147 //__________________________________________________________
148 Int_t CubicFilter::IsInside(Double_t* energies, Int_t mult, Short_t* inGate, Int_t iGate)
149 {
150  Int_t nGate = 0;
151  Gate* gate = static_cast<Gate*> ( fGateList->At(iGate) );
152 
153  if (gate->GetNofGates() <= 0) {
154  fLog.SetProcessMethod("IsInside(Double_t*, Int_t, Short_t*, Int_t )");
155  fLog << error << "Gate index not defined" << dolog;
156  return 0;
157  }
158 
159  for(Int_t i = 0; i < mult; ++i) {
160  inGate[i] = 0;
161  Bool_t IsInGate = false;
162 
163  for(Int_t k = 0; k < gate->GetNofGates(); ++k) {
164  if( (energies[i] >= gate->GetGateInf(k)) && (energies[i] <= gate->GetGateSup(k)) ) {
165  IsInGate = true;
166  }
167  }
168 
169  if (IsInGate) {
170  inGate[i] = 1;
171  nGate++;
172  }
173  }
174 
175  if (nGate < fCondition) {
176  for(Int_t i = 0; i < mult; ++i)
177  inGate[i] = 0;
178  }
179 
180  if (nGate > fCondition+fDimension) {
181  for(Int_t i = 0; i < mult; ++i)
182  inGate[i] = 1;
183  }
184 
185  return nGate;
186 }
187 
188 // private methods
189 
190 //__________________________________________________________
191 void CubicFilter::ResetGates()
192 {
193 
194  for (Int_t i = 0; i < fGateList->GetEntries(); ++i) {
195  Gate* gate = static_cast<Gate*> ( fGateList->At(i) );
196  gate->Reset();
197  }
198 }
199 
200 //__________________________________________________________
201 void CubicFilter::FillGates()
202 {
203  Gate* gate = 0x0;
204  Peak1D* peak = 0x0;
205  IsPeak = true;
206 
207  TIter next(fPeakList);
208  while ( (peak = (Peak1D*)next()) ) {
209  Int_t idx = Peak1D::GetGateAxis(peak->GetLineColorPeak());
210  if (idx == -1) continue; // should not happen
211  gate = static_cast<Gate*> ( fGateList->At(idx) );
212  gate->AddGate(peak->GetPosition()-peak->GetFWHM()/2., peak->GetPosition()+peak->GetFWHM()/2.);
213  }
214  IsBkg = false;
215 }
216 
217 //__________________________________________________________
218 void CubicFilter::FillBkgGates()
219 {
220  Gate* gate = 0x0;
221  Peak1D* peak = 0x0;
222 
223  TIter next(fPeakList);
224  while ( (peak = (Peak1D*)next()) ) {
225 
226  Int_t idx = Peak1D::GetGateAxis(peak->GetLineColorPeak());
227  if (idx == -1) continue;
228 
229  gate = static_cast<Gate*> ( fGateList->At(idx) );
230 
231  TVector2 vecL = peak->GetBkgLeft();
232  TVector2 vecR = peak->GetBkgRight();
233 
234  gate->AddGate(vecL.X(), vecL.Y());
235  gate->AddGate(vecR.X(), vecR.Y());
236 
237  }
238  IsBkg = true;
239 }
240 
241 
242 // Gate
244 
245 //__________________________________________________________
246 Gate::Gate()
247 : TObject(),
248  fGateInf(),
249  fGateSup()
250 {
251  // default constructor
252 }
253 
254 //__________________________________________________________
256 {
257  // default destructor
258 }
259 
260 //__________________________________________________________
262 {
263  fGateInf.Reset(0.);
264  fGateSup.Reset(0.);
265  fGateInf.Set(0);
266  fGateSup.Set(0);
267 }
268 
269 //__________________________________________________________
270 void Gate::AddGate(Double_t gateInf, Double_t gateSup, Option_t* opt)
271 {
272  TString option(opt);
273 
274  option.ToLower();
275  if (option.Contains("reset")) {
276  Reset();
277  }
278 
279  fGateInf.Set(fGateInf.GetSize()+1);
280  fGateInf.AddAt(gateInf, fGateInf.GetSize()-1);
281 
282  fGateSup.Set(fGateSup.GetSize()+1);
283  fGateSup.AddAt(gateSup, fGateSup.GetSize()-1);
284 }
285 
void Reset()
Reset gates.
void Reset()
Reset gates.
Definition: CubicFilter.cpp:69
LogMessage & error(LogMessage &)
Short_t fDimension
number of conditions for gating
Definition: CSFilter.h:62
TList * fPeakList
dimension for projection
Definition: CSFilter.h:64
Double_t GetGateInf(Int_t idx)
Get gate inf.
Definition: CubicFilter.h:87
Bool_t IsBkg
list of peaks
Definition: CSFilter.h:65
CubicFilter class for cubic gates.
Definition: CubicFilter.h:22
virtual ~CubicFilter()
Definition: CubicFilter.cpp:62
LogMessage fLog
flag to know whether gate are made with bkg
Definition: CSFilter.h:67
static Int_t GetGateAxis(Color_t co)
Definition: BasePeak.cpp:111
void AddGate(Double_t gateInf, Double_t gateSup, Int_t axis=0, Option_t *opt="update")
Add gate.
Bool_t IsCombined()
Flag to combined.
Double_t GetGateSup(Int_t idx)
Get Gate sup.
Definition: CubicFilter.h:90
virtual Color_t GetLineColorPeak()
Get line peak color.
Definition: Peak1D.cpp:1658
virtual Double_t GetFWHM(Option_t *axis="X") const
Get FWHM of peak.
Definition: Peak1D.cpp:962
const TVector2 GetBkgRight() const
Definition: Peak1D.h:244
Bool_t IsListFilled(Int_t idx)
Check if gate filled.
Definition: CubicFilter.cpp:76
LogMessage & dolog(LogMessage &)
virtual Double_t GetPosition(Option_t *axis="X") const
Get position of peak.
Definition: Peak1D.cpp:955
void MakeGates(Option_t *opt="peak")
Make gates.
CSFilter base class for filter.
Definition: CSFilter.h:56
void AddGate(Double_t gateInf, Double_t gateSup, Option_t *opt="update")
Add gate.
header file for a general 1D peak
void ImportGates(const Char_t *name, Option_t *opt="update")
Import gates from file.
Definition: CubicFilter.cpp:87
Int_t IsInside(Double_t *energies, Int_t mult, Short_t *inGate, Int_t iGate=0)
Get energies inside gates.
A graphical interface for placing schematic peak onto a 1D histogram with a given position...
Definition: Peak1D.h:79
Short_t fCondition
Definition: CSFilter.h:61
void Reset()
Reset peak.
Definition: CSFilter.cpp:70
const TVector2 GetBkgLeft() const
Get background limits.
Definition: Peak1D.h:242
virtual void SetProcessMethod(const char *)
To set the current method.
Int_t GetNofGates() const
Get number of gates.
Definition: CubicFilter.h:84
ClassImp(CubicFilter) CubicFilter
Definition: CubicFilter.cpp:43
virtual ~Gate()