Skip to content

Commit f7469b8

Browse files
Martin ValaMartin Vala
Martin Vala
authored and
Martin Vala
committed
Added CutSet framework with TCutSimple
1 parent 2512334 commit f7469b8

File tree

9 files changed

+199
-10
lines changed

9 files changed

+199
-10
lines changed

.cproject

+13-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<folderInfo id="cdt.managedbuild.toolchain.gnu.base.2027195071.1539894065" name="/" resourcePath="">
1919
<toolChain id="cdt.managedbuild.toolchain.gnu.base.610516042" name="cdt.managedbuild.toolchain.gnu.base" nonInternalBuilderId="cdt.managedbuild.target.gnu.builder.base" superClass="cdt.managedbuild.toolchain.gnu.base">
2020
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="cdt.managedbuild.target.gnu.platform.base.1096358058" name="Debug Platform" osList="linux,hpux,aix,qnx" superClass="cdt.managedbuild.target.gnu.platform.base"/>
21-
<builder buildPath="${workspace_loc:/root-utils}/" command="${workspace_loc:/root-utils}/scripts/make.sh" id="cdt.managedbuild.target.gnu.builder.base.136499274" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.base"/>
21+
<builder arguments="install" buildPath="${workspace_loc:/root-utils}/" command="${workspace_loc:/root-utils}/scripts/make.sh" id="cdt.managedbuild.target.gnu.builder.base.136499274" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.base"/>
2222
<tool id="cdt.managedbuild.tool.gnu.archiver.base.2123894816" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/>
2323
<tool id="cdt.managedbuild.tool.gnu.cpp.compiler.base.1686965596" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.base">
2424
<option id="gnu.cpp.compiler.option.include.paths.416754120" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" valueType="includePath">
@@ -62,4 +62,16 @@
6262
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileCPP"/>
6363
</scannerConfigBuildInfo>
6464
</storageModule>
65+
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets">
66+
<buildTargets>
67+
<target name="install" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
68+
<buildCommand>/home/mvala/git/root-utils/scripts/make.sh</buildCommand>
69+
<buildArguments/>
70+
<buildTarget>install</buildTarget>
71+
<stopOnError>true</stopOnError>
72+
<useDefaultCommand>true</useDefaultCommand>
73+
<runAllBuilders>true</runAllBuilders>
74+
</target>
75+
</buildTargets>
76+
</storageModule>
6577
</cproject>

CutSet/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
set(SRCS
33
TCutObj.cxx
44
TCutSet.cxx
5+
TCutSimple.cxx
56
)
67

