-
Notifications
You must be signed in to change notification settings - Fork 2
Create Training Data
Lets call my example FinalState class Pi2 for e- p pi+ pi-
Lets suppose I have already completed my Pi2.cpp class definition.
Now I need to create my configured analysis object (CANO), this is done in a ROOT script that then gets passed to chanser_root. i.e.
chanser_root Pi2:Pi2.cpp CreateTrainingData.C
CreateTrainingData.C might look like :
Create my FinalState class object and select the Electron:Proton:Pip:Pim topology. I could add more topologies and then perform the training on each one seperately
auto FS = Pi2::Make("NONE","ALL");
FS->AddTopology("Electron:Proton:Pip:Pim");
Hwre the NONE flag is important. This means I am not using EventBuilder PID as I would like to use the machine learning classifier instead. Instead the code will just use the particle charge and create all possible combitorials.
I do not need a seperate ROOT or hipo output for this only particle data so I don't need the line FS->UseOutputRootTree();
New I define what variables I would like to use for the training. In principle this can be different for each particle species, but here I will just use one ParticleData class which I made following instructions for making my own ParticleData class, called MVAParticleData. In general you will want to experiment with this. In my class for example I change region from discrete values to a float as classifier training does not like discrete variables. My particle data, data members are,
Float_t P=0;
Float_t Theta=0;
Float_t DeltaE=0;
Float_t DeltaTime=0;
Float_t EFrac=0;
Float_t HTCC=0;
Float_t Region=-1;
Now to create these output trees I use a ParticleDataManager and register it as a post Kine action.
ParticleDataManager pdm{"particle",1};
pdm.SetParticleOut(new MVAParticleOutEvent);
FS->RegisterPostKinAction(pdm);
Note the arguements {"particle",1} create a tree called particle and the 1 means the FinalState branches will be added. This allows me to use these to cut on to define signal and background events but I must remember to Ignore these in the training variables
Now here I am going to use mixed sample training by cutting on exclusive events for signal, but I may have wanted to use simulated events as signal. In this case I would include the TruthMatch action class which creates a branch, Truth, which flags when the correct combitorial event has been reconstructed. See the wiki on how to truth match. The code is quite simple,
EventTruthAction etra("EventTruth");
FS->RegisterPostKinAction(etra); //PostKin
I am going to flag some loose cuts for the data. The actual output will therefore contain all combitorials and I can use this flag (will be called DTCuts2) to select signalEvents. But note that I still use the event builder e- ID in this flag to take advantage of the extra PID used for electrons. Events that do not have e- EB PID will still be written but I can remove them from the signal events.
ParticleCutsManager pcm2{"DTCuts2",0};
pcm2.AddParticleCut("e-",new EventBuilderCut); //Use EB for elecron ID
pcm2.AddParticleCut("proton",new DeltaTimeCut(5));
pcm2.AddParticleCut("pi+",new DeltaTimeCut(5));
pcm2.AddParticleCut("pi-",new DeltaTimeCut(5));
FS->RegisterPostTopoAction(pcm2);
I am also going to use a StartTime algorithm based on the e- candidate rather than just the EB Start time, This allows us to analyse events which may have reconstructed more than one electron. See the wiki on start times
StartTimeAction st("StartTime",new C12StartTimeFromParticle("Electron"));
FS->RegisterPreTopoAction(st); //PRETOPO
In case of FT e- I am going to apply an energy correction. You may or may not want to include this,
ParticleCorrectionManager pcorrm{"FTelEnergyCorrection"};
pcorrm.AddParticle("e-",new FTel_pol4_ECorrection());
FS->RegisterPreTopoAction(pcorrm); //PRETOPO
Finally I am going to write this CANO to a ROOT file where it can be accessed for analysis
FS->WriteToFile("Pi2_Training.root"); FS->Print(); FS.reset(); //we are done, delete it
Now I can process data using a seperate script or using chanser_proof (see main code README) if I need multiple runs worth of data.
Here I just show how it looks for the former ROOT script which can actually just be added to the end of CreateTrainingData.C
HipoData hdata;
hdata.SetFile("/path/to/my.hipo");
FinalStateManager fsm;
fsm.SetBaseOutDir("/work/dump/mvatraining"); //where the training data will go
fsm.LoadData(&hdata);
fsm.LoadFinalState("Pi2",
"Pi2_Training.root");//from WriteToFile line
fsm.ProcessAll();