//*-- AUTHOR : J. Markert //_HADES_CLASS_DESCRIPTION //////////////////////////////////////////////////////////////////////////// // HMdcGarReader // Class to read several GARFIELD formats //////////////////////////////////////////////////////////////////////////// using namespace std; #include #include #include #include #include "hmdcgarreader.h" #include "htool.h" #include "TMath.h" #include "TArray.h" #include "TStyle.h" ClassImp(HMdcGarReader) HMdcGarReader::HMdcGarReader(const Char_t* name,const Char_t* title) : TNamed(name,title) { // constructor for HMdcGarReader initVariables(); } HMdcGarReader::~HMdcGarReader() { // destructor of HMdcGarReader } void HMdcGarReader::initVariables() { // inits all variables } TGraph* HMdcGarReader::readXT(TString inputname,Int_t color) { // Reads GARFIELD XT curve from ascii input "inputname" into a TGraph // with LineColor "color", which is returned gStyle->SetPalette(50); FILE* input=0; if(!HTool::openAscii(&input,inputname,"r")) { exit(1); } cout<<"HMdcGarReader::readXT() , Reading XT-data from GARFIELD file\n"<SetMarkerStyle(29); h->SetMarkerColor(4); h->SetMarkerSize(.8); h->SetLineColor(color); HTool::closeAscii(&input); return h; } TGraph* HMdcGarReader::readXTdiffusion(TString inputname,Int_t color) { // Reads GARFIELD integrated diffusion curve from ascii input "inputname" into a TGraph // with LineColor "color", which is returned gStyle->SetPalette(50); FILE* input=0; if(!HTool::openAscii(&input,inputname,"r")) { exit(1); } cout<<"HMdcGarReader::readXTdiffusion() , Reading XT-integrated diffusion data from GARFIELD file\n"<SetMarkerStyle(29); h->SetMarkerColor(4); h->SetMarkerSize(.8); h->SetLineColor(color); HTool::closeAscii(&input); return h; } TGraph* HMdcGarReader::readMagboltzVdrift(TString inputname,Int_t color) { // Reads MAGBOLTZ vdrift/E (E/P:Log10) curve from ascii input "inputname" into a TGraph // with LineColor "color", which is returned TGraph* h=0; gStyle->SetPalette(50); FILE* input=0; if(!HTool::openAscii(&input,inputname,"r")) { exit(1); } cout<<"HMdcGarReader::readMagboltz() , Reading Vdrift/E-data from MAGBOLTZ file\n"<=4&&found==0) { // read e-field in version 4 if(feof(input)) break; res=fgets(line, sizeof(line), input); if(!res) cout<<"could not read next line!"<SetMarkerStyle(29); h->SetMarkerColor(4); h->SetMarkerSize(.8); h->SetLineColor(color); HTool::closeAscii(&input); return h; } TGraph* HMdcGarReader::readMagboltzGasPrint(TString inputname,TString option,Int_t color) { // Reads MAGBOLTZ townsend/E (E/P:Log10) curve from ascii input "inputname" into a TGraph // with LineColor "color", which is returned TGraph* h=0; gStyle->SetPalette(50); FILE* input=0; if(!HTool::openAscii(&input,inputname,"r")) { exit(1); } cout<<"HMdcGarReader::readMagboltzGasPrint() , Reading Gas-Print-data from MAGBOLTZ file\n"<SetMarkerStyle(29); h->SetMarkerColor(4); h->SetMarkerSize(.8); h->SetLineColor(color); HTool::closeAscii(&input); return h; } TGraph* HMdcGarReader::readMagboltzGasPrintVersion6(TString inputname,TString option,Int_t color) { // Reads MAGBOLTZ townsend/E (E/P:Log10) curve from ascii input "inputname" into a TGraph // with LineColor "color", which is returned TGraph* h=0; gStyle->SetPalette(50); FILE* input=0; if(!HTool::openAscii(&input,inputname,"r")) { exit(1); } cout<<"HMdcGarReader::readMagboltzGasPrint() , Reading Gas-Print-data from MAGBOLTZ file\n"<SetMarkerStyle(29); h->SetMarkerColor(4); h->SetMarkerSize(.8); h->SetLineColor(color); HTool::closeAscii(&input); return h; } TArrayD* HMdcGarReader::readMatrix(TString inputname,Int_t& size1,Int_t& size2) { // matrix is written in linear form for 1 and 2-D // In 2-D case: matrix[x][y] is written as loop over y inside loop over x fstream input; input.open(inputname.Data(),ios::in); Char_t line[400]; Char_t Tag []=" Dimension:"; Char_t Tag1[]=" Sizes:"; Char_t Tag2[]=" CONTENTS"; Int_t dimension=0; size1=0; // first index size2=1; // second index while(1) { // reading format information if(input.eof()) break; input.getline(line, sizeof(line)); if (!strncmp(line, Tag ,strlen(Tag))) { sscanf(line,"%*s%i",&dimension); } if (!strncmp(line, Tag1 ,strlen(Tag1))) { if(dimension==1) sscanf(line,"%*s%i" ,&size1); if(dimension==2) sscanf(line,"%*s%i%i",&size1,&size2); } if (!strncmp(line, Tag2 ,strlen(Tag2))) { // end of format information break; } } TArrayD* array=new TArrayD(size1*size2); cout<<"Dimension of array: "<>(*array)[count]; if(dimension==1)cout<<"point : "<SetBinContent(i+1,(*array)[i]); } delete array; return h; } TH2F* HMdcGarReader::readMatrix2DToHist(TString inputname,Float_t binsize1,Float_t start1,Float_t binsize2,Float_t start2) { Int_t size1,size2; TArrayD* array=readMatrix(inputname,size1,size2); // creating hist name from input file TString histname=inputname; if(histname.Contains("/")==1) { // do not use path names histname.Replace(0,inputname.Last('/')+1,"",0); } if(histname.Contains(".")==1) { // skip file extensions histname.Replace(histname.First('.'),histname.Sizeof(),"",0); } TH2F* h=new TH2F(histname.Data(),"",size1,start1,start1+binsize1*size1,size2,start2,start2+binsize2*size2); cout<<"Input file : "<SetBinContent(i+1,j+1,(*array)[j*size1+i]); } } delete array; return h; } TH1F* HMdcGarReader::readHist1D(TString inputname,Float_t scale,Float_t scalex) { fstream input; input.open(inputname.Data(),ios::in); Char_t line[400]; Char_t Tag []=" Minimum:"; Char_t Tag1[]=" Maximum:"; Char_t Tag2[]=" Bins:"; Char_t Tag3[]=" CONTENTS"; Float_t xmin=0; Float_t xmax=0; Int_t bins=0; while(1) { // reading format information if(input.eof()) break; input.getline(line, sizeof(line)); if (!strncmp(line, Tag ,strlen(Tag))) { // minimum range sscanf(line,"%*s%f",&xmin); } if (!strncmp(line, Tag1 ,strlen(Tag1))) { // maximum range sscanf(line,"%*s%f",&xmax); } if (!strncmp(line, Tag2 ,strlen(Tag2))) { // number of bins sscanf(line,"%*s%i",&bins); } if (!strncmp(line, Tag3 ,strlen(Tag2))) { // end of format information break; } } xmin=scalex*xmin; xmax=scalex*xmax; // creating hist name from input file TString histname=inputname; if(histname.Contains("/")==1) { // do not use path names histname.Replace(0,inputname.Last('/')+1,"",0); } if(histname.Contains(".")==1) { // skip file extensions histname.Replace(histname.First('.'),histname.Sizeof(),"",0); } TH1F* h=new TH1F(histname.Data(),"",bins,xmin,xmax); cout<<"Input file : "<SetBinContent(binnumber,content); cout<<"bin "<Scale(scale); input.close(); return h; } TH1F* HMdcGarReader::readHist1D(TString inputname1,TString inputname2,Float_t scale,Float_t scalex) { cout<<"Reading data points:"<GetNbinsX();i++){ h->SetBinError(i+1,herr->GetBinError(i+1)); } herr->Delete(); return h; } TGraph* HMdcGarReader::readHist1DToGraph(TString inputname1,Float_t scale,Float_t scalex) { cout<<"Reading data points:"<GetXaxis()->GetXmax() - h->GetXaxis()->GetXmin())/(Float_t)(h->GetNbinsX()-1)); for(Int_t i=0;iGetNbinsX();i++){ g->SetPoint (i,(i+1)*binstep,h ->GetBinContent(i+1)); } h ->Delete(); return g; } TGraphErrors* HMdcGarReader::readHist1DToGraph(TString inputname1,TString inputname2,Float_t scale,Float_t scalex) { cout<<"Reading data points:"<GetXaxis()->GetXmax() - h->GetXaxis()->GetXmin())/(Float_t)(h->GetNbinsX()-1)); for(Int_t i=0;iGetNbinsX();i++){ g->SetPoint (i,(i+1)*binstep,h ->GetBinContent(i+1)); g->SetPointError(i,0,herr->GetBinContent(i+1)); } h ->Delete(); herr->Delete(); return g; } TObjArray* HMdcGarReader::readSignal(TString inputName,Int_t nbins,Double_t xmin,Double_t xmax,Int_t version) { FILE* inputAscii = fopen(inputName.Data(),"r"); if (inputAscii == NULL) { ::Error("HMdcGarSignalReader::readInput()","Cannot open %s\n",inputName.Data()); exit(1); } cout<<"HMdcGarSignalReader::readInput() : Reading from "<SetXTitle("drift time [ns]"); hsignal->SetYTitle("current [#mu A]"); array->Add(hsignal); Bool_t res=kTRUE; while(!feof(inputAscii)) { // end of file condition //--------------------------------- search first value --------------------------- while(1) { if(feof(inputAscii)) break; res=fgets(line, sizeof(line), inputAscii); if(!res) cout<<"could not read next line!"<SetBinContent(bin,f_current); bin++; } //-------------------------------------------------------------------------------- } else { signalcount++; condition=kFALSE; if (version==704) condition=kTRUE; else if (version==708&&((signalcount)%2==0))condition=kTRUE; if(condition) { sigcount++; // new signal found cout<<"creating hist "<< sigcount<SetXTitle("drift time [ns]"); hsignal->SetYTitle("current [#mu A]"); array->Add(hsignal); bin = 0; } break; } } } //---------------- very last signal of the file ---------------------------------- return array; } TGraph* HMdcGarReader::readGraphE(TString inputName,TString dir,Float_t min,Float_t max,Int_t color,Float_t scale,Bool_t suppressZero) { // inputName = file name of GARFIELD plot e // dir = x (default) coordinate along x // = y coordinate along y // min,max = (default -999999) no cut on range, otherwise collect values along coordinate between min-max // color = (default = 2) color of line/marker // scale = (default = 10) cm -> mm // suppressZero = (default = kTRUE) do not fill field==0 points FILE* inputAscii = fopen(inputName.Data(),"r"); if (inputAscii == NULL) { ::Error("HMdcGarSignalReader::readGraphE()","Cannot open %s\n",inputName.Data()); exit(1); } cout<<"HMdcGarSignalReader::readGraphE() : Reading from "<SetMarkerColor(color); g->SetLineColor(color); Bool_t res=kTRUE; while(!feof(inputAscii)) { // end of file condition //--------------------------------- search first value --------------------------- while(1) { if(feof(inputAscii)) break; res=fgets(line, sizeof(line), inputAscii); if(!res) cout<<"could not read next line!"<= min) && (max ==-999999 || f_x*scale <= max)){ g->SetPoint(bin,f_x*scale,f_e); bin++; } } else { if((min ==-999999 || f_y*scale >= min) && (max ==-999999 || f_y*scale <= max)){ g->SetPoint(bin,f_y*scale,f_e); bin++; } } } } g->Print("All"); return g; }