78
set(INCLUDE_DIRECTORIES

CutSet/CutSetLinkDef.h

+2
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@
77
#pragma link C++ class TCutObj+;
88
#pragma link C++ class TCutSet+;
99

10+
#pragma link C++ class TCutSimple+;
11+
1012
#endif

CutSet/TCutObj.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010
#ifndef ROOT_TCutObj
1111
#define ROOT_TCutObj
1212

13-
#include "TCut.h"
13+
#include <TCut.h>
1414

1515
class TCutObj : public TCut {
1616

1717
public:
18-
TCutObj(const char *name = "Task", const char *title = "Task");
18+
TCutObj(const char *name = "cut", const char *title = "Cut Title");
1919
virtual ~TCutObj();
20+
21+
virtual Bool_t IsSelected(TObject*obj) { return kTRUE; }
2022
private:
2123
ClassDef(TCutObj, 1)
2224
};

CutSet/TCutSet.cxx

+76-4
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,22 @@
77
// Martin Vala ([email protected])
88
//
99

10+
#include <TFormula.h>
11+
#include <TObjArray.h>
12+
#include "TCutObj.h"
13+
1014
#include "TCutSet.h"
1115

1216
ClassImp(TCutSet)
1317

1418
//_________________________________________________________________________________________________
1519
TCutSet::TCutSet(const char *name, const char *title) :
16-
TCut(name, title)
17-
//
18-
// Std constructor
19-
//
20+
TCutObj(name, title),
21+
fCuts(0),
22+
fFormula(0)
23+
//
24+
// Std constructor
25+
//
2026
{
2127
}
2228

@@ -25,5 +31,71 @@ TCutSet::~TCutSet() {
2531
//
2632
// Destructor
2733
//
34+
delete fFormula;
35+
delete fCuts;
36+
}
37+
38+
//______________________________________________________________________________
39+
TCutSet& TCutSet::operator=(const TCutSet& rhs)
40+
{
41+
// Assignment.
42+
43+
if (this != &rhs) TCut::operator=(rhs);
44+
delete fFormula;
45+
fFormula = new TFormula(TString::Format("formula_%s",GetName()).Data(),GetTitle());
46+
return *this;
47+
}
48+
49+
//______________________________________________________________________________
50+
TCutSet& TCutSet::operator=(const char *rhs)
51+
{
52+
// Assignment.
53+
54+
fTitle = rhs;
55+
delete fFormula;
56+
fFormula = new TFormula(TString::Format("formula_%s",GetName()).Data(),GetTitle());
57+
return *this;
58+
}
59+
60+
//_________________________________________________________________________________________________
61+
void TCutSet::AddCut(TCutObj *cut) {
62+
63+
// check for non zero pointer of cut
64+
if (!cut) return;
65+
66+
// creates array of cuts when not done yet
67+
if (!fCuts) fCuts = new TObjArray();
68+
69+
// sets title to parameter id
70+
cut->SetTitle(TString::Format("[%d]",fCuts->GetEntries()).Data());
71+
72+
// adding cut
73+
fCuts->Add(cut);
2874
}
2975

76+
//_________________________________________________________________________________________________
77+
void TCutSet::AddCut(TCutObj &cut) {
78+
79+
// creates array of cuts when not done yet
80+
if (!fCuts) fCuts = new TObjArray();
81+
82+
// sets title to parameter id
83+
cut.SetTitle(TString::Format("[%d]",fCuts->GetEntries()).Data());
84+
85+
// adding cut
86+
fCuts->Add(&cut);
87+
}
88+
89+
//_________________________________________________________________________________________________
90+
Bool_t TCutSet::IsSelected(TObject*obj) {
91+
92+
TCutObj *cut;
93+
for (Int_t i=0;i<fCuts->GetEntries();i++) {
94+
cut = (TCutObj*)fCuts->At(i);
95+
Printf("%s=%d",cut->GetName(),cut->IsSelected(obj));
96+
fFormula->SetParameter(i,cut->IsSelected(obj));
97+
}
98+
99+
Printf("fFormula : %s",fFormula->GetExpFormula("p").Data());
100+
return fFormula->Eval(0);
101+
}

CutSet/TCutSet.h

+21-3
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,32 @@
1010
#ifndef ROOT_TCutSet
1111
#define ROOT_TCutSet
1212

13-
#include "TCut.h"
13+
#include "TCutObj.h"
1414

15-
class TCutSet : public TCut {
15+
class TFormula;
16+
class TObjArray;
17+
class TCutObj;
18+
class TCutSet : public TCutObj {
1619

1720
public:
18-
TCutSet(const char *name = "Task", const char *title = "Task");
21+
TCutSet(const char *name = "cutSet", const char *title = "Cut Set Title");
1922
virtual ~TCutSet();
23+
24+
TCutSet& operator=(const TCutSet& rhs);
25+
TCutSet& operator=(const char *rhs);
26+
27+
void AddCut(TCutObj*cut);
28+
void AddCut(TCutObj&cut);
29+
30+
virtual Bool_t IsSelected(TObject*obj);
31+
32+
TFormula *GetFormula() { return fFormula; }
33+
2034
private:
35+
36+
TObjArray *fCuts; // list of cuts
37+
TFormula *fFormula; // common formula
38+
2139
ClassDef(TCutSet, 1)
2240
};
2341

CutSet/TCutSimple.cxx

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//
2+
// Class TCutSimple
3+
//
4+
// TODO
5+
//
6+
// authors:
7+
// Martin Vala ([email protected])
8+
//
9+
10+
#include "TCutSimple.h"
11+
12+
ClassImp(TCutSimple)
13+
14+
//_________________________________________________________________________________________________
15+
TCutSimple::TCutSimple(const char *name, const char *title) :
16+
TCutObj(name, title)
17+
//
18+
// Std constructor
19+
//
20+
{
21+
}
22+
23+
//_________________________________________________________________________________________________
24+
Bool_t TCutSimple::IsSelected(TObject *obj) {
25+
26+
TNamed *namedObj = (TNamed*) obj;
27+
TString ret = namedObj->GetTitle();
28+
29+
if (ret.Contains("1")) return kTRUE;
30+
31+
return kFALSE;
32+
}
33+

CutSet/TCutSimple.h

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
// Class TCutSimple
3+
//
4+
// TODO
5+
//
6+
// authors:
7+
// Martin Vala ([email protected])
8+
//
9+
10+
#ifndef ROOT_TCutSimple
11+
#define ROOT_TCutSimple
12+
13+
#include "TCutObj.h"
14+
15+
class TCutSimple : public TCutObj {
16+
17+
public:
18+
TCutSimple(const char *name = "cut", const char *title = "Cut Title");
19+
20+
virtual Bool_t IsSelected(TObject*obj);
21+
22+
ClassDef(TCutSimple, 1)
23+
};
24+
25+
#endif

macros/TestCutSet.C

+24
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
11
void TestCutSet() {
22

3+
gSystem->Load("lib/libCutSet.so");
4+
5+
TCutSet cs("MyCutSet","");
6+
// TCutObj c1("c1","");
7+
TCutObj c2("c2","");
8+
9+
TCutSimple c1("c1","");
10+
// TCutSimple c2("c2","");
11+
12+
TNamed *mySimpleObj = new TNamed("myObj","My1");
13+
14+
// cs.AddCut(&c1);
15+
// cs.AddCut(&c2);
16+
cs.AddCut(c1);
17+
cs.AddCut(c2);
18+
19+
cs = c1&&c2;
20+
21+
cs.Print();
22+
23+
// TFormula *f = cs.GetFormula();
24+
Printf("MyFormula1 : %d",(Bool_t)cs.IsSelected(mySimpleObj));
25+
// Printf("MyFormula1 : %d",(Bool_t)cs.IsSelected(new TObject()));
26+
327
}

0 commit comments

Comments
 (0)