Skip to content

Commit

Permalink
tidy up running example
Browse files Browse the repository at this point in the history
  • Loading branch information
dglazier committed Nov 23, 2022
1 parent 9afb088 commit f59b3f3
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 178 deletions.
32 changes: 7 additions & 25 deletions core/TrainingInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ class TrainingInfo : public TNamed{
TrainingInfo()=default;
TrainingInfo(const std::string& name):particle(name){}
TrainingInfo(const std::string& name,const std::string& filename){
std::cout<<"TrainingInfo getting "<<name<<" from "<<filename<<std::endl;
auto file = std::unique_ptr<TFile>(TFile::Open(filename.data()));
*this = *file->Get<TrainingInfo>(name.data());
}
// const std::string objectName{"TrainingInfo"};
std::cout<<"TrainingInfo: getting "<<name<<" from "<<filename<<std::endl;
auto file = std::unique_ptr<TFile>(TFile::Open(filename.data()));
*this = *file->Get<TrainingInfo>(name.data());
}

std::string particle;
std::string treeName;
std::string reconFile;
Expand Down Expand Up @@ -51,31 +51,13 @@ class TrainingInfo : public TNamed{
auto file = std::unique_ptr<TFile>(new TFile(filename.data(),"UPDATE"));
if(file->IsOpen()==kFALSE)
file.reset(new TFile(filename.data(),"recreate"));
cout<<"file "<<file.get()<<" "<<file->IsOpen()<<endl;
// file->WriteTObject(this,particle.data());
Write(particle.data());
std::cout<<"TrainingInfo: wrote info for "<<particle <<" to "<<filename<<std::endl;
}
///////////////////////////////////////////////////////////////////////////////
/* DataLoader* TrainingData(){ */
/* if(genFile.empty()==false){ */
/* dataLoader.reset(new DataWithAccAndGenFiles(treeName,reconFile,genFile)); */
/* dynamic_cast<DataWithAccAndGenFiles*>(dataLoader.get())->SetAccFractionToProcess(recFrac); */
/* dynamic_cast<DataWithAccAndGenFiles*>(dataLoader.get())->SetGenFractionToProcess(genFrac); */
/* } */
/* else{ */
/* dataLoader.reset(new DataWithAcceptanceVar(treeName,reconFile,acceptVar)); */
/* dynamic_cast<DataWithAcceptanceVar*>(dataLoader.get())->SetFractionToProcess(recFrac); */
/* } */
/* dataLoader->ConfigVars(variables); */
/* dataLoader->Filter(recFilter); */
/* return dataLoader.get(); */
/* } */



private:

// std::shared_ptr<DataLoader> dataLoader;//!


ClassDef( TrainingInfo,1);
};
Expand Down
8 changes: 0 additions & 8 deletions examples/toy/ConvertToAccAndGenFiles.C

This file was deleted.

12 changes: 12 additions & 0 deletions examples/toy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

Generates file : toy_training.root

Note, to exit root session, type .q and return.

## To generate reaction data

root Reaction.C
Expand All @@ -30,6 +32,13 @@ Note, acceptance training diagnostic plots will go to fast_sim/acceptance/pi+/ac

macparticles 'RunAcceptanceTraining.C( "pi+","training.root","fast_sim" )'

This is a slightly speeded up configuration, for the publication the following
parameters were set,

accKeras.SetMaxEpochs(100);
accKeras.SetLearnRate(1E-3);
accKeras.SetNetwork({1024,512, 256,128, 64,32,16});

More accurate acceptances can be acheived through reweighting with a BDT

macparticles 'RunReweightTraining.C( "pi+","training.root","fast_sim" )'
Expand All @@ -38,6 +47,9 @@ and we can then train resolutions

macparticles 'RunResolutionTraining.C( "pi+","training.root","fast_sim" )'

By default it is set to train 5 regressors, to smooth the distribution further,
this can be increased to 20, although the training time and disk space
increases proportionaly.

If you are happy with the results you can go on and train the pi- and proton.
If you think the acceptances are not so great you can try tuning the DNN
Expand Down
68 changes: 0 additions & 68 deletions examples/toy/RunAccAndGenResolutionTraining.C

This file was deleted.

