GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CSManager.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 
23 #ifndef Gw_CSManager
24 #include "CSManager.h"
25 #endif
26 
27 #ifndef Gw_CubicFilter
28 #include "CubicFilter.h"
29 #endif
30 
31 #ifndef Gw_CorrelatedSpace
32 #include "CorrelatedSpace.h"
33 #endif
34 
35 #ifndef Gw_Peak1D
36 #include "Peak1D.h"
37 #endif
38 
39 #ifndef Gw_PeakCreator
40 #include "PeakCreator.h"
41 #endif
42 
43 #ifndef ROOT_TCanvas
44 #include "TCanvas.h"
45 #endif
46 
47 #ifndef ROOT_TFolder
48 #include "TFolder.h"
49 #endif
50 
51 #ifndef ROOT_TH1D
52 #include "TH1D.h"
53 #endif
54 
55 #ifndef ROOT_TList
56 #include "TList.h"
57 #endif
58 
59 #ifndef ROOT_TROOT
60 #include "TROOT.h"
61 #endif
62 
63 #include "TStyle.h"
64 
65 
66 using namespace Gw;
67 
68 //
70 
71 const TString CSManager::fgkFolderName = "CSManager";
72 const TString CSManager::fgkFilterFolderName = "Filter";
73  Int_t CSManager::fgNofInstance = 0;
74 
75 //__________________________________________________________
76 CSManager::CSManager()
77  : TNamed("CSManager", "Default"),
78  fRegCS(new TList()),
79  fFilterBaseName("Gate"),
80  fIsCanvasDiv(false),
81  fLog("CSManager")
82 {
83  // default constructor
84  fRegCS->SetOwner(false);
85 
86  SetFolders();
87 }
88 
89 //__________________________________________________________
90 CSManager::CSManager(const char* name, const char* title)
91 : TNamed(name, title),
92  fRegCS(new TList()),
93  fFilterBaseName("Gate"),
94  fIsCanvasDiv(false),
95  fLog("CSManager")
96 {
97  // default constructor
98  fRegCS->SetOwner(false);
99 
100  SetFolders();
101  }
102 
103 //__________________________________________________________
105 {
106  fgNofInstance++;
107  fCInstance = fgNofInstance;
108 
109  TString nameFolder = GetFolderName();
110  TFolder* folder = (TFolder*)gROOT->FindObjectAny(nameFolder.Data());
111  if (folder == 0x0) {
112  folder = gROOT->GetRootFolder()->AddFolder(fgkFolderName.Data(),"Folder");
113  }
114 
115  if ((CorrelatedSpace*)gROOT->FindObjectAny(Form("%s/%s", nameFolder.Data(), GetName())) ) {
116  SetName(Form("%s%d", GetName(), fCInstance-1));
117  }
118  folder->Add(this);
119 
120  nameFolder = GetFilterFolderName();
121 
122  TFolder* folderFilter = (TFolder*)gROOT->FindObjectAny(nameFolder.Data());
123  if (folderFilter == 0x0) {
124  folder->AddFolder(Form("%s_%s",GetName(), fgkFilterFolderName.Data()),"Folder");
125  }
126  folderFilter = (TFolder*)gROOT->FindObjectAny(nameFolder.Data());
127  folderFilter->SetOwner(true);
128 }
129 
130 //__________________________________________________________
132 {
133  Float_t bkg = 0;
134  Float_t gate = 0;
135  for (Int_t i = 0; i < filter->GetNofPeaks(); ++i) {
136  Peak1D* peak = (Peak1D*)filter->GetPeak(i);
137  peak->Area("g");
138  bkg += peak->GetBkgIntegral();
139  gate += peak->GetSubPeakIntegral();
140  }
141  return gate/bkg;
142 }
143 
144 //__________________________________________________________
146 {
147  // default destructor
148  delete fRegCS;
149  TFolder *folder = (TFolder*)gROOT->FindObjectAny(GetFilterFolderName().Data());
150  folder->Delete();
151 }
152 
153 //__________________________________________________________
155 {
156  TString nameFolder = fgkFolderName;
157  nameFolder.Prepend("/");
158 
159  return nameFolder;
160 }
161 
162 //__________________________________________________________
164 {
165  TString nameFolder = fgkFolderName;
166  nameFolder.Prepend("/");
167  nameFolder.Append("/");
168  nameFolder.Append(Form("%s_%s",GetName(), fgkFilterFolderName.Data()));
169  return nameFolder;
170 }
171 
172 //__________________________________________________________
174 {
175  TSeqCollection* listCanvas = gROOT->GetListOfCanvases();
176 
177  TString name(GetName());
178  TCanvas* canvas = 0x0;
179  TIter next(listCanvas);
180 
181  while ( (canvas = (TCanvas*)next()) ) {
182  if ( !name.CompareTo(canvas->GetName()) ) {
183  break;
184  }
185  }
186 
187  if (canvas == 0x0) {
188  canvas = new TCanvas(GetName(), GetTitle());
190  }
191  canvas->SetLeftMargin(0.12);
192  canvas->SetRightMargin(0.05);
193  canvas->Draw();
194 
195  if (!fIsCanvasDiv) {
196  Int_t entries = fRegCS->GetEntries()*2;
197  canvas->Divide(1,entries);
198  fIsCanvasDiv = true;
199  }
200 
201  return canvas;
202 }
203 
204 //__________________________________________________________
205 TVirtualPad* CSManager::GetProjTotPad(Int_t idx)
206 {
207  TCanvas* canvas = GetCanvas();
208  return canvas->cd(2*idx+1);
209 }
210 
211 //__________________________________________________________
212 TVirtualPad* CSManager::GetProjPad(Int_t idx)
213 {
214  TCanvas* canvas = GetCanvas();
215  return canvas->cd(2*idx+2);
216 }
217 
218 //__________________________________________________________
219 void CSManager::DrawProj(Option_t* opt)
220 {
221  CubicFilter* filter = 0x0;
222  Int_t entries = fRegCS->GetEntries();
223 
224  for (Int_t i = 0; i < entries; ++i) {
225 
226  filter = (CubicFilter*)GetFilter(Form("%s%d",GetFilterBaseName(), i));
227  if (filter == 0x0) {
228  fLog.SetProcessMethod("DrawProj(Option_t* )");
229  fLog << error << "filter not defined" << dolog;
230  continue;
231  }
232 
233  GetProjTotPad(i);
234  Float_t ratio = GetRatio(filter);
235 
236  GetProjPad(i);
237 
238  TH1D* proj = GetHisto(i);
239 
240  proj->SetYTitle("Number of Counts");
241  proj->SetXTitle("Energy");
242  proj->SetTitleOffset(1.2,"X");
243  proj->SetTitleOffset(1.5,"Y");
244  proj->SetLabelOffset(0.01);
245 
246  TH1D* projBkg = GetHistoBkg(i);
247  proj->Add(projBkg, -ratio);
248 
249  proj->Draw(opt);
250 
251  filter->Draw("gate");
252  }
253  GetCanvas()->Update();
254 }
255 
256 //__________________________________________________________
257 void CSManager::DrawProjTot(Option_t* opt, Option_t* axis)
258 {
259  Int_t entries = fRegCS->GetEntries();
260 
261  for (Int_t i = 0; i < entries; ++i) {
262  GetProjTotPad(i);
263 
264  TH1D* proj = GetHistoTot(axis, i);
265  proj->SetYTitle("Number of Counts");
266  proj->SetXTitle("Energy");
267  proj->SetTitleOffset(1.2,"X");
268  proj->SetTitleOffset(1.5,"Y");
269  proj->SetLabelOffset(0.01);
270 
271  proj->Draw(opt);
272  }
273  GetCanvas()->Update();
274 }
275 
276 //__________________________________________________________
277 Int_t CSManager::CollectGate(Option_t* opt)
278 {
279  fLog.SetProcessMethod("CollecGate(Option_t* )");
280 
281  // add filter
282  CubicFilter* filter = 0x0;
283 
284  TString option(opt);
285  option.ToLower();
286 
287  // find last drawn histo
288 // TVirtualPad* pad = 0x0;
289 
290  TObject* obj = 0x0;
291  Int_t nPeak = 0;
292  TCanvas* hC = GetCanvas();
293 
294  Int_t entries = fRegCS->GetEntries();
295 
296  for (Int_t i = 0; i < entries; ++i) {
297 
298  filter = (CubicFilter*)GetFilter(Form("%s%d",GetFilterBaseName(), i));
299  if (option.Contains("reset")) {
300  filter->Reset();
301  }
302 
303  TVirtualPad* cpad = 0x0;
304  cpad = hC->GetPad(2*i+1);
305 
306  TIter next(cpad->GetListOfPrimitives());
307  while ( (obj = next()) ) {
308  if ( obj->InheritsFrom("TH1") )
309 // pad = cpad;
310  if ( obj->InheritsFrom("Gw::BasePeak") ) { // clear previous peak
311  Peak1D* peak = dynamic_cast<Peak1D*> (obj);
312  if (peak) {
314  filter->AddPeak(peak);
315  nPeak++;
316  }
317  }
318  }
319  }
320  }
321  fLog << dolog;
322 
323  return nPeak;
324 }
325 
326 //__________________________________________________________
328 {
329  CorrelatedSpace* regCS = dynamic_cast<CorrelatedSpace*> ( CorrelatedSpace::GetCSList()->FindObject(cs) );
330 
331  if (regCS == 0x0) {
332  fLog.SetProcessMethod("Register(CorrelatedSpace* )");
333  fLog << error << "CS not registred !" << dolog;
334  return;
335  }
336 
337  fRegCS->Add(cs);
338  EnableCanvasDiv();
339 }
340 
341 //__________________________________________________________
342 TH1D* CSManager::GetHistoTot(Option_t* axis, Int_t iCS) const
343 {
344  if (iCS >= fRegCS->GetEntries()) {
345  fLog.SetProcessMethod("GetHistoTot(Option_t* )");
346  fLog << error << "CS index too large" << dolog;
347  return 0x0;
348  }
349 
350  CorrelatedSpace* cs = (CorrelatedSpace*)fRegCS->At(iCS);
351  TH1D* proj = cs->GetHistoTot(axis);
352 
353  return proj;
354 }
355 
356 //__________________________________________________________
357 TH1D* CSManager::GetHisto(Int_t iCS) const
358 {
359  if (iCS >= fRegCS->GetEntries()) {
360  fLog.SetProcessMethod("GetHisto(Option_t* )");
361  fLog << error << "CS index too large" << dolog;
362  return 0x0;
363  }
364 
365  CorrelatedSpace* cs = (CorrelatedSpace*)fRegCS->At(iCS);
366  TH1D* proj = cs->GetHisto();
367 
368  return proj;
369 }
370 
371 //__________________________________________________________
372 TH1D* CSManager::GetHistoBkg(Int_t iCS) const
373 {
374  if (iCS >= fRegCS->GetEntries()) {
375  fLog.SetProcessMethod("GetHistoBkg(Option_t* )");
376  fLog << error << "CS index too large" << dolog;
377  return 0x0;
378  }
379 
380  CorrelatedSpace* cs = (CorrelatedSpace*)fRegCS->At(iCS);
381  TH1D* proj = cs->GetHistoBkg();
382 
383  return proj;
384 }
385 
386 //__________________________________________________________
387 CSFilter* CSManager::GetFilter(Option_t* gateName)
388 {
389  // add filter
390  TString nameFolder = GetFilterFolderName();
391 
392  TFolder *folder = (TFolder*)gROOT->FindObjectAny(nameFolder.Data());
393  if (folder == 0x0) {
394  fLog.SetProcessMethod("GetFilter(Option_t* )");
395  fLog << error << "No folder found for filter" << dolog;
396  return 0x0;
397  }
398 
399  TString name = nameFolder;
400  name.Append("/");
401  name.Append(gateName);
402 
403  CubicFilter* filter = (CubicFilter*)gROOT->FindObjectAny(name.Data());
404 
405  if ( filter == 0x0 ) {
406  filter = new CubicFilter();
407  filter->SetName(gateName);
408  folder->Add(filter);
409  }
410  return filter;
411 }
412 
413 //__________________________________________________________
414 void CSManager::Project(Option_t* axis)
415 {
416  if (fRegCS->GetEntries() <= 0) {
417  fLog.SetProcessMethod("Project(Option_t*, Option_t* )");
418  fLog << error << "No correlated space registered" << dolog;
419  return;
420  }
421 
422  CubicFilter* filter = 0x0;
423  CorrelatedSpace* cs = 0x0;
424 
425  for (Int_t i = 0; i < fRegCS->GetEntries(); ++i) {
426  cs = dynamic_cast<CorrelatedSpace*> ( fRegCS->At(i) );
427  filter = (CubicFilter*)GetFilter(Form("%s%d",GetFilterBaseName(), i));
428  filter->MakeGates();
429  cs->Project(filter, axis);
430 
431  filter->MakeGates("bkg");
432  cs->Project(filter, axis);
433  }
434 }
435 
436 //__________________________________________________________
438 {
439  if (dst)
440  dst->Import(src);
441 }
442 
443 
void AddPeak(BasePeak *peak, Option_t *opt="update")
Add Peak.
Definition: CSFilter.cpp:90
TVirtualPad * GetProjPad(Int_t idx)
Get pad of projected spectrum for a given CS.
Definition: CSManager.cpp:212
A single value data.
Definition: Data.h:58
void Reset()
Reset gates.
Definition: CubicFilter.cpp:69
Int_t GetNofPeaks() const
Get number of peaks.
Definition: CSFilter.h:121
header file for PeakCreator.cpp
TString GetFolderName()
Definition: CSManager.cpp:154
LogMessage & error(LogMessage &)
TH1D * GetHistoTot(Option_t *axis="x", Int_t iCS=0) const
Get projection total.
Definition: CSManager.cpp:342
header file for all type of CSManager
void Register(CorrelatedSpace *cs)
Add correlated space.
Definition: CSManager.cpp:327
Int_t fCInstance
filter base name
Definition: CSManager.h:67
CubicFilter class for cubic gates.
Definition: CubicFilter.h:22
virtual ~CSManager()
Definition: CSManager.cpp:145
BasePeak * GetPeak(Int_t idx) const
Get peak.
Definition: CSFilter.h:124
virtual TH1D * GetHistoBkg(Option_t *axis="x")
Get bkg histo.
CSManager correlated spaces manager.
Definition: CSManager.h:53
static PeakCreator * AddPeakCreator(TVirtualPad *pad=0x0)
add a peak creator to the given pad. Current pad if argument is 0x0
void Import(CorrelatedSpace *cs)
Import another CS.
Float_t GetRatio(CSFilter *filter)
Get ratio for removing bgk spectrum from the gated one.
Definition: CSManager.cpp:131
LogMessage fLog
flag for canvas division
Definition: CSManager.h:69
void Project(Option_t *axis)
Project.
Definition: CSManager.cpp:414
void EnableCanvasDiv()
Enable again canvas division.
Definition: CSManager.h:138
static TList * GetCSList()
Get correlated space lsit.
void Draw(Option_t *opt)
Draw peaks.
Definition: CSFilter.cpp:76
virtual Color_t GetLineColorPeak()
Get line peak color.
Definition: Peak1D.cpp:1658
Double_t GetSubPeakIntegral() const
Get integral of background under peak after calling area method.
Definition: Peak1D.h:266
LogMessage & dolog(LogMessage &)
void SetFolders()
log message
Definition: CSManager.cpp:104
header file for all type of CorrelatedSpace
void MakeGates(Option_t *opt="peak")
Make gates.
CSFilter base class for filter.
Definition: CSFilter.h:56
static Bool_t IsvalideGateColor(Color_t co)
Definition: BasePeak.cpp:82
TString GetFilterFolderName()
Definition: CSManager.cpp:163
TH1D * GetHisto(Int_t iCS) const
Get histogramm.
Definition: CSManager.cpp:357
void DrawProj(Option_t *opt)
Draw projection.
Definition: CSManager.cpp:219
Double_t GetBkgIntegral() const
Get integral of background after calling area method.
Definition: Peak1D.h:258
TH1D * GetHistoBkg(Int_t iCS) const
Get histogramm.
Definition: CSManager.cpp:372
ClassImp(BaseNucleus)
void Convert(CorrelatedSpace *src, CorrelatedSpace *dst)
Convert correlated space to another correlated space.
Definition: CSManager.cpp:437
header file for a general 1D peak
TList * fRegCS
number of instances
Definition: CSManager.h:64
virtual void Area(Option_t *opt="h")
to get the Area (+bkg) of this peak
Definition: Peak1D.cpp:1031
virtual TH1D * GetHistoTot(Option_t *axis="x")
Get histo total projection.
Int_t CollectGate(Option_t *opt="reset")
Collect gates on spectra.
Definition: CSManager.cpp:277
virtual void Project(CSFilter *, Option_t *)=0
project
void DrawProjTot(Option_t *opt, Option_t *axis="x")
Draw total projection.
Definition: CSManager.cpp:257
A graphical interface for placing schematic peak onto a 1D histogram with a given position...
Definition: Peak1D.h:79
virtual void SetProcessMethod(const char *)
To set the current method.
CSFilter * GetFilter(Option_t *gateName="Gate")
Get Filter.
Definition: CSManager.cpp:387
Bool_t fIsCanvasDiv
number of CS manager instanced
Definition: CSManager.h:68
const Char_t * GetFilterBaseName()
Get Filter Base Name.
Definition: CSManager.h:132
virtual TH1D * GetHisto(Option_t *axis="x")
Get histo.
TVirtualPad * GetProjTotPad(Int_t idx)
Get pad of total projection spectrum for a given CS.
Definition: CSManager.cpp:205
CorrelatedSpace base class that contains correlated informations.
TCanvas * GetCanvas()
Start view.
Definition: CSManager.cpp:173