Code Monkey home page Code Monkey logo

hcana's Introduction

hcana - Hall C ROOT/C++ analyzer

hcana is an under-development tool to analyze data from the HMS, SHMS and SOS spectrometers in Hall C at JLab. It is being developed to replace the historical Hall C analyzer, ENGINE, which was written in Fortran. hcana will be the package used to analyze Hall C date in the 12 GeV era. hcana is being written in C++, using the CERN ROOT framework. hcana is an extension to the Hall A analyzer, PODD.

NOTE: In the process of retrieving the hcana source code, a copy of the Hall A PODD package will be downloaded. The version of PODD included has been slightly modified for use with hcana. For an official version of PODD, see the ROOT/C++ Analyzer for Hall A page.

Downloading

Instructions for downloading hcana can be found in the Hall C Wiki.

Compiling

hcana may be compiled with either make or scons. Switching between these two build systems make require some cleanup of dependency files, binary files and other autogenerated files.

Before compiling, type source setup.sh or source setup.csh depending on whether your shell is bash or csh.

Compiling with scons

scons

Additional SCons features

To do the equivalent of "make clean", do scons -c To compile with debug capabilities, do scons debug=1 To compile the standalone codes the are part of podd, do scons standalone=1 To run cppcheck (if installed) on the Hall C src diretory, do scons cppcheck=1

Compiling with CMake (experimental)

Do the usual CMake setup

mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=$HOME/local/hcana ..
make -jN install

Here $HOME/local/hcana is an example installation destination; modify as appropriate. You will need to add the bin and lib[64] sub-directories under the installation prefix to your environment:

export PATH=$HOME/local/hcana/bin:$PATH
export LD_LIBRARY_PATH=$HOME/local/hcana/lib64:$LD_LIBRARY_PATH

On macOS, the library directory is usually simply lib instead of lib64.

CMake does not yet support the SCons features "standalone" and "cppcheck".

The default CMake build type is "RelWithDebInfo", i.e. debug symbols are included in the binaries, but the code is optimized, which may cause the debugger to act in a confusing way on occasion. To build a non-optimized debug version, run CMake as follows:

mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=$HOME/local/hcana-dbg ..
make -jN install

Compiling with make (deprecated)

make [-jN]

Running

Basic instructions on how to run hcana are in the Hall C Wiki.

Contributing

To participate in hcana code development, contact Mark Jones or Stephen Wood.

hcana's People

Contributors

ak1508 avatar brash99 avatar dhamilton-glasgow avatar dkb208 avatar hansenjo avatar hszumila avatar jltaylor avatar johnmatter avatar jurebericic avatar markkjones avatar melanierehfuss avatar mmathiso avatar pooser avatar ryan-ambrose avatar sanghwapark avatar sawatzky avatar sawjlab avatar simon-zhamkochyan avatar sjdkay avatar vardant avatar wmhenrytemple avatar xingyueguji avatar yero1990 avatar zahmed9 avatar zviwood avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hcana's Issues

Cppcheck

Add the ability to run cppcheck on the Hall C src/ directory .... perhaps with something like 'scons cppcheck=1' (much like the debug and standalone options are already implemented).

Fix Compiler Warnings

A recent build of hcana, via ROOT 6.08.00 indicates a few compiler warnings that need to be addressed:

src/THcPrimaryKine.cxx: In member function ‘virtual Int_t THcPrimaryKine::ReadDatabase(const TDatime&)’:
src/THcPrimaryKine.cxx:188:28: warning: unused variable ‘here’ [-Wunused-variable]
static const char* const here = "THcPrimaryKine::ReadDatabase";

In file included from src/THcRunParameters.h:10:0,
from src/THcRunParameters.cxx:10:
podd/src/THaRunParameters.h:21:29: warning: ‘virtual THaRunParameters& THaRunParameters::operator=(const THaRunParameters&)’ was hidden [-Woverloaded-virtual]
virtual THaRunParameters& operator=( const THaRunParameters& rhs );

In file included from src/THcRunParameters.cxx:10:0:
src/THcRunParameters.h:12:7: warning: by ‘THcRunParameters& THcRunParameters::operator=(const THcRunParameters&)’ [-Woverloaded-virtual]
class THcRunParameters : public THaRunParameters {
^
src/THcSecondaryKine.cxx: In member function ‘virtual Int_t THcSecondaryKine::ReadDatabase(const TDatime&)’:
src/THcSecondaryKine.cxx:303:1: warning: no return statement in function returning non-void [-Wreturn-type]
}

In file included from podd/src/THaBeam.h:12:0,
from src/THcRasteredBeam.h:13,
from HallCDict.C:69:
podd/src/THaRunParameters.h:21:29: warning: ‘virtual THaRunParameters& THaRunParameters::operator=(const THaRunParameters&)’ was hidden [-Woverloaded-virtual]
virtual THaRunParameters& operator=( const THaRunParameters& rhs );

