initial skeleton of musrt0, not functional yet

This commit is contained in:
nemu 2009-03-25 08:08:48 +00:00
parent ba229f022e
commit 4cb6aa2ec9
6 changed files with 666 additions and 0 deletions

102
src/Makefile.musrt0 Normal file
View File

@ -0,0 +1,102 @@
#---------------------------------------------------
# Makefile.musrt0
#
# 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)
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) -lXMLParser
GLIBS = $(ROOTGLIBS) -lXMLParser
# PSI libs
PSILIBS = -lTLemRunHeader -lPMusr
# Minuit2 lib
MNLIB = -L$(ROOTSYS)/lib -lMinuit2
# MathMore lib
MMLIB = -L$(ROOTSYS)/lib -lMathMore
INSTALLPATH = $(HOME)/analysis/bin
EXEC = musrt0
# some definitions: headers, sources, objects,...
OBJS =
OBJS += $(EXEC).o
# make the executable:
#
all: $(EXEC)
$(EXEC): $(OBJS)
@echo "---> Building $(EXEC) ..."
/bin/rm -f $(SHLIB)
$(LD) $(OBJS) -o $(EXEC) $(GLIBS) $(PSILIBS) $(MNLIB) $(MMLIB)
@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 "copy $(EXEC) to $(INSTALLPATH)"
cp -p $(EXEC) $(INSTALLPATH)

View File

@ -101,6 +101,7 @@ OBJS += PFitter.o
OBJS += PMusrCanvas.o PMusrCanvasDict.o
OBJS += PUserFcnBase.o PUserFcnBaseDict.o
OBJS += PFourier.o
OBJS += PMusrT0.o PMusrT0Dict.o
EXTOBJS =
EXTOBJS += MuSR_td_PSI_bin.o
@ -139,6 +140,10 @@ PMusrCanvasDict.cpp: ../include/PMusrCanvas.h ../include/PMusrCanvasLinkDef.h
@echo "Generating dictionary $@..."
rootcint -v -f $@ -c -p $^
PMusrT0Dict.cpp: ../include/PMusrT0.h ../include/PMusrT0LinkDef.h
@echo "Generating dictionary $@..."
rootcint -v -f $@ -c -p $^
PUserFcnBaseDict.cpp: ../include/PUserFcnBase.h ../include/PUserFcnBaseLinkDef.h
@echo "Generating dictionary $@..."
rootcint -v -f $@ -c -p $^

139
src/classes/PMusrT0.cpp Normal file
View File

@ -0,0 +1,139 @@
/***************************************************************************
PMusrT0.cpp
Author: Andreas Suter
e-mail: andreas.suter@psi.ch
$Id$
***************************************************************************/
/***************************************************************************
* Copyright (C) 2009 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>
using namespace std;
#include <TColor.h>
#include <TRandom.h>
#include <TROOT.h>
#include <TObjString.h>
#include "PMusrT0.h"
ClassImpQ(PMusrT0)
//--------------------------------------------------------------------------
// Constructor
//--------------------------------------------------------------------------
/**
*
*/
PMusrT0::PMusrT0()
{
}
//--------------------------------------------------------------------------
// Constructor
//--------------------------------------------------------------------------
/**
*
* \param rawRunData
* \param histoNo
*/
PMusrT0::PMusrT0(PRawRunData *rawRunData, unsigned int histoNo)
{
}
//--------------------------------------------------------------------------
// Destructor
//--------------------------------------------------------------------------
/**
*
*/
PMusrT0::~PMusrT0()
{
}
//--------------------------------------------------------------------------
// Done (SIGNAL)
//--------------------------------------------------------------------------
/**
* <p>
*
*/
void PMusrT0::Done(Int_t status)
{
Emit("Done(Int_t)", status);
}
//--------------------------------------------------------------------------
// HandleCmdKey (SLOT)
//--------------------------------------------------------------------------
/**
* <p>
*
*/
void PMusrT0::HandleCmdKey(Int_t event, Int_t x, Int_t y, TObject *selected)
{
if (event != kKeyPress)
return;
// cout << ">this " << this << endl;
// cout << ">fMainCanvas " << fMainCanvas << endl;
// cout << ">selected " << selected << endl;
//
//cout << "x : " << (char)x << endl;
//cout << "px: " << (char)fMainCanvas->GetEventX() << endl;
// handle keys and popup menu entries
if (x == 'q') { // quit
Done(0);
} else if (x == 'u') { // unzoom to the original range
cout << endl << "will unzoom ..." << endl;
} else if (x == 't') { // set t0 channel
cout << endl << "will set t0 channel ..." << endl;
} else if (x == 'b') { // set first background channel
cout << endl << "will set first background channel ..." << endl;
} else if (x == 'B') { // set last background channel
cout << endl << "will set last background channel ..." << endl;
} else if (x == 'd') { // set first data channel
cout << endl << "will set first data channel ..." << endl;
} else if (x == 'D') { // set last data channel
cout << endl << "will set last data channel ..." << endl;
}
}
//--------------------------------------------------------------------------
// HandleMenuPopup (SLOT)
//--------------------------------------------------------------------------
/**
* <p>
*
*/
void PMusrT0::HandleMenuPopup(Int_t id)
{
}
//--------------------------------------------------------------------------
// END
//--------------------------------------------------------------------------