74 changes: 1 addition & 73 deletions examples/toy/RunResolutionTraining.C
Original file line number Diff line number Diff line change
Expand Up @@ -13,82 +13,10 @@ void RunResolutionTraining(string particle,string filename,string simdir){
///////////////////////////////
///Here can configure the regressors
DecisionTreeResolModel res(config);
res.SetNRegressors(10);
res.SetNRegressors(5);
res.SetNRandInputs(5);
res.SetApplyExtraScaling();
res.Train(dload.get());

ResolutionPlotter(*dload.get(),config).PlotTraining();

}
/*
{
auto pdg = GetPID(); //give pid on command line e.g. pid=proton
DataWithAcceptanceVar dl("simtree", "toy_training.root","accepted");
dl.Range(0,1.6E6); //gives approx 1M accepted
dl.DetailedTruthVars({{"truP",0,10},
{"truTheta",0,180},
{"truPhi",-180,180}});
dl.SetReconVars({"recP","recTheta","recPhi"});
//dl.SetAcceptVar();
ConfigureSimulation config;
config.Load("fast_simulation/");
config.AddPdg(pdg.Data());
DecisionTreeResolModel res(config);
res.SetNRegressors(2);
res.SetNRandInputs(1);
res.Train(dl);
config.Save();//In case any changes
//make some branches for plotting
dl.AddFriend("recon",config.ResolutionDir()+"predictions.root");
dl.DefineColumn("diffP","truP-recon.recP");
dl.DefineColumn("diffTheta","truTheta-recon.recTheta");
dl.DefineColumn("diffPhi","truPhi-recon.recPhi");
dl.DefineColumn("diffRealPhi","truPhi-recPhi");
dl.DefineColumn("diffRealTheta","truTheta-recTheta");
auto accEvents = dl.GetAcceptedFrame();
//plot histrograms via RDataFrame
auto h0 = accEvents.Histo2D({"DPvP","#DeltaP v P",100,0,10,100,-2,4},"truP","diffP");
new TCanvas();
h0->DrawCopy();
auto h1 = accEvents.Histo1D({"diffTheta","#theta",100,-0.3,0.3},"diffTheta");
new TCanvas();
h1->DrawCopy();
auto h2 = accEvents.Histo1D({"Phi","#phi",100,-TMath::Pi(),TMath::Pi()},"recon.recPhi");
new TCanvas();
h2->DrawCopy();
auto h3 = accEvents.Histo2D({"DPhiVTh","#phi v theta",100,0,TMath::Pi(),100,-20*TMath::DegToRad(),20*TMath::DegToRad()},"truTheta","diffPhi");
new TCanvas();
h3->DrawCopy();
auto h4 = accEvents.Histo2D({"DPhiVTh","#phi v theta",100,0,TMath::Pi(),100,-20*TMath::DegToRad(),20*TMath::DegToRad()},"truTheta","diffRealPhi");
new TCanvas();
h4->DrawCopy();
auto h6 = accEvents.Histo1D({"DPhir","#phi v theta",100,-0.5,0.5},"diffRealPhi");
new TCanvas();
h6->SetLineColor(2);
h6->DrawCopy("same");
auto h5 = accEvents.Histo1D({"DPhif","#phi v theta",100,-0.5,0.5},"diffPhi");
new TCanvas();
h5->DrawCopy();
auto h7 = accEvents.Histo2D({"DPhiDThr","D #phi v theta",100,-0.5,0.5,100,-0.2,0.2},"diffPhi","diffTheta");
new TCanvas();
h7->DrawCopy("col");
auto h8 = accEvents.Histo2D({"DPhiDThf","D #phi v theta",100,-0.5,0.5,100,-0.2,0.2},"diffRealPhi","diffRealTheta");
new TCanvas();
h8->DrawCopy("col");
}
*/
3 changes: 3 additions & 0 deletions python/DTRes.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
y_data = df.GetPredictionsFrame().AsNumpy(y_vars);
y_array = np.vstack([y_data[ykey] for ykey in y_data.keys()]).T

print('DTRes.py : will train with x events ',x_array.shape)
print('DTRes.py : will train with y events ',y_array.shape)

############################################################################
###TRAIN MODELS AND SAVE TO DISC
############################################################################
Expand Down
8 changes: 4 additions & 4 deletions python/KerasWithGaus.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
from platform import python_version

print('Keras.py AcceptanceTraining')
print(tf.__version__)
print(keras.__version__)
print('python version ')
print(python_version())
#print(tf.__version__)
#print(keras.__version__)
#print('python version ')
#print(python_version())
############################################################################
###PREPARE DATA
############################################################################
Expand Down

0 comments on commit f59b3f3

Please sign in to comment.