10 #include "KVIDGraph.h"
11 #include "TObjString.h"
12 #include "TObjArray.h"
18 #include "KVIDGridManager.h"
21 #include "TPluginManager.h"
24 #include "KVIdentificationResult.h"
35 cout <<
"The pad showing graph " << GetName() <<
" has been closed !" << endl;
38 fPad->Disconnect(
"Closed()",
this,
"ResetPad()");
39 if (fPad->GetCanvas()) fPad->GetCanvas()->Disconnect(
"Cleared(TVirtualPad*)",
this,
"ClearPad(TVirtualPad*)");
52 cout <<
"The pad showing graph " << GetName() <<
" has been cleared" << endl;
53 fPad->Disconnect(
"Closed()",
this,
"ResetPad()");
54 if (fPad->GetCanvas()) fPad->GetCanvas()->Disconnect(
"Cleared(TVirtualPad*)",
this,
"ClearPad(TVirtualPad*)");
72 fIdentifiers.SetCleanup();
74 fInfoZones.SetCleanup();
75 fXmin = fYmin = fXmax = fYmax = 0;
82 if (fAutoAddGridManager && gIDGridManager) gIDGridManager->
AddGrid(
this);
84 fLastSavedVersion = NULL;
119 TAttLine::Copy((TAttLine&)obj);
120 TAttFill::Copy((TAttFill&)obj);
121 TAttMarker::Copy((TAttMarker&)obj);
122 ((TCutG&)obj).SetVarX(GetVarX());
123 ((TCutG&)obj).SetVarY(GetVarY());
131 if (fLastScaleX != 1 || fLastScaleY != 1)
132 const_cast < KVIDGraph*
>(
this)->Scale(1. / fLastScaleX,
136 fCuts.Copy(grid.
fCuts);
142 for (
int i = 0; i < fPar.GetNpar(); i++) {
143 par = fPar.GetParameter(i);
144 TString parname(par->GetName());
145 if (!parname.Contains(
"ScaleFactor"))
149 if (fLastScaleX != 1 || fLastScaleY != 1) {
150 const_cast < KVIDGraph*
>(
this)->Scale(fLastScaleX, fLastScaleY);
318 TIter next(isotopes.get());
408 ofstream gridfile(filename);
469 gridfile <<
"# ASCII file generated by " << ClassName() <<
470 "::WriteToAsciiFile" << endl;
471 gridfile <<
"# ID Graph Name : " <<
GetName() << endl;
472 gridfile <<
"# This file can be read using " << ClassName() <<
473 "::ReadFromAsciiFile" << endl;
474 gridfile <<
"# " << endl;
475 gridfile <<
"++" << ClassName() << endl;
478 if (fName !=
"") gridfile <<
"<NAME> " << fName.Data() << endl;
480 gridfile <<
"<VARX> " << GetVarX() << endl;
481 gridfile <<
"<VARY> " << GetVarY() << endl;
487 gridfile <<
"<PARAMETER> " << par->GetName() <<
"=" << par->
GetString() << endl;
504 TIter next_OKline(&
fCuts);
518 gridfile <<
"!" << endl;
563 Info(
"RevertToLastSavedVersion",
"No saved version to revert to! (Sorry)");
566 Bool_t wasDrawn = kFALSE;
626 Int_t mass_formula = -1;
628 while (gridfile.good()) {
630 s.ReadLine(gridfile);
631 if (s.BeginsWith(
'!')) {
635 else if (s.BeginsWith(
"++")) {
638 s.Remove(TString::kBoth,
' ');
639 if (s != ClassName())
640 Warning(
"ReadFromAsciiFile(ofstream&)",
641 "Class name in file %s does not correspond to this class (%s)",
642 s.Data(), ClassName());
644 else if (s.BeginsWith(
"<NAME>")) {
647 s.Remove(TString::kBoth,
' ');
650 else if (s.BeginsWith(
"<VARX>")) {
653 s.Remove(TString::kBoth,
' ');
656 else if (s.BeginsWith(
"<VARY>")) {
659 s.Remove(TString::kBoth,
' ');
662 else if (s.BeginsWith(
"<PARAMETER>")) {
666 TObjArray* toks = s.Tokenize(
'=');
667 if (toks->GetEntries() > 1) {
669 ((TObjString*) toks->At(0))->GetString().
670 Strip(TString::kBoth);
671 KVString value(((TObjString*) toks->At(1))->GetString());
672 value.Remove(TString::kBoth,
' ');
673 if (name !=
"" && value !=
"") {
676 else if (value.IsDigit())
684 else if (s.BeginsWith(
"<LIST>")) {
687 TObjArray* toks = s.Tokenize(
'=');
688 if (toks->GetEntries() > 1) {
690 ((TObjString*) toks->At(0))->GetString().
691 Strip(TString::kBoth);
692 TString list(((TObjString*) toks->At(1))->GetString());
701 else if (s.BeginsWith(
"OnlyZId")) {
703 s.ReplaceAll(
"OnlyZId",
"");
704 s.Remove(TString::kBoth,
' ');
706 mass_formula = s.Atoi();
710 else if (s.BeginsWith(
'+')) {
715 TString lineclass = s;
717 s.ReadLine(gridfile);
719 TObjArray* toks = s.Tokenize(
':');
720 TString type = ((TObjString*) toks->At(0))->GetString();
723 if (toks->GetEntries() > 1) name = ((TObjString*) toks->At(1))->GetString();
726 Warning(
"ReadFromAsciiFile",
727 "In graph : %s\nIdentifier with no name. Identifier type = %s. Line number in graph = %d",
728 GetName(), type.Data(), line_no);
790 ifstream gridfile(filename);
792 if (gridfile.good()) {
796 Warning(
"ReadAsciiFile",
"Could not find file %s. Check filename.", filename);
812 TClass* clas = TClass::GetClass(id_class);
815 "%s is not a valid classname. No known class.", id_class);
818 if (!clas->InheritsFrom(KVIDentifier::Class())) {
820 "%s is not a valid class deriving from KVIDentifier",
846 else if (type ==
"OK" || type ==
"CUT")
AddCut(
id);
847 else if (type ==
"INFO")
AddInfo(
id);
868 else if (type ==
"OK" || type ==
"CUT")
AddCut(
id);
869 else if (type ==
"INFO")
AddInfo(
id);
913 if (!gPad->GetListOfPrimitives()->GetSize()) {
1051 cout << ClassName() <<
" : " <<
GetName() << endl;
1052 cout <<
"Title : " << GetTitle() << endl;
1056 TIter nextOK(&
fCuts);
1078 Double_t x, y, xmin, ymin, xmax, ymax;
1079 xmax = ymax = -999999;
1080 xmin = ymin = 999999;
1081 TIter nextOK(&
fCuts);
1083 for (
int i = 0; i < line->GetN(); i++) {
1084 line->GetPoint(i, x, y);
1085 xmin = (x < xmin ? x : xmin);
1086 xmax = (x > xmax ? x : xmax);
1087 ymin = (y < ymin ? y : ymin);
1088 ymax = (y > ymax ? y : ymax);
1093 for (
int i = 0; i < line->GetN(); i++) {
1094 line->GetPoint(i, x, y);
1095 xmin = (x < xmin ? x : xmin);
1096 xmax = (x > xmax ? x : xmax);
1097 ymin = (y < ymin ? y : ymin);
1098 ymax = (y > ymax ? y : ymax);
1150 if (TMath::Abs(sx) == 1 && TMath::Abs(sy) == 1)
1183 if (!
fPad && !gPad)
return;
1187 Warning(
"DrawAndAdd",
"Changed active pad to pad containing this graph");
1192 TString classname(Classname);
1220 KVIDGraph* g2, Int_t id2_min, Int_t id2_max)
1239 if (line->
GetID() >= id1_min && line->
GetID() <= id1_max)
1246 if (line->
GetID() >= id2_min && line->
GetID() <= id2_max)
1282 if (rejected_by) *rejected_by =
"";
1285 if (rejected_by) *rejected_by =
id->GetName();
1338 if (fName !=
"")
return fName;
1344 tel_list.
Begin(
",");
1409 if (version == -1) cout <<
"no file " +
fPattern +
"_v%d.grid" << endl;
1410 else cout <<
"no file " +
fPattern + Form(
"_v%d.grid", version) << endl;
1431 TString pbis =
fPattern, chemin =
"";
1432 TObjArray* tok = NULL;
1435 Int_t nb = tok->GetEntries();
1436 pbis = ((TObjString*)(*tok)[nb - 1])->GetString();
1438 for (Int_t ii = 0; ii < nb - 1; ii += 1) chemin += ((TObjString*)(*tok)[ii])->GetString();
1441 gROOT->ProcessLine(
".! ls " +
fPattern +
"_v*.grid >> " + chemin +
"listKVIDGraph_" + pbis);
1442 ifstream f_in(chemin +
"listKVIDGraph_" + pbis);
1445 while (f_in.good() && num != version) {
1446 line.ReadLine(f_in);
1447 if (line.Contains(
fPattern +
"_v") && line.Contains(
".grid")) {
1448 tok = line.Tokenize(
".");
1449 line = ((TObjString*)(*tok)[0])->GetString();
1450 line.ReplaceAll(
fPattern +
"_v",
"template");
1451 tok = line.Tokenize(
"template");
1452 num = ((TObjString*)(*tok)[0])->GetString().Atoi();
1453 if (num > temoin) temoin = num;
1457 gROOT->ProcessLine(
".! rm -f " + chemin +
"listKVIDGraph_" + pbis);
1459 if (version == -1)
return temoin;
1460 else if (temoin != version) {
1524 if (gIDGridManager) gIDGridManager->
Modified();
1592 TCutG::SetEditable(editable);
1616 static TString tel_list;
1622 return tel_list.Data();
1626 TObject*
id = next();
1627 if (
id) tel_list =
id->GetName();
1628 while ((
id = next())) tel_list += Form(
",%s", id->GetName());
1639 void KVIDGraph::Streamer(TBuffer& R__b)
1644 if (R__b.IsReading()) {
1645 R__b.ReadClassBuffer(KVIDGraph::Class(),
this);
1649 TIter nxt_cut(&
fCuts);
1650 while ((
id = (
KVIDentifier*)nxt_cut()))
id->fParent =
this;
1652 while ((
id = (
KVIDentifier*)nxt_info()))
id->fParent =
this;
1655 R__b.WriteClassBuffer(KVIDGraph::Class(),
this);
1670 void fill(
const char* name,
double x,
double y = 0.,
double w = 0.)
1674 if (w > 0)((TH2*)h)->Fill(x, y, w);
1740 Int_t tot_events = (Int_t) data->GetSum();
1741 Int_t events_read = 0;
1742 Int_t percent = 0, cumul = 0;
1746 for (
int i = 1; i <= data->GetNbinsX(); ++i) {
1747 for (
int j = 1; j <= data->GetNbinsY(); j++) {
1749 Stat_t poids = data->GetBinContent(i, j);
1753 Axis_t x0 = data->GetXaxis()->GetBinCenter(i);
1754 Axis_t y0 = data->GetYaxis()->GetBinCenter(j);
1755 Axis_t wx = data->GetXaxis()->GetBinWidth(i);
1756 Axis_t wy = data->GetYaxis()->GetBinWidth(j);
1761 Int_t kmax = (Int_t) TMath::Min(20., poids);
1762 Double_t weight = (kmax == 20 ? poids / 20. : 1.);
1763 for (
int k = 0; k < kmax; k++) {
1764 double x = gRandom->Uniform(x0 - .5 * wx, x0 + .5 * wx);
1765 double y = gRandom->Uniform(y0 - .5 * wy, y0 + .5 * wy);
1770 Float_t PID = idr.
PID;
1771 if (idr.
Aident) PID = (idr.
Z + 0.1 * (idr.
PID - 2. * idr.
Z));
1772 Float_t RealA, RealZ;
1773 RealA = (idr.
Aident ? idr.
PID : (Float_t)idr.
A);
1774 RealZ = (idr.
Aident ? (Float_t)idr.
Z : idr.
PID);
1775 idresults.
fill(
"ID_REAL", PID, weight);
1776 idresults.
fill(
"ID_REAL_VS_DE", y, PID, weight);
1777 idresults.
fill(
"ID_REAL_VS_ERES", x, PID, weight);
1779 idresults.
fill(
"Z_A_REAL", RealA - RealZ, gRandom->Gaus(RealZ, 0.15), weight);
1780 idresults.
fill(
"ZADIST_AIDENT", idr.
Z, idr.
A, weight);
1781 idresults.
fill(
"ID_REAL_AIDENT", PID, weight);
1782 idresults.
fill(
"ID_REAL_VS_DE_AIDENT", y, PID, weight);
1783 idresults.
fill(
"ID_REAL_VS_ERES_AIDENT", x, PID, weight);
1786 idresults.
fill(
"ID_REAL_ZIDENT", PID, weight);
1787 idresults.
fill(
"ID_REAL_VS_DE_ZIDENT", y, PID, weight);
1788 idresults.
fill(
"ID_REAL_VS_ERES_ZIDENT", x, PID, weight);
1793 events_read += (Int_t) poids;
1794 percent = (1. * events_read / tot_events) * 100.;
1795 if (percent > cumul) {
1797 gSystem->ProcessEvents();
Base class for KaliVeda framework.
static TPluginHandler * LoadPlugin(const Char_t *base, const Char_t *uri="0")
Extended version of ROOT THashList.
Base class for particle identification in a 2D map.
KVNumberList fRunList
runs for which grid is valid
void Add(TString, KVIDentifier *)
Double_t GetYScaleFactor()
TString fDyName
dynamically generated name
virtual void ReadAsciiFile_WP(Int_t version=-1)
lecture des grilles avec version suivant un modele de fichier
KVIDGraph * fLastSavedVersion
copy of last save version of grid, used for 'undo'
Int_t GetNumberOfCuts() const
void ExtendBeginningAllIdentLines(Double_t, Option_t *="")
KVNameValueList fPar
parameters associated to grid
virtual void SetVarX(const char *v)
void ReadAsciiFile(const Char_t *filename)
void RemoveIdentifier(KVIDentifier *)
Remove and destroy identifier.
Double_t GetXScaleFactor()
virtual void TestIdentification(TH2F *data, KVHashList &histos, KVNameValueList &histo_names)
KVList fCuts
cuts used to define area in which identification is possible
KVList fIdentifiers
list of identification objects
Double_t fLastScaleY
last applied scaling factor on Y
Double_t fLastScaleX
last applied scaling factor on X
void UpdateLastSavedVersion()
update last saved version. mkae copy of current state of graph.
virtual void SetName(const char *name)
void Scale(Double_t sx=-1, Double_t sy=-1)
Called by SetX/YScaleFactor methods to rescale every point of every object in the grid.
void ExtendEndAllIdentLines(Double_t, Option_t *="")
void RemoveInfo(KVIDentifier *)
Remove and destroy cut.
virtual void WriteToAsciiFile(std::ofstream &gridfile)
static void SetAutoAdd(Bool_t yes=kTRUE)
virtual void AddInfo(KVIDentifier *info)
void Increment(Float_t x)
void Draw(Option_t *opt="")
void AddIDTelescope(KVBase *t)
Int_t GetNumberOfIdentifiers() const
virtual void Copy(TObject &) const
Copy this to 'obj'.
virtual void ReadIdentifierFromAsciiFile(TString &name, TString &type, TString &cl, std::ifstream &gridfile)
Read in new identifier object from file.
Int_t GetMassFormula() const
void RevertToLastSavedVersion()
virtual void ReadFromAsciiFile(std::ifstream &gridfile)
void ClearPad(TVirtualPad *)
void WriteParameterListOfIDTelescopes()
virtual void Identify(Double_t, Double_t, KVIdentificationResult *) const =0
TString fPattern
pattern of filenames used to write or read grid
void SetLineColor(Color_t lcolor)
void Print(Option_t *opt="") const
Print out all objects in graph.
virtual void WriteAsciiFile_WP(Int_t version=-1)
KVIDentifier * GetIdentifier(Int_t Z, Int_t A) const
virtual Bool_t IsIdentifiable(Double_t, Double_t, TString *rejected_by=nullptr) const
void FindAxisLimits()
Calculate X/Y min/max of all objects in graph.
virtual void SetVarY(const char *v)
static KVIDGraph * AddGraphs(KVIDGraph *g1, Int_t id1_min, Int_t id1_max, KVIDGraph *g2, Int_t id2_min, Int_t id2_max)
virtual void DrawAndAdd(const Char_t *type="ID", const Char_t *classname="KVIDentifier")
virtual void AddCut(KVIDentifier *cut)
void SetMassFormula(Int_t)
const Char_t * GetName() const
TList fTelescopes
ID telescopes for which grid is valid.
static Bool_t fAutoAddGridManager
if =kTRUE, grids are automatically added to ID grid manager on creation (default)
void WriteAsciiFile(const Char_t *filename)
Open, write and close ascii file containing this grid.
virtual KVIDentifier * New(const Char_t *)
Create new object of class "id_class" which derives from KVIDentifier.
virtual void BackwardsCompatibilityFix()
void AddIDTelescopes(const TList *)
Associate this graph with all ID telescopes in list.
virtual void AddIdentifier(KVIDentifier *id)
virtual void SetInfos(Double_t, Double_t, KVIdentificationResult *) const
loop over KVIDGraph::fInfoZones to set flags in KVIdentificationResult
static KVIDGraph * MakeIDGraph(const Char_t *)
const Char_t * GetNamesOfIDTelescopes() const
void SetXScaleFactor(Double_t=0)
Int_t GetNumberOfInfos() const
TVirtualPad * fPad
pad in which graph is drawn
virtual Bool_t AcceptIDForTest(const KVIdentificationResult &idr)
Axis_t fYmax
min/max Y coordinates of graph
void SetRuns(const KVNumberList &nl)
Set list of runs for which grid is valid.
virtual Int_t CheckVersion(Int_t version)
virtual void SetEditable(Bool_t editable=kTRUE)
void SetYScaleFactor(Double_t=0)
virtual void Initialize()=0
Axis_t fXmax
min/max X coordinates of graph
Bool_t fOnlyZId
set to kTRUE when only to be used to give Z identification of nuclei, no mass info
virtual void Clear(Option_t *opt="")
Int_t fMassFormula
OPTION={GetMethod="GetMassFormula";SetMethod="SetMassFormula";Items=(0="Beta-stability",...
void SetPattern(TString pattern)
void RemoveCut(KVIDentifier *)
Remove and destroy cut.
KVList fInfoZones
contours/lines used to add info to particles (ex: punch-through)
virtual void SetOnlyZId(Bool_t yes=kTRUE)
const KVList * GetIdentifiers() const
void AddGrid(KVIDGraph *)
Add a grid to the collection. It will be deleted by the manager.
Base class for graphical cuts used in particle identification.
virtual void SetName(const char *name)
KVIDGraph * fParent
parent identification map or grid
virtual Int_t GetA() const
virtual void WaitForPrimitive()
virtual Int_t GetZ() const
virtual Int_t GetID() const
virtual void WriteAsciiFile(std::ofstream &, const Char_t *name_prefix="")
virtual void ReadAsciiFile(std::ifstream &)
virtual Bool_t TestPoint(Double_t, Double_t)
Full result of one attempted particle identification.
void AddFlag(std::string grid_name, TString flag)
void Clear(Option_t *opt="")
Reset to initial values.
Bool_t Aident
= kTRUE if A of particle established
Double_t PID
= "real" Z if Zident==kTRUE and Aident==kFALSE, "real" A if Zident==Aident==kTRUE
Int_t A
A of particle found (if Aident==kTRUE)
Int_t Z
Z of particle found (if Zident==kTRUE)
Bool_t Zident
=kTRUE if Z of particle established
Handles lists of named parameters with different types, a list of KVNamedParameter objects.
virtual void Print(Option_t *opt="") const
KVNamedParameter * GetParameter(Int_t idx) const
return the parameter object with index idx
Int_t GetIntValue(const Char_t *name) const
Double_t GetDoubleValue(const Char_t *name) const
void SetValue(const Char_t *name, value_type value)
void RemoveParameter(const Char_t *name)
virtual void Clear(Option_t *opt="")
Int_t GetNpar() const
return the number of stored parameters
const Char_t * GetStringValue(const Char_t *name) const
Bool_t HasParameter(const Char_t *name) const
A generic named parameter storing values of different types.
const Char_t * GetString() const
Strings used to represent a set of ranges of values.
void SetMinMax(Int_t min, Int_t max, Int_t pas=1)
Set list with all values from 'min' to 'max'.
const Char_t * AsString(Int_t maxchars=0) const
KVSeqCollection * GetSubListWithMethod(const Char_t *retvalue, const Char_t *method) const
T * get_object(const TString &name) const
virtual void Execute(const char *method, const char *params, Int_t *error=0)
virtual TObject * Remove(TObject *obj)
Remove object from list.
virtual void Delete(Option_t *option="")
virtual void RecursiveRemove(TObject *obj)
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
void Begin(TString delim) const
KVString Next(Bool_t strip_whitespace=kFALSE) const
void fill(const char *name, double x, double y=0., double w=0.)
KVNameValueList & histo_names
kvidgraph_idresult_filler(KVHashList &h, KVNameValueList &n)