GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RawAmpWatcher.cpp
Go to the documentation of this file.
1 #include <iostream>
2 #include <iomanip>
3 #include <fstream>
4 #include <sstream>
5 #include <vector>
6 #include <string>
7 #include <map>
8 
9 #include "TCanvas.h"
10 #include "TROOT.h"
11 #include "TStyle.h"
12 #include "TH1.h"
13 #include "TF1.h"
14 #include "TSpectrum.h"
15 #include "TBrowser.h"
16 #include "TMath.h"
17 #include "TVirtualFitter.h"
18 #include "TPavesText.h"
19 #include "TSystem.h"
20 #include "TObjString.h"
21 #include "TFrame.h"
22 #include "TSQLResult.h"
23 #include "TSQLRow.h"
24 #include "TSystemDirectory.h"
25 
26 #include "LoupeOnPad.h"
27 #include "BashColor.h"
28 
29 #include "RawAmpWatcher.h"
30 #include "FitSpectra.h"
31 
32 using namespace std;
33 
37 
38 RawAmpWatcher::RawAmpWatcher(const char* name, const char *title) :
39  SpectraViewerWatcher(name,title),
40  fWidth(100),
41  fThreshold(0.01),
42  fUseOffset(false),
43  fDefinePersoBackground(false),
44  fFirstLibGain(2.),
45  fGWRecal(new GWRecal()),
46  fFitFunction(new FitFunctions()),
47  fSourceDefine(false),
48  fCalibResultsTree(0x0),
49  PlotVarExp(""),
50  PlotVarSel(""),
51  PlotVarOpt("")
52 {
54 }
55 
57 
58 void RawAmpWatcher::Exec(const char *option)
59 {
60  TString Opt = option;
61 
62  int Lib=1;
63 
64  TObjArray *GlobalToken = Opt.Tokenize(";");
65  TObject *GlobalObj = 0x0;
66  TIter GlobalIter(GlobalToken);
67 
68  TString CrystalFilter = GlobalToken->Last()->GetName();
69  TString AntiCrystal = "!" + fCrystalName;
70 
71  if(!CrystalFilter.Contains("all",TString::kIgnoreCase) && !CrystalFilter.Contains(fCrystalName,TString::kIgnoreCase)) return;
72  if(CrystalFilter.Contains(AntiCrystal,TString::kIgnoreCase)) return;
73 
74 
75  bool SpectraDrawn = false;
76 
77  while ( (GlobalObj = GlobalIter()) )
78  {
79  TString SubOpt = GlobalObj->GetName();
80 
81  if(SubOpt.Contains("ShowSpectra",TString::kIgnoreCase))
82  {
83  TObjArray *SubToken = SubOpt.Tokenize(" ");
84  TObject *SubObj = 0x0;
85  TIter SubIter(SubToken);
86 
87  while ( (SubObj = SubIter()) )
88  {
89  TString name = SubObj->GetName();
90  if(name.BeginsWith("lib=",TString::kIgnoreCase))
91  {
92  name.Replace(0,4,"");
93  Lib = name.Atoi();
94  }
95  }
96  if(!SpectraDrawn)
97  {
98  ShowSpectra(Lib);
99  SpectraDrawn = true;
100  }
101  }
102  if(SubOpt.Contains("Recal",TString::kIgnoreCase))
103  {
104  TObjArray *SubToken = SubOpt.Tokenize(" ");
105  TObject *SubObj = 0x0;
106  TIter SubIter(SubToken);
107 
108  while ( (SubObj = SubIter()) )
109  {
110  TString name = SubObj->GetName();
111  if(name.BeginsWith("source=",TString::kIgnoreCase))
112  {
113  name.Replace(0,7,"");
114  SetSource(name);
115  }
116  if(name.BeginsWith("lib=",TString::kIgnoreCase))
117  {
118  name.Replace(0,4,"");
119  Lib = name.Atoi();
120  }
121  if(name.BeginsWith("CL=",TString::kIgnoreCase))
122  {
123  name.Replace(0,3,"");
124  TString chlim = name.Copy().Replace(name.Index(","),name.Length()-name.Index(","),"");
125  int ChMin = chlim.Atoi();
126  chlim = name.Copy().Replace(0,name.Index(",")+1,"");
127  int ChMax = chlim.Atoi();
128  fGWRecal->SetGlobalChannelLimits(ChMin,ChMax);
129  }
130  if(name.BeginsWith("PL=",TString::kIgnoreCase))
131  {
132  name.Replace(0,3,"");
133  TString Peaklim = name.Copy().Replace(name.Index(","),name.Length()-name.Index(","),"");
134  double FWHM = Peaklim.Atof();
135  Peaklim = name.Copy().Replace(0,name.Index(",")+1,"");
136  double Ampli = Peaklim.Atof();
137  fGWRecal->SetGlobalPeaksLimits(FWHM,Ampli);
138  }
139  }
140  if(!SpectraDrawn)
141  {
142  ShowSpectra(Lib);
143  SpectraDrawn = true;
144  }
145  FitAllRecal();
146  }
147  if(SubOpt.Contains("Plot",TString::kIgnoreCase))
148  {
149  TObjArray *SubToken = SubOpt.Tokenize(" ");
150  TObject *SubObj = 0x0;
151  TIter SubIter(SubToken);
152 
153  while ( (SubObj = SubIter()) )
154  {
155  TString name = SubObj->GetName();
156  if(name.BeginsWith("exp=",TString::kIgnoreCase))
157  {
158  name.Replace(0,4,"");
159  PlotVarExp = name;
160  }
161  if(name.BeginsWith("sel=",TString::kIgnoreCase))
162  {
163  name.Replace(0,4,"");
164  PlotVarSel = name;
165  }
166  if(name.BeginsWith("opt=",TString::kIgnoreCase))
167  {
168  name.Replace(0,4,"");
169  PlotVarOpt = name;
170  }
171  }
172  if(PlotVarOpt.Contains("same",TString::kIgnoreCase)) PlotVarOpt.Replace(PlotVarOpt.Index("same",0,TString::kIgnoreCase),4,"glob");
174  }
175  }
176 }
177 
179 
180 void RawAmpWatcher::FitAllRoot(const char *FitType, const char *source)
181 {
182  cout<<"Energy calibration parameters for crystal "<<fCrystalName<<" with "<<source<<" source"<<endl;
183  cout<<"Seg"<<"\t\t Area \t Offset Gain \t\t Mean \t E(keV) \t FWHM(KeV) \t FWHM_10(keV) \t TL \t\t TR"<<endl;
184 
185  TCanvas *CurrentCanvas = gPad->GetCanvas();
186 
187  int Pad=0;
188  while(CurrentCanvas->cd(Pad) != CurrentCanvas->cd(Pad+1))
189  {
190  Pad++;
191  CurrentCanvas->cd(Pad);
192  FitSelectedRoot(FitType,source,true);
193  }
194 
195  CurrentCanvas->cd();
196  CurrentCanvas->Update();
197  CurrentCanvas->Modified();
198 
199  gSystem->MakeDirectory("FitResults");
200  ofstream FileOut(((TString)"FitResults/" + fCrystalName + "_Amplitude.fit"));
201  FileOut<<"#Seg"<<"\t"<<"Area"<<"\t"<<" Offset"<<"\t "<<" Gain"<<" \t "<<"Mean"<<" \t "<<"E"<<" \t "<<"FWHM"<<"\t "<<"FWHM_10"<<" \t "<<"LTProp"<<" \t "<<"RTProp"<<endl;
202  for(int i=0 ; i<38 ; i++)FileOut<<i<<"\t"<<TabArea[i]<<" \t "<<TabOffset[i]<<" \t "<<TabGain[i]<<" \t "<<TabMean[i]<<" \t "<<TabE[i]<<" \t "<<TabFWHM[i]<<" \t "<<TabFWHM_10[i]<<" \t "<<TabLTProp[i]<<" \t "<<TabRTProp[i]<<endl;
203  FileOut.close();
204 }
205 
207 
208 void RawAmpWatcher::FitSelectedRoot(const char *FitType, const char *source, bool all)
209 {
210  FitSpectra *FS = new FitSpectra(FitType,source);
211 
212  if(fWidth!=0)
213  {
214  FS->SetWidth(fWidth);
216  FS->SetXmin(fxmin);
217  FS->SetXmax(fxmax);
218  }
219  FS->UseOffset(fUseOffset);
220  FS->GetCurrentHistogram();
222  {
224  }
225  if(gPad->GetListOfPrimitives()->GetSize()>0)
226  {
227  TString Name = FS->GetHistName();
228  TObjArray *array = Name.Tokenize("_");
229  TObject *LastToken = array->At(array->GetLast());
230 
231  int HistNbr = ((TString)LastToken->GetName()).Atoi();
232  PadPos HistPosition = fHistPositionList[HistNbr];
233  TString SegName = HistPosition.SegName;
234  int Profondeur = SegName.Remove(0,1).Atoi();
235  TString SourceName = source;
236 
237  if(Profondeur>3 && SourceName=="152Eu") FS->ReduceListOfPeak();
238 
239  FS->Fit();
240  }
241 
243 
244  int HistNbr = -1;
245 
246  if(FS->GetHistogram()!=0x0 && FS->GetFitStatus()==1)
247  {
248  if(!all)
249  {
250  cout<<"Energy calibration parameters for crystal "<<fCrystalName<<" with "<<source<<" source"<<endl;
251  cout<<"Seg"<<"\t\t Area \t Offset Gain \t\t Mean \t E(keV) \t FWHM(KeV) \t FWHM_10(keV) \t TL \t\t TR"<<endl;
252  }
253 
254  TString Name = FS->GetHistName();
255  TObjArray *array = Name.Tokenize("_");
256  TObject *LastToken = array->At(array->GetLast());
257 
258  HistNbr = ((TString)LastToken->GetName()).Atoi();
259 
260  PadPos HistPosition = fHistPositionList[HistNbr];
261 
262  TString SegName = HistPosition.SegName;
263 
264  int last = FS->GetArea().size()-1;
265 
266  double area = FS->GetArea().at(last);
267  double offset = FS->GetCalibOffset();
268  double gain = FS->GetCalibSlope();
269  double Mean = FS->GetMean().at(last);
270  double E = FS->GetECal().at(last);
271  double FWHM = FS->GetFWHMCal().at(last);
272  double FWHM_10 = FS->GetFWHM_10Cal().at(last);
273  double LTProp = FS->GetLeftTailProp().at(last);
274  double RTProp = FS->GetRightTailProp().at(last);
275 
276  if(fLibNumber==1)
277  {
278  offset = offset*fFirstLibGain;
279  gain = gain*fFirstLibGain;
280  }
281 
282  TabArea[HistNbr] = area;
283  TabOffset[HistNbr] = offset;
284  TabGain[HistNbr] = gain;
285  TabMean[HistNbr] = Mean;
286  TabE[HistNbr] = E;
287  TabFWHM[HistNbr] = FWHM;
288  TabFWHM_10[HistNbr] = FWHM_10;
289  TabLTProp[HistNbr] = LTProp;
290  TabRTProp[HistNbr] = RTProp;
291 
292  if(SegName.Contains("Core"))cout<<"Seg "<<HistNbr<<"("<<SegName<<"): "<<area<<"\t "<<offset<<"\t "<<gain<<" \t "<<Mean<<" \t "<<E<<" \t "<<FWHM<<"\t "<<FWHM_10<<" \t "<<LTProp<<" \t "<<RTProp<<endl;
293  else cout<<"Seg "<<HistNbr<<"("<<SegName<<"): \t "<<area<<" \t "<<offset<<"\t "<<gain<<" \t "<<Mean<<" \t "<<E<<" \t "<<FWHM<<"\t "<<FWHM_10<<" \t "<<LTProp<<" \t "<<RTProp<<endl;
294  }
295  else if(gPad->GetListOfPrimitives()->GetSize()>1)
296  {
297  TString Name = FS->GetHistName();
298  TObjArray *array = Name.Tokenize("_");
299  TObject *LastToken = array->At(array->GetLast());
300 
301  HistNbr = ((TString)LastToken->GetName()).Atoi();
302 
303  PadPos HistPosition = fHistPositionList[HistNbr];
304 
305  TString SegName = HistPosition.SegName;
306 
307  TabArea[HistNbr] = 0.;
308  TabOffset[HistNbr] = 0.;
309  TabGain[HistNbr] = 0.;
310  TabMean[HistNbr] = 0.;
311  TabE[HistNbr] = 0.;
312  TabFWHM[HistNbr] = 0.;
313  TabFWHM_10[HistNbr] = 0.;
314  TabLTProp[HistNbr] = 0.;
315  TabRTProp[HistNbr] = 0.;
316 
317  cout<<"Seg "<<HistNbr<<"("<<SegName<<"): "<<0<<"\t "<<0<<"\t "<<0<<" \t "<<0<<" \t "<<0<<" \t "<<0<<"\t "<<0<<" \t "<<0<<"\t "<<0<<endl;
318 
319  }
320  //delete FS;
321 }
322 
324 
325 void RawAmpWatcher::SetPersoBackground(int NumberIterations, int Direction,int FilterOrder,bool Smoothing,int smoothingWindow,bool Compton)
326 {
327  fDefinePersoBackground = true;
328  fNumberIterations = NumberIterations;
329  fDirection = Direction;
330  fFilterOrder = FilterOrder;
331  fSmoothing = Smoothing;
332  fsmoothingWindow = smoothingWindow;
333  fCompton = Compton;
334 }
335 
337 
338 void RawAmpWatcher::SearchPeak(int NPeaks, double width, double threshold,double xmin, double xmax)
339 {
340  TList *ListOfPrimitives = (TList*) gPad->GetListOfPrimitives();
341  TH1 *h = 0x0;
342 
343  if(ListOfPrimitives->GetSize())
344  {
345  TIter iter(ListOfPrimitives);
346  TObject *o;
347 
348  while( (o = iter()) )
349  {
350  if(o->InheritsFrom("TH1"))
351  {
352  h = (TH1*)o;
353  break;
354  }
355  }
356  }
357 
358  h->SetAxisRange(xmin,xmax);
359 
360  TSpectrum *s = new TSpectrum(10*NPeaks);
361 
362  s->Search(h,width,"",threshold);
363 
364  fWidth = width;
365  fThreshold = threshold;
366  fxmin = xmin;
367  fxmax = xmax;
368 }
369 
371 
372 void RawAmpWatcher::ShowSpectra(int LibraryNumber, const char *DrawOpt)
373 {
374  TString opt = (TString)DrawOpt;
375  TCanvas *c = 0x0;
376 
377  if(opt.Contains("same",TString::kIgnoreCase)) c = (TCanvas*)gPad->GetCanvas();
378  else
379  {
380  TString Name = "RawSpec" + fCrystalName + Form("Lib%d",LibraryNumber);
381  TString Title = "Mapping of the raw spectra for crystal " + fCrystalName;
382 
383  c = CanvasVisu::BuildSegmentedCanvas(Name,Title);
384 
385  c->Connect("ProcessedEvent(Int_t, Int_t, Int_t, TObject*)",
386  "RawAmpWatcher",
387  this,
388  "HandleMovement(Int_t, Int_t, Int_t, TObject*)");
389  }
390  if(c == 0x0) return;
391 
392  c->cd();
393 
394  TList *ListOfHists = (TList*)fListOfLibrairies->At(LibraryNumber);
395 
396  for(int i=0 ; i<fNSg+fNC ; i++)
397  {
398  PadPos HistPosition = fHistPositionList[i];
399 
400  TPad *pad = (TPad*)c->cd(HistPosition.PadNmbr);
401 
402  TH1 *h = 0x0;
403 
404  TPaveText *p = (TPaveText*)pad->GetListOfPrimitives()->FindObject("InfoPad");
405 
406  h = ((TH1*)ListOfHists->At(i));
407  h->GetXaxis()->SetLabelSize(0.07);
408  h->GetYaxis()->SetLabelSize(0.07);
409 
410  int col = 0;
411  for(int k=0 ; k<pad->GetListOfPrimitives()->GetSize() ; k++)
412  {
413  if(pad->GetListOfPrimitives()->At(k)->InheritsFrom("TH1"))col++;
414  }
415 
416  h->SetLineColor(GetColor(col));
417  h->SetFillColor(0);
418  h->SetStats(0);
419  h->Draw(opt);
420 
421  if(p)p->Draw();
422 
423  gPad->SetFrameFillStyle(0);
424 
425  pad->Modified();
426  pad->Update();
427  }
428 
429  if(!opt.Contains("same"))
430  {
431  new LoupeOnPad(c);
432  SetLoupe(false);
433  }
434 }
435 
437 
438 void RawAmpWatcher::ShowHist(int HistNumber, int LibraryNumber, bool same)
439 {
440  SpectraViewerWatcher::ShowHist(HistNumber,LibraryNumber,same);
441  TCanvas *c = gPad->GetCanvas();
442  c->Connect("ProcessedEvent(Int_t, Int_t, Int_t, TObject*)",
443  "RawAmpWatcher",
444  this,
445  "HandleMovement(Int_t, Int_t, Int_t, TObject*)");
446 }
447 
449 
450 void RawAmpWatcher::SpecificFit(int NbrOfSpectra, int FirstHist, int Step)
451 {
452  TCanvas *CurrentCanvas = gPad->GetCanvas();
453 
454  for(int HistNbr=FirstHist ; HistNbr<FirstHist+NbrOfSpectra*Step ; HistNbr+=Step)
455  {
456  PadPos MyMadPos = fHistPositionList[HistNbr];
457  CurrentCanvas->cd(MyMadPos.PadNmbr);
458  if(HistNbr==FirstHist) FitSelectedRecal(true);
459  else FitSelectedRecal(false);
460  }
461 
462  CurrentCanvas->cd();
463  CurrentCanvas->Paint();
464  CurrentCanvas->Update();
465 }
466 
468 
470 {
471  if(fSourceDefine == false)
472  {
474  cout<<"[ERROR] Source not define ==> s + s to define the source "<<endl;
476  return;
477  }
478 
479  TCanvas *CurrentCanvas = gPad->GetCanvas();
480 
481  CurrentCanvas->Paint();
482  CurrentCanvas->Update();
483 
484  TString DirName = "FitResults/GWRecal/" + fRunName;
485  int LibNbr = -1;
486  gSystem->mkdir(DirName,true);
487 
489  for(int HistNbr=0 ; HistNbr<fNC+fNSg ; HistNbr++)
490  {
491  PadPos MyMadPos = fHistPositionList[HistNbr];
492  CurrentCanvas->cd(MyMadPos.PadNmbr);
493  TList *ListOfPrimitives = (TList*) gPad->GetListOfPrimitives();
494  if(ListOfPrimitives->GetSize()>0)
495  {
496  TIter iter(ListOfPrimitives);
497  TObject *o;
498 
499  while( (o = iter()) )
500  {
501  if(o->InheritsFrom("TF1")) delete o;
502  if(LibNbr == -1 && GetCurrentHistAndLib() !=0) LibNbr = GetCurrentHistAndLib()/1000;
503  }
504  }
505  }
506 
507  TString FileName = Form("%s/%s_Amplitude_Lib%d.fit",DirName.Data(),fCrystalName.Data(),LibNbr);
508  fFileOutGWRecal.open(FileName);
509 
510  CurrentCanvas->Paint();
511  CurrentCanvas->Update();
512 
513  for(int HistNbr=0 ; HistNbr<fNC+fNSg ; HistNbr++)
514  {
515  PadPos MyMadPos = fHistPositionList[HistNbr];
516  CurrentCanvas->cd(MyMadPos.PadNmbr);
517  if(HistNbr==0) FitSelectedRecal(true);
518  else FitSelectedRecal(false);
519  }
520 
521  fFileOutGWRecal.close();
522 
524  cout<<"Calibration File write in: "<<FileName<<endl;
526 
527  CurrentCanvas->Paint();
528  CurrentCanvas->Update();
529 }
530 
532 
533 void RawAmpWatcher::FitSelectedRecal(bool PrintHeader)
534 {
535  if(fSourceDefine == false)
536  {
538  cout<<"[ERROR] Source not define ==> s + s to define the source "<<endl;
540  return;
541  }
542 
543  // int HistNbr = ((HistPos)fPadPositionList[gPad->GetNumber()]).HistNbr;
544 
545  TList *ListOfPrimitives = (TList*) gPad->GetListOfPrimitives();
546 
547  if(ListOfPrimitives->GetSize()>0)
548  {
549  TIter iter(ListOfPrimitives);
550  TObject *o;
551 
552  while( (o = iter()) )
553  {
554  if(o->InheritsFrom("TF1")) delete o;
555  }
556 
557  std::stringstream StoredOutput;
558 
559  std::streambuf* NormalOutput = std::cout.rdbuf(StoredOutput.rdbuf());
560  // std::cout.rdbuf(NormalOutput); //Pour recuperer la sortie standart
561 
562  int HistAndLib = GetCurrentHistAndLib();
563 
564  if(HistAndLib==-1) return;
565 
566  int LibNbr = HistAndLib/1000;
567  int HistNbr = HistAndLib - LibNbr*1000;
568 
569  fGWRecal->SetNSpec(1);
570  fGWRecal->SetHistNumber(HistNbr+LibNbr*(fNC+fNSg));
571  fGWRecal->SetStep(1);
572 
573  fGWRecal->SetSpectraFolder(Form("FitResults/GWRecal/%s/CalibratedSpectra/%d",fCrystalName.Data(),LibNbr));
574 
575  GWRecalFit();
576 
577  vector < Fitted > FitResults = fGWRecal->GetFitResults();
578 
579  double xmin=-1;
580  double xmax=-1;
581 
582  int NGoodPeak=0;
583 
584  for(size_t i=0 ; i<FitResults.size() ; i++)
585  {
586  Fitted FitRes = FitResults[i];
587 
588  if(!FitRes.good) continue;
589  NGoodPeak++;
590 
591  TF1 *f = fFitFunction->GetDinoFct(Form("Peak%d",NGoodPeak),FitRes.BgFrom,FitRes.BgTo,5+6*FitRes.NSubPeaks);
592 
593  f->SetParameter(0,FitRes.NSubPeaks);
594  f->SetParameter(1,FitRes.BgFrom);
595  f->SetParameter(2,FitRes.BgTo);
596  f->SetParameter(3,FitRes.BgdOff);
597  f->SetParameter(4,FitRes.BgdSlope);
598 
599  if(xmin == -1) xmin = FitRes.BgFrom;
600  xmax = FitRes.BgTo;
601 
602  int NPeaksToTreat = FitRes.NSubPeaks;
603 
604  for(int j=0 ; j<FitRes.NSubPeaks ; j++)
605  {
606  f->SetParameter(5+j*6+0,FitRes.ampli);
607  f->SetParameter(5+j*6+1,FitRes.posi);
608  f->SetParameter(5+j*6+2,FitRes.fwhm);
609  f->SetParameter(5+j*6+3,FitRes.Lambda);
610  f->SetParameter(5+j*6+4,FitRes.Rho);
611  f->SetParameter(5+j*6+5,FitRes.S);
612 
613  NPeaksToTreat += -1;
614 
615  if(NPeaksToTreat>0)
616  {
617  i++;
618  FitRes = FitResults[i];
619  }
620  }
621  f->Draw("same");
622  }
623 
624  if(fCurrentHist)fCurrentHist->GetXaxis()->SetRangeUser(xmin-(xmax-xmin)*0.1,xmax+(xmax-xmin)*0.1);
625 
626  gPad->SetLogy();
627  gPad->Modified();
628  gPad->Update();
629 
630  std::cout.rdbuf(NormalOutput);
631 
632 
633  std::string line;
634  TString MyLine;
635 
636  while (std::getline(StoredOutput, line, '\n'))
637  {
638  MyLine = line;
639 
640  if(MyLine=="") continue;
641  if((MyLine.BeginsWith("# ") || MyLine=="#") && PrintHeader)
642  {
643  if(MyLine.BeginsWith("# indx"))MyLine.ReplaceAll("indx"," lib");
644  cout<<MyLine<<endl;
645  if(fFileOutGWRecal.is_open()) fFileOutGWRecal<<MyLine<<endl;
646  }
647  else if(MyLine.BeginsWith("#") && !MyLine.BeginsWith("# ") && MyLine!="#")
648  {
649  cout<<MyLine<<endl;
650  }
651  else if(!MyLine.BeginsWith("#"))
652  {
653  if(MyLine.Length()>20)
654  {
655  MyLine.Replace(5,1,Form("%d",LibNbr));
656  if(HistNbr==0) MyLine.Replace(11,2," 0");
657  else MyLine.Replace(11,2,Form("%2.0d",HistNbr));
658  }
659  cout<<MyLine<<endl;
660  if(fFileOutGWRecal.is_open()) fFileOutGWRecal<<MyLine<<endl;
661  }
662  }
663  }
664 }
665 
667 
668 void RawAmpWatcher::SetGlobalChannelLimits(int ChFrom, int ChTo)
669 {
670  fGWRecal->SetGlobalChannelLimits(ChFrom, ChTo);
671 
672  cout<<"Global channel range redefined to [ "<<ChFrom<<";"<<ChTo<<"]"<<endl;
673 }
674 
676 
677 void RawAmpWatcher::SetHistChannelLimits(int SpecNbr, int lib, int ChFrom, int ChTo)
678 {
679  fGWRecal->SetHistChannelLimits(SpecNbr+38*lib,ChFrom,ChTo);
680 
681  cout<<"Channel range of hist n°"<<SpecNbr<<", library "<<lib<<" redefined to [ "<<ChFrom<<";"<<ChTo<<"]"<<endl;
682 }
683 
685 
686 void RawAmpWatcher::SetGlobalPeaksLimits(float DefFWHM, float DefAmpli)
687 {
688  fGWRecal->SetGlobalPeaksLimits(DefFWHM,DefAmpli);
689 
690  cout<<"Global peak limits redefined to FWHM < "<<DefFWHM<<" ; Ampli > "<<DefAmpli<<endl;
691 }
692 
694 
695 void RawAmpWatcher::SetHistPeaksLimits(int SpecNbr, int lib, float FWHM, float Ampli)
696 {
697  fGWRecal->SetHistPeaksLimits(SpecNbr+38*lib,FWHM,Ampli);
698 
699  cout<<"Peak limits for hist n°"<<SpecNbr<<", library "<<lib<<" redefined to FWHM < "<<FWHM<<" ; Ampli > "<<Ampli<<endl;
700 }
702 
704 {
705  int HistAndLib = -1;
706 
707  TList *ListOfPrimitives = (TList*) gPad->GetListOfPrimitives();
708 
709  if(ListOfPrimitives->GetSize()>0)
710  {
711  TIter iter(ListOfPrimitives);
712  TObject *o;
713  fCurrentHist = 0x0;
714 
715  while( (o = iter()) )
716  {
717  if(o->InheritsFrom("TH1")) fCurrentHist = (TH1*)o;
718  }
719 
720  if(fCurrentHist)
721  {
722  TString HistName = fCurrentHist->GetName();
723  if(HistName.Contains("Ampli"))
724  {
725  TObjArray *loa=HistName.Tokenize("_");
726  int LibNbr = ((TString)((TObjString*)loa->At(loa->GetEntries()-2))->GetString()).Atoi();
727  int HistNbr = ((TString)((TObjString*)loa->At(loa->GetEntries()-1))->GetString()).Atoi();
728 
729  HistAndLib = 1000*LibNbr+HistNbr;
730 
731  delete loa;
732  }
733  }
734  }
735  if(HistAndLib==-1)
736  {
737  TString CanvasName = gPad->GetCanvas()->GetName();
738  if(CanvasName.Index("Lib")>=0)
739  {
740  int LibNbr = CanvasName.Replace(0,CanvasName.Index("Lib")+3,"").Atoi();
741  HistAndLib = -1000*LibNbr;
742  }
743  else
744  {
746  cout<<"Not able to evaluate the library number. Probably no multipad drawn. Default library (1) taken."<<endl;
748  int LibNbr = 1;
749  HistAndLib = -1000*LibNbr;
750  }
751 
752  }
753 
754  return HistAndLib;
755 }
756 
758 
760 {
761  int HistAndLib = GetCurrentHistAndLib();
762 
763  if(HistAndLib<0) return;
764 
765  int LibNbr = HistAndLib/1000;
766  int HistNbr = HistAndLib - LibNbr*1000;
767 
768  SetHistChannelLimits(HistNbr,LibNbr,ChFrom,ChTo);
769 }
770 
772 
773 void RawAmpWatcher::SetSelectedHistPeaksLimits(float FWHM, float Ampli)
774 {
775  int HistAndLib = GetCurrentHistAndLib();
776 
777  if(HistAndLib<0) return;
778 
779  int LibNbr = HistAndLib/1000;
780  int HistNbr = HistAndLib - LibNbr*1000;
781 
782  SetHistPeaksLimits(HistNbr,LibNbr,FWHM,Ampli);
783 }
784 
786 
787 void RawAmpWatcher::HandleMovement(Int_t eventType, Int_t eventX, Int_t eventY, TObject *select)
788 {
789 
790  // cout<<endl;
791  // cout<<"LasteventType = "<<fLasteventType<<" ; LasteventX = "<<fLasteventX<<" ; LasteventY = "<<fLasteventY<<endl;
792  // cout<<"eventType = "<<eventType<<" ; eventX = "<<eventX<<" ; eventY = "<<eventY<<" ; ObjectName = "<<select->GetName()<<endl;
793  // cout<<endl;
794 
795  select = 0x0;
796 
797 
798 
799  if( eventType == kKeyPress )
800  {
802  if((EKeySym)eventX == kKey_f && (EKeySym)eventY == kKey_f)
803  FitSelectedRecal(true);
804  if((EKeySym)eventX == kKey_f-96 && (EKeySym)eventY == kKey_f)
805  FitAllRecal();
806 
808 
810  if((EKeySym)eventY == kKey_l && (EKeySym)eventX == kKey_l && (EKeySym)fLasteventY == kKey_c && (EKeySym)fLasteventX == kKey_c)
811  CanvasVisu::OpenContextMenu("SetSelectedHistChannelLimits",this);
812  if((EKeySym)eventX == kKey_l-96 && (EKeySym)eventY == kKey_l && (EKeySym)fLasteventX == kKey_c-96 && (EKeySym)fLasteventY == kKey_c)
813  CanvasVisu::OpenContextMenu("SetGlobalChannelLimits",this);
814 
816  if((EKeySym)eventY == kKey_l && (EKeySym)eventX == kKey_l && (EKeySym)fLasteventY == kKey_p && (EKeySym)fLasteventX == kKey_p )
817  CanvasVisu::OpenContextMenu("SetSelectedHistPeaksLimits",this);
818  if((EKeySym)eventX == kKey_l-96 && (EKeySym)eventY == kKey_l && (EKeySym)fLasteventX == kKey_p-96 && (EKeySym)fLasteventY == kKey_p)
819  CanvasVisu::OpenContextMenu("SetGlobalPeaksLimits",this);
820 
822  if((EKeySym)eventY == kKey_s && (EKeySym)eventX == kKey_s && (EKeySym)fLasteventY == kKey_s && (EKeySym)fLasteventX == kKey_s )
823  {
824  cout<<"List of available sources (more than one allowed): 22Na 40K 56Co 57Co 60Co 88Y 133Ba 134Cs 137Cs 152Eu 208Pb 226Ra 241Am"<<endl;
825  CanvasVisu::OpenContextMenu("SetSource",this);
826  }
827 
829  if((EKeySym)eventY == kKey_h && (EKeySym)fLasteventY == kKey_p) PrintHelp();
830 
832 
834  if((EKeySym)eventY == kKey_c && (EKeySym)eventX == kKey_c && (EKeySym)fLasteventY == kKey_p && (EKeySym)fLasteventX == kKey_p )
836  }
837 
838 
839 
840  fLasteventType = eventType;
841  fLasteventX = eventX;
842  fLasteventY = eventY;
843 
844 }
845 
847 
848 void RawAmpWatcher::SetSource(const char * SourcesNames)
849 {
850  TString Opt = SourcesNames;
851  TObjArray *token = Opt.Tokenize(",");
852  TObject *a_token = 0x0;
853 
854  TIter iter(token);
855 
856  while ( (a_token = iter()) )
857  {
858  TString name = a_token->GetName();
859  if(name != "") fGWRecal->SetSource(name);
860  }
861 
862  fSourceDefine = true;
863 }
864 
866 
868 {
869  if(fCalibResultsTree != 0x0) delete fCalibResultsTree;
870 
871  fCalibResultsTree = new TTree("CalibResultsTree","CalibResultsTree");
872 
873  gPad->GetCanvas()->cd(1);
874  int HistAndLib = GetCurrentHistAndLib();
875  int LibNbr = abs(HistAndLib/1000);
876 
877  TString CalibFileName = Form("FitResults/GWRecal/%s/%s_Amplitude_Lib%d.fit",fRunName.Data(),fCrystalName.Data(),LibNbr);
878  ifstream CalibFile(CalibFileName);
879  if(!CalibFile.is_open())
880  {
882  cout<<"File: "<<CalibFileName<<" not found"<<endl;
883  cout<<"Crystal "<< fCrystalName <<" has not yet been calibrated... exit"<<endl;
885  return -1;
886  }
887  string Line;
888  TString Buffer;
889 
890  double ERef = 0;
891  double Values[100];
892  bool TreeInitialized = false;
893  while(CalibFile)
894  {
895  getline(CalibFile,Line);
896  Buffer = Line;
897 
898  TObjArray *token = Buffer.Tokenize(" ");
899  TObject *a_token = 0x0;
900  TIter iter(token);
901 
902  if(Buffer.Contains("==> Reference peak for extended printouts"))
903  {
904  ERef = ((TString)((TObject*)token->At(2))->GetName()).Atof();
905  fCalibResultsTree->Branch("ERef", &ERef,"ERef/D");
906  }
907 
908  if(Buffer.BeginsWith("# lib"))
909  {
910  int col=0;
911  while ( (a_token = iter()) )
912  {
913  TString name = a_token->GetName();
914  if(name != "" && name != "#")
915  {
916  name.ReplaceAll("%","");
917  name.ReplaceAll("#","");
918  name.ReplaceAll("slope*gain","slope");
919  fCalibResultsTree->Branch(Form("%s",name.Data()), &Values[col],Form("%s/D",name.Data()));
920  col++;
921  TreeInitialized = true;
922  }
923  }
924  }
925  if(!Buffer.BeginsWith("#") && Buffer != "" && TreeInitialized)
926  {
927  int col=0;
928  while ( (a_token = iter()) )
929  {
930  TString name = a_token->GetName();
931  Values[col] = name.Atof();
932  col++;
933  }
934  fCalibResultsTree->Fill();
935  }
936 
937  delete token;
938  }
939 
940  CalibFile.close();
941 
942  return LibNbr;
943 }
944 
946 
948 {
950  cout<<endl;
951  cout<<" _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ "<<endl;
952  cout<<"|*******************************************************************************************************************************************************************|"<<endl;
953  cout<<"|**| |**|"<<endl;
954  cout<<"|**|-------------------------------------------------------------------------------------------------------------------------------------------------------------|**|"<<endl;
955  cout<<"|**|-------------------------------------------------------- Help on the calibration results plotter --------------------------------------------------------|**|"<<endl;
956  cout<<"|**|-------------------------------------------------------------------------------------------------------------------------------------------------------------|**|"<<endl;
957  cout<<"|**| |**|"<<endl;
958  cout<<"|**| --> Plot is made from a TTree containing all the fit parameters values. |**|"<<endl;
959  cout<<"|**| The plot mechanisms are thus the one of a TTree: Draw(\"varexp\", \"selection\", \"option\"). |**|"<<endl;
960  cout<<"|**| |**|"<<endl;
961  cout<<"|**| --> If varexp is entered as any observable versus the segment ID (ex: varexp = \"FW05:spec\"), a specific TH1 is drawn with the value of the observable |**|"<<endl;
962  cout<<"|**| on the Y axis and the Segment ID on the X axis |**|"<<endl;
963  cout<<"|**| |**|"<<endl;
964  cout<<"|**| --> In all other cases, the plot is drawn using the TTree plot utilities. |**|"<<endl;
965  cout<<"|**| |**|"<<endl;
966  cout<<"|**| |**|"<<endl;
967  cout<<"|**| --> The name of the histogram is the one entered (ex: varexp = \"FW05:spec>>HistName\"), |**|"<<endl;
968  cout<<"|**| --> If no name is entered (ex: varexp = \"FW05:spec\"), name is deduced to avoid identical names |**|"<<endl;
969  cout<<"|**| |**|"<<endl;
970  cout<<"|**| |**|"<<endl;
971  cout<<"|**| List of the printables values: |**|"<<endl;
972  cout<<"|**| | lib | spec | pks | ok | ERef | rEnergy | FW05 | FW01 | Area | Position | Width | Ampli | WTML | WTMR | slope | rChi2 | |**|"<<endl;
973  cout<<"|**| |**|"<<endl;
974  cout<<"|*******************************************************************************************************************************************************************|"<<endl;
975  cout<<" ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ "<<endl;
976  cout<<endl;
978 }
979 
981 
983 {
984  int LibNbr = InitTree();
985  if(LibNbr!=-1)
986  {
987  PlotVarExp = "";
988  CanvasVisu::OpenContextMenu("GetPlotParams",this);
989 
990  // TTimer::SingleShot(20,"RawAmpWatcher",this,"PlotCalibResultsAsTree()");
991  if(PlotVarExp!="") PlotCalibResultsAsTree(LibNbr);
992  }
993 }
994 
996 
997 void RawAmpWatcher::GetPlotParams(const char *varexp, const char *selection, const char* option)
998 {
999  PlotVarExp = varexp;
1000  PlotVarSel = selection;
1001  PlotVarOpt = option;
1002 }
1003 
1005 
1007 {
1008  TCanvas *c = 0x0;
1009 
1010  Color_t HistColor = GetColor(0);
1011 
1012  TString test = PlotVarExp;
1013  int dim = 1;
1014  int index=0;
1015  while( (index = test.Index(":")) != -1 )
1016  {
1017  test.Replace(index,1,"");
1018  dim++;
1019  }
1020 
1021  TString HistName;
1022  TString HistNameSave;
1023  TString Observable;
1024 
1025  bool SpecialPlot = false;
1026  if(PlotVarExp.Contains(":spec") && dim==2) SpecialPlot = true;
1027 
1029  if(SpecialPlot)
1030  {
1031  if(PlotVarExp.Contains(">>"))
1032  {
1033  HistName = PlotVarExp.Copy();
1034  HistName.Replace(0,HistName.Index(">>")+2,"");
1035  if(HistName.Contains("(")) HistName.Replace(HistName.Index("("),HistName.Length()-HistName.Index("("),"");
1036  Observable = PlotVarExp.Copy();
1037  Observable.Replace(Observable.Index(":spec"),Observable.Length()-Observable.Index(":spec"),"");
1038  }
1039  else
1040  {
1041  Observable = PlotVarExp.Copy().ReplaceAll(":spec","");
1042  HistName = fCrystalName + Form("_Lib%d_",LibNbr) + Observable;
1043  }
1044  }
1045  else
1046  {
1047  if(PlotVarExp.Contains(">>"))
1048  {
1049  HistName = PlotVarExp.Copy();
1050  HistName.Replace(0,HistName.Index(">>")+2,"");
1051  if(HistName.Contains("(")) HistName.Replace(HistName.Index("("),HistName.Length()-HistName.Index("("),"");
1052  HistNameSave = HistName;
1053  HistName.Append(Form("_%s",fCrystalName.Data()));
1054  }
1055  else
1056  {
1057  Observable = PlotVarExp.Copy().ReplaceAll(":","_vs_");
1058  HistName = fCrystalName + Form("_Lib%d_",LibNbr) + Observable;
1059  }
1060  }
1061 
1062  int n=0;
1063  HistName.Append("_0");
1064  while(gPad->FindObject(HistName) || gROOT->FindObjectAny(HistName))
1065  {
1066  HistName.ReplaceAll(Form("%s_%d",Observable.Data(),n),Form("%s_%d",Observable.Data(),n+1));
1067  n++;
1068  }
1069  PlotVarExp.ReplaceAll(HistNameSave,HistName);
1070 
1072  TString CanvasName = Form("Canvas_%s_%s_Lib%d_%s",fRunName.Data(),fCrystalName.Data(),LibNbr,Observable.Data());
1073 
1075  if(PlotVarOpt.Contains("glob"))
1076  {
1077  CanvasName = Form("Canvas_%s_Lib%d_%s",fRunName.Data(),LibNbr,Observable.Data());
1078  c = (TCanvas*)gROOT->FindObject(CanvasName);
1079  if(c != 0x0)
1080  {
1081  c->cd();
1082  PlotVarOpt.ReplaceAll("glob","same");
1083  }
1084  else PlotVarOpt.ReplaceAll("glob","");
1085  }
1086 
1087  if(!PlotVarOpt.Contains("same",TString::kIgnoreCase))
1088  {
1089  c = (TCanvas*)gROOT->FindObject(CanvasName);
1090  if(c) c->Clear();
1091  else c = new TCanvas(CanvasName,CanvasName);
1092  }
1093  else
1094  {
1095  c = gPad->GetCanvas();
1096 
1097  int col = 0;
1098  for(int k=0 ; k<gPad->GetListOfPrimitives()->GetSize() ; k++)
1099  {
1100  if(gPad->GetListOfPrimitives()->At(k)->InheritsFrom("TH1"))col++;
1101  }
1102 
1103  HistColor = GetColor(col);
1104  }
1105 
1107  if(SpecialPlot)
1108  {
1109  gStyle->SetOptTitle(1);
1110  gStyle->SetOptStat(0);
1111 
1112  TH1F *h = new TH1F(HistName,((TString)Observable + " distribution, crystal " + fCrystalName),38,0,38);
1113  h->GetYaxis()->SetTitle(Observable);
1114 
1115  for(int i=0 ; i<38 ; i++)
1116  {
1117  PadPos p = fHistPositionList[i];
1118 
1119  h->GetXaxis()->SetBinLabel(i+1,p.SegName);
1120 
1121  if(PlotVarSel=="") PlotVarSel = "1";
1122  TSQLResult *Res = fCalibResultsTree->Query(Observable,Form("spec==%d && %s",i,PlotVarSel.Data()));
1123  TSQLRow *Row = Res->Next();
1124  if(Row)h->SetBinContent(i+1,((TString)Row->GetField(0)).Atof());
1125  }
1126 
1127  h->SetLineColor(HistColor);
1128 
1129  h->Draw(PlotVarOpt);
1130  }
1131  else
1132  {
1134  if(dim==1)
1135  {
1136  TH1 *h = (TH1*)gPad->FindObject(HistName);
1137  if(h)h->SetLineColor(HistColor);
1138  }
1139  }
1140 
1141  c->Modified();
1142  c->Update();
1143 }
1144 
1146 {
1147  cout<<endl;
1148  cout<<" _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ "<<endl;
1149  cout<<"|*******************************************************************************************************************************************************************|"<<endl;
1150  cout<<"|**| |**|"<<endl;
1151  cout<<"|**|-------------------------------------------------------------------------------------------------------------------------------------------------------------|**|"<<endl;
1152  cout<<"|**| ---------------------------------------------------------------------- Calibration ---------------------------------------------------------------------|**|"<<endl;
1153  cout<<"|**|-------------------------------------------------------------------------------------------------------------------------------------------------------------|**|"<<endl;
1154  cout<<"|**| |**|"<<endl;
1155  cout<<"|**| FitAll() ==> Analysis of all spectra drawn in the current Canvas | |**|"<<endl;
1156  cout<<"|**| FitSelectedRecal() ==> Analysis of the spectrum drawn in the selected pad | |**|"<<endl;
1157  cout<<"|**| SpecificFit(NHist, FirstHist, Step) ==> Analysis of NHist from seg nbr FirstHist with a step of Step | Def val = 38,0,1 |**|"<<endl;
1158  cout<<"|**| | |**|"<<endl;
1159  cout<<"|**|-------------------------------------------------------------------------------------------------------------------------------------------------------------|**|"<<endl;
1160  cout<<"|**| --------------------------------------------------------------------- Configuration ---------------------------------------------------------------------|**|"<<endl;
1161  cout<<"|**|-------------------------------------------------------------------------------------------------------------------------------------------------------------|**|"<<endl;
1162  cout<<"|**| |**|"<<endl;
1163  cout<<"|**| ----------------------------------------------------------------- Channel configuration ----------------------------------------------------------------|**|"<<endl;
1164  cout<<"|**| SetChannelOffset(Off) ==> Channel offset to subtract to the position of the peaks | Def val = 0 |**|"<<endl;
1165  cout<<"|**| SetGlobalChannelLimits(ChFrom, ChTo) ==> Limit the search to this range in channels | |**|"<<endl;
1166  cout<<"|**| SetHistChannelLimits(SpecNbr, lib, ChFrom, ChTo) ==> Limit the search to this range in channels for spec SpecNbr of lib library | |**|"<<endl;
1167  cout<<"|**| | |**|"<<endl;
1168  cout<<"|**| ------------------------------------------------------------ Theoretical Peaks configuration -----------------------------------------------------------|**|"<<endl;
1169  cout<<"|**| SetSource(fSourceName): List of available sources (more than one allowed; 60Co if nothing given) | |**|"<<endl;
1170  cout<<"|**| -−> 22Na 40K 56Co 57Co 60Co 88Y 133Ba 134Cs 137Cs 152Eu 208Pb 226Ra 241Am | |**|"<<endl;
1171  cout<<"|**| AddPeak(EPeak) ==> Add this energy to the list of lines (can be given more than once) | |**|"<<endl;
1172  cout<<"|**| RemoveClosestPeakTo(EPeak) ==> Remove the line closest to this energy from the list of lines | |**|"<<endl;
1173  cout<<"|**| SetRefPeak(EPeak) ==> Energy (keV) of the reference peak for extended printouts | |**|"<<endl;
1174  cout<<"|**| | |**|"<<endl;
1175  cout<<"|**| --------------------------------------------------------------- Peak search configuration --------------------------------------------------------------|**|"<<endl;
1176  cout<<"|**| SetGlobalPeaksLimits(DefFWHM, DefAmpli) ==> Default fwhm and minmum amplitude for the peaksearch | Def val = 15 5 |**|"<<endl;
1177  cout<<"|**| SetHistPeaksLimits(SpecNbr, lib, FWHM, Ampli) ==> Fwhm and minmum Amplitude for spec SpecNbr of lib library | |**|"<<endl;
1178  cout<<"|**| UseFirstDerivativeSearch() ==> Use the 1st-derivative search (default, always for 2-line sources) | |**|"<<endl;
1179  cout<<"|**| UseSecondDerivativeSearch ==> Use the 2nd-derivative search | |**|"<<endl;
1180  cout<<"|**| | |**|"<<endl;
1181  cout<<"|**| ---------------------------------------------------------------- BackGround configuration ---------------------------------------------------------------|**|"<<endl;
1182  cout<<"|**| UseFlatBackGround() ==> Use a flat function background to fit the peaks (default) | |**|"<<endl;
1183  cout<<"|**| UseAffineBackGround() ==> Use an affine function background to fit the peaks | |**|"<<endl;
1184  cout<<"|**| NoBackGround() ==> No background estimation to fit the peaks | |**|"<<endl;
1185  cout<<"|**| | |**|"<<endl;
1186  cout<<"|**| ------------------------------------------------------------------- Fit configuration ------------------------------------------------------------------|**|"<<endl;
1187  cout<<"|**| UnsetLeftTail() ==> Disable using the Left Tail in peak fit | |**|"<<endl;
1188  cout<<"|**| UnsetRightTail() ==> Disable using the Right Tail in peak fit | |**|"<<endl;
1189  cout<<"|**| UseLinearCalib() ==> add a fake peak at (0,0) to push calibration through origin | |**|"<<endl;
1190  cout<<"|**| UseAffineCalib() ==> affine calibration y = offset + slope*x | |**|"<<endl;
1191  cout<<"|**| UseParabolicCalib() ==> parabolic calibration y = offset + slope*x + curv*x*x | |**|"<<endl;
1192  cout<<"|**| SetGain(Gain) ==> scaling factor for the slope | Def val = 1 |**|"<<endl;
1193  cout<<"|**| | |**|"<<endl;
1194  cout<<"|**|-------------------------------------------------------------------------------------------------------------------------------------------------------------|**|"<<endl;
1195  cout<<"|**| -------------------------------------------------------------------- Verbose options --------------------------------------------------------------------|**|"<<endl;
1196  cout<<"|**|-------------------------------------------------------------------------------------------------------------------------------------------------------------|**|"<<endl;
1197  cout<<"|**| |**|"<<endl;
1198  cout<<"|**| PrintResForXTalk(VerboseMod) ==> Print results as when calculating xTalk coefficients mod==36/37/38 | |**|"<<endl;
1199  cout<<"|**| SetVerbosityLevel(Verb) ==> Verbosity bit0=fit_details, bit1=calib_details, bit2=more_calib_details | Def val = 0 |**|"<<endl;
1200  cout<<"|**| SetFullVerbosity() ==> Set full verbosity | |**|"<<endl;
1201  cout<<"|**| |**|"<<endl;
1202  cout<<"|**|-------------------------------------------------------------------------------------------------------------------------------------------------------------|**|"<<endl;
1203  cout<<"|**| -------------------------------------------------------------------- Plot fit results -------------------------------------------------------------------|**|"<<endl;
1204  cout<<"|**|-------------------------------------------------------------------------------------------------------------------------------------------------------------|**|"<<endl;
1205  cout<<"|**| |**|"<<endl;
1206  cout<<"|**| PlotCalibResults() ==> Plot the fit results using TTree utilities | |**|"<<endl;
1207  cout<<"|**| PrintPlotHelp() ==> Print a manual for the PlotCalibResults method | |**|"<<endl;
1208  cout<<"|**| |**|"<<endl;
1209  cout<<"|**|-------------------------------------------------------------------------------------------------------------------------------------------------------------|**|"<<endl;
1210  cout<<"|**| ---------------------------------------------------------------------- Hotkeys ---------------------------------------------------------------------|**|"<<endl;
1211  cout<<"|**|-------------------------------------------------------------------------------------------------------------------------------------------------------------|**|"<<endl;
1212  cout<<"|**| |**|"<<endl;
1213  cout<<"|**| Set source ==> s+s |**|"<<endl;
1214  cout<<"|**| Fit selected pad ==> f |**|"<<endl;
1215  cout<<"|**| Fit all pads ==> Ctrl pressed and f |**|"<<endl;
1216  cout<<"|**| Set channel limits for the selected pad ==> c+l |**|"<<endl;
1217  cout<<"|**| Set global channel limits ==> Ctrl pressed and c+l |**|"<<endl;
1218  cout<<"|**| Set peak limits for the selected pad ==> p+l |**|"<<endl;
1219  cout<<"|**| Set global peak limits ==> Ctrl pressed and p+l |**|"<<endl;
1220  cout<<"|**| Print help ==> p+h |**|"<<endl;
1221  cout<<"|**| Plot calibration results ==> p+c |**|"<<endl;
1222  cout<<"|**| |**|"<<endl;
1223  cout<<"|*******************************************************************************************************************************************************************|"<<endl;
1224  cout<<" ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ "<<endl;
1225  cout<<endl;
1226 }
1227 
1229 
1230 void RawAmpWatcher::SetGain(float Gain)
1231 {
1232  fGWRecal->SetGain(Gain);
1233 }
1234 
1236 
1237 void RawAmpWatcher::WriteCalibFiles(const char *ConfDirectory)
1238 {
1239  TString OutDirGlob = ConfDirectory;
1240 
1241  TString OutDir;
1242 
1243  TString Passwd = "";
1244 
1245  if(OutDirGlob.Contains(":/"))
1246  {
1247  TObjArray *token = OutDirGlob.Tokenize(":");
1248  OutDir = token->Last()->GetName();
1249  cout<<"Enter password to access to "<<token->First()->GetName()<<endl;
1250  cin>>Passwd;
1251  delete token;
1252  }
1253  else
1254  {
1255  OutDir = OutDirGlob;
1256  }
1257 
1258  if(!gSystem->OpenDirectory(OutDir.Data()))
1259  {
1261  cout<<OutDir<<" not found"<<endl;
1263  return;
1264  }
1265 
1267  TSystemDirectory Dir;
1268  Dir.SetDirectory(OutDir);
1269 
1270  TList *ListOfFolders = Dir.GetListOfFiles();
1271 
1272  for(int i=0 ; i<ListOfFolders->GetSize() ; i++)
1273  {
1274  if(((TString)ListOfFolders->At(i)->GetName()).Length() != 3)
1275  {
1276  ListOfFolders->RemoveAt(i);
1277  i--;
1278  }
1279  }
1280 
1281  for(int i= 0 ; i<ListOfFolders->GetSize() ; i++ )
1282  {
1283  TString CrystalName = ListOfFolders->At(i)->GetName();
1284  TString ConfFilePath = OutDir + "/" + CrystalName + "/" + "PreprocessingFilterPSA.conf";
1285  TString ConfFilePathTot = OutDirGlob + "/" + CrystalName + "/" + "PreprocessingFilterPSA.conf";
1286 
1287  if(!gSystem->IsFileInIncludePath(ConfFilePath))
1288  {
1290  cout<<"No PreprocessingFilterPSA.conf found for crystal "<<CrystalName<<endl;
1292  }
1293  else
1294  {
1295  TString GWFile = "FitResults/GWRecal/" + fRunName + "/" + CrystalName + "_Amplitude_Lib1.fit";
1296  if(!gSystem->IsFileInIncludePath(GWFile))
1297  {
1299  cout<<GWFile<<" not found, test with lib 0"<<endl;
1301  GWFile = "FitResults/GWRecal/" + fRunName + "/" + CrystalName + "_Amplitude_Lib0.fit";
1302  if(!gSystem->IsFileInIncludePath(GWFile))
1303  {
1305  cout<<GWFile<<" not found, crystal ignored"<<endl;
1307  continue;
1308  }
1309  }
1310 
1311  ifstream finAGATA(ConfFilePath);
1312  ifstream finGW(GWFile);
1313 
1314  ofstream fout("Calib_tmp");
1315 
1316  string lineAGATA;
1317  TString BufferAGATA;
1318  string lineGW;
1319  TString BufferGW;
1320 
1321  int segnbr=0;
1322 
1323  while(segnbr<38)
1324  {
1325  getline(finAGATA,lineAGATA);
1326 
1327  BufferAGATA = lineAGATA;
1328 
1329  if(BufferAGATA=="")break;
1330 
1331  TObjArray *token = BufferAGATA.Tokenize(" ");
1332  TString CalibAGATA = ((TObject*)token->At(4))->GetName();
1333  delete token;
1334 
1335  int GWSegNr = -1;
1336  TString CalibGW;
1337 
1338  while(GWSegNr!=segnbr)
1339  {
1340  getline(finGW,lineGW);
1341  BufferGW = lineGW;
1342 
1343  if(BufferGW.BeginsWith("#")) continue;
1344 
1345  token = BufferGW.Tokenize(" ");
1346  TString Seg = ((TObject*)token->At(1))->GetName();
1347  CalibGW = ((TObject*)token->At(13))->GetName();
1348  GWSegNr = Seg.Atoi();
1349  delete token;
1350  }
1351 
1352 // cout<<"AGATA = "<<CalibAGATA<<" ; GW = "<<CalibGW<<endl;
1353 
1354  BufferAGATA.ReplaceAll(CalibAGATA,CalibGW);
1355  fout<<BufferAGATA<<endl;
1356 
1357  segnbr++;
1358  }
1359  while(finAGATA)
1360  {
1361  getline(finAGATA,lineAGATA);
1362 
1363  BufferAGATA = lineAGATA;
1364 
1365  if(BufferAGATA=="")break;
1366 
1367  fout<<BufferAGATA<<endl;
1368  }
1369 
1370  finAGATA.close();
1371  finGW.close();
1372  fout.close();
1373 
1374  int status=0;
1375  if(Passwd != "" && gSystem->Which(gSystem->Getenv("PATH"),"sshpass"))
1376  {
1377  status=system(Form("sshpass -p %s scp Calib_tmp %s",Passwd.Data(),ConfFilePathTot.Data()));
1378  }
1379  else
1380  {
1381  status=system(Form("scp Calib_tmp %s",ConfFilePathTot.Data()));
1382  status=system("rm Calib_tmp");
1383  }
1384 
1386  cout<<ConfFilePath<<" updated !"<<endl;
1388  }
1389  }
1390 }
1391 
void SetXmax(double x)
Definition: FitSpectra.h:36
GWRecal * fGWRecal
Recal Part.
Definition: RawAmpWatcher.h:79
BashColor * fBashColor
Definition: CanvasVisu.h:34
void FitSelectedRecal(bool PrintHeader=true)
B) FitSelected.
double fwhm
Definition: RecalEnergy.h:39
std::vector< double > GetRightTailProp()
Definition: FitSpectra.h:114
ofstream fFileOutGWRecal
Definition: RawAmpWatcher.h:80
double BgFrom
Definition: RecalEnergy.h:32
void SetHistChannelLimits(int SpecNbr, float ChFrom, float ChTo)
******************************************************************************************/// ...
void SetWidth(double w)
Definition: FitSpectra.h:30
TString PlotVarSel
double posi
Definition: RecalEnergy.h:36
virtual void WriteCalibFiles(const char *ConfDirectory="")
******************************************************************************************/// ...
virtual void ShowHist(int HistNumber, int LibraryNumber=1, bool same=false)
Definition: CanvasVisu.C:210
vector< PadPos > fHistPositionList
Definition: CanvasVisu.h:44
double TabRTProp[38]
Definition: RawAmpWatcher.h:27
void SetThreshold(double t)
Definition: FitSpectra.h:32
virtual void Exec(const char *option)
******************************************************************************************/// ...
double BgTo
Definition: RecalEnergy.h:33
std::vector< double > GetFWHMCal()
Definition: FitSpectra.h:106
double fFirstLibGain
Definition: RawAmpWatcher.h:60
void SetGain(float Gain)
f) UseFlatBackGround
double TabE[38]
Definition: RawAmpWatcher.h:23
double BgdOff
Definition: RecalEnergy.h:30
void SetHistPeaksLimits(int SpecNbr, float FWHM, float Ampli)
******************************************************************************************/// ...
bool good
Definition: RecalEnergy.h:46
void SetSelectedHistChannelLimits(int ChFrom=50, int ChTo=32768)
******************************************************************************************/// ...
std::vector< double > GetFWHM_10Cal()
Definition: FitSpectra.h:110
double TabLTProp[38]
Definition: RawAmpWatcher.h:26
int InitTree()
******************************************************************************************/// ...
void Fit()
Definition: FitSpectra.cpp:160
double GetCalibSlope()
Definition: FitSpectra.h:121
FitFunctions * fFitFunction
Definition: RawAmpWatcher.h:82
std::vector< double > GetMean()
Definition: FitSpectra.h:100
void UseOffset(bool off)
Definition: FitSpectra.h:129
TString PlotVarExp
TString fCrystalName
Definition: CanvasVisu.h:67
void SetGlobalChannelLimits(int ChFrom=50, int ChTo=32768)
b) SetChannelLimits
double GetCalibOffset()
Definition: FitSpectra.h:123
void ReduceListOfPeak()
Definition: FitSpectra.cpp:766
TList * fListOfLibrairies
Definition: CanvasVisu.h:64
void SetSource(TString SourceName)
Definition: RecalEnergy.h:111
void SetGain(float Gain)
Definition: RecalEnergy.h:133
void SetSelectedHistPeaksLimits(float FWHM=15, float Ampli=5)
******************************************************************************************/// ...
double TabFWHM_10[38]
Definition: RawAmpWatcher.h:25
double TabMean[38]
Definition: RawAmpWatcher.h:22
double TabGain[38]
Definition: RawAmpWatcher.h:21
void FitSelectedRoot(const char *FitType="Dino", const char *source="60Co", bool all=false)
******************************************************************************************/// ...
void SearchPeak(int NPeaks=2, double width=50, double threshold=0.1, double xmin=0., double xmax=30000.)
******************************************************************************************/// ...
double fThreshold
Definition: RawAmpWatcher.h:32
void SetGlobalChannelLimits(int ChFrom, int ChTo)
Definition: RecalEnergy.h:107
std::vector< double > GetArea()
Definition: FitSpectra.h:116
TH1 * fCurrentHist
Definition: RawAmpWatcher.h:84
void SetXmin(double x)
Definition: FitSpectra.h:34
void PrintPlotHelp()
******************************************************************************************/// ...
std::vector< double > GetLeftTailProp()
Definition: FitSpectra.h:112
virtual void ShowSpectra(int LibraryNumber=1, const char *DrawOpt="")
******************************************************************************************/// ...
double S
Definition: RecalEnergy.h:44
LoupOnPad, a class to Loupe on a Pad in a Canvas with many pads in it.
Definition: LoupeOnPad.h:76
void SetPersoBackground(int NumberIterations=100, int Direction=TSpectrum::kBackDecreasingWindow, int FilterOrder=TSpectrum::kBackOrder8, bool Smoothing=true, int smoothingWindow=TSpectrum::kBackSmoothing3, bool Compton=false)
******************************************************************************************/// ...
static Bool_t OpenContextMenu(const char *method, TObject *obj, const char *alt_method_name="")
Definition: CanvasVisu.C:658
virtual void SetLoupe(bool loupeon=true)
void SetPersoBackground(int NumberIterations=100, int Direction=TSpectrum::kBackDecreasingWindow, int FilterOrder=TSpectrum::kBackOrder8, bool Smoothing=true, int smoothingWindow=TSpectrum::kBackSmoothing3, bool Compton=false)
Definition: FitSpectra.cpp:755
TCanvas * BuildSegmentedCanvas(TString CanvasName, TString CanvasTitle)
Definition: CanvasVisu.C:125
double Rho
Definition: RecalEnergy.h:43
void SetNSpec(int N)
Definition: RecalEnergy.h:102
std::vector< double > GetECal()
Definition: FitSpectra.h:118
double TabOffset[38]
Definition: RawAmpWatcher.h:20
void SetGlobalPeaksLimits(float DefFWHM=15, float DefAmpli=5)
C) PeakSearch.
void GetPlotParams(const char *varexp="FW05:spec", const char *selection="", const char *option="")
******************************************************************************************/// ...
void SetGlobalPeaksLimits(float DefFWHM, float DefAmpli)
Definition: RecalEnergy.h:118
Color_t GetColor(int i)
Definition: CanvasVisu.h:49
bool fDefinePersoBackground
Definition: RawAmpWatcher.h:52
int GetFitStatus()
Definition: FitSpectra.h:86
int NSubPeaks
Definition: RecalEnergy.h:29
void SetSource(const char *SourcesNames)
B) TheoreticalPeaks.
ClassImp(BaseNucleus)
void HandleMovement(Int_t eventType, Int_t eventX, Int_t eventY, TObject *select)
******************************************************************************************/// ...
Int_t fLasteventType
HandleMovement part.
Definition: RawAmpWatcher.h:69
TString PlotVarOpt
void GetCurrentHistogram()
Definition: FitSpectra.cpp:132
TString GetHistName()
Definition: FitSpectra.h:42
void FitAllRoot(const char *FitType="Dino", const char *source="60Co")
******************************************************************************************/// ...
TH1 * GetHistogram()
Definition: FitSpectra.h:39
ADF::LogMessage & endl(ADF::LogMessage &log)
int GetCurrentHistAndLib()
******************************************************************************************/// ...
vector< Fitted > GetFitResults()
Definition: RecalEnergy.h:149
virtual void ShowHist(int HistNumber, int LibraryNumber=1, bool same=false)
******************************************************************************************/// ...
void SpecificFit(int NbrOfSpectra=38, int FirstHist=0, int Step=1)
C) SpecificFit.
void SetSpectraFolder(TString name)
Definition: RecalEnergy.h:100
void UseLinearCalib()
Definition: RecalEnergy.h:130
void PlotCalibResultsAsTreeLaucher()
******************************************************************************************/// ...
void SetHistNumber(int HistNbr)
Definition: RecalEnergy.h:103
void PlotCalibResultsAsTree(int LibNbr)
******************************************************************************************/// ...
RawAmpWatcher(const char *name, const char *title)
*/
double TabArea[38]
Definition: RawAmpWatcher.h:19
TF1 * GetDinoFct(TString Name, double min, double max, int Npar)
******************************************************************************************/// ...
void FitAllRecal()
1) Calibration
TTree * fCalibResultsTree
void SetHistPeaksLimits(int SpecNbr=0, int lib=1, float FWHM=15, float Ampli=5)
b) SetHistPeaksLimits
double Lambda
Definition: RecalEnergy.h:42
void SetStep(int Step)
Definition: RecalEnergy.h:104
double ampli
Definition: RecalEnergy.h:35
void SetHistChannelLimits(int SpecNbr=0, int lib=1, int ChFrom=50, int ChTo=32768)
c) SetChannelLimits
double BgdSlope
Definition: RecalEnergy.h:31
Int_t dim
Definition: ReadMiniTree3.C:34
double TabFWHM[38]
Definition: RawAmpWatcher.h:24