Skip to content

Run FinalState analysis with TMVA classifier

dglazier edited this page Jun 11, 2020 · 2 revisions

Now we have a trained classifier we can run it on our data! This step should be the most straitforward as we just need to add another action to our Configured Analysis Object (CANO).

I will past the full ROOT script below, but the only real difference is that I use the DTCuts2 on the data to reduce the file output size. This is done by replacing the 0 with a 1 in ParticleCutsManager pcm2{"DTCuts2",1};

And include the MVASignalIDActions which looks like,

MVASignalIDAction mva_bdt;
mva_bdt.AddTopology("mva2","BDT","Electron:Proton:Pip:Pim");
mva_bdt.SetParticleOut(new MVAParticleOutEvent);
FS->RegisterPostTopoAction(mva_bdt);

To run the code I just use chanser_root on my script called CreateWithMVA_Pi2.C,

chanser_root Pi2:Pi2.cpp CreateWithMVA_Pi2.C

The rest of the code is

auto FS = dglazier::Pi2::Make("NONE","ALL");
FS->AddTopology("Electron:Proton:Pip:Pim");

FS->SetStartTimePeak(43.9);

//  Make particle trees first in case want to add cut flags
ParticleDataManager pdm{"particle",1};
pdm.SetParticleOut(new MVAParticleOutEvent);
FS->RegisterPostKinAction(pdm);

MVASignalIDAction mva_bdt;
mva_bdt.AddTopology("mva2","BDT","Electron:Proton:Pip:Pim");
mva_bdt.SetParticleOut(new MVAParticleOutEvent);
FS->RegisterPostTopoAction(mva_bdt);

 ////
ParticleCutsManager pcm2{"DTCuts2",1};
pcm2.AddParticleCut("e-",new  DeltaTimeCut(2));
pcm2.AddParticleCut("proton",new DeltaTimeCut(2));
pcm2.AddParticleCut("pi+",new DeltaTimeCut(2));
pcm2.AddParticleCut("pi-",new DeltaTimeCut(2));
FS->RegisterPostTopoAction(pcm2);

ParticleCutsManager pcm1{"DTCuts1",0};
pcm1.AddParticleCut("e-",new  DeltaTimeCut(1));
pcm1.AddParticleCut("proton",new DeltaTimeCut(1));
pcm1.AddParticleCut("pi+",new DeltaTimeCut(1));
pcm1.AddParticleCut("pi-",new DeltaTimeCut(1));
FS->RegisterPostTopoAction(pcm1);

//Truth Matching, before ParticleData so can add to that tree
EventTruthAction etra("EventTruth");
FS->RegisterPostKinAction(etra); //PostKin

///StartTime
StartTimeAction st("StartTime",new C12StartTimeFromParticle("Electron"));
FS->RegisterPreTopoAction(st);  //PRETOPO
//e- energy correction
ParticleCorrectionManager pcorrm{"FTelEnergyCorrection"};
pcorrm.AddParticle("e-",new FTel_pol4_ECorrection());
FS->RegisterPreTopoAction(pcorrm); //PRETOPO

 ////Write to file for later processing
FS->WriteToFile("Pi2_BDT.root");
FS->Print();
//Delete the final state rather than let ROOT try
FS.reset();

//Run the data
HipoData hdata;
hdata.SetFile("/work/jlab/clas12data/pass1_test/skim8_005051.hipo");
FinalStateManager fsm;
fsm.SetBaseOutDir("/work/dump/mvabdt");
fsm.LoadData(&hdata);
fsm.LoadFinalState("Pi2",
	     "Pi2_BDT.root");//from WriteToFile line


fsm.ProcessAll();

And now I can plot my BDT response versus variables for find a good cut value for cleaning up my data,