-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcuts_manip.h
131 lines (105 loc) · 3.04 KB
/
cuts_manip.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/**********************************************
* THIS IS USEFUL WHEN USING like savecut( cutname, "tele1_deuter" )
* I do not compile, but may be possible
*
*/
#include <unistd.h> //sleep
#include "TXMLEngine.h"
#include "TString.h" // good for xml
#include "TCutG.h"
#include "TDirectory.h"
#include "TObject.h"
#include "TFile.h"
#include "TROOT.h"
// string
#include <stdio.h>
// FileExists:
#include <sys/stat.h>
//
#include "TTree.h"
#include "TH1.h"
#include "TPad.h"
/**********************************************************************************
*
* cuts
*
*
**********************************************************************************/
/*
* save the defined cut into cuts.root
*/
void savecut(TCutG *cut, const char* name){
TDirectory *dir=gDirectory;
TCutG *newcut=(TCutG*)cut->Clone( name ); // better to clone before (other dir...)
TFile *nf=new TFile("cuts.root", "UPDATE");
newcut->Write();
nf->ls();
nf->Close();
dir->cd();
// dir->ls();
}//savecut--------------
void loadcuts(){
gROOT->GetListOfSpecials()->ls();// ORIGINAL
TDirectory *dir=gDirectory;
TFile *nf=new TFile("cuts.root", "READ"); // WAS UPDATE, touched cuts.root..
// UNUSED int n=gDirectory->GetNkeys();
if (gDirectory->GetListOfKeys()){
TObject *o;
int max=gDirectory->GetList()->GetEntries();
max=gDirectory->GetListOfKeys()->GetEntries();
for (int iii=0 ; iii<max ; iii++ ){
TString sa1=gDirectory->GetListOfKeys()->At(iii)->GetName();
gDirectory->GetObject( sa1.Data() , o );
TString sa2=o->ClassName();
// important check - else it makes double entries...
if ((sa2.Index("TCutG")==0)&&(gROOT->GetListOfSpecials()->FindObject(o)==NULL)) {
// if ((sa2.Index("TCutG")==0)&&(gDirectory->FindObject(o)==NULL)) {
// gDirectory->Add( (TH1F*)o );
gROOT->GetListOfSpecials()->Add( (TCutG*)o );
}// TCutG
}
}//gDirectory->GetListOfKeys()
nf->ls();
nf->Close();
dir->cd();
gROOT->GetListOfSpecials()->ls();
}//savecut--------------
/* remove rename.............
* gDirectory->rmdir("cutt7d") !!!
* cutt7p->Clone("cutt7pV");cutt7pV->Write()
*/
void rmcut(const char* name, int version=0){
if (version==0){
printf("make a backup and use the version number ;1 ;2%s\n","");
return;
}
TDirectory *dir=gDirectory;
TFile *nf=new TFile("cuts.root", "UPDATE");
char name2[100];
sprintf( name2 , "%s;%d", name, version );
printf("deleting %s\n", name2 );
gDirectory->rmdir( name2 );
nf->ls();
nf->Close();
dir->cd();
}
void cpcut(const char* name, const char* newname){
TDirectory *dir=gDirectory;
TFile *nf=new TFile("cuts.root", "UPDATE");
TObject *o;
gDirectory->GetObject( name , o );
TCutG* cut=(TCutG*)o;
TCutG* newcut=(TCutG*)cut->Clone( newname );
newcut->Write();
// newcut->Print(); newcut->Draw("pawl");
nf->ls();
nf->Close();
dir->cd();
}
void lscuts(){
TDirectory *dir=gDirectory;
TFile *nf=new TFile("cuts.root", "");
nf->ls();
nf->Close();
dir->cd();
}