From 8d90a07f10d5c13de6df13124644c3c6e9ae06e5 Mon Sep 17 00:00:00 2001 From: deserevi <deserevi@nptool> Date: Wed, 12 Jan 2011 21:05:53 +0000 Subject: [PATCH] * First commit for the W1 (Micron) detector + TW1Data.{h,cxx} class is finalized + TW1Physics.{h,cxx} class compiles but is not working --- NPLib/W1/Makefile | 308 ++++++++++++++++++++++++++ NPLib/W1/TW1Data.cxx | 87 ++++++++ NPLib/W1/TW1Data.h | 110 +++++++++ NPLib/W1/TW1Physics.cxx | 478 ++++++++++++++++++++++++++++++++++++++++ NPLib/W1/TW1Physics.h | 120 ++++++++++ 5 files changed, 1103 insertions(+) create mode 100644 NPLib/W1/Makefile create mode 100644 NPLib/W1/TW1Data.cxx create mode 100644 NPLib/W1/TW1Data.h create mode 100644 NPLib/W1/TW1Physics.cxx create mode 100644 NPLib/W1/TW1Physics.h diff --git a/NPLib/W1/Makefile b/NPLib/W1/Makefile new file mode 100644 index 000000000..200ef4a91 --- /dev/null +++ b/NPLib/W1/Makefile @@ -0,0 +1,308 @@ +# Makefile for the ROOT test programs. +# This Makefile shows nicely how to compile and link applications +# using the ROOT libraries on all supported platforms. +# +# Copyright (c) 2000 Rene Brun and Fons Rademakers +# +# Author: Fons Rademakers, 29/2/2000 + +ROOTCONFIG := root-config + +ARCH := $(shell $(ROOTCONFIG) --arch) +PLATFORM := $(shell $(ROOTCONFIG) --platform) +ALTCC := $(shell $(ROOTCONFIG) --cc) +ALTCXX := $(shell $(ROOTCONFIG) --cxx) +ALTF77 := $(shell $(ROOTCONFIG) --f77) +ALTLD := $(shell $(ROOTCONFIG) --ld) + +#CXX = +ObjSuf = o +SrcSuf = cxx +ExeSuf = +DllSuf = so +OutPutOpt = -o # keep whitespace after "-o" + +ifeq (debug,$(findstring debug,$(ROOTBUILD))) +OPT = -g +OPT2 = -g +else +ifneq ($(findstring debug, $(strip $(shell $(ROOTCONFIG) --config))),) +OPT = -g +OPT2 = -g +else +OPT = -O +OPT2 = -O2 +endif +endif + +ROOTCFLAGS := $(shell $(ROOTCONFIG) --cflags) +ROOTLDFLAGS := $(shell $(ROOTCONFIG) --ldflags) +ROOTLIBS := $(shell $(ROOTCONFIG) --libs) +ROOTGLIBS := $(shell $(ROOTCONFIG) --glibs) +HASTHREAD := $(shell $(ROOTCONFIG) --has-thread) +ROOTDICTTYPE := $(shell $(ROOTCONFIG) --dicttype) +ROOTCINT := rootcint + +ifeq ($(ARCH),linux) +# Linux with egcs, gcc 2.9x, gcc 3.x +CXX = g++ +CXXFLAGS = $(OPT2) -Wall -fPIC +LD = g++ +LDFLAGS = $(OPT2) +SOFLAGS = -shared +endif + +ifeq ($(ARCH),linuxkcc) +# Linux with the KAI compiler +CXX = KCC --one_instantiation_per_object +CXXFLAGS = $(OPT) -fPIC +K0 +LD = KCC +LDFLAGS = $(OPT) $(shell $(ROOTCONFIG) --cflags) +SOFLAGS = +endif + +ifeq ($(ARCH),linuxicc) +# Linux with Intel icc compiler +ICC_MAJOR := $(shell icc -v 2>&1 | awk '{ if (NR==1) print $$2 }' | \ + cut -d'.' -f1) +ICC_MINOR := $(shell icc -v 2>&1 | awk '{ if (NR==1) print $$2 }' | \ + cut -d'.' -f2) +CXX = icc +CXXFLAGS = $(OPT) -fPIC -wd1476 +LD = icpc +LDFLAGS = $(OPT) +SOFLAGS = -shared +endif + +ifeq ($(ARCH),linuxppcgcc) +# PPC Linux with gcc and glibc +CXX = g++ +CXXFLAGS = $(OPT2) -Wall -fPIC +LD = g++ +LDFLAGS = $(OPT2) +SOFLAGS = -shared +endif + +ifeq ($(ARCH),linuxia64gcc) +# Itanium Linux with gcc 2.9x +CXX = g++ +CXXFLAGS = $(OPT2) -Wall -fPIC +LD = g++ +LDFLAGS = $(OPT2) +SOFLAGS = -shared +endif + +ifeq ($(ARCH),linuxia64sgi) +# Itanium Linux with sgiCC +CXX = sgiCC +CXXFLAGS = $(OPT) -Wall -fPIC +LD = gsgiCC +LDFLAGS = $(OPT) +SOFLAGS = -shared +endif + +ifeq ($(ARCH),linuxia64ecc) +# Itanium Linux with Intel icc (was ecc) +ICC_MAJOR := $(shell icc -v 2>&1 | awk '{ if (NR==1) print $$2 }' | \ + cut -d'.' -f1) +ICC_MINOR := $(shell icc -v 2>&1 | awk '{ if (NR==1) print $$2 }' | \ + cut -d'.' -f2) +CXX = icc +CXXFLAGS = $(OPT) -fPIC -wd1476 -ftz +LD = icpc +LDFLAGS = $(OPT) +SOFLAGS = -shared +endif + +ifeq ($(ARCH),linuxx8664gcc) +# AMD Opteron and Intel EM64T (64 bit mode) Linux with gcc 3.x +CXX = g++ +CXXFLAGS = $(OPT2) -Wall -fPIC +LD = g++ +LDFLAGS = $(OPT2) +SOFLAGS = -shared +endif + +ifeq ($(ARCH),linuxppc64gcc) +# PPC64 Linux with gcc 3.x +CXX = g++ +CXXFLAGS = $(OPT) -Wall -fPIC +LD = g++ +LDFLAGS = $(OPT) +SOFLAGS = -shared +endif + +ifeq ($(ARCH),linuxx8664icc) +# AMD Opteron and Intel EM64T (64 bit mode) Linux with Intel icc compiler +CXX = icc +CXXFLAGS = $(OPT) -fPIC -wd1476 -wd1572 +LD = icpc +LDFLAGS = $(OPT) +SOFLAGS = -shared +endif + +ifeq ($(ARCH),linuxalphagcc) +# Alpha Linux with gcc +CXX = g++ +CXXFLAGS = $(OPT2) -Wall -fPIC +LD = g++ +LDFLAGS = $(OPT2) +SOFLAGS = -shared +endif + +ifeq ($(ARCH),linuxmips) +# GNU/Linux on mips (BE/LE, O32/N32/N64) with gcc +CXX = g++ +CXXFLAGS = $(OPT2) -Wall -fPIC +LD = g++ +LDFLAGS = $(OPT2) +SOFLAGS = -shared +endif + +ifeq ($(ARCH),linuxhppa) +# GNU/Linux on hppa with gcc +CXX = g++ +CXXFLAGS = $(OPT2) -Wall -fPIC +LD = g++ +LDFLAGS = $(OPT2) +SOFLAGS = -shared +endif + +ifeq ($(ARCH),linuxarm) +# ARM Linux with egcs +CXX = g++ +CXXFLAGS = $(OPT) -Wall -fPIC +LD = g++ +LDFLAGS = $(OPT) +SOFLAGS = -shared +endif + +ifeq ($(ARCH),macosx) +# MacOS X with cc (GNU cc 2.95.2 and gcc 3.3) +MACOSX_MINOR := $(shell sw_vers | sed -n 's/ProductVersion://p' | cut -d . -f 2) +MACOSXTARGET := MACOSX_DEPLOYMENT_TARGET=10.$(MACOSX_MINOR) +CXX = g++ +CXXFLAGS = $(OPT2) -pipe -Wall -W -Woverloaded-virtual +LD = $(MACOSXTARGET) g++ +LDFLAGS = $(OPT2) -bind_at_load +# The SOFLAGS will be used to create the .dylib, +# the .so will be created separately +ifeq ($(subst $(MACOSX_MINOR),,1234),1234) +DllSuf = so +else +DllSuf = dylib +endif +UNDEFOPT = dynamic_lookup +ifneq ($(subst $(MACOSX_MINOR),,12),12) +UNDEFOPT = suppress +LD = g++ +endif +SOFLAGS = -dynamiclib -single_module -undefined $(UNDEFOPT) +endif + +ifeq ($(ARCH),macosxicc) +# MacOS X with Intel icc compiler +MACOSX_MINOR := $(shell sw_vers | sed -n 's/ProductVersion://p' | cut -d . -f 2) +MACOSXTARGET := MACOSX_DEPLOYMENT_TARGET=10.$(MACOSX_MINOR) +ifeq ($(MACOSX_MINOR),5) +MACOSX_MINOR := 4 +endif +CXX = icc +CXXFLAGS = $(OPT) -fPIC -wd1476 +LD = $(MACOSXTARGET) icpc +LDFLAGS = $(OPT) +# The SOFLAGS will be used to create the .dylib, +# the .so will be created separately +ifeq ($(subst $(MACOSX_MINOR),,1234),1234) +DllSuf = so +else +DllSuf = dylib +endif +SOFLAGS = -dynamiclib -single_module -undefined dynamic_lookup +endif + +ifeq ($(ARCH),macosx64) +# MacOS X >= 10.4 with gcc 64 bit mode (GNU gcc 4.*) +# Only specific option (-m64) comes from root-config +MACOSX_MINOR := $(shell sw_vers | sed -n 's/ProductVersion://p' | cut -d . -f 2) +MACOSXTARGET := MACOSX_DEPLOYMENT_TARGET=10.$(MACOSX_MINOR) +CXX = g++ +CXXFLAGS = $(OPT2) -pipe -Wall -W -Woverloaded-virtual +LD = $(MACOSXTARGET) g++ -m64 +LDFLAGS = $(OPT2) -bind_at_load +# The SOFLAGS will be used to create the .dylib, +# the .so will be created separately +ifeq ($(subst $(MACOSX_MINOR),,1234),1234) +DllSuf = so +else +DllSuf = dylib +endif +SOFLAGS = -m64 -dynamiclib -single_module -undefined dynamic_lookup +endif + +ifeq ($(ARCH),macosxxlc) +# MacOS X with IBM xlC compiler +MACOSX_MINOR := $(shell sw_vers | sed -n 's/ProductVersion://p' | cut -d . -f 2) +MACOSXTARGET := MACOSX_DEPLOYMENT_TARGET=10.$(MACOSX_MINOR) +CXX = xlC +CXXFLAGS = $(OPT) +LD = $(MACOSXTARGET) xlC +LDFLAGS = $(OPT) -Wl,-bind_at_load +# The SOFLAGS will be used to create the .dylib, +# the .so will be created separately +DllSuf = dylib +UNDEFOPT = dynamic_lookup +ifneq ($(subst $(MACOSX_MINOR),,12),12) +UNDEFOPT = suppress +LD = xlC +endif +SOFLAGS = -qmkshrobj -single_module -undefined $(UNDEFOPT) +endif + +CXXFLAGS += $(ROOTCFLAGS) +LDFLAGS += $(ROOTLDFLAGS) +LIBS = $(ROOTLIBS) $(SYSLIBS) +GLIBS = $(ROOTGLIBS) $(SYSLIBS) + +INCLUDE = -I$(CLHEP_BASE_DIR)/include -I$(NPLIB)/include + +#------------------------------------------------------------------------------ +SHARELIB = libW1Data.so libW1Physics.so + +all: $(SHARELIB) +#------------------------------------------------------------------------------ +############### Detector ############## + +## W1 ## +libW1Data.so: TW1Data.o TW1DataDict.o + $(LD) $(SOFLAGS) $^ $(OutPutOpt) $@ + +TW1DataDict.cxx: TW1Data.h + rootcint -f $@ -c $^ + +libW1Physics.so: TW1Physics.o TW1PhysicsDict.o + $(LD) $(SOFLAGS) $^ $(OutPutOpt) $@ + +TW1PhysicsDict.cxx: TW1Physics.h + rootcint -f $@ -c $^ + +# dependances +TW1Data.o: TW1Data.cxx TW1Data.h +TW1Physics.o: TW1Physics.cxx TW1Physics.h +####################################### + +############# Clean and More ########## +clean: + @rm -f core *~ *.o *Dict* + +distclean: + make clean; rm -f *.so + +.SUFFIXES: .$(SrcSuf) + +### + +.$(SrcSuf).$(ObjSuf): + $(CXX) $(CXXFLAGS) $(INCLUDE) -c $< + + diff --git a/NPLib/W1/TW1Data.cxx b/NPLib/W1/TW1Data.cxx new file mode 100644 index 000000000..71c31c7bd --- /dev/null +++ b/NPLib/W1/TW1Data.cxx @@ -0,0 +1,87 @@ +/***************************************************************************** + * Copyright (C) 2009-2010 this file is part of the NPTool Project * + * * + * For the licensing terms see $NPTOOL/Licence/NPTool_Licence * + * For the list of contributors see $NPTOOL/Licence/Contributors * + *****************************************************************************/ + +/***************************************************************************** + * Original Author: N. de Sereville contact address: deserevi@ipno.in2p3.fr * + * * + * Creation Date : january 2011 * + * Last update : * + *---------------------------------------------------------------------------* + * Decription: * + * This class holds the raw data storage for the W1 detector from Micron * + * * + *---------------------------------------------------------------------------* + * Comment: * + * * + * * + *****************************************************************************/ +#include <iostream> +using namespace std; + +#include "TW1Data.h" + +ClassImp(TW1Data) + +TW1Data::TW1Data() +{ + // Default constructor + Clear(); +} + + + +TW1Data::~TW1Data() +{ +} + + + +void TW1Data::Clear() +{ + // (Front, E) + fW1_FrontE_DetectorNbr.clear(); + fW1_FrontE_StripNbr.clear(); + fW1_FrontE_Energy.clear(); + // (Front, T) + fW1_FrontT_DetectorNbr.clear(); + fW1_FrontT_StripNbr.clear(); + fW1_FrontT_Time.clear(); + + // (Back, E) + fW1_BackE_DetectorNbr.clear(); + fW1_BackE_StripNbr.clear(); + fW1_BackE_Energy.clear(); + // (Back, T) + fW1_BackT_DetectorNbr.clear(); + fW1_BackT_StripNbr.clear(); + fW1_BackT_Time.clear(); +} + + + +void TW1Data::Dump() const +{ + cout << "XXXXXXXXXXXXXXXXXXXXXXXX New Event [TW1Data::Dump()] XXXXXXXXXXXXXXXXX" << endl; + + // (Front, E) + cout << "W1_FrontE_Mult = " << fW1_FrontE_DetectorNbr.size() << endl; + for (UShort_t i = 0; i < fW1_FrontE_DetectorNbr.size(); i++) + cout << "DetNbr: " << fW1_FrontE_DetectorNbr[i] << " Strip: " << fW1_FrontE_StripNbr[i] << " Energy: " << fW1_FrontE_Energy[i] << endl; + // (Front, T) + cout << "W1_FrontT_Mult = " << fW1_FrontT_DetectorNbr.size() << endl; + for (UShort_t i = 0; i < fW1_FrontT_DetectorNbr.size(); i++) + cout << "DetNbr: " << fW1_FrontT_DetectorNbr[i] << " Strip: " << fW1_FrontT_StripNbr[i] << " Energy: " << fW1_FrontT_Time[i] << endl; + + // (Back, E) + cout << "W1_BackE_Mult = " << fW1_BackE_DetectorNbr.size() << endl; + for (UShort_t i = 0; i < fW1_BackE_DetectorNbr.size(); i++) + cout << "DetNbr: " << fW1_BackE_DetectorNbr[i] << " Strip: " << fW1_BackE_StripNbr[i] << " Energy: " << fW1_BackE_Energy[i] << endl; + // (Back, T) + cout << "W1_BackT_Mult = " << fW1_BackT_DetectorNbr.size() << endl; + for (UShort_t i = 0; i < fW1_BackT_DetectorNbr.size(); i++) + cout << "DetNbr: " << fW1_BackT_DetectorNbr[i] << " Strip: " << fW1_BackT_StripNbr[i] << " Energy: " << fW1_BackT_Time[i] << endl; +} diff --git a/NPLib/W1/TW1Data.h b/NPLib/W1/TW1Data.h new file mode 100644 index 000000000..77074b401 --- /dev/null +++ b/NPLib/W1/TW1Data.h @@ -0,0 +1,110 @@ +#ifndef __W1DATA__ +#define __W1DATA__ +/***************************************************************************** + * Copyright (C) 2009-2010 this file is part of the NPTool Project * + * * + * For the licensing terms see $NPTOOL/Licence/NPTool_Licence * + * For the list of contributors see $NPTOOL/Licence/Contributors * + *****************************************************************************/ + +/***************************************************************************** + * Original Author: N. de Sereville contact address: deserevi@ipno.in2p3.fr * + * * + * Creation Date : january 2011 * + * Last update : * + *---------------------------------------------------------------------------* + * Decription: * + * This class holds the raw data storage for the W1 detector from Micron * + * * + *---------------------------------------------------------------------------* + * Comment: * + * * + * * + *****************************************************************************/ +// C++ headers +#include <vector> + +// ROOT headers +#include "TObject.h" + +using namespace std ; +class TW1Data : public TObject +{ + private: + // Front + // Energy + vector<UShort_t> fW1_FrontE_DetectorNbr; + vector<UShort_t> fW1_FrontE_StripNbr; + vector<Double_t> fW1_FrontE_Energy; + // Time + vector<UShort_t> fW1_FrontT_DetectorNbr; + vector<UShort_t> fW1_FrontT_StripNbr; + vector<Double_t> fW1_FrontT_Time; + + // Back + // Energy + vector<UShort_t> fW1_BackE_DetectorNbr; + vector<UShort_t> fW1_BackE_StripNbr; + vector<Double_t> fW1_BackE_Energy; + // Time + vector<UShort_t> fW1_BackT_DetectorNbr; + vector<UShort_t> fW1_BackT_StripNbr; + vector<Double_t> fW1_BackT_Time; + + + public: + TW1Data(); + virtual ~TW1Data(); + + void Clear(); + void Clear(const Option_t*) {}; + void Dump() const; + + ///////////////////// SETTERS //////////////////////// + // DSSD + // (Front, E) + void SetW1FrontEDetectorNbr(UShort_t DetNbr) {fW1_FrontE_DetectorNbr.push_back(DetNbr);} + void SetW1FrontEStripNbr(UShort_t StripNbr) {fW1_FrontE_StripNbr.push_back(StripNbr);} + void SetW1FrontEEnergy(Double_t Energy) {fW1_FrontE_Energy.push_back(Energy);} + // (Front, T) + void SetW1FrontTDetectorNbr(UShort_t DetNbr) {fW1_FrontT_DetectorNbr.push_back(DetNbr);} + void SetW1FrontTStripNbr(UShort_t StripNbr) {fW1_FrontT_StripNbr.push_back(StripNbr);} + void SetW1FrontTTime(Double_t Time) {fW1_FrontT_Time.push_back(Time);} + + // (Back, E) + void SetW1BackEDetectorNbr(UShort_t DetNbr) {fW1_BackE_DetectorNbr.push_back(DetNbr);} + void SetW1BackEStripNbr(UShort_t StripNbr) {fW1_BackE_StripNbr.push_back(StripNbr);} + void SetW1BackEEnergy(Double_t Energy) {fW1_BackE_Energy.push_back(Energy);} + // (Back, T) + void SetW1BackTDetectorNbr(UShort_t DetNbr) {fW1_BackT_DetectorNbr.push_back(DetNbr);} + void SetW1BackTStripNbr(UShort_t StripNbr) {fW1_BackT_StripNbr.push_back(StripNbr);} + void SetW1BackTTime(Double_t Time) {fW1_BackT_Time.push_back(Time);} + + ///////////////////// GETTERS //////////////////////// + // DSSD + // (Front, E) + UShort_t GetW1FrontEMult() {return fW1_FrontE_DetectorNbr.size();} + UShort_t GetW1FrontEDetectorNbr(Int_t i) {return fW1_FrontE_DetectorNbr.at(i);} + UShort_t GetW1FrontEStripNbr(Int_t i) {return fW1_FrontE_StripNbr.at(i);} + Double_t GetW1FrontEEnergy(Int_t i) {return fW1_FrontE_Energy.at(i);} + // (Front, T) + UShort_t GetW1FrontTMult() {return fW1_FrontT_DetectorNbr.size();} + UShort_t GetW1FrontTDetectorNbr(Int_t i) {return fW1_FrontT_DetectorNbr.at(i);} + UShort_t GetW1FrontTStripNbr(Int_t i) {return fW1_FrontT_StripNbr.at(i);} + Double_t GetW1FrontTTime(Int_t i) {return fW1_FrontT_Time.at(i);} + + // (Back, E) + UShort_t GetW1BackEMult() {return fW1_BackE_DetectorNbr.size();} + UShort_t GetW1BackEDetectorNbr(Int_t i) {return fW1_BackE_DetectorNbr.at(i);} + UShort_t GetW1BackEStripNbr(Int_t i) {return fW1_BackE_StripNbr.at(i);} + Double_t GetW1BackEEnergy(Int_t i) {return fW1_BackE_Energy.at(i);} + // (Back, T) + UShort_t GetW1BackTMult() {return fW1_BackT_DetectorNbr.size();} + UShort_t GetW1BackTDetectorNbr(Int_t i) {return fW1_BackT_DetectorNbr.at(i);} + UShort_t GetW1BackTStripNbr(Int_t i) {return fW1_BackT_StripNbr.at(i);} + Double_t GetW1BackTTime(Int_t i) {return fW1_BackT_Time.at(i);} + + ClassDef(TW1Data, 1) // TW1Data raw data +}; + +#endif diff --git a/NPLib/W1/TW1Physics.cxx b/NPLib/W1/TW1Physics.cxx new file mode 100644 index 000000000..042cbbf7f --- /dev/null +++ b/NPLib/W1/TW1Physics.cxx @@ -0,0 +1,478 @@ +/***************************************************************************** + * Copyright (C) 2009-2010 this file is part of the NPTool Project * + * * + * For the licensing terms see $NPTOOL/Licence/NPTool_Licence * + * For the list of contributors see $NPTOOL/Licence/Contributors * + *****************************************************************************/ + +/***************************************************************************** + * Original Author: Adrien MATTA contact address: matta@ipno.in2p3.fr * + * * + * Creation Date : november 2009 * + * Last update : * + *---------------------------------------------------------------------------* + * Decription: * + * This class hold W1 Physics * + * * + *---------------------------------------------------------------------------* + * Comment: * + * * + * * + *****************************************************************************/ +// NPL +#include "TW1Physics.h" +#include "RootOutput.h" +#include "RootInput.h" + +// STL +#include <iostream> +#include <sstream> +#include <fstream> +#include <limits> +#include <stdlib.h> +using namespace std; +using namespace LOCAL; +// ROOT +#include "TChain.h" + +// tranform an integer to a string +string itoa(int value) +{ + std::ostringstream o; + + if (!(o << value)) return ""; + + return o.str(); +} + + + +ClassImp(TW1Physics) +/////////////////////////////////////////////////////////////////////////// +TW1Physics::TW1Physics() + : m_NumberOfDetector(0), + m_EventData(new TW1Data), + m_PreTreatedData(new TW1Data), + m_EventPhysics(this), + m_E_Threshold(0), + m_Pedestal_Threshold(0) +{ +} + + + +/////////////////////////////////////////////////////////////////////////// +TW1Physics::~TW1Physics() +{ +} + + + +/////////////////////////////////////////////////////////////////////////// +void TW1Physics::Clear() +{ + DetectorNumber .clear() ; + StripNumber .clear() ; + Energy .clear() ; + Time .clear() ; +} + + + +/////////////////////////////////////////////////////////////////////////// +void TW1Physics::ReadConfiguration(string Path) + { + ifstream ConfigFile ; + ConfigFile.open(Path.c_str()) ; + string LineBuffer ; + string DataBuffer ; + + double TLX , BLX , BRX , TRX , TLY , BLY , BRY , TRY , TLZ , BLZ , BRZ , TRZ ; + double Theta = 0 , Phi = 0 , R = 0 , beta_u = 0 , beta_v = 0 , beta_w = 0 ; + bool check_A = false ; + bool check_B = false ; + bool check_C = false ; + bool check_D = false ; + + bool check_Theta = false ; + bool check_Phi = false ; + bool check_R = false ; + bool check_beta = false ; + bool ReadingStatus = false ; + + while (!ConfigFile.eof()) + { + + getline(ConfigFile, LineBuffer); + + // If line is a Start Up ThinSi bloc, Reading toggle to true + if (LineBuffer.compare(0, 6, "ThinSi") == 0) + { + cout << "Detector found: " << endl ; + ReadingStatus = true ; + } + + // Else don't toggle to Reading Block Status + else ReadingStatus = false ; + + // Reading Block + while(ReadingStatus) + { + // Pickup Next Word + ConfigFile >> DataBuffer ; + + // Comment Line + if (DataBuffer.compare(0, 1, "%") == 0) { ConfigFile.ignore ( std::numeric_limits<std::streamsize>::max(), '\n' );} + + // Finding another telescope (safety), toggle out + else if (DataBuffer.compare(0, 6, "ThinSi") == 0) { + cout << "WARNING: Another Telescope is find before standard sequence of Token, Error may occured in Telecope definition" << endl ; + ReadingStatus = false ; + } + + //Position method + else if (DataBuffer.compare(0, 3, "A=") == 0) { + check_A = true; + ConfigFile >> DataBuffer ; + TLX = atof(DataBuffer.c_str()) ; + ConfigFile >> DataBuffer ; + TLY = atof(DataBuffer.c_str()) ; + ConfigFile >> DataBuffer ; + TLZ = atof(DataBuffer.c_str()) ; + + } + + else if (DataBuffer.compare(0, 3, "B=") == 0) { + check_B = true; + ConfigFile >> DataBuffer ; + BLX = atof(DataBuffer.c_str()) ; + ConfigFile >> DataBuffer ; + BLY = atof(DataBuffer.c_str()) ; + ConfigFile >> DataBuffer ; + BLZ = atof(DataBuffer.c_str()) ; + + } + + else if (DataBuffer.compare(0, 3, "C=") == 0) { + check_C = true; + ConfigFile >> DataBuffer ; + BRX = atof(DataBuffer.c_str()) ; + ConfigFile >> DataBuffer ; + BRY = atof(DataBuffer.c_str()) ; + ConfigFile >> DataBuffer ; + BRZ = atof(DataBuffer.c_str()) ; + + } + + else if (DataBuffer.compare(0, 3, "D=") == 0) { + check_D = true; + ConfigFile >> DataBuffer ; + TRX = atof(DataBuffer.c_str()) ; + ConfigFile >> DataBuffer ; + TRY = atof(DataBuffer.c_str()) ; + ConfigFile >> DataBuffer ; + TRZ = atof(DataBuffer.c_str()) ; + + } + + + //Angle method + else if (DataBuffer.compare(0, 6, "THETA=") == 0) { + check_Theta = true; + ConfigFile >> DataBuffer ; + Theta = atof(DataBuffer.c_str()) ; + } + + else if (DataBuffer.compare(0, 4, "PHI=") == 0) { + check_Phi = true; + ConfigFile >> DataBuffer ; + Phi = atof(DataBuffer.c_str()) ; + } + + else if (DataBuffer.compare(0, 2, "R=") == 0) { + check_R = true; + ConfigFile >> DataBuffer ; + R = atof(DataBuffer.c_str()) ; + } + + + else if (DataBuffer.compare(0, 5, "BETA=") == 0) { + check_beta = true; + ConfigFile >> DataBuffer ; + beta_u = atof(DataBuffer.c_str()) ; + ConfigFile >> DataBuffer ; + beta_v = atof(DataBuffer.c_str()) ; + ConfigFile >> DataBuffer ; + beta_w = atof(DataBuffer.c_str()) ; + } + + /////////////////////////////////////////////////// + // If no Detector Token and no comment, toggle out + else + {ReadingStatus = false; cout << "Wrong Token Sequence: Getting out " << DataBuffer << endl ;} + + ///////////////////////////////////////////////// + // If All necessary information there, toggle out + + if ( (check_A && check_B && check_C && check_D) || (check_Theta && check_Phi && check_R && check_beta) ) + { + ReadingStatus = false; + + ///Add The previously define telescope + //With position method + if ((check_A && check_B && check_C && check_D) || !(check_Theta && check_Phi && check_R)) { + m_NumberOfDetector++; + } + + //with angle method + else if ((check_Theta && check_Phi && check_R) || !(check_A && check_B && check_C && check_D)) { + m_NumberOfDetector++; + } + + // Reinitialisation of Check Boolean + + check_A = false ; + check_B = false ; + check_C = false ; + check_D = false ; + + check_Theta = false ; + check_Phi = false ; + check_R = false ; + check_beta = false ; + ReadingStatus = false ; + + } + + } + } + + InitializeStandardParameter() ; + ReadAnalysisConfig() ; +} + + +/////////////////////////////////////////////////////////////////////////// +void TW1Physics::AddParameterToCalibrationManager() +{ + CalibrationManager* Cal = CalibrationManager::getInstance(); + + for (int i = 0; i < m_NumberOfDetector; i++) { + for (int j = 0; j < 16; j++) { + Cal->AddParameter("W1", "Detector"+itoa(i+1)+"_Strip"+itoa(j+1)+"_E","W1_DETECTOR_"+itoa(i+1)+"_STRIP_"+itoa(j+1)+"_E") ; + Cal->AddParameter("W1", "Detector"+itoa(i+1)+"_Strip"+itoa(j+1)+"_T","W1_DETECTOR_"+itoa(i+1)+"_STRIP_"+itoa(j+1)+"_T") ; + } + } +} + + + +/////////////////////////////////////////////////////////////////////////// +void TW1Physics::InitializeRootInput() +{ + TChain* inputChain = RootInput::getInstance()->GetChain(); + inputChain->SetBranchStatus("W1" , true); + inputChain->SetBranchStatus("fW1_*", true); + inputChain->SetBranchAddress("W1" , &m_EventData); +} + + + +/////////////////////////////////////////////////////////////////////////// +void TW1Physics::InitializeRootOutput() +{ + TTree* outputTree = RootOutput::getInstance()->GetTree(); + outputTree->Branch("W1", "TW1Physics", &m_EventPhysics); +} + + + +/////////////////////////////////////////////////////////////////////////// +void TW1Physics::BuildPhysicalEvent() +{ + BuildSimplePhysicalEvent(); +} + + + +/////////////////////////////////////////////////////////////////////////// +void TW1Physics::BuildSimplePhysicalEvent() +{ + PreTreat(); +/* + for (unsigned int i = 0; i < m_PreTreatedData->GetEnergyMult(); i++) { + DetectorNumber .push_back( m_PreTreatedData->GetEnergyDetectorNbr(i) ); + StripNumber .push_back( m_PreTreatedData->GetEnergyStripNbr(i) ); + Energy .push_back( m_PreTreatedData->GetEnergy(i) ); + // Look For associate Time + for (unsigned int j = 0; j < m_PreTreatedData->GetTimeMult(); j++) { + if (m_PreTreatedData->GetEnergyDetectorNbr(i) == m_PreTreatedData->GetTimeDetectorNbr(j) && m_PreTreatedData->GetEnergyStripNbr(i)==m_PreTreatedData->GetTimeStripNbr(j)) + Time.push_back(m_PreTreatedData->GetTime(j)); + } + } + */ + return; +} + + + +/////////////////////////////////////////////////////////////////////////// +void TW1Physics::PreTreat() +{ + ClearPreTreatedData(); + + // (Front, E) + for (int i = 0; i < m_EventData->GetW1FrontEMult(); i++) { + if (ChannelStatus[m_EventData->GetW1FrontEDetectorNbr(i)][m_EventData->GetW1FrontEStripNbr(i)]) { + double E = fSi_E(m_EventData , i); + if (E > m_E_Threshold && m_EventData->GetW1FrontEEnergy(i) > m_Pedestal_Threshold) { + m_PreTreatedData->SetW1FrontEDetectorNbr(m_EventData->GetW1FrontEDetectorNbr(i)); + m_PreTreatedData->SetW1FrontEStripNbr(m_EventData->GetW1FrontEStripNbr(i)); + m_PreTreatedData->SetW1FrontEEnergy(E); + } + } + } + // (Front, T) + for (int i = 0; i < m_EventData->GetW1FrontTMult(); i++) { + if (ChannelStatus[m_EventData->GetW1FrontTDetectorNbr(i)][m_EventData->GetW1FrontTStripNbr(i)]) { + double T = fSi_T(m_EventData , i); + m_PreTreatedData->SetW1FrontTDetectorNbr(m_EventData->GetW1FrontTDetectorNbr(i)); + m_PreTreatedData->SetW1FrontTStripNbr(m_EventData->GetW1FrontTStripNbr(i)); + m_PreTreatedData->SetW1FrontTTime(T); + } + } + + // (Back, E) + for (int i = 0; i < m_EventData->GetW1BackEMult(); i++) { + if (ChannelStatus[m_EventData->GetW1BackEDetectorNbr(i)][m_EventData->GetW1BackEStripNbr(i)]) { + double E = fSi_E(m_EventData , i); + if (E > m_E_Threshold && m_EventData->GetW1BackEEnergy(i) > m_Pedestal_Threshold) { + m_PreTreatedData->SetW1BackEDetectorNbr(m_EventData->GetW1BackEDetectorNbr(i)); + m_PreTreatedData->SetW1BackEStripNbr(m_EventData->GetW1BackEStripNbr(i)); + m_PreTreatedData->SetW1BackEEnergy(E); + } + } + } + // (Back, T) + for (int i = 0; i < m_EventData->GetW1BackTMult(); i++) { + if (ChannelStatus[m_EventData->GetW1BackTDetectorNbr(i)][m_EventData->GetW1BackTStripNbr(i)]) { + double T = fSi_T(m_EventData , i); + m_PreTreatedData->SetW1BackTDetectorNbr(m_EventData->GetW1BackTDetectorNbr(i)); + m_PreTreatedData->SetW1BackTStripNbr(m_EventData->GetW1BackTStripNbr(i)); + m_PreTreatedData->SetW1BackTTime(T); + } + } +} + + + +/////////////////////////////////////////////////////////////////////////// +void TW1Physics::InitializeStandardParameter() +{ + // Enable all channels + vector<bool> TempChannelStatus; + ChannelStatus.clear(); + TempChannelStatus.resize(16,true); + for (int i = 0; i < m_NumberOfDetector; i ++) ChannelStatus[i+1] = TempChannelStatus; +} + + + +/////////////////////////////////////////////////////////////////////////// +void TW1Physics::ReadAnalysisConfig() +{ + bool ReadingStatus = false; + + // path to file + string FileName = "./configs/ConfigW1.dat"; + + // open analysis config file + ifstream AnalysisConfigFile; + AnalysisConfigFile.open(FileName.c_str()); + + if (!AnalysisConfigFile.is_open()) { + cout << " No ConfigMust2.dat found: Default parameter loaded for Analayis " << FileName << endl; + return; + } + cout << " Loading user parameter for Analysis from ConfigW1.dat " << endl; + + // read analysis config file + string LineBuffer,DataBuffer; + while (!AnalysisConfigFile.eof()) { + // Pick-up next line + getline(AnalysisConfigFile, LineBuffer); + + // search for "header" + if (LineBuffer.compare(0, 11, "ConfigW1") == 0) ReadingStatus = true; + + // loop on tokens and data + while (ReadingStatus) { + AnalysisConfigFile >> DataBuffer; + + // Search for comment symbol (%) + if (DataBuffer.compare(0, 1, "%") == 0) { + AnalysisConfigFile.ignore(numeric_limits<streamsize>::max(), '\n' ); + } + + else if (DataBuffer.compare(0, 18, "PEDESTAL_THRESHOLD") == 0) { + AnalysisConfigFile >> DataBuffer; + m_Pedestal_Threshold = atoi(DataBuffer.c_str() ); + cout << "Pedestal threshold = " << m_Pedestal_Threshold << endl; + } + + else if (DataBuffer.compare(0, 4, "W1") == 0) { + AnalysisConfigFile >> DataBuffer; + string whatToDo = DataBuffer; + if (whatToDo.compare(0, 11, "DISABLE_ALL") == 0) { + AnalysisConfigFile >> DataBuffer; + cout << whatToDo << " " << DataBuffer << endl; + int Detector = atoi(DataBuffer.substr(2,1).c_str()); + vector< bool > ChannelStatusBuffer; + ChannelStatusBuffer.resize(16,false); + ChannelStatus[Detector] = ChannelStatusBuffer; + } + + else if (whatToDo.compare(0, 15, "DISABLE_CHANNEL") == 0) { + AnalysisConfigFile >> DataBuffer; + cout << whatToDo << " " << DataBuffer << endl; + int telescope = atoi(DataBuffer.substr(2,1).c_str()); + int channel = -1; + if (DataBuffer.compare(3,3,"STR") == 0) { + channel = atoi(DataBuffer.substr(6).c_str()); + *(ChannelStatus[telescope].begin()+channel) = false; + } + + else { + cout << "Warning: detector type for Must2 unknown!" << endl; + } + } + else { + cout << "Warning: don't know what to do (lost in translation)" << endl; + } + } + else { + ReadingStatus = false; +// cout << "WARNING: Wrong Token Sequence" << endl; + } + } + } +} + + + +/////////////////////////////////////////////////////////////////////////// +double LOCAL::fSi_E( TW1Data* m_EventData , int i ) +{ + return CalibrationManager::getInstance()->ApplyCalibration( "W1/Detector" + itoa( m_EventData->GetW1FrontEDetectorNbr(i) ) + "_Strip" + itoa( m_EventData->GetW1FrontEStripNbr(i) ) +"_E", + m_EventData->GetW1FrontEEnergy(i) ); +} + + +double LOCAL::fSi_T( TW1Data* m_EventData , int i ) +{ + return CalibrationManager::getInstance()->ApplyCalibration( "W1/Detector" + itoa( m_EventData->GetW1FrontEDetectorNbr(i) ) + "_Strip" + itoa( m_EventData->GetW1FrontEStripNbr(i) ) +"_T", + m_EventData->GetW1FrontTTime(i) ); +} + + + diff --git a/NPLib/W1/TW1Physics.h b/NPLib/W1/TW1Physics.h new file mode 100644 index 000000000..424d87236 --- /dev/null +++ b/NPLib/W1/TW1Physics.h @@ -0,0 +1,120 @@ +#ifndef __W1Physics__ +#define __W1Physics__ +/***************************************************************************** + * Copyright (C) 2009-2010 this file is part of the NPTool Project * + * * + * For the licensing terms see $NPTOOL/Licence/NPTool_Licence * + * For the list of contributors see $NPTOOL/Licence/Contributors * + *****************************************************************************/ + +/***************************************************************************** + * Original Author: N. de Sereville contact address: deserevi@ipno.in2p3.fr * + * * + * Creation Date : january 2011 * + * Last update : * + *---------------------------------------------------------------------------* + * Decription: * + * This class holds the physics class for the W1 detector from Micron * + * * + *---------------------------------------------------------------------------* + * Comment: * + * * + * * + *****************************************************************************/ +// STL +#include <vector> +using namespace std ; + +// ROOT +#include "TObject.h" + +// NPL +#include "TW1Data.h" +#include "../include/VDetector.h" +#include "../include/CalibrationManager.h" + + +class TW1Physics : public TObject, public NPA::VDetector +{ + public: // Constructor and Destructor + TW1Physics(); + ~TW1Physics(); + + public: // Calibrated Data + vector<UShort_t> DetectorNumber; + vector<UShort_t> StripNumber; + vector<Double_t> Energy; + vector<Double_t> Time; + + public: // inherrited from VDetector + // Read stream at ConfigFile to pick-up parameters of detector (Position,...) using Token + void ReadConfiguration(string); + + // Add Parameter to the CalibrationManger + void AddParameterToCalibrationManager(); + + // Activated associated Branches and link it to the private member DetectorData address + // In this method mother Branches (Detector) AND daughter leaf (fDetector_parameter) have to be activated + void InitializeRootInput(); + + // Create associated branches and associated private member DetectorPhysics address + void InitializeRootOutput(); + + // This method is called at each event read from the Input Tree. Aime is to build treat Raw dat in order to extract physical parameter. + void BuildPhysicalEvent(); + + // Same as above, but only the simplest event and/or simple method are used (low multiplicity, faster algorythm but less efficient ...). + // This method aimed to be used for analysis performed during experiment, when speed is requiered. + // NB: This method can eventually be the same as BuildPhysicalEvent. + void BuildSimplePhysicalEvent(); + + // Those two method all to clear the Event Physics or Data + void ClearEventPhysics() {Clear();} + void ClearEventData() {m_EventData->Clear();} + + + public: // Specific to W1 + // Clear The PreTeated object + void ClearPreTreatedData() {m_PreTreatedData->Clear();} + + // Remove bad channel, calibrate the data and apply threshold + void PreTreat(); + + // Initialize the standard parameter for analysis + // ie: all channel enable, maximum multiplicity for strip = number of telescope + void InitializeStandardParameter(); + + // Read the user configuration file; if no file found, load standard one + void ReadAnalysisConfig(); + + + private: // Data not written in the tree + int m_NumberOfDetector; //! + TW1Data* m_EventData; //! + TW1Data* m_PreTreatedData; //! + TW1Physics* m_EventPhysics; //! + + double m_E_Threshold; //! + double m_Pedestal_Threshold; //! + + + private: // Map of activated Channel + map< int, vector<bool> > ChannelStatus; //! + + public: // Return True if the channel is activated + // bool IsValidChannel(int DetectorNbr, int StripNbr) ; + + void Clear(); + void Clear(const Option_t*) {}; + + ClassDef(TW1Physics,1) // TW1Physics +}; + + +namespace LOCAL +{ + double fSi_E( TW1Data* EventData , int i ); + double fSi_T( TW1Data* EventData , int i ); +} + +#endif -- GitLab