4 #include "KVItvFinderDialog.h"
12 #include "KVTestIDGridDialog.h"
13 #include "KVIdentificationResult.h"
14 #include "KVNameValueListGUI.h"
15 #include "KVMultiGaussIsotopeFit.h"
18 #include "KVIDGridEditor.h"
19 #include "KVInputDialog.h"
29 {
"Limit range of fit",
false},
30 {
"PID min for fit", 0.},
31 {
"PID max for fit", 10.},
32 {
"Minimum probability [%]", 50.},
33 {
"Minimum #sigma", 1.e-2},
34 {
"Maximum #sigma", 5.e-2},
35 {
"+ve bkg. slope",
false}
49 std::unique_ptr<KVPIDIntervalPainter> _p(p);
50 auto pleft =
p->get_left_interval();
51 auto pright =
p->get_right_interval();
52 if (pleft) pleft->set_right_interval(pright);
53 if (pright) pright->set_left_interval(pleft);
73 gROOT->ProcessLine(
Form(
"KVItvFinderDialog* _dummy_itv=(KVItvFinderDialog*)%p",
this));
78 fMain->
Connect(
"CloseWindow()",
"KVItvFinderDialog",
this,
"DoClose()");
92 delete fRootEmbeddedCanvas615->
GetCanvas();
93 fCanvas =
new TCanvas(
"c123", 10, 10, WID);
94 fCanvas->
AddExec(
"toto",
"if(_dummy_itv)_dummy_itv->HandleKey();");
108 const char* xpms[] = {
118 "bld_colorselect.png",
124 const char* tips[] = {
125 "Save intervals in current grid",
127 "Create a new interval set",
128 "Create a new interval",
129 "Update interval lists",
130 "Remove selected intervals",
131 "Multigauss fit to isotopes in interval set",
132 "Set parameters for fit",
133 "Remove fit from selected interval set",
134 "Test identification",
135 "Set log scale on y axis",
136 "Unzoom the histogram",
154 const char* method[] = {
162 "SetFitParameters()",
171 fToolBar =
new TGToolBar(fControlOscillo, 450, 80);
180 bb->
Connect(
"Clicked()",
"KVItvFinderDialog",
this, method[i]);
192 fIntervalSetListView->
Connect(
"SelectionChanged()",
"KVItvFinderDialog",
this,
"DisplayPIDint()");
208 const char* xpms[] = {
213 const char* tips[] = {
223 const char* method[] = {
230 fToolBar2 =
new TGToolBar(fControlOscillo, 450, 80);
239 bb->
Connect(
"Clicked()",
"KVItvFinderDialog",
this, method[i]);
247 fIntervalListView->
Connect(
"SelectionChanged()",
"KVItvFinderDialog",
this,
"SelectionITVChanged()");
268 current_interval_set =
nullptr;
274 fLinearHisto->
Draw(
"hist");
276 int tmp[30] = {3, 3, 3, 4, 4, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6};
277 for (
int ii = 0; ii < 30; ii++) fNpeaks[ii] = tmp[ii];
296 if (nSelected == 1) {
301 current_interval_set =
nullptr;
314 fItvPaint.
Execute(
"HighLight",
"0");
320 if (!painter)
Info(
"SelectionITVChanged",
"%d %d not found...", zz, aa);
335 if (nSelected == 1) {
340 current_interval_set =
nullptr;
355 current_interval_set =
nullptr;
359 auto zz = current_interval_set->
GetZ();
363 fItvPaint.
Execute(
"SetDisplayLabel",
"0");
367 tmp->Execute(
"SetDisplayLabel",
"1");
376 fitparams.
Set(massfit);
380 tmp->Execute(
"DeactivateIntervals",
"");
395 last_drawn_interval =
nullptr;
424 dummy->Connect(
"IntMod()",
"KVItvFinderDialog",
this,
"UpdatePIDList()");
425 fItvPaint.
Add(dummy);
426 last_drawn_interval = dummy;
443 std::vector<int> alist;
444 for (
int ii = 0; ii < itvs->
GetNPID(); ii++) {
447 delete_painter_from_painter_list(pid);
448 alist.push_back(itv->
GetA());
502 if (list.IsEmpty()) {
507 for (
int ii = 0; ii < list.GetEntries(); ii++) {
536 "KVIDGridEditor::SaveCurrentGrid",
Form(
"Do you wat to save the grid here : %s", fn.
Data()),
546 const char* filetypes[] = {
547 "ID Grid files",
"*.dat",
558 if (!filenam.
Contains(
'.')) filenam +=
".dat";
565 current_interval_set =
nullptr;
586 if (!itvs->
GetNPID())
continue;
594 if (!itvs->
GetNPID())
continue;
614 if (list.IsEmpty() || list.GetEntries() > 1) {
615 current_interval_set =
nullptr;
624 double pid = mm->GetX();
633 auto aa_guessstimate =
TMath::Nint(current_interval_set->
GetZ() * 2 + (pid - current_interval_set->
GetZ()) / 0.12);
635 if (!current_interval_set->
GetNPID()) {
636 aa = aa_guessstimate;
653 iint = current_interval_set->
GetNPID();
657 for (
int ii = 1; ii < current_interval_set->
GetNPID(); ii++) {
662 if ((aa_guessstimate > (aa - 1)) &&
664 aa = aa_guessstimate;
671 interval* itv =
new interval(current_interval_set->
GetZ(), aa, mm->GetX(), mm->GetX() - 0.05, mm->GetX() + 0.05);
679 TIter next_painter(&fItvPaint);
682 if (pidpnt->
GetInterval() == left_interval) left_painter = pidpnt;
683 else if (pidpnt->
GetInterval() == right_interval) right_painter = pidpnt;
694 right_painter->set_left_interval(dummy);
699 dummy->Connect(
"IntMod()",
"KVItvFinderDialog",
this,
"UpdatePIDList()");
702 fItvPaint.
Add(dummy);
706 fItvPaint.
Execute(
"Update",
"");
719 if (list.IsEmpty() || list.GetEntries() > 1) {
720 current_interval_set =
nullptr;
732 auto aa_guessstimate =
TMath::Nint(current_interval_set->
GetZ() * 2 + (pid - current_interval_set->
GetZ()) / 0.12);
734 if (!current_interval_set->
GetNPID()) {
735 aa = aa_guessstimate;
752 iint = current_interval_set->
GetNPID();
756 for (
int ii = 1; ii < current_interval_set->
GetNPID(); ii++) {
761 if ((aa_guessstimate > (aa - 1)) &&
763 aa = aa_guessstimate;
778 TIter next_painter(&fItvPaint);
781 if (pidpnt->
GetInterval() == left_interval) left_painter = pidpnt;
782 else if (pidpnt->
GetInterval() == right_interval) right_painter = pidpnt;
793 right_painter->set_left_interval(dummy);
798 dummy->Connect(
"IntMod()",
"KVItvFinderDialog",
this,
"UpdatePIDList()");
801 fItvPaint.
Add(dummy);
805 fItvPaint.
Execute(
"Update",
"");
821 bool ok =
false;
TString myZ; myZ.
Form(
"%d", fNextIntervalZ);
822 new KVInputDialog(fMain,
"Enter Z for new set of isotopes:", &myZ, &ok);
825 fNextIntervalZ = myZ.
Atoi();
835 void KVItvFinderDialog::remove_interval_from_interval_set(
interval_set* itvs,
interval* itv,
bool remove_fit)
839 delete_painter_from_painter_list(pid);
854 current_interval_set =
nullptr;
856 if (nSelected == 1) {
860 if (nSelected >= 1) {
861 for (
int ii = 0; ii < nSelected; ii++) {
863 remove_interval_from_interval_set(current_interval_set, itv);
871 else if (nSelected > 1) {
872 for (
int ii = 0; ii < nSelected; ii++) {
890 current_interval_set =
nullptr;
891 if (nSelected == 1) {
897 if (nSelected == 1) {
900 fItvPaint.
Execute(
"Update",
"");
908 TIter next_itv(&list);
910 while ((itv = (
interval*)next_itv())) {
916 fItvPaint.
Execute(
"Update",
"");
932 current_interval_set =
nullptr;
933 if (nSelected == 1) {
938 if (nSelected == 1) {
941 fItvPaint.
Execute(
"Update",
"");
949 TIter next_itv(&list);
951 while ((itv = (
interval*)next_itv())) {
957 fItvPaint.
Execute(
"Update",
"");
974 if (nSelected == 1) {
979 current_interval_set =
nullptr;
998 current_interval_set =
nullptr;
1024 fItvPaint.
Execute(
"SetDisplayLabel",
"0");
1025 current_interval_set =
nullptr;
1056 if (!current_interval_set)
return;
1059 std::vector<double> pidlist;
1062 while ((intvl = (
interval*)nxt_int())) {
1064 pidlist.push_back(intvl->
GetPID());
1067 current_interval_set->
GetZ() - 0.5, current_interval_set->
GetZ() + 0.5,
1070 bool fit_limited =
false;
1084 if(negative_bkg_slope_changed)
1087 fLinearHisto->
Fit(&fitfunc,
"NR");
1092 fLinearHisto->
Fit(&fitfunc,
"NRME");
1096 fitfunc.
SetFitRange(current_interval_set->
GetZ() - 0.5,current_interval_set->
GetZ() + 0.5);
1108 tmp->Execute(
"DeactivateIntervals",
"");
1111 int most_prob_A = 0;
1116 double delta_pid = 0.001;
1117 TList accepted_intervals;
1118 for (
double pid = fitfunc.
GetPIDmin() ; pid <= fitfunc.
GetPIDmax(); pid += delta_pid) {
1123 if (proba > min_proba) {
1125 if (*Amax > most_prob_A) {
1127 most_prob_A = *Amax;
1129 while (intvl->
GetA() < most_prob_A) {
1132 accepted_intervals.
Add(intvl);
1137 most_prob_A = *Amax;
1139 while (intvl->
GetA() < most_prob_A) {
1142 accepted_intervals.
Add(intvl);
1146 else if (most_prob_A) {
1157 while ((intvl = (
interval*)nxt_int())) {
1159 while (vec_alist[ig - 1] < intvl->
GetA()) {
1163 remaining_gaussians.
Add(ig);
1164 remaining_alist.
Add(intvl->
GetA());
1168 fItvPaint.
Execute(
"Update",
"");
1177 zlist.
Add(current_interval_set->
GetZ());
1191 for (ig = 1; ig <= alist.
GetNValues(); ++ig) {
1209 bool cancel =
false;
1212 dialog->EnableDependingOnBool(
"PID min for fit",
"Limit range of fit");
1213 dialog->EnableDependingOnBool(
"PID max for fit",
"Limit range of fit");
1214 dialog->DisplayDialog();
1227 if (!current_interval_set)
return;
1229 std::vector<int> alist;
1232 while ((intvl = (
interval*)nxt_int())) {
1233 alist.push_back(intvl->
GetA());
1252 if (!fCanvas)
return;
1275 std::cout <<
"Mouse shortcuts : Wheel-click Fit intervals of current Z" << std::endl;
1276 std::cout <<
" Double-click Set/Unset log scale on Y axis" << std::endl;
1277 std::cout <<
" Shift-click Add an interval where clicked" << std::endl;
1294 if (zz == 1) fLinearHisto->
SetAxisRange(0.9, zz + 0.5,
"X");
1295 else fLinearHisto->
SetAxisRange(zz - 0.5, zz + 0.5,
"X");
1297 int nfound = fSpectrum.
Search(fLinearHisto, fSig,
"goff", ((zz == 2) ? 0.1 * fRat : fRat));
1299 #if ROOT_VERSION_CODE > ROOT_VERSION(5,99,01)
1307 nfound =
TMath::Min(fNpeaks[zz - 1], nfound);
1312 int zrefs[] = {1, 4, 7, 9, 11, 12, 15, 16, 19, 21, 23, 25, 27, 29, 31, 34, 35, 38, 40, 42, 44, 47, 49, 51, 53};
1313 int zref = zrefs[zz - 1];
1316 for (
int p = 0;
p < nfound;
p++) {
1317 if (std::abs(xpeaks[idx[
p]] - xpeaks[0]) < .0001) idref =
p;
1319 Info(
"FindPIDIntervals",
"Z=%d : idref = %d ", zz, idref);
1321 for (
int p = 0;
p < nfound;
p++) {
1323 double pid = xpeaks[idx[
p]];
1324 itvs->
add(zref + (
p - idref), pid, pid - 0.05, pid + 0.05);
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t np
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
char * Form(const char *fmt,...)
char * StrDup(const char *str)
R__EXTERN TStyle * gStyle
R__EXTERN TSystem * gSystem
const Char_t * GetName() const override
const KVNameValueList * GetParameters() const
void WriteAsciiFile(const Char_t *filename)
Open, write and close ascii file containing this grid.
const KVList * GetIdentifiers() const
Hybrid charge & mass identification grid.
const KVList * GetIntervalSets() const
void Initialize() override
interval_set * GetIntervalSet(int zint) const
void AddIntervalSet(interval_set *)
add an interval set to the grid, updating the corresponding parameters
TH1 * LinearizeHistoToPID(const TH2 *hdata, int nbins=100) const override
void RemoveIntervalSet(int zint)
Remove interval set for given Z from grid.
Base class for graphical cuts used in particle identification.
GUI for finding/fixing mass identification intervals.
void DrawInterval(interval_set *itvs, bool label=0)
void ClearInterval(interval_set *itvs)
void ProcessIdentification(Int_t zmin=-1, Int_t zmax=-1)
void AddInterval(double pid)
void Identify()
KVBase::OpenContextMenu("Identify(double,double)",this);.
void SetFitParameters()
Open dialog to modify parameters for multigauss mass fit.
void FindPIDIntervals(Int_t zz)
KVItvFinderDialog(KVIDZAFromZGrid *gg, TH2 *hh)
static KVNameValueList mass_fit_parameters
parameters for user control of multi-gaussian fit
void RemoveFit()
Remove fit of currently selected interval set from pad.
void ExportToGrid()
Write all PID intervals in grid parameters "PIDRANGE", "PIDRANGE%d", etc.
void SelectionITVChanged()
void TestIdent()
fGrid->SetOnlyZId(0);
void LinearizeHisto(int nbins)
Double_t fpeaks(Double_t *x, Double_t *par)
void ZoomOnCanvas()
Display the interval set for a given Z when the user double clicks on it.
Enhanced version of ROOT TGListView widget.
virtual void SetDataColumns(Int_t ncolumns)
void SetDoubleClickAction(const char *receiver_class, void *receiver, const char *slot)
virtual void Display(const TCollection *l)
KVUnownedList GetSelectedObjects() const
TObject * GetLastSelectedObject() const
void AllowContextMenu(Bool_t on=kTRUE)
virtual void SetDataColumn(Int_t index, const Char_t *name, const Char_t *method="", Int_t mode=kTextCenterX)
Function for fitting PID mass spectra.
static TString get_name_of_isotope_gaussian(int z, int a)
double GetPIDvsAfit_a1() const
static TString get_name_of_multifit(int z)
double GetGaussianWidth(int) const
static void UnDrawAnyGaussian(int z, TVirtualPad *pad=gPad)
Remove the graphical representation of any gaussian for this Z from the given pad.
void DrawFitWithGaussians(Option_t *opt="", const TString &fit_title="") const
double GetCentroid(int i) const
void SetSigmaLimits(double smin, double smax)
void PositiveBkgSlope(bool yes=true)
void SetFitRange(double min, double max)
Change range of fit.
double GetPIDvsAfit_a2() const
std::optional< int > GetMostProbableA(double PID, double &P) const
double GetBackgroundSlope() const
double GetPIDvsAfit_a0() const
double GetGaussianNorm(int i) const
double GetBackgroundConstant() const
void ReleaseCentroids()
Release the constraint on the positions of the centroids.
void UnDraw(TVirtualPad *pad=gPad) const
Remove the graphical representation of this fit from the given pad.
static void UnDrawGaussian(int z, int a, TVirtualPad *pad=gPad)
GUI for setting KVNameValueList parameters.
Handles lists of named parameters with different types, a list of KVNamedParameter objects.
Double_t GetDoubleValue(const Char_t *name) const
void SetValue(const Char_t *name, value_type value)
void RemoveParameter(const Char_t *name)
Bool_t HasStringParameter(const Char_t *name) const
Bool_t GetBoolValue(const Char_t *name) const
const Char_t * GetStringValue(const Char_t *name) const
bool Set(const KVString &)
Bool_t HasParameter(const Char_t *name) const
TString GetTStringValue(const Char_t *name) const
Strings used to represent a set of ranges of values.
const Char_t * AsQuotedString() const
const Char_t * AsString(Int_t maxchars=0) const
void Remove(Int_t)
Remove value 'n' from the list.
void Add(Int_t)
Add value 'n' to the list.
void Set(const TString &l)
IntArray GetArray() const
Graphical representation of a PID interval in the KVIDZAFromZGrid mass assignation GUI.
void SetCanvas(TCanvas *cc)
void DeactivateIntervals()
interval * GetInterval() const
void Draw(Option_t *option="") override
void SetDisplayLabel(bool dis=true)
void HighLight(bool hi=true)
void set_right_interval(KVPIDIntervalPainter *i)
void Execute(const char *method, const char *params, Int_t *error=0) override
TObject * First() const override
KVSeqCollection * GetSubListWithMethod(const Char_t *retvalue, const Char_t *method) const
TObject * Remove(TObject *obj) override
Remove object from list.
void Add(TObject *obj) override
TObject * FindObject(const char *name) const override
TObject * Last() const override
Int_t GetSize() const override
void Clear(Option_t *option="") override
TObject * At(Int_t idx) const override
void AddAt(TObject *obj, Int_t idx) override
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
GUI for testing identification grids.
virtual void SetFillColor(Color_t fcolor)
virtual void SetLineColor(Color_t lcolor)
virtual void SetMarkerStyle(Style_t mstyle=1)
virtual void SetBottomMargin(Float_t bottommargin)
virtual void SetLeftMargin(Float_t leftmargin)
virtual void SetRightMargin(Float_t rightmargin)
virtual void SetTopMargin(Float_t topmargin)
virtual void SetRangeUser(Double_t ufirst, Double_t ulast)
Int_t GetEventX() const override
TVirtualPad * cd(Int_t subpadnumber=0) override
Int_t GetEvent() const override
virtual Int_t GetEntries() const
static const TArrayI & GetPalette()
TGDimension GetDefaultSize() const override
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
void MapSubwindows() override
void SetCleanup(Int_t mode=kLocalCleanup) override
virtual void Resize(TGDimension size)
void MapWindow() override
void SetWindowName(const char *name=nullptr) override
virtual void CenterOnParent(Bool_t croot=kTRUE, EPlacement pos=kCenter)
virtual void RequestFocus()
virtual TFitResultPtr Fit(const char *formula, Option_t *option="", Option_t *goption="", Double_t xmin=0, Double_t xmax=0)
void Draw(Option_t *option="") override
virtual void SetAxisRange(Double_t xmin, Double_t xmax, Option_t *axis="X")
void Add(TObject *obj) override
TObject * Last() const override
const char * GetName() const override
void AddExec(const char *name, const char *command) override
Double_t AbsPixeltoX(Int_t px) override
void Modified(Bool_t flag=1) override
void SetLogy(Int_t value=1) override
Int_t GetLogy() const override
Bool_t Connect(const char *signal, const char *receiver_class, void *receiver, const char *slot)
void AdoptCanvas(TCanvas *c)
TCanvas * GetCanvas() const
Int_t GetCanvasWindowId() const
virtual Int_t Search(const TH1 *hist, Double_t sigma=2, Option_t *option="", Double_t threshold=0.05)
Double_t * GetPositionX() const
const char * Data() const
void Form(const char *fmt,...)
TString & Remove(EStripType s, char c)
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
TString & ReplaceAll(const char *s1, const char *s2)
void SetOptTitle(Int_t tit=1)
void SetOptStat(Int_t stat=1)
virtual char * ExpandPathName(const char *path)
virtual void Modified(Bool_t flag=1)=0
virtual TList * GetListOfPrimitives() const=0
virtual TVirtualPad * cd(Int_t subpadnumber=0)=0
virtual TObject * WaitPrimitive(const char *pname="", const char *emode="")=0
virtual TObject * GetPrimitive(const char *name) const=0
void add(int aa, double pid, double pidmin=-1., double pidmax=-1.)
void SetPIDmin(double pidmin)
void SetPIDmax(double pidmax)
Double_t Min(Double_t a, Double_t b)
Double_t Gaus(Double_t x, Double_t mean=0, Double_t sigma=1, Bool_t norm=kFALSE)
void Sort(Index n, const Element *a, Index *index, Bool_t down=kTRUE)