//*-- AUTHOR : J. Markert //_HADES_CLASS_DESCRIPTION //////////////////////////////////////////////////////////////////////////// // HMdcGarEffMaker // Class to produce parameters for HMdcCellEff // The input file is produced by HMdcGarSignalReader and contains the // the needed Hists to perform the calculations. The final parameter file // is written to the ascii output and a root output containing the created // and fitted hists is written too. //////////////////////////////////////////////////////////////////////////// using namespace std; #include #include #include #include "hmdcgareffmaker.h" #include "htool.h" #include "TString.h" #include "TFile.h" #include "TDirectory.h" #include "TH1.h" #include "TROOT.h" #include "TKey.h" #include "TStyle.h" #include "TMath.h" #include "TList.h" #include "TObjString.h" #include "TF1.h" Int_t HMdcGarEffMaker::colors[10]={1,2,4,6,8,30,38,28,46,44}; ClassImp(HMdcGarEffMaker) HMdcGarEffMaker::HMdcGarEffMaker(const Char_t* name,const Char_t* title) : TNamed(name,title) { // constructor for HMdcGarEffMaker initVariables(); } HMdcGarEffMaker::~HMdcGarEffMaker() { // destructor of HMdcGarEffMaker } void HMdcGarEffMaker::setFileNameAsciiOut(TString myfile) { // Sets root output of HMdcGarEffMaker fNameAsciiOut=myfile; if(fNameAsciiOut.CompareTo("")==0) { Error("HMdcGarEffMaker:setFileNameAsciiOut()","NO ASCII OUTPUT FILE SEPCIFIED!"); exit(1); }; cout<<"HMdcGarEffMaker::setFileNameAsciiOut(): OUTPUT FILE= "< per mdc // type==1 -> per angle Char_t namehist[300]; Char_t titlehist[300]; if(type==0) { // per mdc sprintf(namehist ,"%s%i%s","heff_max[",mdc,"]"); sprintf(titlehist,"%s%i%s","heff_max[",mdc,"]"); heff_max= new TH1D(namehist,titlehist,20,0,20); heff_max->SetLineColor(colors[mdc]); sprintf(namehist ,"%s%i%s","heff_max_distance[",mdc,"]"); sprintf(titlehist,"%s%i%s","heff_max_distance[",mdc,"]"); heff_max_distance= new TH1D(namehist,titlehist,20,0,20); heff_max_distance->SetLineColor(colors[mdc]); for(Int_t i=0;iSetLineColor(colors[i]); } } if(type==1) { // per angle sprintf(namehist ,"%s%i%s%02i%s","heff_cut_trend[",mdc,"][",angle,"]"); sprintf(titlehist,"%s%i%s%02i%s","heff_cut_trend[",mdc,"][",angle,"]"); heff_cut_trend= new TH1D(namehist,titlehist,60,0,60); heff_cut_trend->SetLineColor(colors[mdc]); sprintf(namehist ,"%s%i%s%02i%s","heff_time1[",mdc,"][",angle,"]"); sprintf(titlehist,"%s%i%s%02i%s","heff_time1[",mdc,"][",angle,"]"); heff_time1= new TH1D(namehist,titlehist,getNSamples(),0,getNSamples()); heff_time1->SetLineColor(colors[mdc]); heff_time1->SetMarkerStyle(29); heff_time1->SetMarkerColor(2); heff_time1->SetMarkerSize(.8); } } void HMdcGarEffMaker::writeHists(Int_t type) { // writes the created hists to an output Root file // type==0 -> per mdc // type==1 -> per angle if(type==0) { // per mdc HTool::writeObject(heff_max); HTool::writeObject(heff_max_distance); for(Int_t i=0;i per mdc // type==1 -> per angle if(type==0) { // per mdc HTool::deleteObject(heff_max); HTool::deleteObject(heff_max_distance); for(Int_t i=0;iSetBatch(); cout<<"--------------------------------------------------------------"<cd(); Char_t mypath[300]; TDirectory* dir=0; for(Int_t mdc=0;mdc<4;mdc++) { sprintf(mypath,"%s%i","mdc ",mdc); dir=HTool::changeToDir(mypath); createHists(mdc,0,0); for(Int_t angle=0;angle<18;angle++) { cout<<"mdc "<cd(); dir=HTool::changeToDir(mypath); writeHists (1); deleteHists(1); HTool::close(&inputRoot); } outputRoot->cd(); dir=HTool::changeToDir(mypath); writeHists (0); deleteHists(0); dir->cd(".."); } } if(getVersion()==2) { if(!HTool::open(&outputRoot,fNameRootOut,"RECREATE")) { exit(1); } if(!HTool::open(&inputRoot,fNameRootIn,"READ")) { exit(1); } outputRoot->cd(); Char_t mypath[300]; TDirectory* dir=0; for(Int_t mdc=0;mdc<4;mdc++) { sprintf(mypath,"%s%i","mdc ",mdc); dir=HTool::changeToDir(mypath); createHists(mdc,0,0); for(Int_t angle=0;angle<18;angle++) { cout<<"mdc "<cd(".."); } HTool::close(&inputRoot); } } TH1F* HMdcGarEffMaker::getHist(TFile* input,TString namehist) { // Gets hist from file TH1F* hsum =(TH1F*)input->Get(namehist.Data()); return hsum; } void HMdcGarEffMaker::fillEffHist(Int_t mdc,Int_t angle) { // Fills the efficiency hists from the hist read from input file Char_t mypath[300]; Char_t namehist[300]; TString mydir=""; TH1F* hsum =0; for(Int_t sample=0;sampleSetBinContent(sample+1,(Double_t)hsum->Integral(0,1000)); } HTool::deleteObject(hsum); } else continue; } } void HMdcGarEffMaker::fillCutHist(Int_t mdc,Int_t angle) { // Fills the cut hists from efficiency hists Int_t i=1; for(Int_t step=0;stepGetBinContent(getNSamples()-i)) > (getMinSignal(mdc)*(step+1)*0.05) && i<100 ) { heff_cut[step]->SetBinContent(angle+1,(getNSamples()-1-i)); i++; } } } void HMdcGarEffMaker::fillMaxHists(Int_t angle) { // Fills the max hists heff_max ->SetBinContent(angle+1,heff_time1->GetMinimum()); heff_max_distance->SetBinContent(angle+1,heff_time1->GetMinimumBin()); } void HMdcGarEffMaker::fillTrendHists(Int_t angle) { // Fill the trend hists from the cut hists for(Int_t step=0;stepSetBinContent((5*step)+1,(heff_cut[step]->GetBinContent(angle+1))*.1); } } void HMdcGarEffMaker::fitTrendHists(Int_t mdc,Int_t angle) { // Fit trend hists to get the parameters for HMdcCellEff TF1 *fitlinear=new TF1("linearfit","pol1",0,10); heff_cut_trend->Fit("linearfit","Q"); fitpars[mdc][angle][0]=fitlinear->GetParameter(0);// y offset fitpars[mdc][angle][1]=fitlinear->GetParameter(1);// slope }