GAGGPIDCutCreator.C can edit existing cuts
This commit is contained in:
parent
9700accb0f
commit
46e5700a34
|
@ -12,20 +12,24 @@
|
||||||
|
|
||||||
void GAGGPIDCutCreator(TString dataList,
|
void GAGGPIDCutCreator(TString dataList,
|
||||||
TString saveFileName = "GAGGPIDCuts.root",
|
TString saveFileName = "GAGGPIDCuts.root",
|
||||||
|
int detID = -100, // -100 = new, -X = append from X, X = only X
|
||||||
int peakRange=1200,
|
int peakRange=1200,
|
||||||
int tailRange=400,
|
int tailRange=400,
|
||||||
bool isLogz = false,
|
bool isLogz = false,
|
||||||
TString gate = "",
|
float frac = 0.3
|
||||||
TString treeName = "tree"
|
|
||||||
){
|
){
|
||||||
|
|
||||||
printf("================ Graphic Cut Creator for GAGG ============== \n");
|
printf("================ Graphic Cut Creator for GAGG ============== \n");
|
||||||
|
|
||||||
TChain * chain = new TChain(treeName);
|
TChain * chain = new TChain("tree");
|
||||||
chain->Add(dataList);
|
chain->Add(dataList);
|
||||||
|
|
||||||
chain->GetListOfFiles()->Print();
|
chain->GetListOfFiles()->Print();
|
||||||
|
|
||||||
|
Long64_t numEntries = chain->GetEntries();
|
||||||
|
|
||||||
|
printf(" total number of entries : %llu, using the first %.0f%% data.\n", numEntries, frac*100.);
|
||||||
|
|
||||||
TString varX, varY, tag;
|
TString varX, varY, tag;
|
||||||
|
|
||||||
gStyle->SetOptStat("neiou");
|
gStyle->SetOptStat("neiou");
|
||||||
|
@ -36,16 +40,53 @@ void GAGGPIDCutCreator(TString dataList,
|
||||||
cCutCreator->Update();
|
cCutCreator->Update();
|
||||||
if( isLogz ) cCutCreator->cd()->SetLogz();
|
if( isLogz ) cCutCreator->cd()->SetLogz();
|
||||||
|
|
||||||
TCutG * cut = NULL;
|
TString expression, gate;
|
||||||
TObjArray * cutList = new TObjArray();
|
|
||||||
|
|
||||||
TString expression;
|
|
||||||
|
|
||||||
TH2F * h[NGAGG];
|
TH2F * h[NGAGG];
|
||||||
|
|
||||||
int count = 0;
|
TFile * cutFile;
|
||||||
for (Int_t i = 0; i < NGAGG; i++) {
|
TCutG * cut = NULL;
|
||||||
|
TObjArray * cutList;
|
||||||
|
|
||||||
|
|
||||||
|
/// load the cutFile and load the cutList
|
||||||
|
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
for (Int_t i = startID; i < stopID; i++) {
|
||||||
|
|
||||||
varX.Form("gaggT"); varY.Form("gaggP");
|
varX.Form("gaggT"); varY.Form("gaggP");
|
||||||
|
|
||||||
|
@ -54,7 +95,10 @@ void GAGGPIDCutCreator(TString dataList,
|
||||||
expression.Form("%s:%s>>h%d", varY.Data(), varX.Data(),i);
|
expression.Form("%s:%s>>h%d", varY.Data(), varX.Data(),i);
|
||||||
gate.Form("gaggID==%d", i);
|
gate.Form("gaggID==%d", i);
|
||||||
|
|
||||||
chain->Draw(expression, gate, "col");
|
chain->Draw(expression, gate, "col", numEntries * frac);
|
||||||
|
|
||||||
|
cut = (TCutG*) cutList->At(i);
|
||||||
|
cut->Draw("same");
|
||||||
|
|
||||||
if( h[i]->Integral() < 1000 ) {
|
if( h[i]->Integral() < 1000 ) {
|
||||||
h[i]->SetMarkerStyle(20);
|
h[i]->SetMarkerStyle(20);
|
||||||
|
@ -62,8 +106,10 @@ void GAGGPIDCutCreator(TString dataList,
|
||||||
h[i]->Draw("");
|
h[i]->Draw("");
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("======== make a graphic cut on the plot (double click to stop), %d-th cut: ", i );
|
printf("======== make a graphic cut on the plot (double click to stop), %2d-th cut: ", i );
|
||||||
|
|
||||||
|
if( detID != -100 )
|
||||||
|
|
||||||
cCutCreator->Modified(); cCutCreator->Update();
|
cCutCreator->Modified(); cCutCreator->Update();
|
||||||
|
|
||||||
gPad->WaitPrimitive();
|
gPad->WaitPrimitive();
|
||||||
|
@ -71,7 +117,7 @@ void GAGGPIDCutCreator(TString dataList,
|
||||||
cut = (TCutG*) gROOT->FindObject("CUTG");
|
cut = (TCutG*) gROOT->FindObject("CUTG");
|
||||||
|
|
||||||
if( cut == NULL ){
|
if( cut == NULL ){
|
||||||
printf(" stopped by user. no file saved or changed. \n");
|
printf(" stopped by user.\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,17 +127,26 @@ void GAGGPIDCutCreator(TString dataList,
|
||||||
cut->SetVarY(varY.Data());
|
cut->SetVarY(varY.Data());
|
||||||
cut->SetTitle(tag);
|
cut->SetTitle(tag);
|
||||||
cut->SetLineColor(i+1);
|
cut->SetLineColor(i+1);
|
||||||
cutList->Add(cut);
|
if( detID != -100 ){
|
||||||
|
cutList->AddAt(cut, abs(detID));
|
||||||
|
}else{
|
||||||
|
cutList->Add(cut);
|
||||||
|
}
|
||||||
printf(" cut-%d \n", i);
|
printf(" cut-%d \n", i);
|
||||||
|
|
||||||
count ++;
|
count ++;
|
||||||
}
|
}
|
||||||
|
|
||||||
TFile * cutFile = new TFile(saveFileName, "recreate");
|
|
||||||
cutList->Write("cutList", TObject::kSingleKey);
|
cutList->Write("cutList", TObject::kSingleKey);
|
||||||
|
if( detID == -100) {
|
||||||
printf("====> saved %d cuts into %s\n", count, saveFileName.Data());
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
gROOT->ProcessLine(".q");
|
gROOT->ProcessLine(".q");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user