2022-05-24 18:21:12 -04:00
|
|
|
#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);
|
2023-05-18 16:33:51 -04:00
|
|
|
cut = (TCutG*) cutList->At(k);
|
2022-05-24 18:21:12 -04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2023-05-18 16:33:51 -04:00
|
|
|
TString name; name.Form("cut%2d", countCut);
|
2022-05-24 18:21:12 -04:00
|
|
|
cut->SetName(name);
|
2023-05-18 16:33:51 -04:00
|
|
|
cut->SetVarX("AoQ");
|
|
|
|
cut->SetVarY("Z");
|
2022-05-24 18:21:12 -04:00
|
|
|
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");
|
|
|
|
|
|
|
|
}
|