GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LLaBr3Watchers.C
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2010 by Olivier Stezowski *
3  * stezow(AT)ipnl.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 
21 #include "LLaBr3Watchers.h"
22 #include "TMath.h"
23 #include <fstream>
24 #include "MetaWatchers.h"
25 #include "TrackedWatchers.h"
26 
28 
30 
32 {
33  Double_t tmp = E;
34 
35  // not very useful .... keep it in case as an exemple
36  if ( E < threshold_adc_min || E > threshold_adc_max ) {
37  has_fired = false;
38  }
39  else
40  E = A + B*tmp + C*TMath::Power(tmp,2) ;
41 }
42 
43 BaseLLaBr3Watcher::BaseLLaBr3Watcher(const char *name, const char *title, TDirectory *sp_dir, TDirectory *tag_dir):
44  RancLegnaroWatcher(name,title,sp_dir,tag_dir)
45 {
46  // to be sure the LUT is initialized
47  InitLUT();
48  fNumberOfModules = 0;
49 
50  if ( !LoadCalibration("LLaBr3.conf") )
51  fLog << warning << "LLaBr3.conf not found in the current directory ... LoadCalibration should be called at least once, please use LoadCalibration !! " << dolog;
52 }
53 
55 {
56 }
57 
58 // should add nmore test to be sure the file is consistant ...
59 Bool_t BaseLLaBr3Watcher::LoadCalibration(const char *calib_file)
60 {
61  std::ifstream in(calib_file); std::string tmp;
62 
63  if ( in.is_open() == false )
64  return false;
65 
66  getline(in,tmp);
67  tmp += " ";
68  while ( in.good() && !in.eof() ) { // read input stream line by line
69 
70  if ( tmp[0] == '#' ) {
71  getline(in,tmp);
72  continue;
73  } // this line is a comment
74  {
75  Float_t r, theta, phy, a, b, c; Int_t tmin, tmax;
76  Int_t which;
77  std::istringstream decode(tmp);
78 
79  decode >> which;
80  if ( which == -1 ) { // this is LUT
81  for (Short_t i = 0; i < fNumberOfModules; i++ )
82  for (Short_t j = 0; j < gNumberOfItems; j++ )
83  decode >> gLUT[j][i] ;
84 
85 /* cout << " LUT " << endl;
86  for (Short_t i = 0; i < fNumberOfModules; i++ )
87  for (Short_t j = 0; j < gNumberOfItems; j++ )
88  cout << j << " " << i << " " << gLUT[j][i] << endl ; */
89  }
90  else { // this a module
91  if ( which < gMaxNumberOfModules ) {
92 
93  std::cout << " Reading LaBr3 Module # " << fNumberOfModules << std::endl;
94  decode >> r >> theta >> phy >> tmin >> tmax >> a >> b >> c ;
95 
97 
98  fLaBr3[which].P.SetMagThetaPhi(r,theta*TMath::Pi()/180.0,phy*TMath::Pi()/180.0);
99 
100  fLaBr3[which].threshold_adc_min = tmin;
101  fLaBr3[which].threshold_adc_max = tmax;
102 
103  fLaBr3[which].A = a;
104  fLaBr3[which].B = b;
105  fLaBr3[which].C = c;
106 
107  }
108  else {;}
109  }
110  }
111  // add null character at the end since getline
112  // does not store \n and it may give troubles when decoding
113  getline(in,tmp);
114  tmp += " ";
115  }
116  in.close();
117 
118  fLog << " LLaBr3 has been configured with " << fNumberOfModules << " modules " << dolog;
119 
120  return true;
121 }
122 
124 {
125  // module 1
126  gLUT[0][0] = 96;
127  gLUT[1][0] = 97;
128 
129  // module 2
130  gLUT[0][1] = 98;
131  gLUT[1][1] = 99;
132 
133  // module 3
134  gLUT[0][2] = 100;
135  gLUT[1][2] = 101;
136 
137  // module 2
138  gLUT[0][3] = 0;
139  gLUT[1][3] = 0;
140 
141  // module 3
142  gLUT[0][4] = 0;
143  gLUT[1][4] = 0;
144 }
145 
146 void BaseLLaBr3Watcher::Exec(Option_t *option)
147 {
148  // be sure the frame has been set properly
149  if ( fFrame == 0x0 )
150  { SetLastExecStatus(1); return; }
151  else {
152  if ( !fFrame->IsValid() )
153  { SetLastExecStatus(1); return; }
154  }
155 
156  // fill the array of floats
157  RancLegnaroWatcher::Exec(option);
158 
159  // fill up the different modules : calibrates and check the threshold
160  // to know the number of detector fired in this event
161  for (Int_t i = 0u; i < fNumberOfModules; i++) {
162 
163  // fill the data part
164  fLaBr3[i].E = rawBuf[gLUT[0][i]];
165  fLaBr3[i].T = rawBuf[gLUT[1][i]];
166 
167  // if out of range,
168  fLaBr3[i].has_fired = true; fLaBr3[i].Calibrate();
169  }
170 }
171 
172 
174 
175 DisplayLLaBr3::DisplayLLaBr3(const char *name, const char *title, TDirectory *sp_dir, TDirectory *tag_dir):
176  BaseLLaBr3Watcher(name,title,sp_dir,tag_dir),
177  fVertexBuilder(0x0),
178  fCounts(0x0),
179  fHitPattern(0x0),
180  fE_no_doppler(gMaxNumberOfModules),
181  fE_doppler(gMaxNumberOfModules),
182  fT(gMaxNumberOfModules)
183 {
184  // Vertex used for doppler correction, last registered
185  fVertexBuilder = VertexBuilder::theCurrentVertexBuilder();
186 
187  fCounts = MakeTH1<TH1F>("NbModules","To get the number of modules fired",gMaxNumberOfModules,0,gMaxNumberOfModules);
188  fHitPattern = MakeTH1<TH1F>("HitPattern","Hit pattern",gMaxNumberOfModules,0,gMaxNumberOfModules);
189 
190  for (Short_t i = 0u; i < fNumberOfModules; i++) {
191 
192  TString tmp; TH1F *h;
193 
194  tmp = Form("LaBr3_E_%d",i);
195  h = MakeTH1<TH1F>(tmp.Data(),"Calibrated energy",1000,0,6000);
196  fE_no_doppler.Add ( h ) ;
197 
198  tmp = Form("LaBr3_E_Doppler_%d",i);
199  h = MakeTH1<TH1F>(tmp.Data(),"Doppler corrected energy",1000,0,6000);
200  fE_doppler.Add ( h ) ;
201 
202  tmp = Form("LaBr3_T_%d",i);
203  h = MakeTH1<TH1F>(tmp.Data(),"Time",1000,0,6000);
204  fT.Add ( h ) ;
205  }
206 }
207 
209 {
210 
211 }
212 
213 void DisplayLLaBr3::DoCanvas(TCanvas *c, Option_t * /*o*/)
214 {
215  c->Divide(4, 2, 0.001, 0.001); //
216 
217  for (Int_t i = 0u; i < fNumberOfModules; i++) {
218  c->cd(i+1);
219  TH1 *h = (TH1 *)fE_no_doppler.At(i); h->Draw();
220  }
221 }
222 
223 void DisplayLLaBr3::Exec(Option_t *option)
224 {
225  // fill the array of floats
226  BaseLLaBr3Watcher::Exec(option);
227 
228  // count the nummber of detectors that have fired
229  UShort_t nb_fired = 0u;
230 
231  for (Int_t i = 0u; i < fNumberOfModules; i++) {
232 
233  if ( fLaBr3[i].has_fired ) {
234  fHitPattern->Fill(i);
235  nb_fired++;
236  }
237  else { continue; }
238  //
239  TH1 *h;
240 
241  // calibrated
242  h = (TH1 *)fE_no_doppler.At(i);
243  h->Fill(fLaBr3[i].E);
244  h = (TH1 *)fT.At(i);
245  h->Fill(fLaBr3[i].T);
246 
247  //cout << fLaBr3[i].Xr << " " << fLaBr3[i].Yr << " " << fLaBr3[i].Zr << endl;
248 
249  if ( fVertexBuilder->GetVertex()->GetBeta() > 0.01 ) {
250  h = (TH1 *)fE_doppler.At(i);
251  h->Fill(fLaBr3[i].E);
252  }
253 
254  }
255  fCounts->Fill(nb_fired);
256 }
257 
259 
260 MyLLaBr3Tree::MyLLaBr3Tree(const char *name, const char *title, TTree *tree) :
261  BaseLLaBr3Watcher(name,title),
262  TTreeBuilder(name,title,tree)
263 {
264  if ( GetTree() ) { // just add the branch for that watcher
265  SetBranches();
266  }
267 }
268 
270 {
271  GetTree()->Branch("NbLaBr", &fNbLaBr3, "NbLaBr/I");
272  GetTree()->Branch("WhichLaBr3", fWhichLaBr3, "WhichLaBr3[NbLaBr]/s");
273 
274  GetTree()->Branch("ELaBr3", fELaBr3, "E[NbLaBr]/F");
275  GetTree()->Branch("TLaBr3", fTLaBr3, "T[NbLaBr]/F");
276 }
277 
279 {
280 }
281 
282 void MyLLaBr3Tree::Exec(Option_t *option)
283 {
284  if ( gDebug > 3 )
285  printf("MyLLaBr3Tree::Exec is called \n");
286 
287  // fill the array of floats and compute the PRISMA physics
288  BaseLLaBr3Watcher::Exec(option);
289 
290  fNbLaBr3 = 0;
291  for (Int_t i = 0u; i < fNumberOfModules; i++) {
292 /* if ( !fLaBr3[i].has_fired ) {
293  continue;
294  } */
295 
296  fWhichLaBr3[fNbLaBr3] = i;
297  fELaBr3[fNbLaBr3] = fLaBr3[i].E;
298  fTLaBr3[fNbLaBr3] = fLaBr3[i].T;
299 
300  fNbLaBr3++;
301  }
302 
303  // fill the tree only if this is the owner of the tree ... otherwise by TreeMaster
304  FillTree();
305 }
306 
307 
308 
309 
310 
311 
312 
313 
314 
315 
virtual Bool_t IsValid() const
true if it is a valid pointer
Definition: Frame.h:616
TBrowser * b
virtual VertexInterface * GetVertex()
Get the vertex data interface.
printf("******************************************************************** \n")
Double_t C
Int_t threshold_adc_max
MyLLaBr3Tree(const char *name, const char *title, TTree *tree=0x0)
static const Short_t gNumberOfItems
MyLLaBr3 fLaBr3[gMaxNumberOfModules]
Double_t B
Bool_t has_fired
virtual ~DisplayLLaBr3()
LogMessage & warning(LogMessage &)
TVector3 P
virtual ~BaseLLaBr3Watcher()
Base classe for LaBr3.
Base for a watcher on an ancillary (raw) frame.
static Short_t gLUT[gNumberOfItems][gMaxNumberOfModules]
static void InitLUT()
Double_t A
virtual void Exec(Option_t *option="")
watch the current frame
virtual Double_t GetBeta(Double_t=0.0) const =0
get recoil velocity
ClassImp(BaseLLaBr3Watcher)
virtual void Exec(Option_t *option="")
watch the current frame
void SetLastExecStatus(Short_t s=0)
reset last status. 0 means no error, 0 < means error, > 0 means ok with conditions ...
Definition: Watchers.h:294
Base class for a Watcher that fill a TTree or some branches of a TTree.
Definition: TTreeWatchers.h:51
LogMessage fLog
Definition: Watchers.h:86
virtual void Exec(Option_t *option="")
watch the current frame
Double_t E
DisplayLLaBr3(const char *, const char *, TDirectory *sp_dir=0x0, TDirectory *tag_dir=0x0)
static const Short_t gMaxNumberOfModules
LogMessage & dolog(LogMessage &)
Double_t T
BaseLLaBr3Watcher(const char *, const char *, TDirectory *sp_dir=0x0, TDirectory *tag_dir=0x0)
Short_t fNumberOfModules
ADF::SharedFP * fFrame
virtual void FillTree()
Fill the tree if it is the owner of the tree.
Float_t rawBuf[gMaxSlots *gMaxChannels+gExtraSize]
virtual void Exec(Option_t *option="")
watch the current frame
ADF::LogMessage & endl(ADF::LogMessage &log)
virtual void DoCanvas(TCanvas *c, Option_t *o)
To be overwritten by real implementation if a canvas is produced.
Int_t threshold_adc_min
TObjArray fE_no_doppler
void Calibrate()
virtual void SetBranches()
TObjArray fE_doppler
Bool_t LoadCalibration(const char *calib_file="LLaBr3.conf")
TTree * GetTree()
to get the current Tree
static VertexBuilder * theCurrentVertexBuilder()
to get the current VertexWatcher (for other watchers) i.e. the last one registered.