newly added

This commit is contained in:
nemu 2008-02-15 09:14:53 +00:00
parent 5ab34c0ab1
commit 39fafe825a
4 changed files with 306 additions and 6 deletions

91
src/Makefile.musrparam Normal file
View File

@ -0,0 +1,91 @@
#---------------------------------------------------
# Makefile.musrparam
#
# Author: Andreas Suter
# e-mail: andreas.suter@psi.ch
#
# $Id$
#---------------------------------------------------
#---------------------------------------------------
# get compilation and library flags from root-config
ROOTCFLAGS = $(shell $(ROOTSYS)/bin/root-config --cflags)
ROOTLIBS = $(shell $(ROOTSYS)/bin/root-config --libs)
ROOTGLIBS = $(shell $(ROOTSYS)/bin/root-config --glibs)
#---------------------------------------------------
# depending on the architecture, choose the compiler,
# linker, and the flags to use
#
OSTYPE = linux
ifeq ($(OSTYPE),linux)
OS = LINUX
endif
ifeq ($(OSTYPE),linux-gnu)
OS = LINUX
endif
ifeq ($(OSTYPE),darwin)
OS = DARWIN
endif
# -- Linux
ifeq ($(OS),LINUX)
CXX = g++
CXXFLAGS = -g -Wall -fPIC
PMUSRPATH = ./include
MNPATH = $(ROOTSYS)/include
GSLPATH = /usr/include/gsl
INCLUDES = -I $(PMUSRPATH) -I $(MNPATH) -I $(GSLPATH)
LD = g++
LDFLAGS = -g
endif
# -- Darwin
ifeq ($(OS),DARWIN)
CXX = g++
CXXFLAGS = -g -Wall -fPIC
INCLUDES = -I../include
LD = g++
LDFLAGS = -g
endif
# the output from the root-config script:
CXXFLAGS += $(ROOTCFLAGS)
LDFLAGS +=
# the ROOT libraries (G = graphic)
LIBS = $(ROOTLIBS)
GLIBS = $(ROOTGLIBS)
EXEC = musrparam
# some definitions: headers, sources, objects,...
OBJS =
OBJS += $(EXEC).o
# make the executable:
#
all: $(EXEC)
$(EXEC): $(OBJS)
@echo "---> Building $(EXEC) ..."
$(LD) $(OBJS) -o $(EXEC) $(LIBS)
@echo "done"
# clean up: remove all object file (and core files)
# semicolon needed to tell make there is no source
# for this target!
#
clean:; @rm -f $(OBJS)
@echo "---> removing $(OBJS)"
#
$(OBJS): %.o: %.cpp
$(CXX) $(INCLUDES) $(CXXFLAGS) -c $<
install: all
@echo "doesn't do anything yet ..."

209
src/musrparam.cpp Normal file
View File

