Skip to content
Snippets Groups Projects
THcDC.cxx 45.4 KiB
Newer Older
/** \class THcDC
    \ingroup Detectors

\brief Analyze a package of horizontal drift chambers.

Uses the
first letter of the apparatus name as a prefix to parameter names.  The
paramters, read in the Setup method, determine the number of chambers and
the number of parameters per plane.

\author S. A. Wood, based on Fortran ENGINE

*/

#include "THcDC.h"
#include "THaEvData.h"
#include "THaDetMap.h"
#include "THcDetectorMap.h"
#include "THcGlobals.h"
#include "THaCutList.h"
#include "THcParmList.h"
#include "THcDCTrack.h"
#include "VarDef.h"
#include "VarType.h"
#include "THaTrack.h"
#include "TClonesArray.h"
#include "TMath.h"
#include "THaApparatus.h"

#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <iostream>

#include "spdlog/spdlog.h"
#include "spdlog/sinks/stdout_color_sinks.h" //support for stdout logging
#include "spdlog/sinks/basic_file_sink.h" // support for basic file logging


using namespace std;

//_____________________________________________________________________________
THcDC::THcDC(
 const char* name, const char* description,
				  THaApparatus* apparatus ) :
  hcana::ConfigLogging<THaTrackingDetector>(name,description,apparatus)
{
  // Constructor

  fNPlanes = 0;			// No planes until we make them

  fXCenter = NULL;
  fYCenter = NULL;
  fMinHits = NULL;
  fMaxHits = NULL;
  fMinCombos = NULL;
  fSpace_Point_Criterion = NULL;

  fTdcWinMin = NULL;
  fTdcWinMax = NULL;
  fCentralTime = NULL;
  fNWires = NULL;
  fNChamber = NULL;
  fWireOrder = NULL;
  fDriftTimeSign = NULL;
  fZPos = NULL;
  fAlphaAngle = NULL;
  fBetaAngle = NULL;
  fGammaAngle = NULL;
  fPitch = NULL;
  fCentralWire = NULL;
  fPlaneTimeZero = NULL;
  fSigma = NULL;
  // These should be set to zero (in a parameter file) in order to
  // replicate historical ENGINE behavior
  fFixLR = 1;
  fFixPropagationCorrection = 1;
  fProjectToChamber = 0;  // Use 1 for SOS chambers
  fDCTracks = new TClonesArray( "THcDCTrack", 20 );

  fNChamHits = 0;
  fPlaneEvents = 0;

  //The version defaults to 0 (old HMS style). 1 is new HMS style and 2 is SHMS style.
  fVersion = 0;

  //Create and return a shared_ptr to a multithreaded console logger.
  //_logger = spdlog::get("config");
  //if(!_logger) {
  //  _logger = spdlog::stdout_color_mt("config");
  //}
}

//_____________________________________________________________________________
void THcDC::Setup(const char* name, const char* description)
{
  // Create the chamber and plane objects using parameters.
  static const char* const here = "Setup";

  THaApparatus *app = GetApparatus();
  if(app) {
Eric Pooser's avatar
Eric Pooser committed
    // cout << app->GetName() << endl;
    fPrefix[0]=tolower(app->GetName()[0]);
    fPrefix[1]='\0';
  } else {
    cout << "No apparatus found" << endl;
  // For now, decide chamber style from the spectrometer name.
  // Should override with a paramter
  //cout<<"HMS Style??\t"<<fHMSStyleChambers<<endl;
  string planenamelist;
  DBRequest list[]={
    {"dc_num_planes",&fNPlanes, kInt},
    {"dc_num_chambers",&fNChambers, kInt},
    {"dc_tdc_time_per_channel",&fNSperChan, kDouble},
    {"dc_wire_velocity",&fWireVelocity,kDouble},
    {"dc_plane_names",&planenamelist, kString},
    {"dc_version", &fVersion, kInt, 0, optional},
    {"dc_tdcrefcut", &fTDC_RefTimeCut, kInt, 0, 1},
  fTDC_RefTimeCut = 0;		// Minimum allowed reference times
  gHcParms->LoadParmValues((DBRequest*)&list,fPrefix);
Mark Jones's avatar
Mark Jones committed

  if(fVersion==0) {
    fHMSStyleChambers = 1;
  } else {
    fHMSStyleChambers = 0;
  }

  _logger->info("Plane Name List: {}", planenamelist);
  _logger->info("Drift Chambers: {} planes in {} chambers", fNPlanes, fNChambers);
  //cout << "Plane Name List: " << planenamelist << endl;
  //cout << "Drift Chambers: " <<  fNPlanes << " planes in " << fNChambers << " chambers" << endl;

  vector<string> plane_names = vsplit(planenamelist);

  if(plane_names.size() != (UInt_t) fNPlanes) {
    //cout << "ERROR: Number of planes " << fNPlanes << " doesn't agree with number of plane names " << plane_names.size() << endl;
    _logger->error("ERROR: Number of planes {} doesn't agree with number of plane names {}",
                   fNPlanes, plane_names.size());

    // Should quit.  Is there an official way to quit?
  }
  fPlaneNames = new char* [fNPlanes];
  for(Int_t i=0;i<fNPlanes;i++) {
    fPlaneNames[i] = new char[plane_names[i].length()+1];
    strcpy(fPlaneNames[i], plane_names[i].c_str());
  }

  char *desc = new char[strlen(description)+100];
  char *desc1= new char[strlen(description)+100];
  for(Int_t i=0;i<fNPlanes;i++) {
    strcpy(desc, description);
    strcat(desc, " Plane ");
    strcat(desc, fPlaneNames[i]);

    THcDriftChamberPlane* newplane = new THcDriftChamberPlane(fPlaneNames[i], desc, i+1, this);
    if( !newplane or newplane->IsZombie() ) {
      Error( Here(here), "Error creating Drift Chamber plane %s. Call expert.", name);
      MakeZombie();
      delete [] desc;
      delete [] desc1;
      return;
    }
    fPlanes.push_back(newplane);
    newplane->SetDebug(fDebug);
Eric Pooser's avatar
Eric Pooser committed
    // cout << "Created Drift Chamber Plane " << fPlaneNames[i] << ", " << desc << endl;
  for(UInt_t i=0;i<fNChambers;i++) {

    // Should construct a better chamber name
    THcDriftChamber* newchamber = new THcDriftChamber(desc1, desc, i+1, this);
    //cout << "Created Drift Chamber " << i+1 << ", " << desc1 << endl;
    _logger->info("Created Drift Chamber {}, {}" , i+1 , desc1);
    newchamber->SetHMSStyleFlag(fHMSStyleChambers); // Tell the chamber its style
  delete [] desc;
  delete [] desc1;
Loading
Loading full blame...