65
src/include/PMusrT0.h Normal file
View File

@ -0,0 +1,65 @@
/***************************************************************************
PMusrT0.h
Author: Andreas Suter
e-mail: andreas.suter@psi.ch
$Id$
***************************************************************************/
/***************************************************************************
* Copyright (C) 2009 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. *
***************************************************************************/
#ifndef _PMUSRT0_H_
#define _PMUSRT0_H_
#include <TObject.h>
#include <TQObject.h>
#include <TStyle.h>
#include <TRootCanvas.h>
#include <TGMenu.h>
#include <TCanvas.h>
#include "PMusr.h"
//--------------------------------------------------------------------------
/**
* <p>The preprocessor tag __MAKECINT__ is used to hide away from rootcint
* the overly complex spirit header files.
*/
class PMusrT0 : public TObject, public TQObject
{
public:
PMusrT0();
PMusrT0(PRawRunData *rawRunData, unsigned int histoNo);
virtual ~PMusrT0();
private:
virtual void Done(Int_t status=0); // *SIGNAL*
virtual void HandleCmdKey(Int_t event, Int_t x, Int_t y, TObject *selected); // SLOT
virtual void HandleMenuPopup(Int_t id); // SLOT
ClassDef(PMusrT0, 1)
};
#endif // _PMUSRT0_H_

View File

@ -0,0 +1,41 @@
/***************************************************************************
PMusrT0LinkDef.h
Author: Andreas Suter
e-mail: andreas.suter@psi.ch
$Id$
***************************************************************************/
/***************************************************************************
* Copyright (C) 2007 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. *
***************************************************************************/
#ifdef __CINT__
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ class PMusrT0+;
#endif

314
src/musrt0.cpp Normal file
View File

