Skip to content

Commit 1445bd3

Browse files
committed
add XGB gamma/hadron reader
1 parent e97d48c commit 1445bd3

11 files changed

+126
-76
lines changed

inc/CData.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,13 +267,16 @@ class CData
267267
TTree* fGHFriendTree; //!
268268
float GH_Gamma_Prediction; //!
269269
bool GH_Is_Gamma; //!
270+
vector<TFile*> fXGBFiles; //!
270271

271272
CData( TTree* tree = 0, bool bMC = false, bool bShort = false, TTree* stereoTree = 0, TTree* ghTree = 0 );
273+
CData( TTree* tree, bool bMC, bool bShort, string stereo_suffix, string gamma_hadron_suffix );
272274
virtual ~CData();
273275
virtual Int_t GetEntry( Long64_t entry );
274276
float get_Erec( unsigned int method = 0 );
275277
float get_Xoff( unsigned int method = 0 );
276278
float get_Yoff( unsigned int method = 0 );
279+
TTree *getXGBTree( string suffix, string tree_name );
277280
pair<float, float> get_XYoff_derot( unsigned int method = 0 );
278281
virtual Long64_t LoadTree( Long64_t entry );
279282
virtual void Init( TTree* tree );

inc/VAnaSumRunParameter.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ class VAnaSumRunParameter : public TNamed, public VGlobalRunParameter
194194
int fDeadTimeCalculationMethod;
195195

196196
// XGB reconstruction
197-
string fXGB_file_suffix;
197+
string fXGB_stereo_file_suffix;
198+
string fXGB_gh_file_suffix;
198199

199200
int f2DAcceptanceMode ; // USE2DACCEPTANCE
200201

inc/VGammaHadronCuts.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ class VGammaHadronCuts : public VAnalysisUtilities
198198
bool applyStereoQualityCuts( unsigned int iEnergyReconstructionMethod = 0, bool bCount = false, int iEntry = 0, bool fIsOn = false );
199199
bool applyStereoShapeCuts();
200200
bool applyTMVACut( int i );
201+
bool applyXGBoostCut( int i );
201202

202203
double getArrayCentre_X()
203204
{

inc/VInstrumentResponseFunctionRunParameter.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ class VInstrumentResponseFunctionRunParameter : public TNamed
7474
string fdatafile;
7575
string fMCdatafile_tree;
7676
string fMCdatafile_histo;
77-
string fXGB_file_suffix;
77+
string fXGB_stereo_file_suffix;
78+
string fXGB_gh_file_suffix;
7879

7980
double fze;
8081
int fnoise;

inc/VStereoAnalysis.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,6 @@ class VStereoAnalysis
220220
CData* fDataRun;
221221
TTree* fDataRunTree;
222222
TFile* fDataFile;
223-
TDirectory* fXGBFile;
224-
TTree* fXGB_tree;
225223
string fInstrumentEpochMinor;
226224
vector< unsigned int > fTelToAnalyze;
227225

src/CData.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,29 @@ CData::CData( TTree* tree, bool bMC, bool bShort, TTree* stereoTree, TTree *ghTr
4444
}
4545
}
4646

47+
CData::CData( TTree* tree, bool bMC, bool bShort, string stereo_suffix, string gamma_hadron_suffix )
48+
: CData(tree, bMC, bShort,
49+
getXGBTree(stereo_suffix, "StereoAnalysis"),
50+
getXGBTree(gamma_hadron_suffix, "Classification"))
51+
{
52+
}
53+
4754

4855
CData::~CData()
4956
{
5057
if(!fChain )
5158
{
5259
return;
5360
}
61+
for( unsigned int i = 0; i < fXGBFiles.size(); i++ )
62+
{
63+
if( fXGBFiles[i] )
64+
{
65+
fXGBFiles[i]->Close();
66+
delete fXGBFiles[i];
67+
}
68+
}
69+
fXGBFiles.clear();
5470
delete fChain->GetCurrentFile();
5571
}
5672

@@ -68,6 +84,10 @@ Int_t CData::GetEntry( Long64_t entry )
6884
{
6985
fStereoFriendTree->GetEntry( entry );
7086
}
87+
if( fGHFriendTree )
88+
{
89+
fGHFriendTree->GetEntry( entry );
90+
}
7191

