_ROOT Version: 6.17/01
_Platform: linuxx8664gcc
_Compiler: gcc version 8.3.1 20190223
Hello,
I have a file (gg_all_4k_100ns.root) which contains 2D-histograms (his2D_clean etc). I take, say Y-projections/slices from one of the histograms. This gives me several spectra with name starting with “pY”. Now, I want to write ONLY these spectra to a new file. Can you please guide me on how to achieve this.
Please note that - I DO NOT want my original file to be modified!
Here is what I have been doing:
root [0] .L can2root_utils_cc.so
root [1] loadF("gg_all_4k_100ns.root");
root [2] .ls
TFile** gg_all_4k_100ns.root
TFile* gg_all_4k_100ns.root
KEY: TH2F his2D;1 gamma-gamma matrix
KEY: TH2F his2D_rand;1 Random gamma-gamma matrix
KEY: TH2F his2D_sub_rand;1 his2D minus his2D_rand
KEY: TH2F his2D_2Dbgsub;1 2D background subtracted his2D
KEY: TH2F his2D_rand_2Dbgsub;1 2D background subtracted his2D_rand
KEY: TH2F his2D_sub_rand_2Dbgsub;1 2D background subtracted his2D_sub_rand
KEY: TH2F his2D_clean;1 2Dbg and 2Drand_GG subtracted his2D
root [3] setGateX("his2D_clean",528);
Gate on 528keV. X-Axis limits are 1053 : 1061
Found 0 peaks
root [4] setGateX("his2D_clean",442);
Gate on 442keV. X-Axis limits are 881 : 889
Found 0 peaks
root [5] setGateX("his2D_clean",670);
Gate on 670keV. X-Axis limits are 1337 : 1345
Found 0 peaks
root [6] setGateX("his2D_clean",451);
Gate on 451keV. X-Axis limits are 899 : 907
Found 0 peaks
root [7] .ls
TFile** gg_all_4k_100ns.root
TFile* gg_all_4k_100ns.root
OBJ: TH2F his2D_clean 2Dbg and 2Drand_GG subtracted his2D : 0 at: 0x1a343f0
OBJ: TH1D pY_528_his2D_clean 2Dbg and 2Drand_GG subtracted his2D : 0 at: 0x1694810
OBJ: TH1D pY_442_his2D_clean 2Dbg and 2Drand_GG subtracted his2D : 0 at: 0x14fb650
OBJ: TH1D pY_670_his2D_clean 2Dbg and 2Drand_GG subtracted his2D : 0 at: 0x1b134d0
OBJ: TH1D pY_451_his2D_clean 2Dbg and 2Drand_GG subtracted his2D : 0 at: 0x1bdb220
KEY: TH2F his2D;1 gamma-gamma matrix
KEY: TH2F his2D_rand;1 Random gamma-gamma matrix
KEY: TH2F his2D_sub_rand;1 his2D minus his2D_rand
KEY: TH2F his2D_2Dbgsub;1 2D background subtracted his2D
KEY: TH2F his2D_rand_2Dbgsub;1 2D background subtracted his2D_rand
KEY: TH2F his2D_sub_rand_2Dbgsub;1 2D background subtracted his2D_sub_rand
KEY: TH2F his2D_clean;1 2Dbg and 2Drand_GG subtracted his2D
root [8] gSystem->Exec("rootcp gg_all_4k_100ns.root:pY* test.root");
WARNING: can't find pY* in gg_all_4k_100ns.root
I have defined different macros in my custom macro file : can2root_utils.cc
Thank you very much for your comment. I am still in a learning phase, and do not use ROOT quite often. So, I am sorry if you find my questions too naive.
The following method works. Is that what you suggest? But then it is too cumbersome, since I have to copy each and every histogram one-by-one manually. Is there more elegant way to achieve this?
root [1] loadF("gg_all_4k_100ns.root");
root [2] .ls
TFile** gg_all_4k_100ns.root
TFile* gg_all_4k_100ns.root
KEY: TH2F his2D;1 gamma-gamma matrix
KEY: TH2F his2D_rand;1 Random gamma-gamma matrix
KEY: TH2F his2D_sub_rand;1 his2D minus his2D_rand
KEY: TH2F his2D_2Dbgsub;1 2D background subtracted his2D
KEY: TH2F his2D_rand_2Dbgsub;1 2D background subtracted his2D_rand
KEY: TH2F his2D_sub_rand_2Dbgsub;1 2D background subtracted his2D_sub_rand
KEY: TH2F his2D_clean;1 2Dbg and 2Drand_GG subtracted his2D
root [3] setGateX("his2D_clean",528);
Gate on 528keV. X-Axis limits are 1053 : 1061
Found 0 peaks
root [4] setGateX("his2D_clean",442);
Gate on 442keV. X-Axis limits are 881 : 889
Found 0 peaks
root [5] setGateX("his2D_clean",670);
Gate on 670keV. X-Axis limits are 1337 : 1345
Found 0 peaks
root [6] setGateX("his2D_clean",451);
Gate on 451keV. X-Axis limits are 899 : 907
Found 0 peaks
root [7] openF("histos.root");
root [8] TH1D* pY_528 = (TH1D*)RFile->Get("pY_528_his2D_clean");
root [9] pY_528->Write();
root [10] TH1D* pY_442 = (TH1D*)RFile->Get("pY_442_his2D_clean");
root [11] pY_442->Write();
root [12] TH1D* pY_670 = (TH1D*)RFile->Get("pY_670_his2D_clean");
root [13] pY_670->Write();
root [14] TH1D* pY_451 = (TH1D*)RFile->Get("pY_451_his2D_clean");
root [15] pY_451->Write();
root [16] .ls
TFile** histos.root
TFile* histos.root
KEY: TH1D pY_528_his2D_clean;1 2Dbg and 2Drand_GG subtracted his2D
KEY: TH1D pY_442_his2D_clean;1 2Dbg and 2Drand_GG subtracted his2D
KEY: TH1D pY_670_his2D_clean;1 2Dbg and 2Drand_GG subtracted his2D
KEY: TH1D pY_451_his2D_clean;1 2Dbg and 2Drand_GG subtracted his2D
root [17] newf->Write();
root [18] .q
What if I have to copy several spectra starting with say pY_? Again putting them in a string names[] would be ugly. In that case I would like to use a wildcard i.e. to copy all the histograms which start with pY_.