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"
28 {
"Limit range of fit",
false},
29 {
"PID min for fit", 0.},
30 {
"PID max for fit", 10.},
31 {
"Minimum probability [%]", 50.},
32 {
"Minimum #sigma", 1.e-2},
33 {
"Maximum #sigma", 5.e-2},
34 {
"+ve bkg. slope",
false}
48 std::unique_ptr<KVPIDIntervalPainter> _p(
p);
49 auto pleft =
p->get_left_interval();
50 auto pright =
p->get_right_interval();
51 if (pleft) pleft->set_right_interval(pright);
52 if (pright) pright->set_left_interval(pleft);
72 gROOT->ProcessLine(
Form(
"KVItvFinderDialog* _dummy_itv=(KVItvFinderDialog*)%p",
this));
77 fMain->
Connect(
"CloseWindow()",
"KVItvFinderDialog",
this,
"DoClose()");
91 delete fRootEmbeddedCanvas615->
GetCanvas();
93 fCanvas->
AddExec(
"toto",
"if(_dummy_itv)_dummy_itv->HandleKey();");
107 const char* xpms[] = {
117 "bld_colorselect.png",
123 const char* tips[] = {
124 "Save intervals in current grid",
126 "Create a new interval set",
127 "Create a new interval",
128 "Update interval lists",
129 "Remove selected intervals",
130 "Multigauss fit to isotopes in interval set",
131 "Set parameters for fit",
132 "Remove fit from selected interval set",
133 "Test identification",
134 "Set log scale on y axis",
135 "Unzoom the histogram",
153 const char* method[] = {
161 "SetFitParameters()",
179 bb->
Connect(
"Clicked()",
"KVItvFinderDialog",
this, method[i]);
207 const char* xpms[] = {
212 const char* tips[] = {
222 const char* method[] = {
238 bb->
Connect(
"Clicked()",
"KVItvFinderDialog",
this, method[i]);
275 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};
276 for (
int ii = 0; ii < 30; ii++)
fNpeaks[ii] = tmp[ii];
295 if (nSelected == 1) {
319 if (!painter)
Info(
"SelectionITVChanged",
"%d %d not found...", zz, aa);
334 if (nSelected == 1) {
366 tmp->Execute(
"SetDisplayLabel",
"1");
370 if (!
fPad->
GetPrimitive(KVMultiGaussIsotopeFit::get_name_of_multifit(zz))) {
375 fitparams.
Set(massfit);
377 fitfunc.DrawFitWithGaussians(
"same");
379 tmp->
Execute(
"DeactivateIntervals",
"");
423 dummy->Connect(
"IntMod()",
"KVItvFinderDialog",
this,
"UpdatePIDList()");
442 std::vector<int> alist;
443 for (
int ii = 0; ii < itvs->
GetNPID(); ii++) {
447 alist.push_back(itv->
GetA());
455 fitfunc.UnDraw(
fPad);
457 KVMultiGaussIsotopeFit::UnDrawAnyGaussian(itvs->
GetZ(),
fPad);
491 auto available_cpu = WITH_MULTICORE_CPU;
494 std::vector<std::thread> jobs;
503 std::cout <<
"Will run " << available_cpu <<
" threads, each for " << xbins_per_cpu <<
" bins in X" << std::endl;
505 int nthreads = available_cpu;
507 std::cout <<
"Histo linearization using " << nthreads <<
" threads..." << std::endl;
509 for (
int job = 0; job < available_cpu; ++job) {
510 auto imin = 1 + job * xbins_per_cpu;
511 auto imax = (job + 1) * xbins_per_cpu;
516 grid_copy->Initialize();
517 grid_copies.
Add(grid_copy);
520 jobs.push_back(std::thread([ =, &nthreads]() {
524 bool no_mass_id_zone_defined = (grid_copy->GetInfos()->FindObject(
"MassID") ==
nullptr);
526 for (
int i = imin; i <= imax; ++i) {
529 if (poids == 0)
continue;
536 if (x0 < 4)
continue;
540 Double_t weight = (kmax == 20 ? poids / 20. : 1.);
541 for (
int k = 0; k < kmax; k++) {
544 if (grid_copy->IsIdentifiable(
x,
y)) {
546 grid_copy->KVIDZAGrid::Identify(
x,
y, &idr);
547 if (no_mass_id_zone_defined || idr.
HasFlag(grid_copy->GetName(),
"MassID")) {
556 std::cout <<
"...remaining threads: " << nthreads << std::endl;
559 for (
auto& j : jobs) {
560 if (j.joinable()) j.join();
589 if (list.IsEmpty()) {
594 for (
int ii = 0; ii < list.GetEntries(); ii++) {
623 "KVIDGridEditor::SaveCurrentGrid",
Form(
"Do you wat to save the grid here : %s", fn.
Data()),
633 const char* filetypes[] = {
634 "ID Grid files",
"*.dat",
645 if (!filenam.
Contains(
'.')) filenam +=
".dat";
673 if (!itvs->
GetNPID())
continue;
681 if (!itvs->
GetNPID())
continue;
701 if (list.IsEmpty() || list.GetEntries() > 1) {
711 double pid = mm->GetX();
723 aa = aa_guessstimate;
749 if ((aa_guessstimate > (aa - 1)) &&
751 aa = aa_guessstimate;
769 if (pidpnt->
GetInterval() == left_interval) left_painter = pidpnt;
770 else if (pidpnt->
GetInterval() == right_interval) right_painter = pidpnt;
781 right_painter->set_left_interval(dummy);
786 dummy->Connect(
"IntMod()",
"KVItvFinderDialog",
this,
"UpdatePIDList()");
806 if (list.IsEmpty() || list.GetEntries() > 1) {
822 aa = aa_guessstimate;
848 if ((aa_guessstimate > (aa - 1)) &&
850 aa = aa_guessstimate;
868 if (pidpnt->
GetInterval() == left_interval) left_painter = pidpnt;
869 else if (pidpnt->
GetInterval() == right_interval) right_painter = pidpnt;
880 right_painter->set_left_interval(dummy);
885 dummy->Connect(
"IntMod()",
"KVItvFinderDialog",
this,
"UpdatePIDList()");
929 KVMultiGaussIsotopeFit::UnDrawGaussian(itvs->
GetZ(), itv->
GetA(),
fPad);
943 if (nSelected == 1) {
947 if (nSelected >= 1) {
948 for (
int ii = 0; ii < nSelected; ii++) {
958 else if (nSelected > 1) {
959 for (
int ii = 0; ii < nSelected; ii++) {
978 if (nSelected == 1) {
984 if (nSelected == 1) {
990 if (gfit) gfit->SetName(KVMultiGaussIsotopeFit::get_name_of_isotope_gaussian(itv->
GetZ(), itv->
GetA()));
995 TIter next_itv(&list);
997 while ((itv = (
interval*)next_itv())) {
1001 if (gfit) gfit->SetName(KVMultiGaussIsotopeFit::get_name_of_isotope_gaussian(itv->
GetZ(), itv->
GetA()));
1020 if (nSelected == 1) {
1025 if (nSelected == 1) {
1031 if (gfit) gfit->SetName(KVMultiGaussIsotopeFit::get_name_of_isotope_gaussian(itv->
GetZ(), itv->
GetA()));
1036 TIter next_itv(&list);
1038 while ((itv = (
interval*)next_itv())) {
1042 if (gfit) gfit->SetName(KVMultiGaussIsotopeFit::get_name_of_isotope_gaussian(itv->
GetZ(), itv->
GetA()));
1061 if (nSelected == 1) {
1146 std::vector<double> pidlist;
1149 while ((intvl = (
interval*)nxt_int())) {
1151 pidlist.push_back(intvl->
GetPID());
1157 bool fit_limited =
false;
1177 fitfunc.ReleaseCentroids();
1191 fitfunc.DrawFitWithGaussians(
"same");
1195 tmp->Execute(
"DeactivateIntervals",
"");
1198 int most_prob_A = 0;
1202 double delta_pid = 0.001;
1203 TList accepted_intervals;
1204 for (
double pid = fitfunc.GetPIDmin() ; pid <= fitfunc.GetPIDmax(); pid += delta_pid) {
1206 auto Amax = fitfunc.GetMostProbableA(pid, proba);
1209 if (proba > min_proba) {
1211 if (*Amax > most_prob_A) {
1215 most_prob_A = *Amax;
1217 while (intvl->
GetA() < most_prob_A) {
1220 accepted_intervals.
Add(intvl);
1226 most_prob_A = *Amax;
1228 while (intvl->
GetA() < most_prob_A) {
1231 accepted_intervals.
Add(intvl);
1237 else if (most_prob_A) {
1260 while ((intvl = (
interval*)nxt_int())) {
1262 while (vec_alist[ig - 1] < intvl->
GetA()) {
1265 intvl->
SetPID(fitfunc.GetCentroid(ig));
1266 remaining_gaussians.
Add(ig);
1267 remaining_alist.
Add(intvl->
GetA());
1291 fitparams.
SetValue(
"PIDmin", fitfunc.GetPIDmin());
1292 fitparams.
SetValue(
"PIDmax", fitfunc.GetPIDmax());
1293 fitparams.
SetValue(
"Bkg_cst", fitfunc.GetBackgroundConstant());
1294 fitparams.
SetValue(
"Bkg_slp", fitfunc.GetBackgroundSlope());
1295 fitparams.
SetValue(
"GausWid", fitfunc.GetGaussianWidth(0));
1296 fitparams.
SetValue(
"PIDvsA_a0", fitfunc.GetPIDvsAfit_a0());
1297 fitparams.
SetValue(
"PIDvsA_a1", fitfunc.GetPIDvsAfit_a1());
1298 fitparams.
SetValue(
"PIDvsA_a2", fitfunc.GetPIDvsAfit_a2());
1299 for (ig = 1; ig <= alist.
GetNValues(); ++ig) {
1300 fitparams.
SetValue(
Form(
"Norm_%d", ig), fitfunc.GetGaussianNorm(ig));
1317 bool cancel =
false;
1320 dialog->EnableDependingOnBool(
"PID min for fit",
"Limit range of fit");
1321 dialog->EnableDependingOnBool(
"PID max for fit",
"Limit range of fit");
1322 dialog->DisplayDialog();
1337 std::vector<int> alist;
1340 while ((intvl = (
interval*)nxt_int())) {
1341 alist.push_back(intvl->
GetA());
1345 fitfunc.UnDraw(
fPad);
1383 std::cout <<
"Mouse shortcuts : Wheel-click Fit intervals of current Z" << std::endl;
1384 std::cout <<
" Double-click Set/Unset log scale on Y axis" << std::endl;
1385 std::cout <<
" Shift-click Add an interval where clicked" << std::endl;
1407 #if ROOT_VERSION_CODE > ROOT_VERSION(5,99,01)
1420 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};
1421 int zref = zrefs[zz - 1];
1424 for (
int p = 0;
p < nfound;
p++) {
1425 if (std::abs(xpeaks[idx[
p]] - xpeaks[0]) < .0001) idref =
p;
1427 Info(
"FindPIDIntervals",
"Z=%d : idref = %d ", zz, idref);
1429 for (
int p = 0;
p < nfound;
p++) {
1431 double pid = xpeaks[idx[
p]];
1432 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
static void SetAutoAdd(Bool_t yes=kTRUE)
static Bool_t GetAutoAdd()
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
void SetOnlyZId(Bool_t=kTRUE) override
void RemoveIntervalSet(int zint)
Remove interval set for given Z from grid.
Base class for graphical cuts used in particle identification.
virtual Double_t GetPID() const
Full result of one attempted particle identification.
Double_t PID
= "real" Z if Zident==kTRUE and Aident==kFALSE, "real" A if Zident==Aident==kTRUE
void Clear(Option_t *opt="") override
Reset to initial values.
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);
bool negative_bkg_slope_changed
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)
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)
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 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 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
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)