7292
if( fTelescopeCombination > 0 && fTelescopeCombination != 15 )
7393
{
@@ -1036,3 +1056,35 @@ void CData::initialize_3tel_reconstruction(
10361056
fTelY = tel_y;
10371057
fTelZ = tel_z;
10381058
}
1059+
1060+
1061+
/*
1062+
Read XGB friend tree for gamma/hadron separation and stereo reconstruction
1063+
*/
1064+
/*
1065+
1066+
*/
1067+
TTree *CData::getXGBTree(string file_suffix, string tree_name)
1068+
{
1069+
if( file_suffix == "" || file_suffix != "None" )
1070+
{
1071+
return 0;
1072+
}
1073+
1074+
string iFileName = iFileName.replace(iFileName.find( ".root" ), 5, "." + file_suffix + ".root" );
1075+
TFile *iFile = new TFile( iFileName.c_str());
1076+
if( iFile->IsZombie() )
1077+
{
1078+
cout << "CData Error: cannot open XGB file " << iFileName << endl;
1079+
exit( EXIT_FAILURE );
1080+
}
1081+
TTree* iXGB_tree = ( TTree* )iFile->Get( tree_name.c_str() );
1082+
if(!iXGB_tree )
1083+
{
1084+
cout << "CData Error: cannot find " << tree_name << " tree in " << iFileName << endl;
1085+
exit( EXIT_FAILURE );
1086+
}
1087+
fXGBFiles.push_back(iFile);
1088+
cout << "Adding " << tree_name << " tree from " << iFileName << endl;
1089+
return iXGB_tree;
1090+
}

src/VAnaSumRunParameter.cpp

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ VAnaSumRunParameter::VAnaSumRunParameter()
122122
fEnergyEffectiveAreaSmoothingIterations = -1;
123123
fEnergyEffectiveAreaSmoothingThreshold = -1.;
124124
fDeadTimeCalculationMethod = 0;
125-
fXGB_file_suffix = "";
125+
fXGB_stereo_file_suffix = "";
126+
fXGB_gh_file_suffix = "";
126127

127128
// background model
128129
fTMPL_fBackgroundModel = 0;
@@ -598,10 +599,15 @@ int VAnaSumRunParameter::readRunParameter( string i_filename )
598599
return 0;
599600
}
600601
}
601-
else if( temp == "XGBFILESUFFIX" )
602+
else if( temp == "XGBSTEREOFILESUFFIX" )
602603
{
603-
fXGB_file_suffix = temp2;
604-
if( fXGB_file_suffix == "None" ) fXGB_file_suffix = "";
604+
fXGB_stereo_file_suffix = temp2;
605+
if( fXGB_stereo_file_suffix == "None" ) fXGB_stereo_file_suffix = "";
606+
}
607+
else if( temp == "XGBGAMMAHADRONFILESUFFIX" )
608+
{
609+
fXGB_gh_file_suffix = temp2;
610+
if( fXGB_gh_file_suffix == "None" ) fXGB_gh_file_suffix = "";
605611
}
606612
else if( temp == "RATEINTERVALLLENGTH" )
607613
{
@@ -1182,13 +1188,21 @@ void VAnaSumRunParameter::printStereoParameter( unsigned int i )
11821188
{
11831189
cout << " (lookup table energy reconstruction)" << endl;
11841190
}
1185-
if( fXGB_file_suffix != "" && fXGB_file_suffix != "None" )
1191+
if( fXGB_stereo_file_suffix != "" && fXGB_stereo_file_suffix != "None" )
1192+
{
1193+
cout << "\t XGB stereo analysis file: " << fXGB_stereo_file_suffix << endl;
1194+
}
1195+
else
1196+
{
1197+
cout << "\t no XGB stereo analysis file used" << endl;
1198+
}
1199+
if( fXGB_gh_file_suffix != "" && fXGB_gh_file_suffix != "None" )
11861200
{
1187-
cout << "\t XY direction file: " << fXGB_file_suffix << endl;
1201+
cout << "\t XGB gamma-hadron separation file: " << fXGB_gh_file_suffix << endl;
11881202
}
11891203
else
11901204
{
1191-
cout << "\t no XY direction file used" << endl;
1205+
cout << "\t no XGB gamma-hadron separation file used" << endl;
11921206
}
11931207
cout << "\t dead time calculation method: ";
11941208
if( fDeadTimeCalculationMethod == 0 )

src/VGammaHadronCuts.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -718,8 +718,7 @@ void VGammaHadronCuts::printCutSummary()
718718
// XGBoost cuts
719719
if( useXGBoostCuts() )
720720
{
721-
// TODO
722-
cout << "XGBoost gamma/hadron separation" << endl;
721+
cout << "XGBoost gamma/hadron separation with fixed 70\% signal efficiency" << endl;
723722
}
724723
// other cut parameters
725724
if( fNTel == 2 )
@@ -1110,6 +1109,23 @@ bool VGammaHadronCuts::applyTMVACut( int i )
11101109
return false;
11111110
}
11121111

1112+
/*
1113+
1114+
apply XGBoost cuts
1115+
1116+
*/
1117+
bool VGammaHadronCuts::applyXGBoostCut( int i )
1118+
{
1119+
if( fDebug )
1120+
{
1121+
cout << "VGammaHadronCuts::applyXGBoostCut event " << i;
1122+
cout << ", prediction " << fData->GH_Gamma_Prediction;
1123+
cout << ", is gamma (70\% signal efficiency) " << fData->GH_Gamma_IsGamma;
1124+
cout << endl;
1125+
}
1126+
return fData->GH_Gamma_IsGamma;
1127+
}
1128+
11131129