@ -0,0 +1,209 @@
/***************************************************************************
musrparam.cpp
Author: Andreas Suter
e-mail: andreas.suter@psi.ch
$Id$
***************************************************************************/
/***************************************************************************
* Copyright (C) 2008 by Andreas Suter *
* andreas.suter@psi.ch *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
#include <TString.h>
#include <TObjArray.h>
#include <TObjString.h>
void musrparam_syntax()
{
cout << endl << "usage: musrparam <input-filename> <output-filename>";
cout << endl << " <input-filename>: file name of the control file to extract the parameters.";
cout << endl << " It has the following structure:";
cout << endl << " msr-file-name-1, temp-1";
cout << endl << " msr-file-name-2, temp-2";
cout << endl << " etc.";
cout << endl << " It is allowed to add comment lines which start with '%'";
cout << endl;
cout << endl << " <output-filename>: file name of the generated output file";
cout << endl << " The output will have the structure:";
cout << endl << " msr-file-name-1, temp-1, par1, err_par1, par2, err_par2, par3, err_par3, ... ";
cout << endl << " msr-file-name-2, temp-2, par1, err_par1, par2, err_par2, par3, err_par3, ... ";
cout << endl << " etc.";
cout << endl << " If positive and negative errors are present, it will be par1, err_par1-, err_par1+, etc.";
cout << endl << endl;
}
int main(int argc, char *argv[])
{
if (argc != 3) {
musrparam_syntax();
return -1;
}
TString inputFln(argv[1]);
TString outputFln(argv[2]);
vector<TString> param;
// open input file for read
ifstream fin;
fin.open(inputFln.Data(), iostream::in);
if (!fin.is_open()) {
cout << endl << "**ERROR** Couldn't open input file " << inputFln.Data() << " will quit.";
cout << endl << endl;
return -1;
}
// read file
int lineNo = 0;
char str[256];
TString tstr;
TString paramStr;
TObjArray *tokens;
TObjString *ostr;
ifstream fmsr;
while (!fin.eof()) {
// read a line
fin.getline(str, sizeof(str));
lineNo++;
// check if only a comment or empty line
if ((str[0] == '%') || strlen(str) == 0)
continue;
// tokenize string
tstr = TString(str);
tokens = tstr.Tokenize(" ,;\t");
// check if there are two elements, namely msr-file-name, temp
if (tokens->GetEntries() != 2) {
cout << endl << "**ERROR** in line " << lineNo << ". Found " << tokens->GetEntries() << " tokens instead of 2, will quit.";
cout << endl << endl;
fin.close();
return -1;
}
// keep msr-file name and temperature
paramStr = TString(str) + TString(", ");
// open msr-file
ostr = dynamic_cast<TObjString*>(tokens->At(0));
fmsr.open(ostr->GetString().Data(), iostream::in);
if (!fmsr.is_open()) {
cout << endl << "**ERROR** Couldn't open msr file " << ostr->GetString().Data() << " will quit.";
cout << endl << endl;
fin.close();
return -1;
}
// read msr-file relevant parts
bool fitParamFound = false;
bool done = false;
TString msrLine;
TObjArray *msrTokens;
TObjString *msrOstr;
while (!fmsr.eof() && !done) {
// read a line
fmsr.getline(str, sizeof(str));
msrLine = TString(str);
if (msrLine.Contains("FITPARAMETER")) {
fitParamFound = true;
continue;
}
if (fitParamFound) {
if (msrLine.BeginsWith("#")) // comment
continue;
if (msrLine.IsWhitespace()) { // end if FTIPARAMETER block
done = true;
continue;
}
// get parameters and errors
msrTokens = msrLine.Tokenize(" \t");
if (msrTokens->GetEntries() < 4) { // not enough tokens: no name value error
cout << endl << "**ERROR** Found " << tokens->GetEntries() << " tokens only (in " << ostr->GetString().Data() << "), will quit.";
cout << endl << endl;
fmsr.close();
fin.close();
return -1;
}
// keep parameter value
msrOstr = dynamic_cast<TObjString*>(msrTokens->At(2));
paramStr += msrOstr->GetString();
paramStr += TString(", ");
// keep parameter error/neg. error
msrOstr = dynamic_cast<TObjString*>(msrTokens->At(3));
paramStr += msrOstr->GetString();
paramStr += TString(", ");
if (msrTokens->GetEntries() >= 5) { // check for positive errors
msrOstr = dynamic_cast<TObjString*>(msrTokens->At(4));
if (msrOstr->GetString().IsFloat()) {
paramStr += msrOstr->GetString();
paramStr += TString(", ");
}
}
// clean up
if (msrTokens) {
delete msrTokens;
msrTokens = 0;
}
}
}
fmsr.close();
paramStr.Remove(TString::kTrailing, ' ');
paramStr.Remove(TString::kTrailing, ',');
param.push_back(paramStr);
// clean up
if (tokens) {
delete tokens;
tokens = 0;
}
}
fin.close();
// open output file for write
ofstream fout;
fout.open(outputFln.Data(), iostream::out);
if (!fout.is_open()) {
cout << endl << "**ERROR** Couldn't open output file " << outputFln.Data() << " will quit.";
cout << endl << endl;
return -1;
}
for (UInt_t i=0; i<param.size(); i++) {
fout << param[i] << endl;
}
fout.close();
// clean up
param.clear();
return 0;
}

View File

@ -16,9 +16,9 @@ asym, 0.26, 0.26, 0.26, 0.26
phase, 0.0, 90.0, 180.0, 270.0
#------------------------------------------------------
# N0's
N0, 1100, 1000, 1020, 990
N0, 110, 100, 102, 99
#------------------------------------------------------
# bkg's
bkg, 12, 10, 15, 8
bkg, 2, 1, 2, 3
#------------------------------------------------------
# end

View File

@ -29,11 +29,11 @@ void skewedGaussian()
FILE *fp;
char fln[256];
strcpy(fln, "skewedGauss.dat");
const Double_t B0 = 100.0; // (G)
const Double_t sm = 2.0; // (G)
const Double_t sp = 10.0; // (G)
const Double_t sm = 4.0; // (G)
const Double_t sp = 5.0; // (G)
sprintf(fln, "skewedGauss-B%0.2lf-sm%0.2lf-sp%0.2lf.dat", B0, sm, sp);
const Int_t noOfPoints = 1000;