4 #include "KVItvFinderDialog.h"
12 #include "KVTestIDGridDialog.h"
13 #include "KVIdentificationResult.h"
14 #include "KVNameValueListGUI.h"
15 #include <KVMultiGaussIsotopeFit.h>
27 {
"Limit range of fit",
false},
28 {
"PID min for fit", 0.},
29 {
"PID max for fit", 10.},
30 {
"Minimum probability [%]", 50.},
31 {
"Minimum #sigma", 1.e-2},
32 {
"Maximum #sigma", 5.e-2}
46 std::unique_ptr<KVPIDIntervalPainter> _p(
p);
47 auto pleft =
p->get_left_interval();
48 auto pright =
p->get_right_interval();
49 if (pleft) pleft->set_right_interval(pright);
50 if (pright) pright->set_left_interval(pleft);
70 gROOT->ProcessLine(
Form(
"KVItvFinderDialog* _dummy_itv=(KVItvFinderDialog*)%p",
this));
75 fMain->
Connect(
"CloseWindow()",
"KVItvFinderDialog",
this,
"DoClose()");
89 delete fRootEmbeddedCanvas615->
GetCanvas();
91 fCanvas->
AddExec(
"toto",
"if(_dummy_itv)_dummy_itv->HandleKey();");
105 const char* xpms[] = {
115 "bld_colorselect.png",
121 const char* tips[] = {
122 "Save intervals in current grid",
124 "Create a new interval set",
125 "Create a new interval",
126 "Update interval lists",
127 "Remove selected intervals",
128 "Multigauss fit to isotopes in interval set",
129 "Set parameters for fit",
130 "Remove fit from selected interval set",
131 "Test identification",
132 "Set log scale on y axis",
133 "Unzoom the histogram",
151 const char* method[] = {
159 "SetFitParameters()",
177 bb->
Connect(
"Clicked()",
"KVItvFinderDialog",
this, method[i]);
205 const char* xpms[] = {
210 const char* tips[] = {
220 const char* method[] = {
236 bb->
Connect(
"Clicked()",
"KVItvFinderDialog",
this, method[i]);
273 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};
274 for (
int ii = 0; ii < 30; ii++)
fNpeaks[ii] = tmp[ii];
292 Int_t nSelected = list->GetSize();
293 if (nSelected == 1) {
317 if (!painter)
Info(
"SelectionITVChanged",
"%d %d not found...", zz, aa);
331 Int_t nSelected = list->GetSize();
332 if (nSelected == 1) {
364 tmp->Execute(
"SetDisplayLabel",
"1");
368 if (!
fPad->
GetPrimitive(KVMultiGaussIsotopeFit::get_name_of_multifit(zz))) {
373 fitparams.
Set(massfit);
375 fitfunc.DrawFitWithGaussians(
"same");
377 tmp->
Execute(
"DeactivateIntervals",
"");
421 dummy->Connect(
"IntMod()",
"KVItvFinderDialog",
this,
"UpdatePIDList()");
440 std::vector<int> alist;
441 for (
int ii = 0; ii < itvs->
GetNPID(); ii++) {
445 alist.push_back(itv->
GetA());
451 fitfunc.UnDraw(
fPad);
453 KVMultiGaussIsotopeFit::UnDrawAnyGaussian(itvs->
GetZ(),
fPad);
487 auto available_cpu = WITH_MULTICORE_CPU;
490 std::vector<std::thread> jobs;
499 std::cout <<
"Will run " << available_cpu <<
" threads, each for " << xbins_per_cpu <<
" bins in X" << std::endl;
501 int nthreads = available_cpu;
503 std::cout <<
"Histo linearization using " << nthreads <<
" threads..." << std::endl;
505 for (
int job = 0; job < available_cpu; ++job) {
506 auto imin = 1 + job * xbins_per_cpu;
507 auto imax = (job + 1) * xbins_per_cpu;
512 grid_copy->Initialize();
513 grid_copies.
Add(grid_copy);
516 jobs.push_back(std::thread([ =, &nthreads]() {
520 bool no_mass_id_zone_defined = (grid_copy->GetInfos()->FindObject(
"MassID") ==
nullptr);
522 for (
int i = imin; i <= imax; ++i) {
525 if (poids == 0)
continue;
532 if (x0 < 4)
continue;
536 Double_t weight = (kmax == 20 ? poids / 20. : 1.);
537 for (
int k = 0; k < kmax; k++) {
540 if (grid_copy->IsIdentifiable(
x,
y)) {
542 grid_copy->KVIDZAGrid::Identify(
x,
y, &idr);
543 if (no_mass_id_zone_defined || idr.
HasFlag(grid_copy->GetName(),
"MassID")) {
552 std::cout <<
"...remaining threads: " << nthreads << std::endl;
555 for (
auto& j : jobs) {
556 if (j.joinable()) j.join();
585 if (!list->GetSize()) {
590 for (
int ii = 0; ii < list->GetSize(); ii++) {
619 "KVIDGridEditor::SaveCurrentGrid",
Form(
"Do you wat to save the grid here : %s", fn.
Data()),
629 const char* filetypes[] = {
630 "ID Grid files",
"*.dat",
641 if (!filenam.
Contains(
'.')) filenam +=
".dat";
669 if (!itvs->
GetNPID())
continue;
677 if (!itvs->
GetNPID())
continue;
697 if (!list->GetSize() || list->GetSize() > 1) {
707 double pid = mm->GetX();
719 aa = aa_guessstimate;
745 if ((aa_guessstimate > (aa - 1)) &&
747 aa = aa_guessstimate;
765 if (pidpnt->
GetInterval() == left_interval) left_painter = pidpnt;
766 else if (pidpnt->
GetInterval() == right_interval) right_painter = pidpnt;
777 right_painter->set_left_interval(dummy);
782 dummy->Connect(
"IntMod()",
"KVItvFinderDialog",
this,
"UpdatePIDList()");
802 if (!list->GetSize() || list->GetSize() > 1) {
818 aa = aa_guessstimate;
844 if ((aa_guessstimate > (aa - 1)) &&
846 aa = aa_guessstimate;
864 if (pidpnt->
GetInterval() == left_interval) left_painter = pidpnt;
865 else if (pidpnt->
GetInterval() == right_interval) right_painter = pidpnt;
876 right_painter->set_left_interval(dummy);
881 dummy->Connect(
"IntMod()",
"KVItvFinderDialog",
this,
"UpdatePIDList()");
919 KVMultiGaussIsotopeFit::UnDrawGaussian(itvs->
GetZ(), itv->
GetA(),
fPad);
930 Int_t nSelected = list->GetSize();
933 if (nSelected == 1) {
936 nSelected = list->GetSize();
937 if (nSelected >= 1) {
938 for (
int ii = 0; ii < nSelected; ii++) {
948 else if (nSelected > 1) {
949 for (
int ii = 0; ii < nSelected; ii++) {
963 Int_t nSelected = list->GetSize();
966 if (nSelected == 1) {
970 nSelected = list->GetSize();
972 if (nSelected == 1) {
978 if (gfit) gfit->SetName(KVMultiGaussIsotopeFit::get_name_of_isotope_gaussian(itv->
GetZ(), itv->
GetA()));
983 TIter next_itv(list.get());
985 while ((itv = (
interval*)next_itv())) {
989 if (gfit) gfit->SetName(KVMultiGaussIsotopeFit::get_name_of_isotope_gaussian(itv->
GetZ(), itv->
GetA()));
1005 Int_t nSelected = list->GetSize();
1008 if (nSelected == 1) {
1011 nSelected = list->GetSize();
1013 if (nSelected == 1) {
1019 if (gfit) gfit->SetName(KVMultiGaussIsotopeFit::get_name_of_isotope_gaussian(itv->
GetZ(), itv->
GetA()));
1024 TIter next_itv(list.get());
1026 while ((itv = (
interval*)next_itv())) {
1030 if (gfit) gfit->SetName(KVMultiGaussIsotopeFit::get_name_of_isotope_gaussian(itv->
GetZ(), itv->
GetA()));
1047 Int_t nSelected = list->GetSize();
1049 if (nSelected == 1) {
1134 std::vector<double> pidlist;
1137 while ((intvl = (
interval*)nxt_int())) {
1139 pidlist.push_back(intvl->
GetPID());
1160 fitfunc.ReleaseCentroids();
1170 fitfunc.DrawFitWithGaussians(
"same");
1174 tmp->Execute(
"DeactivateIntervals",
"");
1177 int most_prob_A = 0;
1181 double delta_pid = 0.001;
1182 TList accepted_intervals;
1183 for (
double pid = fitfunc.GetPIDmin() ; pid <= fitfunc.GetPIDmax(); pid += delta_pid) {
1185 auto Amax = fitfunc.GetMostProbableA(pid, proba);
1186 if (proba > min_proba) {
1188 if (Amax > most_prob_A) {
1194 while (intvl->
GetA() < most_prob_A) {
1197 accepted_intervals.
Add(intvl);
1205 while (intvl->
GetA() < most_prob_A) {
1208 accepted_intervals.
Add(intvl);
1214 else if (most_prob_A) {
1237 while ((intvl = (
interval*)nxt_int())) {
1239 while (vec_alist[ig - 1] < intvl->
GetA()) {
1242 intvl->
SetPID(fitfunc.GetCentroid(ig));
1243 remaining_gaussians.
Add(ig);
1244 remaining_alist.
Add(intvl->
GetA());
1268 fitparams.
SetValue(
"PIDmin", fitfunc.GetPIDmin());
1269 fitparams.
SetValue(
"PIDmax", fitfunc.GetPIDmax());
1270 fitparams.
SetValue(
"Bkg_cst", fitfunc.GetBackgroundConstant());
1271 fitparams.
SetValue(
"Bkg_slp", fitfunc.GetBackgroundSlope());
1272 fitparams.
SetValue(
"GausWid", fitfunc.GetGaussianWidth(0));
1273 fitparams.
SetValue(
"PIDvsA_a0", fitfunc.GetPIDvsAfit_a0());
1274 fitparams.
SetValue(
"PIDvsA_a1", fitfunc.GetPIDvsAfit_a1());
1275 fitparams.
SetValue(
"PIDvsA_a2", fitfunc.GetPIDvsAfit_a2());
1276 for (ig = 1; ig <= alist.
GetNValues(); ++ig) {
1277 fitparams.
SetValue(
Form(
"Norm_%d", ig), fitfunc.GetGaussianNorm(ig));
1292 bool cancel =
false;
1294 dialog->EnableDependingOnBool(
"PID min for fit",
"Limit range of fit");
1295 dialog->EnableDependingOnBool(
"PID max for fit",
"Limit range of fit");
1296 dialog->DisplayDialog();
1310 std::vector<int> alist;
1313 while ((intvl = (
interval*)nxt_int())) {
1314 alist.push_back(intvl->
GetA());
1318 fitfunc.UnDraw(
fPad);
1356 std::cout <<
"Mouse shortcuts : Wheel-click Fit intervals of current Z" << std::endl;
1357 std::cout <<
" Double-click Set/Unset log scale on Y axis" << std::endl;
1358 std::cout <<
" Shift-click Add an interval where clicked" << std::endl;
1380 #if ROOT_VERSION_CODE > ROOT_VERSION(5,99,01)
1393 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};
1394 int zref = zrefs[zz - 1];
1397 for (
int p = 0;
p < nfound;
p++) {
1398 if (
abs(xpeaks[idx[
p]] - xpeaks[0]) < .0001) idref =
p;
1400 Info(
"FindPIDIntervals",
"Z=%d : idref = %d ", zz, idref);
1402 for (
int p = 0;
p < nfound;
p++) {
1404 double pid = xpeaks[idx[
p]];
1405 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.
void Initialize() override
interval_set * GetIntervalSet(int zint) const
void SetOnlyZId(Bool_t=kTRUE) override
KVList * GetIntervalSets()
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);
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
TList * GetSelectedObjects() 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
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)