16 #include "StEStructCuts.h"
29 StEStructCuts::StEStructCuts(
const char* cutFileName) : mcutFileName(0), mMaxStore(100) {
32 if(cutFileName) setCutFile(cutFileName);
36 StEStructCuts::~StEStructCuts(){
if(mcutFileName)
delete [] mcutFileName ;
44 void StEStructCuts::printCuts(ostream& os,
int i){
45 os<<
"<CutType=\""<<mcutTypeName<<
"\">"<<endl;
46 if(i>=0)os<<
"<index>"<<i<<
"</index>"<<endl;
48 os<<
"</CutType>"<<endl;
53 void StEStructCuts::initVars(){
55 mvarName =
new char*[mMaxStore];
56 mvalues =
new float[mMaxStore];
57 mminVal =
new float[mMaxStore];
58 mmaxVal =
new float[mMaxStore];
59 mvarHistsNoCut =
new TH1*[mMaxStore];
60 mvarHistsCut =
new TH1*[mMaxStore];
67 void StEStructCuts::deleteVars() {
70 for(
int i=0;i<mnumVars; i++){
71 delete [] mvarName[i];
72 delete mvarHistsCut[i];
73 delete mvarHistsNoCut[i];
80 delete [] mvarHistsNoCut;
81 delete [] mvarHistsCut;
87 void StEStructCuts::setCutFile(
const char* cutFileName) {
89 if(!cutFileName)
return;
90 if(mcutFileName)
delete [] mcutFileName;
92 mcutFileName=
new char[strlen(cutFileName)+1];
93 strcpy(mcutFileName,cutFileName);
100 bool StEStructCuts::loadCutDB() {
105 if (!strcmp(mcutFileName,
"testdb")) {
106 loadBaseCuts(
"primaryVertexZ",
"-15",
"25");
107 loadBaseCuts(
"Pt",
"0.15",
"5");
108 loadBaseCuts(
"Phi",
"-1",
"0.8");
109 loadBaseCuts(
"Eta",
"-1.5",
"0.5");
115 if (!strcmp(mcutFileName,
"template")) {
131 loadBaseCuts(
"primaryVertexZ",
"-50.",
"50");
134 loadBaseCuts(
"Flag",
"0",
"2000");
135 loadBaseCuts(
"Charge",
"-1",
"1");
136 loadBaseCuts(
"NFitPoints",
"15",
"50");
137 loadBaseCuts(
"NFitPerNMax",
"0.52",
"1.0");
138 loadBaseCuts(
"GlobalDCA",
"0.",
"3.0");
139 loadBaseCuts(
"Chi2",
"0.",
"3.0");
140 loadBaseCuts(
"dPtByPt",
"0.",
"3.0");
141 loadBaseCuts(
"Pt",
"0.15",
"15.45");
142 loadBaseCuts(
"Yt",
"0.1",
"2.");
143 loadBaseCuts(
"Phi",
"-1",
"1");
144 loadBaseCuts(
"Eta",
"-1.0",
"1.0");
145 loadBaseCuts(
"NSigmaElectron",
"0.0",
"1.5");
148 loadBaseCuts(
"DeltaPhi",
"-.5",
"0.333");
149 loadBaseCuts(
"DeltaEta",
"0.",
"0.15");
150 loadBaseCuts(
"DeltaMt",
"-7.",
"0.250");
151 loadBaseCuts(
"qInv",
"0.1",
"5.0");
152 loadBaseCuts(
"EntranceSep",
"5.0",
"200");
153 loadBaseCuts(
"ExitSep",
"0.0",
"600");
154 loadBaseCuts(
"Quality",
"-0.5",
"0.75");
155 loadBaseCuts(
"MidTpcSepLikeSign",
"5.",
"7.5");
156 loadBaseCuts(
"MidTpcSepUnlikeSign",
"5.",
"7.5");
163 if (!strcmp(mcutFileName,
"AuAu130")) {
175 loadBaseCuts(
"primaryVertexZ",
"-75.",
"75");
178 loadBaseCuts(
"Flag",
"0",
"2000");
179 loadBaseCuts(
"Charge",
"-1",
"1");
180 loadBaseCuts(
"NFitPoints",
"10",
"50");
181 loadBaseCuts(
"NFitPerNMax",
"0.52",
"1.0");
182 loadBaseCuts(
"GlobalDCA",
"0.",
"3.0");
183 loadBaseCuts(
"Pt",
"0.15",
"2.0");
184 loadBaseCuts(
"Phi",
"-1",
"1");
185 loadBaseCuts(
"Eta",
"-1.3",
"1.3");
201 bool StEStructCuts::loadCuts(){
203 if(!isLoaded())
return false;
206 cout <<
"Using entry " << mcutFileName <<
" in cut DB." << endl;
211 cout <<
"Loading file " << mcutFileName <<endl;
212 ifstream from(mcutFileName);
215 cout<<
" Cut file Not Found "<<endl;
221 char line[256], lineRead[256];
223 char** val =
new char*[100];
230 from.getline(lineRead,256);
231 strcpy(line,lineRead);
232 if( (line[0]==
'#') )
continue;
233 if((puteol=strstr(line,
"#")))*puteol=
'\0';
237 while((fcomma=strstr(val[ival],
","))){
244 const char* name=val[0];
245 char** values=&val[1];
246 if(!loadBaseCuts(name,(
const char**)values,ival))loadUserCuts(name,(
const char**)values,ival);
259 bool StEStructCuts::loadBaseCuts(
const char* name,
const char* val1,
const char* val2,
const char* val3,
const char* val4) {
264 char** tmp =
new char*[count];
265 tmp[0] =
new char[strlen(val1) + 1];
266 tmp[1] =
new char[strlen(val2) + 1];
270 tmp[2] =
new char[strlen(val3) + 1];
274 tmp[3] =
new char[strlen(val4) + 1];
277 bool retVal = loadBaseCuts(name, (
const char**)tmp, count);
283 void StEStructCuts::loadUserCuts(
const char* name,
const char* val1,
const char* val2) {
285 char** tmp =
new char*[2];
286 tmp[0] =
new char[strlen(val1) + 1];
287 tmp[1] =
new char[strlen(val2) + 1];
290 loadUserCuts(name, (
const char**)tmp, 2);
295 int StEStructCuts::createCutHists(
const char* name,
float* range,
int nvals){
298 cout<<
" Creating Cut Histogram for "<<name;
299 cout<<
" with range of cuts = ";
300 for(
int ii=0;ii<nvals;ii++)cout<<range[ii]<<
",";
303 if(mnumVars==mMaxStore)resize();
305 mvarName[mnumVars]=
new char[strlen(name)+1];
306 strcpy(mvarName[mnumVars],name);
308 float delta=(range[1]-range[0])/2;
309 float Max=range[1]+delta;
310 float Min=range[0]-delta;
313 mvarHistsCut[mnumVars]=
new TH1F((hc.str()).c_str(),(hc.str()).c_str(),200,Min,Max);
316 mvarHistsNoCut[mnumVars]=
new TH1F((hnc.str()).c_str(),(hnc.str()).c_str(),200,Min,Max);
326 void StEStructCuts::addCutHists(TH1* before, TH1* after,
const char* name){
328 if(mnumVars==mMaxStore)resize();
330 mvarHistsNoCut[mnumVars]=before;
331 mvarHistsCut[mnumVars]=after;
333 mvarName[mnumVars] =
new char[strlen(name)+1];
334 strcpy(mvarName[mnumVars],name);
336 mvarName[mnumVars]=
new char[5];
337 strcpy(mvarName[mnumVars],
"none");
339 mvalues[mnumVars]=-9999.;
345 void StEStructCuts::fillHistogram(
const char* name,
float value,
bool passed){
352 for(i=0; i<mnumVars; i++)
if(strstr(mvarName[i],name))
break;
354 if(i==mnumVars)
return;
356 mvarHistsNoCut[i]->Fill(value);
357 if(passed) mvarHistsCut[i]->Fill(value);
361 void StEStructCuts::fillHistogram(
const char* name,
float val1,
float val2,
bool passed){
368 std::string hName = name; hName +=
"2D";
372 for(i=0; i<mnumVars; i++)
if(strstr(mvarName[i],hName.c_str()))
break;
378 TAxis *x = mvarHistsNoCut[i]->GetXaxis();
379 val1 = (val1 > x->GetXmin()) ? val1 : x->GetXmin()+0.5;
380 val1 = (val1 < x->GetXmax()) ? val1 : x->GetXmax()-0.5;
382 TAxis *y = mvarHistsNoCut[i]->GetYaxis();
383 val2 = (val2 > y->GetXmin()) ? val2 : y->GetXmin()+0.5;
384 val2 = (val2 < y->GetXmax()) ? val2 : y->GetXmax()-0.5;
386 mvarHistsNoCut[i]->Fill(val1,val2);
387 if(passed) mvarHistsCut[i]->Fill(val1,val2);
391 void StEStructCuts::fillHistogram(
const char* name,
float val1,
float val2,
float val3,
bool passed){
398 string hName = name; hName +=
"3D";
402 for(i=0; i<mnumVars; i++)
if(strstr(mvarName[i],hName.c_str()))
break;
408 TAxis *x = mvarHistsNoCut[i]->GetXaxis();
409 val1 = (val1 > x->GetXmin()) ? val1 : x->GetXmin()+0.5;
410 val1 = (val1 < x->GetXmax()) ? val1 : x->GetXmax()-0.5;
412 TAxis *y = mvarHistsNoCut[i]->GetYaxis();
413 val2 = (val2 > y->GetXmin()) ? val2 : y->GetXmin()+0.5;
414 val2 = (val2 < y->GetXmax()) ? val2 : y->GetXmax()-0.5;
416 mvarHistsNoCut[i]->Fill(val1,val2);
417 if(passed) mvarHistsCut[i]->Fill(val1,val2);
421 void StEStructCuts::fillHistograms(
bool passed){
427 for(
int i=0;i<mnumVars; i++){
428 mvarHistsNoCut[i]->Fill(mvalues[i],1.0);
429 if(passed)mvarHistsCut[i]->Fill(mvalues[i],1.0);
434 void StEStructCuts::writeCutHists(TFile* tf){
437 for(
int i=0; i<mnumVars; i++)mvarHistsCut[i]->Write();
438 for(
int i=0; i<mnumVars; i++)mvarHistsNoCut[i]->Write();
441 void StEStructCuts::resize(){
443 int newMax=2*mMaxStore;
444 float* tmp=
new float[newMax];
445 memcpy(tmp,mvalues,mMaxStore*
sizeof(
float));
449 char** tmpC=
new char*[newMax];
450 memcpy(tmpC,mvarName,mMaxStore*
sizeof(
char*));
454 TH1** tmpH =
new TH1*[newMax];
455 memcpy(tmpH,mvarHistsNoCut,mMaxStore*
sizeof(TH1*));
456 delete [] mvarHistsNoCut;
459 tmpH =
new TH1*[newMax];
460 memcpy(tmpH,mvarHistsCut,mMaxStore*
sizeof(TH1*));
461 delete [] mvarHistsCut;
468 void StEStructCuts::printCuts(
const char* fileName){
470 ofstream ofs(fileName);
472 cout<<
" couldn't open file="<<fileName<<endl;