@ -0,0 +1,314 @@
/***************************************************************************
musrt0.cpp
Author: Andreas Suter
e-mail: andreas.suter@psi.ch
$Id$
***************************************************************************/
/***************************************************************************
* Copyright (C) 2007 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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
using namespace std;
#include <TApplication.h>
#include <TSAXParser.h>
#include <TROOT.h>
#include "PMusr.h"
#include "PStartupHandler.h"
#include "PMsrHandler.h"
#include "PRunDataHandler.h"
#include "PMusrT0.h"
//--------------------------------------------------------------------------
/**
* <p>
*
*/
void musrt0_syntax()
{
cout << endl << "usage: musrt0 <msr-file> | --version | --help";
cout << endl << " <msr-file>: msr/mlog input file";
cout << endl << " 'musrt0 <msr-file>' will execute musrt0";
cout << endl << " 'musrt0' or 'musrt0 --help' will show this help";
cout << endl << " 'musrt0 --version' will print the musrt0 version";
cout << endl << endl;
}
//--------------------------------------------------------------------------
int main(int argc, char *argv[])
{
bool show_syntax = false;
int status;
bool success = true;
switch (argc) {
case 1:
show_syntax = true;
break;
case 2:
if (strstr(argv[1], "--version")) {
cout << endl << "musrt0 version: $Id$";
cout << endl << endl;
return PMUSR_SUCCESS;
} else if (strstr(argv[1], "--help")) {
show_syntax = true;
} else {
// check if filename has extension msr or mlog
if (!strstr(argv[1], ".msr") && !strstr(argv[1], ".mlog")) {
cout << endl << "**ERROR** " << argv[1] << " is not a msr/mlog-file!" << endl;
show_syntax = true;
}
}
break;
default:
show_syntax = true;
}
if (show_syntax) {
musrt0_syntax();
return PMUSR_WRONG_STARTUP_SYNTAX;
}
// get default path (for the moment only linux like)
char *pmusrpath;
char musrpath[128];
pmusrpath = getenv("MUSRFITPATH");
if (pmusrpath == 0) { // not set, will try default one
strcpy(musrpath, "/home/nemu/analysis/bin");
cout << endl << "**WARNING** MUSRFITPATH environment variable not set will try " << musrpath << endl;
} else {
strncpy(musrpath, pmusrpath, sizeof(musrpath));
}
// read startup file
char startup_path_name[128];
sprintf(startup_path_name, "%s/musrfit_startup.xml", musrpath);
TSAXParser *saxParser = new TSAXParser();
PStartupHandler *startupHandler = new PStartupHandler();
saxParser->ConnectToHandler("PStartupHandler", startupHandler);
status = saxParser->ParseFile(startup_path_name);
// check for parse errors
if (status) { // error
cout << endl << "**WARNING** reading/parsing musrfit_startup.xml failed.";
cout << endl;
/*
// clean up
if (saxParser) {
delete saxParser;
saxParser = 0;
}
if (startupHandler) {
delete startupHandler;
startupHandler = 0;
}
*/
}
startupHandler->CheckLists();
// read msr-file
PMsrHandler *msrHandler = new PMsrHandler(argv[1]);
status = msrHandler->ReadMsrFile();
if (status != PMUSR_SUCCESS) {
switch (status) {
case PMUSR_MSR_FILE_NOT_FOUND:
cout << endl << "**ERROR** couldn't find '" << argv[1] << "'" << endl << endl;
break;
case PMUSR_MSR_SYNTAX_ERROR:
cout << endl << "**SYNTAX ERROR** in file " << argv[1] << ", full stop here." << endl << endl;
break;
default:
cout << endl << "**UNKNOWN ERROR** when trying to read the msr-file" << endl << endl;
break;
}
return status;
}
// check if the fittype is not NonMusr
PMsrRunList *runList = msrHandler->GetMsrRunList();
for (unsigned int i=0; i<runList->size(); i++) {
if (runList->at(i).fFitType == MSR_FITTYPE_NON_MUSR) {
cout << endl << "**ERROR** t0 setting for NonMusr fittype doesn't make any sense, will quit ..." << endl;
success = false;
break;
}
}
// read all the necessary runs (raw data)
PRunDataHandler *dataHandler;
if (success) {
if (startupHandler)
dataHandler = new PRunDataHandler(msrHandler, startupHandler->GetDataPathList());
else
dataHandler = new PRunDataHandler(msrHandler);
success = dataHandler->IsAllDataAvailable();
if (!success) {
cout << endl << "**ERROR** Couldn't read all data files, will quit ..." << endl;
}
}
vector<PMusrT0*> t0Vector;
if (success) {
/*
// generate Root application needed for PMusrCanvas
TApplication app("App", &argc, argv);
*/
// generate vector of all necessary PMusrT0 objects
PMusrT0 *musrT0;
for (unsigned int i=0; i<runList->size(); i++) {
switch (runList->at(i).fFitType) {
case MSR_FITTYPE_SINGLE_HISTO:
for (unsigned int j=0; j<runList->at(i).fRunName.size(); j++) { // necessary in case of ADDRUN
musrT0 = new PMusrT0(dataHandler->GetRunData(runList->at(i).fRunName[j]), runList->at(i).fForwardHistoNo);
t0Vector.push_back(musrT0);
}
break;
case MSR_FITTYPE_ASYM:
for (unsigned int j=0; j<runList->at(i).fRunName.size(); j++) { // necessary in case of ADDRUN
musrT0 = new PMusrT0(dataHandler->GetRunData(runList->at(i).fRunName[j]), runList->at(i).fForwardHistoNo);
t0Vector.push_back(musrT0);
musrT0 = new PMusrT0(dataHandler->GetRunData(runList->at(i).fRunName[j]), runList->at(i).fBackwardHistoNo);
t0Vector.push_back(musrT0);
}
break;
case MSR_FITTYPE_ASYM_RRF:
for (unsigned int j=0; j<runList->at(i).fRunName.size(); j++) { // necessary in case of ADDRUN
musrT0 = new PMusrT0(dataHandler->GetRunData(runList->at(i).fRunName[j]), runList->at(i).fForwardHistoNo);
t0Vector.push_back(musrT0);
musrT0 = new PMusrT0(dataHandler->GetRunData(runList->at(i).fRunName[j]), runList->at(i).fBackwardHistoNo);
t0Vector.push_back(musrT0);
musrT0 = new PMusrT0(dataHandler->GetRunData(runList->at(i).fRunName[j]), runList->at(i).fRightHistoNo);
t0Vector.push_back(musrT0);
musrT0 = new PMusrT0(dataHandler->GetRunData(runList->at(i).fRunName[j]), runList->at(i).fLeftHistoNo);
t0Vector.push_back(musrT0);
}
break;
default:
break;
}
}
/*
vector<PMusrT0*> t0CanvasVector;
PMusrT0 *t0Canvas;
bool ok = true;
for (unsigned int i=0; i<msrHandler->GetMsrPlotList()->size(); i++) {
if (startupHandler)
musrCanvas = new PMusrCanvas(i, msrHandler->GetMsrTitle()->Data(),
10+i*100, 10+i*100, 800, 600,
startupHandler->GetFourierDefaults(),
startupHandler->GetMarkerList(),
startupHandler->GetColorList());
else
musrCanvas = new PMusrCanvas(i, msrHandler->GetMsrTitle()->Data(),
10+i*100, 10+i*100, 800, 600);
if (!musrCanvas->IsValid()) {
cout << endl << "**SEVERE ERROR** Couldn't invoke all necessary objects, will quit.";
cout << endl;
ok = false;
break;
}
// connect signal/slot
TQObject::Connect("TCanvas", "Closed()", "PMusrCanvas", musrCanvas, "LastCanvasClosed()");
// ugly but rootcint cannot handle the spirit-parser framework
musrCanvas->SetMsrHandler(msrHandler);
musrCanvas->SetRunListCollection(runListCollection);
if (!musrCanvas->IsValid()) { // something went wrong
ok = false;
break;
}
musrCanvas->Connect("Done(Int_t)", "TApplication", &app, "Terminate(Int_t)");
// keep musrCanvas objects
canvasVector.push_back(musrCanvas);
}
// check that everything is ok
if (ok)
app.Run(true); // true needed that Run will return after quit so that cleanup works
// clean up
cout << endl << "clean up canvas vector ...";
char canvasName[32];
for (unsigned int i=0; i<canvasVector.size(); i++) {
// check if canvas is still there before calling the destructor **TO BE DONE**
sprintf(canvasName, "fMainCanvas%d", i);
cout << endl << ">> canvasName=" << canvasName << ", canvasVector[" << i << "]=" << canvasVector[i];
if (gROOT->GetListOfCanvases()->FindObject(canvasName) != 0) {
cout << endl << ">> canvasName=" << canvasName << ", found ...";
cout << endl;
canvasVector[i]->~PMusrCanvas();
} else {
cout << endl << ">> canvasName=" << canvasName << ", NOT found ...";
cout << endl;
}
}
canvasVector.empty();
*/
}
cout << endl;
// clean up
if (saxParser) {
delete saxParser;
saxParser = 0;
}
if (startupHandler) {
delete startupHandler;
startupHandler = 0;
}
if (msrHandler) {
delete msrHandler;
msrHandler = 0;
}
if (dataHandler) {
delete dataHandler;
dataHandler = 0;
}
if (t0Vector.size() > 0) {
for (unsigned int i=0; i<t0Vector.size(); i++) {
if (t0Vector[i] != 0) {
delete t0Vector[i];
t0Vector[i] = 0;
}
}
t0Vector.clear();
}
return 0;
}