CSidc1.C
//-----------------------------------------------------------------------------
// $Header: /asis/offline/ceres/cool/project/RCS/CSidc1.C,v 3.5 1997/06/30 14:49:10 lenkeit Exp $
//
// COOL Program Library
// Copyright (C) CERES collaboration, 1996
//
// Implementation of class CSidc1
//
//-----------------------------------------------------------------------------
#include <iostream.h>
#include "CSidc1.h"
#include "CSidcDeltaR.h"
#include "CMCDigiHit.h"
CSidc1::CSidc1(const char* setupFile)
{
//
// Initialize members inherited from CDetector
//
id = SiDC1;
name = "SiDC1";
//
// May be I should comment on this:
// The reason for this massacre is that there exist nothing
// like virtual data member. Each of the defined setup pointers
// has is own scope. With other words there's an ambiguity
// which can only be resolved by either using always the proper
// scope operator or by hacking the code below. I know it looks
// somehow unusual but eases further programming.
//
CDetector::setup = CSidc::setup = new CSidcSetup;
if (setupFile == 0) {
CString setupName = CString(C_DEFAULT_SETUP_PATH)+
CString(C_SETUPFILE_SIDC1);
setup->read(setupName.data());
}
else
setup->read(setupFile);
// the local delta-R correction.
CString deltaRFileName = CString(C_DEFAULT_SETUP_PATH)+
CString("drsd1.vec");
CSidc::deltaRcorrection = new CSidcDeltaR(deltaRFileName.data());
//
// Set the proper size of the collections
// anode [0-359], time bin [0-255], nnim [0-23]
//
cells.resize(setup->getNAnodes(), setup->getNTimeBins());
nims.resize(setup->getNNim(), setup->getNTimeBins());
//
// read fallback values for pedestals and
// anodewise t0 corrections from file
//
CString fileName = CString(C_DEFAULT_SETUP_PATH)+
CString(C_CALIBRATION_FILE_SIDC1);
readLookupItemsFromFile(fileName.data());
}
CSidc1::~CSidc1() { delete setup; }
CSidc1::CSidc1(const CSidc1 &) {}
CSidc1 & CSidc1::operator = (const CSidc1 &) { return *this; }
double CSidc1::calculateAmplitude(double anodeNumber, double hitAnode, double sigAnode,
double dEdx)
{
//
// Calculation of the amplitude for each anode for MCHits,
// needed for function digitize.
// for '95 data wafer type = 1
// for '96 data wafer type = 2 (splitted anode structure)
//
if(setup->getWaferType() == 1){
const double sqrt2 = 1.4142135624;
double amplitude;
double distLowerEdge = anodeNumber - (hitAnode - int(hitAnode) + 0.5);
double distUpperEdge = distLowerEdge + 1;
amplitude = 0.5 * (erf(distUpperEdge/(sqrt2*sigAnode)) -
erf(distLowerEdge/(sqrt2*sigAnode)));
amplitude = dEdx * amplitude;
return amplitude;
}
//
// for anode structure see dipl. thesis Marc Hemberger S.55
//
else if(setup->getWaferType() == 2){
const double normFactor = 1.4142135624 * sigAnode; // normalization factor for gauss function
double amplitude = 0;
double amplitude_part = 0;
double hitDistToEdge = hitAnode - int(hitAnode) + 0.5; // distance of hit to lower edge of anode
double distLowerEdge = anodeNumber - 0.25 - hitDistToEdge; // a11:outside anode. width=61um
double distUpperEdge = anodeNumber - 0.1667 - hitDistToEdge;
amplitude_part = 0.5 * (erf(distUpperEdge/normFactor) -
erf(distLowerEdge/normFactor));
amplitude += amplitude_part;
distLowerEdge = anodeNumber - hitDistToEdge; // a22:inside anode. width=122um
distUpperEdge = anodeNumber + 0.167 - hitDistToEdge;
amplitude_part = 0.5 * (erf(distUpperEdge/normFactor) -
erf(distLowerEdge/normFactor));
amplitude += amplitude_part;
distLowerEdge = anodeNumber + 0.25 - hitDistToEdge; // a0:central anode. width=366um
distUpperEdge = anodeNumber + 0.75 - hitDistToEdge;
amplitude_part = 0.5 * (erf(distUpperEdge/normFactor) -
erf(distLowerEdge/normFactor));
amplitude += amplitude_part;
distLowerEdge = anodeNumber + 0.833 - hitDistToEdge; // a21:inside anode. width=122um
distUpperEdge = anodeNumber + 1 - hitDistToEdge;
amplitude_part = 0.5 * (erf(distUpperEdge/normFactor) -
erf(distLowerEdge/normFactor));
amplitude += amplitude_part;
distLowerEdge = anodeNumber + 1.1667 - hitDistToEdge; // a12:outside anode. width=61um
distUpperEdge = anodeNumber + 1.25 - hitDistToEdge;
amplitude_part = 0.5 * (erf(distUpperEdge/normFactor) -
erf(distLowerEdge/normFactor));
amplitude += amplitude_part;
amplitude = dEdx * amplitude;
return amplitude;
}
else{
cerr << "CSidc1::calculateAmpltude():\n";
cerr << "\tERROR\n";
cerr << "\twafer type not defined : " << setup->getWaferType()
<< " anode amplitude set to 0\n";
return 0.;
}
}