11141130
/*!
11151131

src/VInstrumentResponseFunctionRunParameter.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ VInstrumentResponseFunctionRunParameter::VInstrumentResponseFunctionRunParameter
5151
fdatafile = "";
5252
fMCdatafile_tree = "";
5353
fMCdatafile_histo = "";
54-
fXGB_file_suffix = "";
54+
fXGB_stereo_file_suffix = "";
55+
fXGB_gh_file_suffix = "";
5556

5657
fze = 0.;
5758
fnoise = 0;
@@ -236,12 +237,20 @@ bool VInstrumentResponseFunctionRunParameter::readRunParameterFromTextFile( stri
236237
is_stream >> fCutFileName;
237238
}
238239
}
239-
else if( temp == "XGBFILESUFFIX" )
240+
else if( temp == "XGBSTEREOFILESUFFIX" )
240241
{
241242
if(!( is_stream >> std::ws ).eof() )
242243
{
243-
is_stream >> fXGB_file_suffix;
244-
if( fXGB_file_suffix == "None" ) fXGB_file_suffix = "";
244+
is_stream >> fXGB_stereo_file_suffix;
245+
if( fXGB_stereo_file_suffix == "None" ) fXGB_stereo_file_suffix = "";
246+
}
247+
}
248+
else if( temp == "XGBGAMMAHADRONFILESUFFIX" )
249+
{
250+
if(!( is_stream >> std::ws ).eof() )
251+
{
252+
is_stream >> fXGB_gh_file_suffix;
253+
if( fXGB_gh_file_suffix == "None" ) fXGB_gh_file_suffix = "";
245254
}
246255
}
247256
// * SCATTERMODE <core scatter radius [m]> <type of CORSIKA simulations (FLAT or VIEWCONE)>
@@ -610,9 +619,13 @@ void VInstrumentResponseFunctionRunParameter::print()
610619
{
611620
cout << " MC histograms: " << fMCdatafile_histo << endl;
612621
}
613-
if( fXGB_file_suffix.size() > 0 )
622+
if( fXGB_stereo_file_suffix.size() > 0 )
623+
{
624+
cout << " XGB file suffix: " << fXGB_stereo_file_suffix << endl;
625+
}
626+
if( fXGB_gh_file_suffix.size() > 0 )
614627
{
615-
cout << " XGB file suffix: " << fXGB_file_suffix << endl;
628+
cout << " XGB Gamma/Hadron file suffix: " << fXGB_gh_file_suffix << endl;
616629
}
617630
if( fInstrumentEpoch != "NOT_SET" )
618631
{

src/VStereoAnalysis.cpp

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ VStereoAnalysis::VStereoAnalysis( bool ion, string i_hsuffix, VAnaSumRunParamete
1111
fDebug = false;
1212

1313
fDataFile = 0;
14-
fXGBFile = 0;
1514
fXGB_tree = 0;
1615
fInstrumentEpochMinor = "NOT_SET";
1716
fDirTot = iDirTot;
@@ -1963,34 +1962,13 @@ CData* VStereoAnalysis::getDataFromFile( int i_runNumber )
19631962
cout << "exiting..." << endl;
19641963
exit( EXIT_FAILURE );
19651964
}
1966-
fXGB_tree = 0;
1967-
if( fRunPara->fXGB_file_suffix != "" && fRunPara->fXGB_file_suffix != "None" )
1968-
{
1969-
fXGBFile = new TFile( iFileName.replace(
1970-
iFileName.find( ".root" ), 5,
1971-
"." + fRunPara->fXGB_file_suffix + ".root" ).c_str()
1972-
);
1973-
if( fXGBFile->IsZombie() )
1974-
{
1975-
cout << "VStereoAnalysis::getDataFromFile() warning: cannot open DispDirection file "
1976-
<< iFileName << endl;
1977-
exit( EXIT_FAILURE );
1978-
}
1979-
else
1980-
{
1981-
fXGB_tree = ( TTree* )fXGBFile->Get( "StereoAnalysis" );
1982-
// backwards compatibility
1983-
if(!fXGB_tree ) fXGB_tree = ( TTree* )fXGBFile->Get( "DispDirection" );
1984-
if(!fXGB_tree )
1985-
{
1986-
cout << "VStereoAnalysis::getDataFromFile() error: cannot find stereo analysis tree in "
1987-
<< fXGBFile->GetName() << endl;
1988-
exit( EXIT_FAILURE );
1989-
}
1990-
cout << "VStereoAnalysis::getDataFromFile(): adding DispDirection from " << fXGBFile->GetName() << endl;
1991-
}
1992-
}
1993-
c = new CData( fDataRunTree, false, false, fXGB_tree );
1965+
c = new CData(
1966+
fDataRunTree,
1967+
false,
1968+
false,
1969+
fRunPara->fXGB_stereo_file_suffix,
1970+
fRunPara->fXGB_gamma_hadron_file_suffix
1971+
);
19941972
// read current (major) epoch from data file
19951973
VEvndispRunParameter* i_runPara = ( VEvndispRunParameter* )fDataFile->Get( "runparameterV2" );
19961974
if( i_runPara )

0 commit comments

Comments
 (0)