#include "htofhitf.h"
#include "hades.h"
#include "htofraw.h"
#include "htofhit.h"
#include "htofhitsim.h"
#include "htofcalpar.h"
#include "hruntimedb.h"
#include "hcategory.h"
#include "hiterator.h"
#include "hdebug.h"
#include "tofdef.h"
#include "hevent.h"
#include "heventheader.h"
#include "hspectrometer.h"
#include "hdetector.h"
#include "hgeomvolume.h"
#include "hgeomcompositevolume.h"
#include "hgeomtransform.h"
#include "htofgeompar.h"
#include "hdetgeompar.h"
#include "hgeomvector.h"
#include "hspecgeompar.h"
#include "hstarthit.h"
#include "hstartdef.h"
#include "TMath.h"
void HTofHitF::initParContainer(HSpectrometer *spec, HRuntimeDb *rtdb) {
fCalPar=(HTofCalPar *)rtdb->getContainer("TofCalPar");
fTofGeometry=(HTofGeomPar *)rtdb->getContainer("TofGeomPar");
fSpecGeometry = (HSpecGeomPar *)rtdb->getContainer("SpecGeomPar");
}
HTofHitF::HTofHitF(void) {
fCalPar = NULL;
fCalParSim = NULL;
fRawCat = fHitCat = NULL;
fRawCatTmp = fHitCatTmp = NULL;
fStartHitCat = NULL;
fTofSimulation = kFALSE;
fLoc.set(3,0,0,0);
iter = NULL;
iterTmp = NULL;
}
HTofHitF::HTofHitF(const Text_t *name,const Text_t *title) : HReconstructor (name,title) {
fCalPar = NULL;
fCalParSim = NULL;
fRawCat = fHitCat = NULL;
fRawCatTmp = fHitCatTmp = NULL;
fStartHitCat = NULL;
fTofSimulation = kFALSE;
fLoc.set(3,0,0,0);
iter = NULL;
iterTmp = NULL;
}
HTofHitF::~HTofHitF(void) {
if(iter) delete iter;
}
HTofHit *HTofHitF::makeHit(TObject *address) {
return new(address) HTofHit;
}
void HTofHitF::fillHit(HTofHit *hit, HTofRaw *raw) {
}
Bool_t HTofHitF::init(void) {
Bool_t r=kTRUE;
HSpectrometer *spec = gHades->getSetup();
HRuntimeDb *rtdb = gHades->getRuntimeDb();
HEvent *ev = gHades->getCurrentEvent();
printf("initialization of Tof hit finder\n");
if (spec && rtdb && ev) {
HDetector *tof = spec->getDetector("Tof");
HDetector *start = spec->getDetector("Start");
if (tof) {
initParContainer(spec,rtdb);
fRawCat = ev->getCategory(catTofRaw);
if (!fRawCat) {
fRawCat= tof->buildCategory(catTofRaw);
if (!fRawCat) return kFALSE;
else ev->addCategory(catTofRaw,fRawCat,"Tof");
}
iter=(HIterator*)fRawCat->MakeIterator("native");
fHitCat = ev->getCategory(catTofHit);
if (!fHitCat) {
fHitCat = spec->getDetector("Tof")->buildCategory(catTofHit);
if (!fHitCat) return kFALSE;
else ev->addCategory(catTofHit,fHitCat,"Tof");
}
} else {
Error("init","TOF setup is not defined");
r = kFALSE;
}
if (start) {
fStartHitCat = ev->getCategory(catStartHit);
if (!fStartHitCat) Warning("init","Start hit level not defined; setting start time to 0");
} else {
Warning("init","Start detector not found; setting start time to 0");
fStartHitCat = 0;
}
} else {
Error("init","Setup, RuntimeDb or event structure not found");
r = kFALSE;
}
return r;
}
Int_t HTofHitF::execute(void) {
#if DEBUG_LEVEL>2
gDebuger->enterFunc("HTofHitF::execute");
#endif
Bool_t sim=kFALSE;
if ( fTofSimulation) sim=kTRUE;
else if (!fTofSimulation) sim=kFALSE;
fillHitCat(sim,kFALSE);
if(fTofSimulation&&gHades->getEmbeddingMode()>0){
fillHitCat(kTRUE,kTRUE);
mergeHitCats();
}
#if DEBUG_LEVEL>2
gDebuger->leaveFunc("HTofHitF::execute");
#endif
return 0;
}
void HTofHitF::fillGeometry(HTofHit *hit) {
HGeomVector rLocal,r;
Float_t d,phi,theta;
Float_t rad2deg = 180./TMath::Pi();
HModGeomPar *module=fTofGeometry->getModule(hit->getSector(),hit->getModule());
HGeomTransform &trans = module->getLabTransform();
HGeomVolume *rodVol=module->getRefVolume()->getComponent(hit->getCell());
HGeomTransform &rodTrans=rodVol->getTransform();
r.setX(hit->getXpos());
r.setY(0.);
r.setZ(0.);
rLocal=rodTrans.transFrom(r);
r=trans.transFrom(rLocal);
HGeomVolume *tv=fSpecGeometry->getTarget(0);
if (tv) r -= tv->getTransform().getTransVector();
d = r.length();
theta = (d>0.) ? (rad2deg * TMath::ACos(r.getZ() / d)) : 0.;
phi = rad2deg * TMath::ATan2( r.getY(), r.getX());
if (phi < 0.) phi += 360.;
if (tv) r += tv->getTransform().getTransVector();
hit->setXYZLab(r.getX(), r.getY(), r.getZ());
hit->setDistance( d );
hit->setTheta(theta);
hit->setPhi(phi);
}
void HTofHitF::fillHitCat(Bool_t sim,Bool_t embed)
{
Float_t atofCorr = 0.000000276;
HTofRaw *raw=NULL;
HTofHit *hit=NULL;
HStartHit *sH=NULL;
Float_t atof;
Float_t axpos;
Float_t startTime=0.0;
Float_t subCl;
Float_t subCr;
Float_t slopeAdcL;
Float_t slopeAdcR;
Float_t xposAdc;
Float_t depE;
Float_t leftA;
Float_t rightA;
Float_t twalk;
Float_t twoffT;
Int_t flagadc;
if(!sim)
{
if (fStartHitCat) {
if((sH=(HStartHit *)fStartHitCat->getObject(0))!=NULL){
startTime =sH->getTime();
}
else{
startTime = 0.0;
}
} else {
startTime = 0.0;
}
} else {
startTime=0.0;
}
HIterator* iterLocal;
HCategory* catHitLocal;
HTofCalPar* calparLocal;
if(sim&&embed) iterLocal=iterTmp;
else iterLocal=iter;
if(sim&&embed) catHitLocal=fHitCatTmp;
else catHitLocal=fHitCat;
if(sim&&embed) calparLocal=fCalParSim;
else calparLocal=fCalPar;
iterLocal->Reset();
while ( (raw=(HTofRaw *)iterLocal->Next())!=NULL) {
fLoc[0]=raw->getSector();
fLoc[1]=raw->getModule();
fLoc[2]=raw->getCell();
if(raw->getLeftTime() && raw->getRightTime()){
hit = (HTofHit *)catHitLocal->getSlot(fLoc);
if (hit) {
hit=makeHit(hit);
HTofCalParCell& cell=(*calparLocal)[fLoc[0]][fLoc[1]][fLoc[2]];
atof = (raw->getLeftTime() * cell.getLeftK() +
raw->getRightTime()*cell.getRightK())/2.0 - cell.getTimK();
atof -= startTime;
axpos = cell.getVGroup()*(raw->getRightTime() * cell.getRightK() -
raw->getLeftTime()*cell.getLeftK())/2.0 +cell.getPosK();
if(!sim){
atof = atof + (axpos*axpos*atofCorr);
}
xposAdc=0.0;
depE=0.0;
leftA=0.0;
rightA=0.0;
flagadc=0;
twoffT=cell.getTimeWalkC3();
twalk=twoffT;
if(raw->getLeftCharge() || raw->getRightCharge()) {
subCl = (raw->getLeftCharge() - cell.getPedestalL());
subCr = (raw->getRightCharge() - cell.getPedestalR());
slopeAdcL = (cell.getEdepK())*(TMath::Exp((cell.getGainAsym())/(cell.getAttLen())));
slopeAdcR = (cell.getEdepK())*(TMath::Exp(-(cell.getGainAsym())/(cell.getAttLen())));
if(raw->getLeftCharge()){
flagadc=-1;
depE=(subCl*cell.getEdepK())*(TMath::Exp((cell.getGainAsym()-axpos)/(cell.getAttLen())));
leftA=subCl*slopeAdcL;
if(leftA>0.0) twalk=twalk+(cell.getTimeWalkC1()/(TMath::Sqrt(leftA)))-(twoffT/2.0);
}
if(raw->getRightCharge()){
flagadc=1;
depE=(subCr*cell.getEdepK())*(TMath::Exp((axpos-cell.getGainAsym())/(cell.getAttLen())));
rightA=subCr*slopeAdcR;
if(rightA>0.0) twalk=twalk+(cell.getTimeWalkC2()/(TMath::Sqrt(rightA)))-(twoffT/2.0);
}
if(raw->getLeftCharge() && raw->getRightCharge()) {
flagadc=2;
xposAdc=(cell.getAttLen()/2.0)*(TMath::Log(subCl/subCr)) + cell.getGainAsym();
depE=(cell.getEdepK())*(TMath::Sqrt(subCl*subCr));
}
}
if(!sim){
atof = atof + twalk;
}
hit->setSector((Char_t) fLoc[0]);
hit->setModule((Char_t) fLoc[1]);
hit->setCell((Char_t) fLoc[2]);
hit->setTof(atof);
hit->setXpos(axpos);
hit->setXposAdc(xposAdc);
hit->setEdep(depE);
hit->setLeftAmp(leftA);
hit->setRightAmp(rightA);
hit->setAdcFlag(flagadc);
fillHit(hit,raw);
fillGeometry(hit);
}
}
}
}
void HTofHitF::mergeHitCats()
{
HTofHitSim* hit;
HTofHitSim* hittmp;
TIterator* hititer=fHitCatTmp->MakeIterator("native");
hititer->Reset();
while ( (hittmp=(HTofHitSim *)hititer->Next())!=NULL)
{
fLoc[0]=hittmp->getSector();
fLoc[1]=hittmp->getModule();
fLoc[2]=hittmp->getCell();
hit= (HTofHitSim*) fHitCat->getObject(fLoc);
if(hit)
{
new (hit) HTofHitSim(*hittmp);
}
else
{
hit= (HTofHitSim*) fHitCat->getSlot(fLoc);
if(hit)
{
new (hit)HTofHitSim(*hittmp);
}
else
{
Error("mergeHitCats()","Could not retrieve slot in catTofHit!");
}
}
}
delete hititer;
}
ClassImp(HTofHitF)
Last change: Sat May 22 13:16:13 2010
Last generated: 2010-05-22 13:16
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.