// Created by Paul Mullen (paulmullen66@gmail.com) August 2010 // mass_ana.C - EZCA and ROOT test macro // // An EPICS db was created to use with this example (Mass.db) // record(ai, "mass_meas"){ // field(DESC, "Measured mass") // field(PREC, "3") // } // Before running this example, start a softIoc with: // softIoc -s -m user=$USER -d Mass.db #include #include #include #include #include #include #include #include #include #include #include using namespace std; Double_t gaussian(Double_t *x, Double_t *par) { double arg = 0; if (par[2]) arg = (x[0] - par[1])/par[2]; return par[0]*TMath::Exp(-0.5*arg*arg); } int main(int argc, char **argv){ TApplication *theApp = new TApplication("MassAna", 0, NULL); gStyle->SetOptFit(); char histfile[120]; sprintf(histfile, "%s", argv[1]); printf("Opening file: %s ......... \n", histfile); TFile *hf1 = new TFile(histfile); TH1F *hist; hist = (TH1F *) hf1->Get("Mp"); // Draw histogram TCanvas *canv=new TCanvas("canv"); canv->cd(); hist->Draw(); // Fit histogram and get mean TF1 *fitfunc = new TF1("fitfunc", gaussian, 0, 3, 3); fitfunc->SetParameters(10, hist->GetMean(), hist->GetRMS()); fitfunc->SetParNames("A", "m_{meas}", "#sigma"); hist->Fit("fitfunc"); canv->Update(); double m[1]; m[0] = fitfunc->GetParameter(1); //Get a description of the variable we are going to set char desc[100]; ezcaGet("mass_meas.DESC", ezcaString, 1, desc); printf("\nSetting '%s' to %5.3f in EPICS\n", desc, m[0]); ezcaPut("mass_meas.VAL", ezcaDouble, 1, m); theApp->Run(); return 0; }