In file included from HallCDict.C:76:0:
src/THcRunParameters.h:12:7: warning: by ‘THcRunParameters& THcRunParameters::operator=(const THcRunParameters&)’ [-Woverloaded-virtual]
class THcRunParameters : public THaRunParameters {

Difference in calculation of hodo fptimes between ENGINE and HCANA

Comment from Gabriel Niculescu: " Because hcana calculates fptimes separately for each plane (as it should, one would argue) the mechanism of rejecting "out-of-time" hits based on average hit times does not work as well. There is no easy fix for this but I do not anticipate this to be a problem. One can get a similar result by implementing a method of rejecting fptimes (as opposed to individual time hits) in the THcHodoscope class. This is on my "to-do" list. "

SOS tracking

The current tracking code only handles HMS chambers. Adding compatibility for the SOS chambers will get us close to what we need for the SHMS as the SOS and SHMS use chambers with the same geometry.

Where to get spectrometer setting variables from

In Podd, the THaSpectrometer class gets the spectrometer angle and momentum setting from a database file db_run.dat. As THcHallCSpectrometer inherits from THaSpectrometer, it also gets the angle and momentum from this file. The Hall C ENGINE got these values from a database file, which hcana also supports. So, right now, hcana needs to have these values defined in a Hall A style database file and in a Hall C style.

What do we do about this? We could override the THaSpectrometer::ReadRunDatabase. We would need to duplicate the geometry calculations done there.

Add config event handler for "TI setup data"

There is a (semi-)new TI config related blob in Event 125 that stores some trigger/TM related settings that needs a decoder in THcConfigEvtHandler.cxx. Runs after SHMS 1295 and HMS 718 will have blobs with the information below.

The word format is defined by this code in the hcvme0[12].c ROLs:

/* Log prescales, misc TI related information from ffile */
*rol->dabufp++ = (0xd0000000);        // 'misc' header block
*rol->dabufp++ = (0xabcd0000+1);      // last +N is version ID number
*rol->dabufp++ = nped;                //
*rol->dabufp++ = scaler_period;       //
*rol->dabufp++ = syncCnt;             //
for(i=0; i<NUM_PRESCALES; i++) {      // Input Trigger prescale settings
  *rol->dabufp++ = prescales[i];
}
*rol->dabufp++ = (0xd000000f);        // 'misc' trailer block

Beam information

Need to add class(es) for beam information, utilizing EPICS and raster information.

THcPrimaryKine W Calculation

Hi Guys,

More than an issue it's a question. How are the values for W computed? I track it down to a TLorentzVector but couldn't find the lines. Because I'm getting a bunch of 1e+38 values from the 2397 run replay at cdaql1 hcana ROOTfiles/coin_replay_production_2397_-1.root.

primkine

Time of flight calibration code

The Hall C ENGINE had an option to output certain information so that an external program could calculate the various hodoscope parameters such as time offsets, timewalk corrections etc. hcana needs the hooks to output the information needed by this external program. Ideally, this information should be able to be put in the ntuple/tree so that it can be analyzed by a root macro. Doing this will also allow one to change cuts without having to rerun the analyzer by doing the cuts in the root macro.

Source code file directories and names

It would be good to structure the source code better.

Suggestions:

