91 lines
2.4 KiB
C
91 lines
2.4 KiB
C
#include <TH2F.h>
|
|
#include <TFile.h>
|
|
#include <TChain.h>
|
|
#include <TROOT.h>
|
|
#include <TStyle.h>
|
|
#include <TCanvas.h>
|
|
#include <TCutG.h>
|
|
#include <TString.h>
|
|
#include <TObjArray.h>
|
|
|
|
void PIDCutCreator(TH2F* hist,
|
|
TString saveFileName = "PIDCuts.root",
|
|
bool isLogz = false
|
|
){
|
|
|
|
printf("================ Graphic Cut Creator for PID ============== \n");
|
|
|
|
gStyle->SetOptStat("neiou");
|
|
|
|
TCanvas * cCutCreator = new TCanvas("cCutCreator", "PID Cut Creator", 100, 100, 800, 800);
|
|
if( !cCutCreator->GetShowToolBar() ) cCutCreator->ToggleToolBar();
|
|
|
|
cCutCreator->Update();
|
|
if( isLogz ) cCutCreator->cd()->SetLogz();
|
|
hist->Draw("colz");
|
|
|
|
TFile * cutFile;
|
|
TCutG * cut = NULL;
|
|
TObjArray * cutList;
|
|
|
|
///===================== load the cutFile and load the cutList
|
|
|
|
int numCut = 0;
|
|
cutFile = new TFile(saveFileName, "UPDATE");
|
|
if( cutFile == NULL ){
|
|
cutFile = new TFile(saveFileName, "recreate");
|
|
}
|
|
bool listExist = cutFile->GetListOfKeys()->Contains("cutList");
|
|
if( !listExist ) {
|
|
cutList = new TObjArray();
|
|
}else{
|
|
cutList = (TObjArray*) cutFile->FindObjectAny("cutList");
|
|
numCut = cutList->GetLast()+1;
|
|
printf("----- found %d cuts \n", numCut);
|
|
for( int k = 0; k < numCut; k++){
|
|
if( cutList->At(k) != NULL ){
|
|
printf("found a cut at %2d \n", k);
|
|
cut = (TCutG*) cutList->At(k);
|
|
cut->Draw("same");
|
|
}else{
|
|
printf(" No cut at %2d \n", k);
|
|
}
|
|
}
|
|
}
|
|
cCutCreator->Modified(); cCutCreator->Update();
|
|
|
|
int countCut = 0;
|
|
while (true){
|
|
|
|
printf("======== make a graphic cut on the plot (double click to stop), %2d-th cut: ", countCut );
|
|
|
|
gPad->WaitPrimitive();
|
|
|
|
cut = (TCutG*) gROOT->FindObject("CUTG");
|
|
|
|
if( cut == NULL ){
|
|
printf(" stopped by user.\n");
|
|
break;
|
|
}
|
|
|
|
TString name; name.Form("cut%2d", countCut);
|
|
cut->SetName(name);
|
|
cut->SetVarX("AoQ");
|
|
cut->SetVarY("Z");
|
|
cut->SetTitle(Form("cut%2d", countCut));
|
|
cut->SetLineColor(countCut+1);
|
|
printf(" cut-%d \n", countCut);
|
|
|
|
cutList->AddAtAndExpand(cut, countCut);
|
|
countCut ++;
|
|
|
|
}
|
|
|
|
///================= Summary
|
|
|
|
cutList->Write("cutList", TObject::kSingleKey);
|
|
printf("====> saved %d cuts into %s\n", countCut, saveFileName.Data());
|
|
gROOT->ProcessLine(".q");
|
|
|
|
}
|