GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GammaFilter.cpp
Go to the documentation of this file.
1 
2 #ifndef ROOT_TFile
3 #include <TFile.h>
4 #endif
5 
6 #ifndef GW_GAMMAFILTER_H
7 #include "GammaFilter.h"
8 #endif
9 
10 using namespace Gw;
11 
13 
14 // GammaFilter members /////////////////////////////////////////////////////
16 {
17  fCompton = fEfficiency = fDoppler = NULL;
18 
19  // TMP a profite for the compton scattering
20  // linear from 0 to 0.1 and then constant to 1
21  fComptonShape = new TH1F("GammaFilter_ComptonShape","ComptonShape",1000,0,1);
22  for (Int_t i = 0; i < 1000; i++ ) {
23  if ( i < 200 ) fComptonShape->SetBinContent(i+1,0.005*i);
24  else fComptonShape->SetBinContent(i+1,1);
25  }
26 
27  SetNameTitle("GammaFilter","Standard Experimental Filter for Raw Gamma-rays");
28 }
29 
30 GammaFilter::GammaFilter(Axis_t xmin, Axis_t xmax, Float_t eff, Float_t PT, Float_t dop)
31 {
32  Axis_t lxmin, lxmax;
33  fCompton = fEfficiency = fDoppler = NULL;
34 
35  // check without saying anything
36  lxmin = xmin; lxmax = xmax;
37  if ( lxmin > lxmax ) { lxmin = xmax; lxmax = xmin; }
38 
39  Int_t bin = Int_t ( lxmax - lxmin );
40 
41  fEfficiency = new TH1F("GammaFilter_Efficiency","Efficiency",bin,lxmin,lxmax);
42  fCompton = new TH1F("GammaFilter_Compton","Compton",bin,lxmin,lxmax);
43  fDoppler = new TH1F("GammaFilter_Doppler","Doppler",bin,lxmin,lxmax);
44 
45  for (Int_t i = 1; i < bin ; i++ ) {
46  fEfficiency->SetBinContent(i,TMath::Abs(eff));
47  fCompton->SetBinContent(i,TMath::Abs(PT));
48  fDoppler->SetBinContent(i,TMath::Abs(dop));
49  }
50  // IMPORTANT to set the underflow and overflow to 0 !
51  fEfficiency->SetBinContent(0,0); fEfficiency->SetBinContent(bin,0);
52 
53  SetNameTitle("GammaFilter","Standard Experimental Filter for Raw Gamma-rays");
54 }
55 
57 {
58  if ( fCompton != NULL ) { delete fCompton; fCompton = NULL; }
59  if ( fEfficiency != NULL ) { delete fEfficiency; fEfficiency = NULL; }
60  if ( fDoppler != NULL ) { delete fDoppler; fDoppler = NULL; }
61  if ( fComptonShape != NULL ) { delete fComptonShape; fComptonShape = NULL; }
62 }
63 
64 Bool_t GammaFilter::InitFilter(const char *rootfile)
65 {
66  TH1F *h;
67 
68  // delete the previous definition
69  if ( fCompton != NULL ) { delete fCompton; fCompton = NULL; }
70  if ( fDoppler != NULL ) { delete fDoppler; fDoppler = NULL; }
71  if ( fEfficiency != NULL ) { delete fEfficiency; fEfficiency = NULL; }
72 
73  TFile *rfile = TFile::Open(rootfile);
74  if ( rfile ) { // the file is open
75  h = (TH1F *)rfile->Get("GammaFilter_Efficiency");
76  if ( h ) { // the correct histogram has been found
77  fEfficiency = h; fEfficiency->SetDirectory(0);
78  fEfficiency->SetBinContent(0,0);
79  fEfficiency->SetBinContent(fEfficiency->GetNbinsX()+1,0);
80  }
81  h = (TH1F *)rfile->Get("GammaFilter_Compton");
82  if ( h ) { // the correct histogram has been found
83  fCompton = h; fCompton->SetDirectory(0);
84  }
85  h = (TH1F *)rfile->Get("GammaFilter_Doppler");
86  if ( h ) { // the correct histogram has been found
87  fDoppler = h; fDoppler->SetDirectory(0);
88  }
89  }
90  delete rfile;
91 
92  return IsEffective();
93 }
94 
96 {
97  return (fEfficiency != NULL) && (fCompton != NULL) && (fDoppler != NULL) ;
98 }
99 // void GammaFilter::SetEfficiency(TH1F &)
100 //{
101 // The first bin (0) and the highest bin (dim+1) must be equal to 0 to automatically reject
102 // (see the IsRejected member) any gamma-ray that are out of the range defined by the histogram.
103 //}
104 
105 Bool_t GammaFilter::Compton (GammaLink *gam, Float_t &e)
106 {
107  Bool_t ok; Float_t etmp;
108 
109  etmp = gam->GetEnergy().Get(); // to get the gamma-ray energy
110 
111  ok = fCompton->GetBinContent(fCompton->FindBin(etmp)) < fRand->Current()->Rndm();
112  if ( ok ) e = fComptonShape->GetRandom() * etmp;
113 
114  return ok;
115 }
116 
117 Int_t GammaFilter::ApplyE(const TSeqCollection &li_gamma, TBuffer &b)
118 {
119  TObject *obj; GammaLink *gam;
120  Float_t e;
121  Int_t nb;
122 
123  nb = 0; TIter next(&li_gamma);
124  while( (obj = next()) != NULL ) {
125  gam = (GammaLink *)obj;
126 
127  // efficiency
128  if ( IsRejected(gam) ) continue;
129 
130  // compton
131  if ( Compton(gam,e) ) { nb++; b << e; continue; }
132 
133  // doppler broadring
134  nb++; b << Doppler(gam);
135  }
136  return nb;
137 }
138 
139 Int_t GammaFilter::ApplyE(const TSeqCollection &li_gamma, Float_t *energies)
140 {
141  TObject *obj; GammaLink *gam;
142  Float_t e;
143  Int_t nb;
144 
145  nb = 0; TIter next(&li_gamma);
146  while( (obj = next()) != NULL ) {
147  gam = (GammaLink *)obj;
148 
149  // efficiency
150  if ( IsRejected(gam) ) continue;
151 
152  // compton
153  if ( Compton(gam,e) ) { energies[nb++] = e; continue; }
154 
155  // doppler broadring
156  energies[nb++] = Doppler(gam);
157  }
158  return nb;
159 }
160 // End GammaFilter members /////////////////////////////////////////////////
161 
162 
TBrowser * b
virtual Int_t ApplyE(const TSeqCollection &, TBuffer &)
Apply this filter to the list of gamma-rays.
Bool_t InitFilter(const char *)
to modifiy the efficency curve.
Definition: GammaFilter.cpp:64
ClassImp(GammaFilter)
TH1F * fComptonShape
Definition: GammaFilter.h:46
TRandom * Current() const
to get the current TRandomom object
Definition: Random.h:118
virtual Data_T Get() const
get the value, can be overloaded
Definition: Data.h:70
bool IsRejected(GammaLink *)
True if this gamma ray is not detected.
Definition: GammaFilter.h:113
This class is a base class for any experimental filter.
Definition: BaseFilter.h:28
Standard filter for gamma-rays (EUROBALL-like appproach)
Definition: GammaFilter.h:41
Float_t Doppler(GammaLink *)
return a random number assuming a gaussian at the gamma-rays position with a width given by fDoppler ...
Definition: GammaFilter.h:115
TH1F * fEfficiency
Definition: GammaFilter.h:49
Bool_t Compton(GammaLink *, Float_t &)
true if this gamma-ray has not given all its energy.
Bool_t IsEffective()
check out if it has been correctly initiated
Definition: GammaFilter.cpp:95
virtual ~GammaFilter()
Definition: GammaFilter.cpp:56
Random * fRand
Definition: BaseFilter.h:31