  1. Put the interface headers in an include directory. This nearly all the header files I think.
  2. Put (and install) the header files in their own directory. For example include/hcana/HEADER.h.
  3. This leads to use cases like:
#include "hcana/THcParmList.h"

(note this doesn't have to happen in the current source code include directories can be added to compiler flags).

  1. This header name space then leads to clearer class names. (Using class name prefixes is old fashioned and ignores the namespace feature of C++).
#include "hcana/ParameterList.h"
  1. Clearer header file and class names leads us finally to functional separation. Perhaps by detector type: (note this is just a suggestion)
#include "hcana/cer/Cherenkov.h"
#include "hcana/cer/CherenkovHit.h"

Here is how it could look:

hcana/include
├── beam
│   ├── BCMCurrent.h
│   ├── RasteredBeam.h
│   ├── Raster.h
│   └── RasterRawHit.h
├── cer
│   ├── Aerogel.h
│   ├── AerogelHit.h
│   ├── Cherenkov.h
│   └── CherenkovHit.h
├── core
│   ├── Analyzer.h
│   ├── ConfigEvtHandler.h
│   ├── DetectorMap.h
│   ├── DummySpectrometer.h
│   ├── Formula.h
│   ├── Globals.h
│   ├── HallCSpectrometer.h
│   ├── HitList.h
│   ├── Interface.h
│   ├── ParmList.h
│   ├── PeriodicReport.h
│   ├── Run.h
│   ├── RunParameters.h
│   └── SignalHit.h
├── dc
│   ├── DC.h
│   ├── DCHit.h
│   ├── DCLookupTTDConv.h
│   ├── DCTimeToDistConv.h
│   ├── DCTrack.h
│   ├── DCWire.h
│   ├── DriftChamber.h
│   └── DriftChamberPlane.h
├── hodo
│   ├── HodoEff.h
│   ├── HodoHit.h
│   ├── Hodoscope.h
│   └── ScintillatorPlane.h
├── phys
├── raw
│   ├── RawAdcHit.h
│   ├── RawDCHit.h
│   ├── RawHit.h
│   ├── RawHodoHit.h
│   ├── RawShowerHit.h
│   └── RawTdcHit.h
├── recon
│   ├── CoinTime.h
│   ├── ExtTarCor.h
│   ├── PrimaryKine.h
│   ├── ReactionPoint.h
│   ├── SecondaryKine.h
│   └── SpacePoint.h
├── scaler
│   ├── Scaler9001.h
│   ├── Scaler9250.h
│   └── ScalerEvtHandler.h
├── shower
│   ├── ShowerArray.h
│   ├── Shower.h
│   ├── ShowerHit.h
│   └── ShowerPlane.h
└── trig
    ├── TimeSyncEvtHandler.h
    ├── TrigApp.h
    ├── TrigDet.h
    ├── TrigRawHit.h
    └── TIBlobModule.h

Again, this is just a suggestion to help others understand the code, and is common practice in C++ projects.

Eliminate compiler warnings

Eliminate or reduce the compiler warnings.

E.g.

unused variable 'x'
'x' may be used uninitialized in this function
'x' will be initialized after 'y' when initialized here
comparison between signed and unsigned integer expressions

Fixed length (53) arrays in hodoscope code

A number arrays in THcHodosope, THcScintillatorPlane, and THcHallCSpectrometer have a fixed length of 53. (53 is the number of scintillator bars in the HMS +1). The length of these arrays should be derived from the parameters.

A number of these arrays are probably for holding processed hit information. This information would better be held in a structure or class with multiple variables. The THcDCHit class for thre wire chambers might be used as an example.

Compile errors with new raster classes

On MacOSX, I get the following warnings and errors when trying to compile hcana with the new raster classes:

g++ -o src/THcRaster.os -c -O -Wall -Woverloaded-virtual -pthread -pthread -m64 -stdlib=libc++ -fPIC -fPIC -DNDEBUG -DMACVERS -DHAS_SSTREAM -DHALLC_MODS -Isrc -Ipodd/src -Ipodd/hana_decode -Ipodd/hana_scaler -I/Users/brash/Dropbox/root/include src/THcRaster.cxx
In file included from src/THcRaster.cxx:14:
src/THcRaster.h:30:42: warning: array index 2 is past the end of the array (which contains 2 elements) [-Warray-bounds]
TVector3 GetPosition() const { return fPosition[2]; }
^ ~
src/THcRaster.h:52:3: note: array 'fPosition' declared here
TVector3 fPosition[2]; // Beam position at 1st, 2nd BPM or at the target (meters)
^
src/THcRaster.cxx:61:3: error: cannot delete expression of type 'Double_t [2]'
delete [] fPedADC;
^ ~~~~~~~
src/THcRaster.cxx:62:3: error: cannot delete expression of type 'Double_t [2]'
delete [] fAvgPedADC;
^ ~~~~~~~~~~
1 warning and 2 errors generated.
scons: *** [src/THcRaster.os] Error 1
scons: building terminated because of errors.

The error traces to the THcRaster destructor ... commenting out the two delete statements allows hcana to compile, but may cause runtime errors I suppose. I wonder why fPedADC and fAvgPedADC are defined at Double_t types in the first place ...

I also note that the warning appears to be a serious one ... fPosition is indeed defined to be an array of size 2, and so in principle only fPosition[0] and fPosition[1] are meaningful.

As I don't really understand at this point any of the raster code, I won't attempt a fix ... just raising this issue for Buddhini's benefit.

Out of bounds array index in THcScalerEvtHandler

if(scaldata < scal_prev_read[nscal-1]) {

Valgrind reports and "invalid read of size 4" at this location (see below). Debugging reveals that the array index nscal is zero, causing the code to read scal_prev_read[-1]. In fact, in the test replay I am doing, run 4914 with the UTIL_KAONLT/scripts_Replay/replay_production_coin.C script, nscal is always zero at this point in the code.

Looks like a logic error.

As a temporary fix, I have changed that line to

if(nscal > 0 && scaldata < scal_prev_read[nscal-1]) {

but I doubt that that does what is intended here.

Partial output of

valgrind --suppressions=/apps/root/6.08.00/root/etc/valgrind-root.supp --leak-check=yes --track-origins=yes ./hcana -q -b .x UTIL_KAONLT/scripts_Replay/replay_production_coin.C(4914,10000)

544 errors in context 3 of 44:
==38116== Invalid read of size 4
==38116==    at 0x4FA1C8D: THcScalerEvtHandler::AnalyzeBuffer(unsigned int*, bool) (THcScalerEvtHandler.cxx:538)
==38116==    by 0x4F9F168: THcScalerEvtHandler::Analyze(THaEvData*) (THcScalerEvtHandler.cxx:234)
==38116==    by 0x53AE125: THaAnalyzer::MainAnalysis() (THaAnalyzer.cxx:1274)
==38116==    by 0x53AE984: THaAnalyzer::Process(THaRunBase*) (THaAnalyzer.cxx:1425)
==38116==  Address 0x2966cd9c is 4 bytes before a block of size 2,048 alloc'd
==38116==    at 0x4C2A1E3: operator new(unsigned long) (vg_replace_malloc.c:334)
==38116==    by 0x4FA84B1: __gnu_cxx::new_allocator<unsigned int>::allocate(unsigned long, void const*) (new_allocator.h:104)
==38116==    by 0x4FA7BCB: std::allocator_traits<std::allocator<unsigned int> >::allocate(std::allocator<unsigned int>&, unsigned long) (alloc_traits.h:360)
==38116==    by 0x4FA6A8F: std::_Vector_base<unsigned int, std::allocator<unsigned int> >::_M_allocate(unsigned long) (stl_vector.h:170)
==38116==    by 0x4FA6B8B: void std::vector<unsigned int, std::allocator<unsigned int> >::_M_emplace_back_aux<unsigned int>(unsigned int&&) (vector.tcc:412)
==38116==    by 0x4FA5C82: void std::vector<unsigned int, std::allocator<unsigned int> >::emplace_back<unsigned int>(unsigned int&&) (vector.tcc:101)
==38116==    by 0x4FA4EC3: std::vector<unsigned int, std::allocator<unsigned int> >::push_back(unsigned int&&) (stl_vector.h:932)
==38116==    by 0x4F9FF23: THcScalerEvtHandler::AnalyzeBuffer(unsigned int*, bool) (THcScalerEvtHandler.cxx:370)
==38116==    by 0x4F9F168: THcScalerEvtHandler::Analyze(THaEvData*) (THcScalerEvtHandler.cxx:234)
==38116==    by 0x53AE125: THaAnalyzer::MainAnalysis() (THaAnalyzer.cxx:1274)
==38116==    by 0x53AE984: THaAnalyzer::Process(THaRunBase*) (THaAnalyzer.cxx:1425)

SCons build error: undefined reference to `typeinfo for THcFormula'

Trying to build hcana according to instructions on the wiki. When doing

./podd/scons/scons.py debug=1 -j4

the build eventually errors out with

./libHallC.so: undefined reference to THcFormula::THcFormula(char const*, char const*, THaVarList const*, THaCutList const*)' ./libHallC.so: undefined reference totypeinfo for THcFormula'

(The same happens without any debug or -j parameters.)

Building with "make -j4" works.

Not sure if this is related to #23, which seems to be about shared library version numbers.

Please Delete the CMAKE build

@sawjlab Please just delete the cmake build. It is not worth it. The analyzer should also just remove it but Ole blocked me from filing issues on the analyzer and has totally thrown away all the effort I (and others) put into the initial PR by rewriting a cmake build in the worst way. Please just forget I even brought it up because it only breaks things for me now.

Podd update

Need to update podd to get updated code for 2D histograms DEFs.

CMake build broken

CMake Error at CMakeLists.txt:11 (include):
  include could not find load file:

    PoddCMakeEnv


CMake Error at CMakeLists.txt:20 (find_package):
  No "FindROOT.cmake" found in CMAKE_MODULE_PATH.

FindROOT.cmake should not be installed by analyzer. ROOT comes fully equipped. This is literally undoing the point of using cmake.

Problem downloading evio on cdaql1

With the changes to podd/site_scons/construct.py to use curl to download the evio library, scons
fails on cdaql1. When running curl , it can not connect to github.com .

Scons files from podd in hcana directory

Various files for building podd clutter the top hcana directory when running scons from the top hcana directory. These files include:

haDict.*
NormAnaDict.*
THaDecDict.*
THaScalDict.*

EPICS events

Figure how to handle EPICS events. The Hall A analyzer does have some code for EPICS. Need to determine if this can be reused for the way Hall C puts EPICS events into the data stream and how the analysis uses the EPICS events.

Uninitialized data in matrix multiplication in THcDC

dray = AA*TT;

Valgrind reports that some operations in the above line refer to uninitialized memory and hence will likely produce garbage results. It might the matrix AA or the vector TT, which may not even be uninitialized per se, but be initialized with values which come from function calls that retrieve uninitialized data. It's not obvious, and I haven't been able to track this down yet. It is unlikely to be false positive though, based on my experience with valgrind.

Partial output of replaying 10000 events (note: 2.8 such errors per event):

valgrind --suppressions=/apps/root/6.08.00/root/etc/valgrind-root.supp --leak-check=yes --track-origins=yes ./hcana -q -b .x UTIL_KAONLT/scripts_Replay/replay_production_coin.C(4914,10000)

28240 errors in context 4 of 44:
==38116== Conditional jump or move depends on uninitialised value(s)
==38116==    at 0x6186055: TObject::operator=(TObject const&) (TObject.cxx:107)
==38116==    by 0x83E38BD: TVectorT<double>::operator=(TVectorT<double> const&) (TVectorT.cxx:686)
==38116==    by 0x83E398B: TVectorT<double>::TVectorT(TVectorT<double> const&) (TVectorT.cxx:217)
==38116==    by 0x83E3B2F: TVectorT<double> operator*<double>(TMatrixT<double> const&, TVectorT<double> const&) (TVectorT.cxx:1436)
==38116==    by 0x4F4E082: THcDC::TrackFit() (THcDC.cxx:1011)
==38116==    by 0x4F4BBDC: THcDC::CoarseTrack(TClonesArray&) (THcDC.cxx:604)
==38116==    by 0x540281D: THaSpectrometer::CoarseTrack() (THaSpectrometer.cxx:290)
==38116==    by 0x53AD225: THaAnalyzer::PhysicsAnalysis(int) (THaAnalyzer.cxx:1098)
==38116==    by 0x53AE190: THaAnalyzer::MainAnalysis() (THaAnalyzer.cxx:1281)
==38116==    by 0x53AE984: THaAnalyzer::Process(THaRunBase*) (THaAnalyzer.cxx:1425)
==38116==  Uninitialised value was created by a stack allocation
==38116==    at 0x4F4D853: THcDC::TrackFit() (THcDC.cxx:926)

Compilation error on Mac OS X for new addition of THcHodoHit.cxx

When compiling on Mac OS X Yosemite, I get the following error:

g++ -o src/THcHodoHit.os -c -O -Wall -Woverloaded-virtual -pthread -pthread -m64 -stdlib=libc++ -fPIC -fPIC -DNDEBUG -DMACVERS -DHAS_SSTREAM -DHALLC_MODS -I/Users/brash/Dropbox/Research/analyzer-evio/evio-4.4.5/Darwin-x86_64/include -Isrc -Ipodd/src -Ipodd/hana_decode -Ipodd/hana_scaler -I/Users/brash/Dropbox/root/include src/THcHodoHit.cxx
src/THcHodoHit.cxx:18:40: error: addition of default argument on redeclaration makes this constructor a default constructor
THcHodoHit::THcHodoHit( THcRawHodoHit hit=NULL, Double_t posPed=0.0,
^ ~~~~
src/THcHodoHit.h:19:3: note: previous declaration is here
THcHodoHit( THcRawHodoHit
hit, Double_t posPed,
^
1 error generated.
scons: *** [src/THcHodoHit.os] Error 1
scons: building terminated because of errors.

If I simply remove the "=NULL" definition on *hit, it compiles without issue. I am just not sure how important this might be ... comments?

Best,
E.

Drift chamber debug flags

Modify HCANA so that it uses the same drift chamber debug parameters as ENGINE and that the printout is the same.

Update podd version

Podd version should be updated.

This would allow me to change some code to avoid core dumps when trying to read non-existing parameter using the THcParmList::LoadParmValues.

SCons command-line flags not propagated into podd build

When using any type of command-line flag for scons to build hcana, these flags are apparently not used for building the podd submodul: Example:

scons -j8 debug=1

compiles podd sources like

c++ -o src/THaADCHelicity.os -c -O -Wall -Woverloaded-virtual -Wextra -Wno-missing-field-initializers -Wno-unused-parameter -std=c++11 -m64 -pthread -rdynamic -fPIC -DNDEBUG -DLINUXVERS -DHAS_SSTREAM -I/home/ole/evio-4.4.6/Linux-x86_64/include -Isrc -Ihana_decode -I/opt/ROOT/6.10-04/include src/THaADCHelicity.C

but the hcana sources later like

g++ -o src/THcAerogel.os -c -g -O0 -Wall -Woverloaded-virtual -std=c++11 -m64 -pthread -rdynamic -fPIC -fPIC -DLINUXVERS -DHAS_SSTREAM -DHALLC_MODS -I/home/ole/evio-4.4.6/Linux-x86_64/include -Isrc -Ipodd/src -Ipodd/hana_decode -I/opt/ROOT/6.10-04/include src/THcAerogel.cxx

and the hcana build, but not the podd build, is very obviously parallelized.

scons improvements

The top SConscript.py file has a list, "hcheaders", for all the .h files in src. src/SConscript.py has a list, "list" of all the .cxx files in src. When a new class is added, both of these files must be updated. One of these lists should be automatically generated from the other.

Furthermore, it should be possible to avoid hand writing either of these lists. They could be generating from the file names of all the .cxx files in src.

Even more ideally, the file src/HallC_LinkDef.h which has a line for each class in it, could be generated automatically. If this is done, then Makefile should also be updated to autogenerate HallC_LinkDef.h and it's source code list "SRC".

Output report system

The Cebaf Test Package, used in the ENGINE, as a report system. The report system allows one to define a template for an end of run analysis Printout/Report. Everything in the template file is simply output to an output file, except that what is inside braces ({}) is evaluated as an expression. The variables in the expression could be parameters, values from the hardware scalers, or "test scalers". (A test scaler is the number of times a given test was true/passed.)

A similar report system, ideally one that can use existing report templates, should be added to hcana. It should take advantage of existing infrastructure in podd as much as possible.

Bug with basic post process usage

Below is my replay script. There is a segfault (see stacktrace below). I think this is likely a design flaw associated with the podd's use of static for the list of "post processes".
If std::cout isn't used, then there is no problem.

In addition to the class SimplePostProcess, the only other change from the source adopted from is adding the post process via

  auto* pp = new SimplePostProcess([](){ std::cout << "qwerty\n"; return 0;});
  analyzer->AddPostProcess(pp);
#include "THttpServer.h"
#include <functional>
#include <iostream>
#include <string>
 
class SimplePostProcess : public THaPostProcess {
public:
  using Function_t = std::function<int()>;
  Function_t flambda;
  SimplePostProcess(Function_t&& f) : flambda(std::forward<Function_t>(f)) { }
  //SimplePostProcess()  { }
  virtual ~SimplePostProcess(){ }

  virtual Int_t Init(const TDatime& ) {
    //std::cout << derp;
    return 0;
  }
  virtual Int_t Process( const THaEvData*, const THaRunBase*, Int_t code ){ 
    printf("asdf\n");
    flambda();
    return 0;
  }
  virtual Int_t Close(){ return 0; }
};

#if defined(__ROOTCLING__)
#pragma link C++ class SimplePostProcess+;
#pragma link C++ class std::vector<SimplePostProcess*>+;
#endif

void replay_production_all_shms (Int_t RunNumber = 0, Int_t MaxEvent = 0) {

  // Get RunNumber and MaxEvent if not provided.
  if(RunNumber == 0) {
    cout << "Enter a Run Number (-1 to exit): ";
    cin >> RunNumber;
    if( RunNumber<=0 ) return;
  }
  if(MaxEvent == 0) {
    cout << "\nNumber of Events to analyze: ";
    cin >> MaxEvent;
    if(MaxEvent == 0) {
      cerr << "...Invalid entry\n";
      exit;
    }
  }

  // Create file name patterns.
  const char* RunFileNamePattern = "shms_all_%05d.dat";
  vector<TString> pathList;
  pathList.push_back(".");
  pathList.push_back("./raw");
  pathList.push_back("./raw/../raw.copiedtotape");
  pathList.push_back("./cache");

  const char* ROOTFileNamePattern = "ROOTfiles/shms_replay_production_all_%d_%d.root";
  
  // Load global parameters
  gHcParms->Define("gen_run_number", "Run Number", RunNumber);
  gHcParms->AddString("g_ctp_database_filename", "DBASE/SHMS/standard.database");
  gHcParms->Load(gHcParms->GetString("g_ctp_database_filename"), RunNumber);
  gHcParms->Load(gHcParms->GetString("g_ctp_parm_filename"));
  gHcParms->Load(gHcParms->GetString("g_ctp_kinematics_filename"), RunNumber);
  // Load parameters for SHMS trigger configuration
  gHcParms->Load("PARAM/TRIG/tshms.param");
  // Load fadc debug parameters
  gHcParms->Load("PARAM/SHMS/GEN/p_fadc_debug.param");

  // Load the Hall C detector map
  gHcDetectorMap = new THcDetectorMap();
  gHcDetectorMap->Load("MAPS/SHMS/DETEC/STACK/shms_stack.map");

  // Add trigger apparatus
  THaApparatus* TRG = new THcTrigApp("T", "TRG");
  gHaApps->Add(TRG);
  // Add trigger detector to trigger apparatus
  THcTrigDet* shms = new THcTrigDet("shms", "SHMS Trigger Information");
  TRG->AddDetector(shms);

  // Set up the equipment to be analyzed
  THcHallCSpectrometer* SHMS = new THcHallCSpectrometer("P", "SHMS");
  gHaApps->Add(SHMS);
  // Add Noble Gas Cherenkov to SHMS apparatus
  THcCherenkov* ngcer = new THcCherenkov("ngcer", "Noble Gas Cherenkov");
  SHMS->AddDetector(ngcer);
  // Add drift chambers to SHMS apparatus
  THcDC* dc = new THcDC("dc", "Drift Chambers");
  SHMS->AddDetector(dc);
  // Add hodoscope to SHMS apparatus
  THcHodoscope* hod = new THcHodoscope("hod", "Hodoscope");
  SHMS->AddDetector(hod);
  // Add Heavy Gas Cherenkov to SHMS apparatus
  THcCherenkov* hgcer = new THcCherenkov("hgcer", "Heavy Gas Cherenkov");
  SHMS->AddDetector(hgcer);
  // Add Aerogel Cherenkov to SHMS apparatus
  THcAerogel* aero = new THcAerogel("aero", "Aerogel");
  SHMS->AddDetector(aero);
  // Add calorimeter to SHMS apparatus
  THcShower* cal = new THcShower("cal", "Calorimeter");
  SHMS->AddDetector(cal);

  // Add rastered beam apparatus
  THaApparatus* beam = new THcRasteredBeam("P.rb", "Rastered Beamline");
  gHaApps->Add(beam);
  // Add physics modules
  // Calculate reaction point
  THaReactionPoint* prp = new THaReactionPoint("P.react", "SHMS reaction point", "P", "P.rb");
  gHaPhysics->Add(prp);
  // Calculate extended target corrections
  THcExtTarCor* pext = new THcExtTarCor("P.extcor", "HMS extended target corrections", "P", "P.react");
  gHaPhysics->Add(pext);
  // Calculate golden track quantites
  THaGoldenTrack* gtr = new THaGoldenTrack("P.gtr", "SHMS Golden Track", "P");
  gHaPhysics->Add(gtr);
  // Calculate primary (scattered beam - usually electrons) kinematics
  THcPrimaryKine* kin = new THcPrimaryKine("P.kin", "SHMS Single Arm Kinematics", "P", "P.rb");
  gHaPhysics->Add(kin);
  // Calculate the hodoscope efficiencies
  THcHodoEff* peff = new THcHodoEff("phodeff", "SHMS hodo efficiency", "P.hod");
  gHaPhysics->Add(peff);

  // Add event handler for prestart event 125.
  THcConfigEvtHandler* ev125 = new THcConfigEvtHandler("HC", "Config Event type 125");
  gHaEvtHandlers->Add(ev125);
  // Add event handler for EPICS events
  THaEpicsEvtHandler* hcepics = new THaEpicsEvtHandler("epics", "HC EPICS event type 180");
  gHaEvtHandlers->Add(hcepics);
  // Add event handler for scaler events
  THcScalerEvtHandler* pscaler = new THcScalerEvtHandler("P", "Hall C scaler event type 1");
  pscaler->AddEvtType(1);
  pscaler->AddEvtType(129);
  pscaler->SetDelayedType(129);
  pscaler->SetUseFirstEvent(kTRUE);
  gHaEvtHandlers->Add(pscaler);
  // Add event handler for DAQ configuration event
  THcConfigEvtHandler *pconfig = new THcConfigEvtHandler("pconfig", "Hall C configuration event handler");
  gHaEvtHandlers->Add(pconfig);

  // Set up the analyzer - we use the standard one,
  // but this could be an experiment-specific one as well.
  // The Analyzer controls the reading of the data, executes
  // tests/cuts, loops over Acpparatus's and PhysicsModules,
  // and executes the output routines.
  THcAnalyzer* analyzer = new THcAnalyzer;

  auto* pp = new SimplePostProcess([](){ std::cout << "qwerty\n"; return 0;});
  analyzer->AddPostProcess(pp);

  // A simple event class to be output to the resulting tree.
  // Creating your own descendant of THaEvent is one way of
  // defining and controlling the output.
  THaEvent* event = new THaEvent;

  // Define the run(s) that we want to analyze.
  // We just set up one, but this could be many.
  THcRun* run = new THcRun( pathList, Form(RunFileNamePattern, RunNumber) );

  // Set to read in Hall C run database parameters
  run->SetRunParamClass("THcRunParameters");
  
  // Eventually need to learn to skip over, or properly analyze the pedestal events
  run->SetEventRange(1, MaxEvent); // Physics Event number, does not include scaler or control events.
  run->SetNscan(1);
  run->SetDataRequired(0x7);
  run->Print();

  // Define the analysis parameters
  TString ROOTFileName = Form(ROOTFileNamePattern, RunNumber, MaxEvent);
  analyzer->SetCountMode(2);  // 0 = counter is # of physics triggers
                              // 1 = counter is # of all decode reads
                              // 2 = counter is event number
  analyzer->SetEvent(event);
  // Set EPICS event type
  analyzer->SetEpicsEvtType(180);
  // Define crate map
  analyzer->SetCrateMapFileName("MAPS/db_cratemap.dat");
  // Define output ROOT file
  analyzer->SetOutFile(ROOTFileName.Data());
  // Define DEF-file
  analyzer->SetOdefFile("DEF-files/SHMS/PRODUCTION/pstackana_production_all.def");
  // Define cuts file
  analyzer->SetCutFile("DEF-files/SHMS/PRODUCTION/CUTS/pstackana_production_cuts.def");  // optional
  // File to record accounting information for cuts
  analyzer->SetSummaryFile(Form("REPORT_OUTPUT/SHMS/PRODUCTION/summary_all_production_%d_%d.report", RunNumber, MaxEvent));  // optional
  // Start the actual analysis.
  analyzer->Process(run);
  // Create report file from template
  analyzer->PrintReport("TEMPLATES/SHMS/PRODUCTION/pstackana_production.template",
  			Form("REPORT_OUTPUT/SHMS/PRODUCTION/replay_shms_all_production_%d_%d.report", RunNumber, MaxEvent));  // optional

}
Starting analysis
asdf

 *** Break *** segmentation violation



===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0  0x00007ff9142b68fa in __GI___waitpid (pid=1286, stat_loc=stat_loc
entry=0x7ffcd4073358, options=options
entry=0) at ../sysdeps/unix/sysv/linux/waitpid.c:29
#1  0x00007ff9142259cb in do_system (line=<optimized out>) at ../sysdeps/posix/system.c:148
#2  0x00007ff919552173 in TUnixSystem::Exec (shellcmd=<optimized out>, this=0x1a297c0) at /opt/software/sources/root/core/unix/src/TUnixSystem.cxx:2119
#3  TUnixSystem::StackTrace() () at /opt/software/sources/root/core/unix/src/TUnixSystem.cxx:2413
#4  0x00007ff919554a44 in TUnixSystem::DispatchSignals (this=0x1a297c0, sig=kSigSegmentationViolation) at /opt/software/sources/root/core/unix/src/TUnixSystem.cxx:3644
#5  <signal handler called>
#6  0x00007ff914c38616 in std::ostream::sentry::sentry (this=0x7ffcd4075ad0, __os=...) at /opt/software/builds/gcc_8.1.0_build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/ostream.tcc:46
#7  0x00007ff914c38c28 in std::__ostream_insert<char, std::char_traits<char> > (__out=..., __s=__s
entry=0x7ff919eb2d7e "qwerty\n", __n=7) at /opt/software/builds/gcc_8.1.0_build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/ostream_insert.h:76
#8  0x00007ff914c39037 in std::operator<< <std::char_traits<char> > (__out=..., __s=0x7ff919eb2d7e "qwerty\n") at /opt/software/builds/gcc_8.1.0_build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/char_traits.h:320
#9  0x00007ff919eb7a7c in ?? ()
#10 0x0000000006d8e238 in ?? ()
#11 0x0000000006d8e238 in ?? ()
#12 0x00007ffcd4075b70 in ?? ()
#13 0x00007ff919eb78e3 in ?? ()
#14 0x00007ff919eb7a50 in ?? ()
#15 0x0000000006d8e238 in ?? ()
#16 0x00007ffcd4075b90 in ?? ()
#17 0x00007ff919eb7f15 in ?? ()
#18 0x0000000006d8e238 in ?? ()
#19 0x0000000006d8e238 in ?? ()
#20 0x00007ffcd4075bd0 in ?? ()
#21 0x00007ff919eb7d33 in ?? ()
#22 0x0000000500000000 in ?? ()
#23 0x0000000006d8e220 in ?? ()
#24 0x00000000d4075bd0 in ?? ()
#25 0x000000000728bb00 in ?? ()
#26 0x0000000006dfea10 in ?? ()
#27 0x0000000006d8e220 in ?? ()
#28 0x00007ffcd4075c20 in ?? ()
#29 0x00007ff915b680b0 in THaAnalyzer::PostProcess(int) () from /home/whit/lib/libHallA.so
===========================================================

MYDIR remains undefined if called from a shell script

$MYDIR is not being defined if "source setup.csh" is called from a script (in interactive mode there is no problem).

You can reproduce the issue by running a shell script such a:

#!/bin/csh -vx
# _FILE_ SetHcana.csh
set HCANADIR="/path/to/hcana/"
source "$HCANADIR/setup.csh"
hcana -l -b -q SomeScript.C

Then,

./SetHcana.csh

Which will display:

/path/to/hcana/: error while loading shared
libraries: libHallC.so: cannot open shared object file: No such file or
directory.

Scaler analysis code

Analyze scalers.
Put scaler totals somewhere that reports (THcAnalyzer::PrintReport) can use them to calculate rates, etc.

HitList warnings not suppressed

I am getting a bunch of warnings of the type:

HitList(event=350): refindex 4 (3, 2, 127) missing for (3, 2, 12)
HitList(event=350): refindex 4 (3, 2, 127) missing for (3, 2, 13)
HitList(event=350): refindex 4 (3, 2, 127) missing for (3, 2, 17)
HitList(event=350): refindex 4 (3, 2, 127) missing for (3, 2, 24)
HitList(event=350): refindex 4 (3, 2, 127) missing for (3, 2, 23)
HitList(event=350): refindex 4 (3, 2, 127) missing for (3, 2, 26)
HitList(event=350): refindex 4 (3, 2, 127) missing for (3, 2, 16)
HitList(event=350): refindex 4 (3, 2, 127) missing for (3, 2, 27)
HitList(event=350): refindex 4 (3, 2, 127) missing for (3, 2, 18)
HitList(event=350): refindex 4 (3, 2, 127) missing for (3, 2, 19)
HitList(event=350): refindex 4 (3, 2, 127) missing for (3, 2, 70)
HitList(event=350): refindex 4 (3, 2, 127) missing for (3, 2, 73)

I chased this down as being part of the "present" mechanism for some detector variables. Is anybody else seeing this?

Address various suggestions for improvement from cppcheck output

I started looking into using cppcheck to analyze source code. I started with the hcana/src directory, but of course this should be applied to the entire Hall A analyzer as well, in principle.

Cppcheck produced a lot of suggestions for improvement, which break down into several categories:

a) warnings about unused variables, etc.
b) potential performance hits
c) style issues

I took some time to fix a few of the things that showed up from categories a) and b) ... that was pretty simple. However, there remain to broad types of things that cppcheck complains about:

  1. C-style pointer casting
  2. Failure to initialize member variables in the constructor of a class.

Below is the output of cppcheck from just one of the pieces of source code in hcana/src:

[src/THcAerogel.cxx:263]: (style) C-style pointer casting
[src/THcAerogel.cxx:267]: (style) C-style pointer casting
[src/THcAerogel.cxx:273]: (style) C-style pointer casting
[src/THcAerogel.cxx:279]: (style) C-style pointer casting
[src/THcAerogel.cxx:285]: (style) C-style pointer casting
[src/THcAerogel.cxx:305]: (style) C-style pointer casting
[src/THcAerogel.cxx:454]: (style) C-style pointer casting
[src/THcAerogel.cxx:52]: (warning) Member variable 'THcAerogel::fPosGain' is not initialized in the constructor.
[src/THcAerogel.cxx:52]: (warning) Member variable 'THcAerogel::fNegGain' is not initialized in the constructor.
[src/THcAerogel.cxx:52]: (warning) Member variable 'THcAerogel::fA_Pos' is not initialized in the constructor.
[src/THcAerogel.cxx:52]: (warning) Member variable 'THcAerogel::fA_Neg' is not initialized in the constructor.
... and so on.

Looking at the first few entries, the code looks like this:

.
.
while(ihit < fNhits) {
THcAerogelHit* hit = (THcAerogelHit *) fRawHitList->At(ihit);
.
.

So, you can see the type of thing that it is complaining about. The question is: what do we do about this? One option, as I understand it, is to replace these casts with one of the C++-style casts (static_cast<...>, const_cast<...>, etc.). A second (better?) option is to use STL vectors. A third option is to just ignore this and proceed ahead.

I have to admit I don't understand at this point if the uninitialized member variable warnings are so-called "false positives" of cppcheck, or if there is some non-standard procedure that is being followed in our code.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.