4#include "KVItvFinderDialog.h"
11#include "KVTestIDGridDialog.h"
12#include "KVIdentificationResult.h"
13#include "KVNameValueListGUI.h"
14#include <KVMultiGaussIsotopeFit.h>
26 {
"Limit range of fit",
false},
27 {
"PID min for fit", 0.},
28 {
"PID max for fit", 10.},
29 {
"Minimum probability [%]", 50.},
30 {
"Minimum #sigma", 1.e-2},
31 {
"Maximum #sigma", 5.e-2}
45 std::unique_ptr<KVPIDIntervalPainter> _p(
p);
46 auto pleft =
p->get_left_interval();
47 auto pright =
p->get_right_interval();
48 if (pleft) pleft->set_right_interval(pright);
49 if (pright) pright->set_left_interval(pleft);
69 gROOT->ProcessLine(
Form(
"KVItvFinderDialog* _dummy_itv=(KVItvFinderDialog*)%p",
this));
74 fMain->
Connect(
"CloseWindow()",
"KVItvFinderDialog",
this,
"DoClose()");
88 delete fRootEmbeddedCanvas615->
GetCanvas();
90 fCanvas->
AddExec(
"toto",
"if(_dummy_itv)_dummy_itv->HandleKey();");
104 const char* xpms[] = {
114 "bld_colorselect.png",
120 const char* tips[] = {
121 "Save intervals in current grid",
123 "Create a new interval set",
124 "Create a new interval",
125 "Update interval lists",
126 "Remove selected intervals",
127 "Multigauss fit to isotopes in interval set",
128 "Set parameters for fit",
129 "Remove fit from selected interval set",
130 "Test identification",
131 "Set log scale on y axis",
132 "Unzoom the histogram",
150 const char* method[] = {
158 "SetFitParameters()",
176 bb->
Connect(
"Clicked()",
"KVItvFinderDialog",
this, method[i]);
204 const char* xpms[] = {
209 const char* tips[] = {
219 const char* method[] = {
235 bb->
Connect(
"Clicked()",
"KVItvFinderDialog",
this, method[i]);
272 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};
273 for (
int ii = 0; ii < 30; ii++)
fNpeaks[ii] = tmp[ii];
291 Int_t nSelected = list->GetSize();
292 if (nSelected == 1) {
316 if (!painter)
Info(
"SelectionITVChanged",
"%d %d not found...", zz, aa);
330 Int_t nSelected = list->GetSize();
331 if (nSelected == 1) {
363 tmp->Execute(
"SetDisplayLabel",
"1");
367 if (!
fPad->
GetPrimitive(KVMultiGaussIsotopeFit::get_name_of_multifit(zz))) {
372 fitparams.
Set(massfit);
374 fitfunc.DrawFitWithGaussians(
"same");
376 tmp->
Execute(
"DeactivateIntervals",
"");
420 dummy->Connect(
"IntMod()",
"KVItvFinderDialog",
this,
"UpdatePIDList()");
439 std::vector<int> alist;
440 for (
int ii = 0; ii < itvs->
GetNPID(); ii++) {
444 alist.push_back(itv->
GetA());
450 fitfunc.UnDraw(
fPad);
452 KVMultiGaussIsotopeFit::UnDrawAnyGaussian(itvs->
GetZ(),
fPad);
486 auto available_cpu = WITH_MULTICORE_CPU;
489 std::vector<std::thread> jobs;
498 std::cout <<
"Will run " << available_cpu <<
" threads, each for " << xbins_per_cpu <<
" bins in X" << std::endl;
500 int nthreads = available_cpu;
502 std::cout <<
"Histo linearization using " << nthreads <<
" threads..." << std::endl;
504 for (
int job = 0; job < available_cpu; ++job) {
505 auto imin = 1 + job * xbins_per_cpu;
506 auto imax = (job + 1) * xbins_per_cpu;
511 grid_copy->Initialize();
512 grid_copies.
Add(grid_copy);
515 jobs.push_back(std::thread([ =, &nthreads]() {
519 bool no_mass_id_zone_defined = (grid_copy->GetInfos()->FindObject(
"MassID") ==
nullptr);
521 for (
int i = imin; i <= imax; ++i) {
524 if (poids == 0)
continue;
531 if (x0 < 4)
continue;
535 Double_t weight = (kmax == 20 ? poids / 20. : 1.);
536 for (
int k = 0; k < kmax; k++) {
539 if (grid_copy->IsIdentifiable(
x,
y)) {
541 grid_copy->KVIDZAGrid::Identify(
x,
y, &idr);
542 if (no_mass_id_zone_defined || idr.
HasFlag(grid_copy->GetName(),
"MassID")) {
551 std::cout <<
"...remaining threads: " << nthreads << std::endl;
554 for (
auto& j : jobs) {
555 if (j.joinable()) j.join();
584 if (!list->GetSize()) {
589 for (
int ii = 0; ii < list->GetSize(); ii++) {
618 "KVIDGridEditor::SaveCurrentGrid",
Form(
"Do you wat to save the grid here : %s", fn.
Data()),
628 const char* filetypes[] = {
629 "ID Grid files",
"*.dat",
640 if (!filenam.
Contains(
'.')) filenam +=
".dat";
668 if (!itvs->
GetNPID())
continue;
676 if (!itvs->
GetNPID())
continue;
696 if (!list->GetSize() || list->GetSize() > 1) {
706 double pid = mm->GetX();
718 aa = aa_guessstimate;
744 if ((aa_guessstimate > (aa - 1)) &&
746 aa = aa_guessstimate;
764 if (pidpnt->
GetInterval() == left_interval) left_painter = pidpnt;
765 else if (pidpnt->
GetInterval() == right_interval) right_painter = pidpnt;
776 right_painter->set_left_interval(dummy);
781 dummy->Connect(
"IntMod()",
"KVItvFinderDialog",
this,
"UpdatePIDList()");
801 if (!list->GetSize() || list->GetSize() > 1) {
817 aa = aa_guessstimate;
843 if ((aa_guessstimate > (aa - 1)) &&
845 aa = aa_guessstimate;
863 if (pidpnt->
GetInterval() == left_interval) left_painter = pidpnt;
864 else if (pidpnt->
GetInterval() == right_interval) right_painter = pidpnt;
875 right_painter->set_left_interval(dummy);
880 dummy->Connect(
"IntMod()",
"KVItvFinderDialog",
this,
"UpdatePIDList()");
918 KVMultiGaussIsotopeFit::UnDrawGaussian(itvs->
GetZ(), itv->
GetA(),
fPad);
929 Int_t nSelected = list->GetSize();
932 if (nSelected == 1) {
935 nSelected = list->GetSize();
936 if (nSelected >= 1) {
937 for (
int ii = 0; ii < nSelected; ii++) {
947 else if (nSelected > 1) {
948 for (
int ii = 0; ii < nSelected; ii++) {
962 Int_t nSelected = list->GetSize();
965 if (nSelected == 1) {
969 nSelected = list->GetSize();
971 if (nSelected == 1) {
977 if (gfit) gfit->SetName(KVMultiGaussIsotopeFit::get_name_of_isotope_gaussian(itv->
GetZ(), itv->
GetA()));
982 TIter next_itv(list.get());
984 while ((itv = (
interval*)next_itv())) {
988 if (gfit) gfit->SetName(KVMultiGaussIsotopeFit::get_name_of_isotope_gaussian(itv->
GetZ(), itv->
GetA()));
1004 Int_t nSelected = list->GetSize();
1007 if (nSelected == 1) {
1010 nSelected = list->GetSize();
1012 if (nSelected == 1) {
1018 if (gfit) gfit->SetName(KVMultiGaussIsotopeFit::get_name_of_isotope_gaussian(itv->
GetZ(), itv->
GetA()));
1023 TIter next_itv(list.get());
1025 while ((itv = (
interval*)next_itv())) {
1029 if (gfit) gfit->SetName(KVMultiGaussIsotopeFit::get_name_of_isotope_gaussian(itv->
GetZ(), itv->
GetA()));
1046 Int_t nSelected = list->GetSize();
1048 if (nSelected == 1) {
1133 std::vector<double> pidlist;
1136 while ((intvl = (
interval*)nxt_int())) {
1138 pidlist.push_back(intvl->
GetPID());
1159 fitfunc.ReleaseCentroids();
1169 fitfunc.DrawFitWithGaussians(
"same");
1173 tmp->Execute(
"DeactivateIntervals",
"");
1176 int most_prob_A = 0;
1180 double delta_pid = 0.001;
1181 TList accepted_intervals;
1182 for (
double pid = fitfunc.GetPIDmin() ; pid <= fitfunc.GetPIDmax(); pid += delta_pid) {
1184 auto Amax = fitfunc.GetMostProbableA(pid, proba);
1185 if (proba > min_proba) {
1187 if (Amax > most_prob_A) {
1193 while (intvl->
GetA() < most_prob_A) {
1196 accepted_intervals.
Add(intvl);
1204 while (intvl->
GetA() < most_prob_A) {
1207 accepted_intervals.
Add(intvl);
1213 else if (most_prob_A) {
1236 while ((intvl = (
interval*)nxt_int())) {
1238 while (vec_alist[ig - 1] < intvl->
GetA()) {
1241 intvl->
SetPID(fitfunc.GetCentroid(ig));
1242 remaining_gaussians.
Add(ig);
1243 remaining_alist.
Add(intvl->
GetA());
1267 fitparams.
SetValue(
"PIDmin", fitfunc.GetPIDmin());
1268 fitparams.
SetValue(
"PIDmax", fitfunc.GetPIDmax());
1269 fitparams.
SetValue(
"Bkg_cst", fitfunc.GetBackgroundConstant());
1270 fitparams.
SetValue(
"Bkg_slp", fitfunc.GetBackgroundSlope());
1271 fitparams.
SetValue(
"GausWid", fitfunc.GetGaussianWidth(0));
1272 fitparams.
SetValue(
"PIDvsA_a0", fitfunc.GetPIDvsAfit_a0());
1273 fitparams.
SetValue(
"PIDvsA_a1", fitfunc.GetPIDvsAfit_a1());
1274 fitparams.
SetValue(
"PIDvsA_a2", fitfunc.GetPIDvsAfit_a2());
1275 for (ig = 1; ig <= alist.
GetNValues(); ++ig) {
1276 fitparams.
SetValue(
Form(
"Norm_%d", ig), fitfunc.GetGaussianNorm(ig));
1291 bool cancel =
false;
1293 dialog->EnableDependingOnBool(
"PID min for fit",
"Limit range of fit");
1294 dialog->EnableDependingOnBool(
"PID max for fit",
"Limit range of fit");
1295 dialog->DisplayDialog();
1309 std::vector<int> alist;
1312 while ((intvl = (
interval*)nxt_int())) {
1313 alist.push_back(intvl->
GetA());
1317 fitfunc.UnDraw(
fPad);
1355 std::cout <<
"Mouse shortcuts : Wheel-click Fit intervals of current Z" << std::endl;
1356 std::cout <<
" Double-click Set/Unset log scale on Y axis" << std::endl;
1357 std::cout <<
" Shift-click Add an interval where clicked" << std::endl;
1379#if ROOT_VERSION_CODE > ROOT_VERSION(5,99,01)
1392 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};
1393 int zref = zrefs[zz - 1];
1396 for (
int p = 0;
p < nfound;
p++) {
1397 if (
abs(xpeaks[idx[
p]] - xpeaks[0]) < .0001) idref =
p;
1399 Info(
"FindPIDIntervals",
"Z=%d : idref = %d ", zz, idref);
1401 for (
int p = 0;
p < nfound;
p++) {
1403 double pid = xpeaks[idx[
p]];
1404 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
R__EXTERN TRandom * gRandom
char * Form(const char *fmt,...)
char * StrDup(const char *str)
R__EXTERN TStyle * gStyle
R__EXTERN TSystem * gSystem
const KVNameValueList * GetParameters() const
static void SetAutoAdd(Bool_t yes=kTRUE)
static Bool_t GetAutoAdd()
const KVList * GetIdentifiers() const
const Char_t * GetName() const
void WriteAsciiFile(const Char_t *filename)
Open, write and close ascii file containing this grid.
Hybrid charge & mass identification grid.
KVList * GetIntervalSets()
interval_set * GetIntervalSet(int zint) const
void SetOnlyZId(Bool_t=kTRUE)
Base class for graphical cuts used in particle identification.
virtual Double_t GetPID() const
Full result of one attempted particle identification.
void Clear(Option_t *opt="")
Reset to initial values.
Double_t PID
= "real" Z if Zident==kTRUE and Aident==kFALSE, "real" A if Zident==Aident==kTRUE
Bool_t HasFlag(std::string grid_name, TString flag)
GUI for finding/fixing mass identification intervals.
KVListView * fIntervalListView
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 delete_painter_from_painter_list(KVPIDIntervalPainter *)
void Identify()
KVBase::OpenContextMenu("Identify(double,double)",this);.
void SetFitParameters()
Open dialog to modify parameters for multigauss mass fit.
interval_set * current_interval_set
void FindPIDIntervals(Int_t zz)
KVItvFinderDialog(KVIDZAFromZGrid *gg, TH2 *hh)
KVListView * fIntervalSetListView
static KVNameValueList mass_fit_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 remove_interval_from_interval_set(interval_set *itvs, interval *itv, bool remove_fit=true)
KVPIDIntervalPainter * last_drawn_interval
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)
TObject * GetLastSelectedObject() const
void AllowContextMenu(Bool_t on=kTRUE)
TList * GetSelectedObjects() const
virtual void SetDataColumn(Int_t index, const Char_t *name, const Char_t *method="", Int_t mode=kTextCenterX)
Extended TList class which owns its objects by default.
Function for fitting PID mass spectra.
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 Draw(Option_t *option="")
void DeactivateIntervals()
void SetDisplayLabel(bool dis=true)
void HighLight(bool hi=true)
void set_right_interval(KVPIDIntervalPainter *i)
interval * GetInterval() const
virtual TObject * FindObject(const char *name) const
KVSeqCollection * GetSubListWithMethod(const Char_t *retvalue, const Char_t *method) const
virtual void Clear(Option_t *option="")
virtual Int_t GetSize() const
virtual TObject * Last() const
virtual void Execute(const char *method, const char *params, Int_t *error=0)
virtual TObject * First() const
virtual TObject * At(Int_t idx) const
virtual void Add(TObject *obj)
virtual void AddAt(TObject *obj, Int_t idx)
virtual TObject * Remove(TObject *obj)
Remove object from list.
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 Int_t GetNbinsY() const
virtual TFitResultPtr Fit(const char *formula, Option_t *option="", Option_t *goption="", Double_t xmin=0, Double_t xmax=0)
virtual Int_t GetNbinsX() const
void Draw(Option_t *option="") override
virtual Int_t Fill(const char *name, Double_t w)
virtual void SetAxisRange(Double_t xmin, Double_t xmax, Option_t *axis="X")
virtual Double_t GetBinContent(Int_t bin) const
void Add(TObject *obj) override
TObject * Last() const override
const char * GetName() const override
virtual void Execute(const char *method, const char *params, Int_t *error=nullptr)
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)
virtual Double_t Uniform(Double_t x1, Double_t x2)
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
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)
RVec< PromoteType< T > > abs(const RVec< T > &v)
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)