/* ************************************************************************* */ /* provides BeamSpot position uniformly for use in L3 modules */ /* Author: Fedor Ratnikov (CDF/Rutgers) */ /* Supported algorithms: */ /* 0 - trivial case (0,0,0) position */ /* $Id: L3BeamSpot.cc,v 1.1 2003/12/10 20:51:46 dldecker Exp $ */ /* ************************************************************************* */ #include #include #include #include "TriggerObjects/SVDD_StorableBank.hh" #include "Level3Mods/L3BeamSpot.hh" namespace { // grabbed from svtsim/src/svtsim_getsvddinfo.cc bool getSVDDBeam3D(const EventRecord *event,float *bx,float *dxdz,float *by,float *dydz) { int svdd_found = 0; int block = 0; int card = 0; bool fitstatus=false; *bx = *dxdz = *by = *dydz = 0.; EventRecord::ConstIterator svdd_iter(event,"SVDD_StorableBank"); if ( svdd_iter.is_valid( ) ) { ConstHandle svdd_h(svdd_iter); Trigger_StorableBank::ConstBlockIter triter(svdd_h, block, card); /* * Loop through blocks/cards looking for a BEAMINFO card section */ for (ConstBankIterTDC block(svdd_h); block.is_valid(); ++block) { int iblock = block.block_index(); for (ConstBlockIterTDC module(block); module.is_valid(); ++module) { enum { BEAMINFO3D = 11 }; int icard = module.module_index(); int dlen = module.module_data_size(); if (dlen==0) continue; if ((module.data_word(0)>>16 & 0xffff)!=BEAMINFO3D) continue; /* * OK, found a card section of type BEAMINFO3D */ svdd_found = 1; int nsvdd_words = module.module_data_size()-2; short sbx = ((module.data_word(1) >> 16) & 0xFFFF); // microns short sby = (module.data_word(1) & 0xFFFF) ; // microns short sdxdz = ((module.data_word(2) >> 16) & 0xFFFF); // microrads short sdydz = (module.data_word(2) & 0xFFFF) ; // microrads fitstatus = (module.data_word(3)!=0); *bx = sbx/10000.; *dxdz = sdxdz/1000000.; *by = sby/10000.; *dydz = sdydz/1000000.; if (svdd_found) break; } if (svdd_found) break; } } return(svdd_found!=0 && fitstatus); } } L3BeamSpot::L3BeamSpot () : _mBeamPosition (0., 0., 0.), _mDxDz (0), _mDyDz (0), _mAlgoritm (STATIC_0_0), _mCotBeam (0), _mIsSet (false) { } HepPoint3D L3BeamSpot::position (double fZ) const { return HepPoint3D (_mBeamPosition.x () + _mDxDz * fZ, _mBeamPosition.y () + _mDyDz * fZ, fZ); } L3BeamSpot::~L3BeamSpot () { delete _mCotBeam; _mCotBeam = 0; } bool L3BeamSpot::beginRun (const EventRecord* fEvent) { int run = AbsEnv::instance ()->runNumber(); switch (_mAlgoritm) { case STATIC_0_0: _mBeamPosition = HepPoint3D (0., 0., 0.); _mDxDz = _mDxDz = 0.; _mIsSet = true; break; case PREVIOUS_RUN: case CALIB_DB: if (_mAlgoritm == PREVIOUS_RUN) run--; if (!_mCotBeam) _mCotBeam = new CotBeam ("default"); _mCotBeam->loadRun (run); if (_mCotBeam->isValid ()) { _mBeamPosition = _mCotBeam->position (); _mDxDz = _mDxDz = 0.; _mIsSet = true; } else { _mIsSet = false; } break; default: break; } return isValid (); } bool L3BeamSpot::event (const EventRecord* fEvent) { switch (_mAlgoritm) { case SVDD: { float x = 0., y = 0., dxdz = 0., dydz = 0.; _mIsSet = getSVDDBeam3D (fEvent, &x, &dxdz, &y, &dydz); if (isValid ()) { _mBeamPosition = HepPoint3D (x, y, 0.); _mDxDz = dxdz; _mDyDz = dydz; } } break; default: break; } return isValid (); } const std::string L3BeamSpot::description () { char result [256]; sprintf (result, "provide Beam Spot position for the current data. Supported algorithms are: 0 - %s, 1 - %s, 2 - %s, 3 - %s (not implemented), 4-%s", L3BeamSpot::algorithmName (0), L3BeamSpot::algorithmName (1), L3BeamSpot::algorithmName (2), L3BeamSpot::algorithmName (3), L3BeamSpot::algorithmName (4)); return result; ; } const std::string L3BeamSpot::status () const { if (isValid ()) { char result [256]; sprintf (result, "Algorithm used: %d (%s); beam spot position: (%f,%f,%f), slopes: (%f,%f)", _mAlgoritm, L3BeamSpot::algorithmName (_mAlgoritm), (float) _mBeamPosition.x (), (float) _mBeamPosition.y (), (float) _mBeamPosition.z (), _mDxDz, _mDyDz); return result; } else { return "Beam spot position is undefined"; } } const char* L3BeamSpot::algorithmName (int fAlgorithm) { return (Algorithm) fAlgorithm == STATIC_0_0 ? "Fixed (0,0,0)" : (Algorithm) fAlgorithm == CALIB_DB ? "CalibDB" : (Algorithm) fAlgorithm == PREVIOUS_RUN ? "Previous Run" : (Algorithm) fAlgorithm == SVX ? "SVX" : (Algorithm) fAlgorithm == SVDD ? "SVDD" : "Unknown"; }