2022-03-18 18:34:13 -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>
|
|
|
|
|
|
|
|
#include "mapping.h"
|
|
|
|
|
|
|
|
void GAGGPIDCutCreator(TString dataList,
|
|
|
|
TString saveFileName = "GAGGPIDCuts.root",
|
2022-03-18 21:14:43 -04:00
|
|
|
int detID = -100, // -100 = new, -X = append from X, X = only X
|
2022-03-18 18:34:13 -04:00
|
|
|
int peakRange=1200,
|
|
|
|
int tailRange=400,
|
2022-03-18 21:14:43 -04:00
|
|
|
bool isLogz = false,
|
|
|
|
float frac = 0.3
|
2022-03-18 18:34:13 -04:00
|
|
|
){
|
|
|
|
|
|
|
|
printf("================ Graphic Cut Creator for GAGG ============== \n");
|
|
|
|
|
2022-03-18 21:14:43 -04:00
|
|
|
TChain * chain = new TChain("tree");
|
2022-03-18 18:34:13 -04:00
|
|
|
chain->Add(dataList);
|
|
|
|
|
|
|
|
chain->GetListOfFiles()->Print();
|
|
|
|
|
2022-03-18 21:14:43 -04:00
|
|
|
Long64_t numEntries = chain->GetEntries();
|
|
|
|
|
|
|
|
printf(" total number of entries : %llu, using the first %.0f%% data.\n", numEntries, frac*100.);
|
|
|
|
|
2022-03-18 18:34:13 -04:00
|
|
|
TString varX, varY, tag;
|
|
|
|
|
|
|
|
gStyle->SetOptStat("neiou");
|
|
|
|
|
|
|
|
TCanvas * cCutCreator = new TCanvas("cCutCreator", "GAGG PID Cut Creator", 100, 100, 800, 800);
|
|
|
|
if( !cCutCreator->GetShowToolBar() ) cCutCreator->ToggleToolBar();
|
|
|
|
|
|
|
|
cCutCreator->Update();
|
|
|
|
if( isLogz ) cCutCreator->cd()->SetLogz();
|
|
|
|
|
2022-03-18 21:14:43 -04:00
|
|
|
TString expression, gate;
|
|
|
|
TH2F * h[NGAGG];
|
2022-03-18 18:34:13 -04:00
|
|
|
|
2022-03-18 21:14:43 -04:00
|
|
|
TFile * cutFile;
|
|
|
|
TCutG * cut = NULL;
|
|
|
|
TObjArray * cutList;
|
2022-03-18 18:34:13 -04:00
|
|
|
|
2022-03-18 21:14:43 -04:00
|
|
|
|
|
|
|
/// load the cutFile and load the cutList
|
|
|
|
|
2022-03-18 18:34:13 -04:00
|
|
|
|
2022-03-18 21:14:43 -04:00
|
|
|
int startID = 0;
|
|
|
|
int stopID = NGAGG;
|
|
|
|
|
|
|
|
if( detID != -100 ) {
|
|
|
|
cutFile = new TFile(saveFileName, "UPDATE");
|
|
|
|
bool listExist = cutFile->GetListOfKeys()->Contains("cutList");
|
|
|
|
if( !listExist ) {
|
|
|
|
cutList = new TObjArray();
|
|
|
|
}else{
|
|
|
|
cutList = (TObjArray*) cutFile->FindObjectAny("cutList");
|
|
|
|
int 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);
|
|
|
|
}else{
|
|
|
|
printf(" No cut at %2d \n", k);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( detID < 0 ) startID = abs(detID);
|
|
|
|
if( detID >= 0 ){
|
|
|
|
startID = detID;
|
|
|
|
stopID = detID+1;
|
|
|
|
}
|
|
|
|
|
|
|
|
}else{
|
|
|
|
cutFile = new TFile(saveFileName, "recreate");
|
|
|
|
cutList = new TObjArray();
|
|
|
|
}
|
|
|
|
printf("=================== plotting histogram, start at GAGG-%0d \n", startID);
|
|
|
|
|
2022-03-18 18:34:13 -04:00
|
|
|
int count = 0;
|
|
|
|
|
2022-03-18 21:14:43 -04:00
|
|
|
for (Int_t i = startID; i < stopID; i++) {
|
2022-03-18 18:34:13 -04:00
|
|
|
|
|
|
|
varX.Form("gaggT"); varY.Form("gaggP");
|
|
|
|
|
|
|
|
h[i] = new TH2F(Form("h%d", i), Form("GAGG-%d",i), 500, 0, tailRange, 500, 0, peakRange);
|
|
|
|
|
|
|
|
expression.Form("%s:%s>>h%d", varY.Data(), varX.Data(),i);
|
|
|
|
gate.Form("gaggID==%d", i);
|
|
|
|
|
2022-03-18 21:14:43 -04:00
|
|
|
chain->Draw(expression, gate, "col", numEntries * frac);
|
|
|
|
|
|
|
|
cut = (TCutG*) cutList->At(i);
|
|
|
|
cut->Draw("same");
|
2022-03-18 18:34:13 -04:00
|
|
|
|
|
|
|
if( h[i]->Integral() < 1000 ) {
|
|
|
|
h[i]->SetMarkerStyle(20);
|
|
|
|
h[i]->SetMarkerSize(0.4);
|
|
|
|
h[i]->Draw("");
|
|
|
|
}
|
|
|
|
|
2022-03-18 21:14:43 -04:00
|
|
|
printf("======== make a graphic cut on the plot (double click to stop), %2d-th cut: ", i );
|
2022-03-18 18:34:13 -04:00
|
|
|
|
2022-03-18 21:14:43 -04:00
|
|
|
if( detID != -100 )
|
|
|
|
|
2022-03-18 18:34:13 -04:00
|
|
|
cCutCreator->Modified(); cCutCreator->Update();
|
|
|
|
|
|
|
|
gPad->WaitPrimitive();
|
|
|
|
|
|
|
|
cut = (TCutG*) gROOT->FindObject("CUTG");
|
|
|
|
|
|
|
|
if( cut == NULL ){
|
2022-03-18 21:14:43 -04:00
|
|
|
printf(" stopped by user.\n");
|
2022-03-18 18:34:13 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
TString name; name.Form("cut%d", i);
|
|
|
|
cut->SetName(name);
|
|
|
|
cut->SetVarX(varX.Data());
|
|
|
|
cut->SetVarY(varY.Data());
|
|
|
|
cut->SetTitle(tag);
|
|
|
|
cut->SetLineColor(i+1);
|
2022-03-18 21:14:43 -04:00
|
|
|
if( detID != -100 ){
|
|
|
|
cutList->AddAt(cut, abs(detID));
|
|
|
|
}else{
|
|
|
|
cutList->Add(cut);
|
|
|
|
}
|
2022-03-18 18:34:13 -04:00
|
|
|
printf(" cut-%d \n", i);
|
|
|
|
|
|
|
|
count ++;
|
|
|
|
}
|
|
|
|
|
|
|
|
cutList->Write("cutList", TObject::kSingleKey);
|
2022-03-18 21:14:43 -04:00
|
|
|
if( detID == -100) {
|
|
|
|
printf("====> saved %d cuts into %s\n", count, saveFileName.Data());
|
|
|
|
}else{
|
|
|
|
if( detID < 0 ) {
|
|
|
|
printf("====> ReDo %d cuts into %s, from GAGG-%2d\n", count, saveFileName.Data(), startID);
|
|
|
|
}else{
|
|
|
|
printf("====> ReDo %d cuts into %s, GAGG-%2d\n", count, saveFileName.Data(), startID);
|
|
|
|
}
|
|
|
|
}
|
2022-03-18 18:34:13 -04:00
|
|
|
gROOT->ProcessLine(".q");
|
|
|
|
|
|
|
|
}
|