GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CalibCo60.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2004-2006 by Olivier Stezowski & Christophe Theisen *
3  * stezow(AT)ipnl.in2p3.fr, christophe.theisen(AT)cea.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_CALIBCO60_H
24 #include "CalibCo60.h"
25 #endif
26 
27 #ifndef ROOT_TROOT
28 #include "TROOT.h"
29 #endif
30 #ifndef ROOT_TPad
31 #include "TPad.h"
32 #endif
33 #ifndef ROOT_TSpectrum
34 #include "TSpectrum.h"
35 #endif
36 #ifndef ROOT_TMath
37 #include "TMath.h"
38 #endif
39 #ifndef ROOT_TCanvas
40 #include "TCanvas.h"
41 #endif
42 
43 #ifndef Gw_Peak1D
44 #include "Peak1D.h"
45 #endif
46 
47 #include <iostream>
48 #include <fstream>
49 
50 using namespace std;
51 using namespace Gw;
52 
53 // ROOT dictionnary
55 
56 //__________________________________________________________________________________________________
57 CalibCo60::CalibCo60()
58 {
59 
60 }
61 
62 //__________________________________________________________________________________________________
63 CalibCo60::~CalibCo60()
64 {
65 
66 }
67 
68 //__________________________________________________________________________________________________
69 void CalibCo60::Calibrate(const TH1 */*histo*/, TF1 *function, Double_t channel1, Double_t channel2, Option_t */*AxisOption*/)
70 {
71  // The user can give the 2 channels corresponding to the 2 peaks
72  channel1 = TMath::Abs(channel1);
73  channel2 = TMath::Abs(channel2);
74  if (channel1 == channel2) {
75  printf("info in <Calibco60::DoCalib> parameters are identical !!\n");
76  return;
77  }
78 
79  if (channel1 > channel2) { //just invert the 2 given values
80  Double_t tmp = channel2;
81  channel2 = channel1;
82  channel1 = tmp;
83  }
84 
85  //channel1 corresponds to peak1 = 1173.228
86  //channel2 corresponds to peak2 = 1332.492
87 
88  fRaw.Set(2);
89  fRaw[0] = channel1; fRaw[1] = channel2;
90  fTabulated.Set(2);
91  fTabulated[0] = 1173.228 ; fTabulated[1] = 1332.492;
92 
93  BaseCalib::Calibrate(function);
94 }
95 
96 //__________________________________________________________________________________________________
97 void CalibCo60::Calibrate(const TH1 *histo, TF1 *function, Option_t* /*AxisOption*/, Double_t sigma,
98  Option_t* SearchOption, Double_t threshold)
99 {
100  // The assumption is that the 2 most intense peaks are 1.17 and 1.33 MeV respectively
101  // The method TSpectrum::Search is used in the range of the given histogram
102  // The user have to change the range of the histogram to search peaks
103  // The other parameters (sigma,option, threshold) are those of TSpectrum::Search (see the ROOT documenatation for details)
104 
105 
106  // TSpectrum part
107  TSpectrum spectrum;
108  Int_t NbPeaks = spectrum.Search(histo,sigma,SearchOption,threshold);
109  if (NbPeaks <= 1) {
110  printf("info in <CalibCo60::DoCalib> ERROR !! Number of Peaks found < 2 !!\n");
111  return;
112  }
113 
114  //Double_t *tab_X = spectrum.GetPositionX();
115  // Double_t *tab_Y = spectrum.GetPositionY();
116  Int_t *index = new Int_t[NbPeaks];
117  TMath::Sort(NbPeaks,spectrum.GetPositionY(),index,1);
118  Peak1D p1, p2;
119  p1.SetPosition(spectrum.GetPositionX()[index[0]]); p1.SetIntensity(spectrum.GetPositionY()[index[0]]);
120  p2.SetPosition(spectrum.GetPositionX()[index[1]]); p2.SetIntensity(spectrum.GetPositionY()[index[1]]);
121 
122  if (gDebug > 0) {
123  printf("Nb Peaks found = %i\n",NbPeaks);
124  for (Int_t i=0 ; i<NbPeaks ; i++) {
125  printf(" [%i] Position : %8.3f Intensity : %8.3f\n",i,spectrum.GetPositionX()[i],spectrum.GetPositionY()[i]);
126  }
127  }
128 
129  fRaw.Set(2);
130  fTabulated.Set(2);
131  fTabulated[0] = 1173.228 ; fTabulated[1] = 1332.492;
132 
133  // perform the calibration
134  if (p1.GetPosition() == p2.GetPosition()) {
135  printf("info in <Calibco60::DoCalib> The 2 most intense peaks have got the same positions !! Abort calibration !!\n");
136  return;
137  }
138  if (p1.GetPosition() < p2.GetPosition()) {
139  fRaw[0] = p1.GetPosition(); fRaw[1] = p2.GetPosition();
140  } else {
141  fRaw[0] = p2.GetPosition(); fRaw[1] = p1.GetPosition();
142  }
143 
144  BaseCalib::Calibrate(function);
145 
146  //delete pointers
147  if (index) delete [] index;
148 
149 }
150 
151 
152 
153 
154 
155 
156 
157 
158 
159 
printf("******************************************************************** \n")
virtual void SetPosition(const Double_t position, Option_t *axis="X")
Set Position of peak.
Definition: Peak1D.cpp:546
TH1F * histo[MaxValue]
Definition: ReadDaqAlone.C:31
ClassImp(CalibCo60)
header file for a general 1D peak
A graphical interface for placing schematic peak onto a 1D histogram with a given position...
Definition: Peak1D.h:79
CalibCo60 is a service class in order to find calibration coefficients for a TH1 espacially with Co60...
Definition: CalibCo60.h:53