////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Component: CalData.cc // Purpose: Implementation of the CalData class. // // Created: 16/04/99 Marc Paterno // History: 02/05/99 Pierre Savard: Added Iterator and changed constructor // 12/09/99 Pierre Savard: Port to new EDM // 01/05/03 Dan MacQueen: Changed _locs(ieta) to _locs(ieta,iphi) // 30/06/03 W. Sakumoto: Standardize/validate offline LERs in puff // 16/01/04 A. Wyatt Streamer change to lengthen valCode // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #include #include #include "BaBar/Cdf.hh" #include "ErrorLogger_i/gERRLOG.hh" #include "AbsEnv/AbsEnv.hh" #include "Edm/EventRecord.hh" #include "Edm/ConstEventIter.hh" #include "CalorGeometry/Locations.hh" #include "CalorGeometry/TowerDescription.hh" #include "CalorObjects/CalData.hh" #include "CalorObjects/CalTower.hh" #include "CalorObjects/TowerType.hh" #include "CalorObjects/Calib.hh" #include "CalorObjects/CalDataNtuplizer.hh" #include "EdmUtilities/CdfClassImp.hh" #include "CalorObjects/plugSpike.hh" #include "CalorObjects/TowerCorrectionColl.hh" #include "CalorObjects/CEMTowerCorrColl.hh" #include "CalorObjects/CHATowerCorrColl.hh" #include "CalorObjects/WHATowerCorrColl.hh" #include "CalorObjects/PEMTowerCorrColl.hh" #include "CalorObjects/PPRTowerCorrColl.hh" #include "CalorObjects/PHATowerCorrColl.hh" #include "CalorObjects/MPATowerCorrColl.hh" //include // DEBUG.LER only WKS:27Jun03 //include "RawDataBanks/RawQieStorableBank.hh" // DEBUG.LER only WKS:27Jun03 // namespace calor { using namespace std; // Static function for ntuplizer CalDataNtuplizer* CalData::_p_ntuplizer = 0; // // Memory management // CalData::CalData():StorableObject(){ UChar_t iEta; UChar_t iPhi; _isPuffed = false; _locs =0; _paramVersion=3; // use memset here instead? for (iEta = 0; iEta < TOWER_NETA; ++iEta) for (iPhi = 0; iPhi < TOWER_MAX_NPHI; ++iPhi) _data[iEta][iPhi] = 0; } CalData::~CalData(){} void CalData::destroy(void) { CalData::deallocate() ; delete this ; } void CalData::deallocate(void){ if(_locs != 0){ delete _locs; _locs = 0; } for (size_t iEta = 0; iEta < TOWER_NETA; ++iEta){ for (size_t iPhi = 0; iPhi < TOWER_MAX_NPHI; ++iPhi){ CalTower* p_temp = _data[iEta][iPhi]; if (p_temp != 0) delete p_temp ; } } StorableObject::deallocate() ; } std::string CalData::class_name(void) const { return(CalData::Class_Name()) ; } Version_t CalData::class_version( void) const { return(CalData::Class_Version()) ; } //============================================================================= // Iostream //============================================================================= void CalData::print(std::ostream& os) const { StorableObject::print(os) ; _calibrations.print(os); os << "List of calorimeter towers with energy: " << std::endl; int intow = 0; CalData::ConstIterator end = this->end(); for(CalData::ConstIterator iter= this->begin(); iter != end; ++iter){ CalTower* t = iter.tower(); t->print(os); intow++; } os << std::endl; os << "Number of towers with energy: " << intow << std::endl; } //============================================================================= // Edm input/output //============================================================================= bool CalData::postread(EventRecord* p_record) { bool status = StorableObject::postread(p_record) ; return(status) ; } bool CalData::prewrite(EventRecord* p_record) { bool status = StorableObject::prewrite(p_record) ; return(status) ; } bool CalData::deactivate(EventRecord* p_record) { bool status = StorableObject::deactivate(p_record) ; return(status) ; } bool CalData::activate(EventRecord* p_record) { bool status = StorableObject::activate(p_record) ; return(status) ; } void CalData::Streamer(TBuffer& iobuffer){ unsigned int start = 0 ; unsigned int byte_count = 0 ; if (iobuffer.IsReading()){ Version_t original_version = iobuffer.ReadVersion(&start, &byte_count) ; if (original_version < 3 || original_version > 12){ ERRLOG(ELerror,"CalData: ") << "Unsupported CalData class version cannot be treated" << endmsg; } else{ StorableObject::Streamer( iobuffer ); // version of parameters used if(original_version > 5){ iobuffer >> _paramVersion; } else { _paramVersion=0; } // stream in calib version (for now bogus) uint4 iDBset; iobuffer >> iDBset; uint2 pedNumber; // number of counts to subtract - will get used soon iobuffer >> pedNumber; // read calibrations float cem,cha,wha,ppr,pem,pha,mpa; uint2 pcem,pcha,pwha,pppr,ppem,ppha,pmpa; iobuffer >> cem; iobuffer >> cha; iobuffer >> wha; iobuffer >> ppr; iobuffer >> pem; iobuffer >> pha; iobuffer >> mpa; if (original_version<8) { float dummyf; iobuffer >> dummyf; } if(original_version < 5){ pcem = 50; pcha = 50; pwha =50; pppr =50; ppem =50; ppha=50; pmpa=200; } else{ iobuffer >> pcem; iobuffer >> pcha; iobuffer >> pwha; iobuffer >> pppr; iobuffer >> ppem; iobuffer >> ppha; iobuffer >> pmpa; if (original_version<8) { uint2 dummy; iobuffer >> dummy; } } _calibrations = CalDataCalib(cem,cha,wha,ppr,pem,pha,mpa, pcem,pcha,pwha,pppr,ppem,ppha,pmpa); // set puffiness state _isPuffed = false; int n_items = 0 ; iobuffer >> n_items ; UChar_t iEta,iPhi; ULong_t valCode; int towerType; for(int i = 0; i != n_items; ++i) { iobuffer >> iEta; iobuffer >> iPhi; if(original_version < 10){ UChar_t valDummy; iobuffer >> valDummy; valCode = (ULong_t) valDummy; } else { if(original_version < 12){ UShort_t valDummy; iobuffer >> valDummy; valCode = (ULong_t) valDummy; } else { iobuffer >> valCode; } } towerType = TOWER_TYPE[iEta]; CalTower* t = createTower(towerType); t->setValidCode(valCode); // need to figure out what to do with this... t->setIeta(iEta); t->setIphi(iPhi); t->readFromBuffer(iobuffer,original_version); _data[iEta][iPhi] = t; } } iobuffer.CheckByteCount(start, byte_count, CalData::IsA()) ; } else if (iobuffer.IsWriting()) { byte_count = iobuffer.WriteVersion(CalData::IsA(), kTRUE) ; Version_t current_version = class_version() ; if (current_version < 5 || current_version > 12){ ERRLOG(ELerror,"CalData: ") << "Unsupported CalData class version cannot be treated" << endmsg; } else{ StorableObject::Streamer( iobuffer ); // version of parameters used iobuffer << _paramVersion; // stream out calib version (for now bogus) uint4 iDBset = 0; iobuffer << iDBset; uint2 pedNumber = 50; // number of counts to subtract - this should be read from // database. Okay for now but must be changed... iobuffer << pedNumber; // stream out calib constants iobuffer << _calibrations.calibCem(); iobuffer << _calibrations.calibCha(); iobuffer << _calibrations.calibWha(); iobuffer << _calibrations.calibPpr(); iobuffer << _calibrations.calibPem(); iobuffer << _calibrations.calibPha(); iobuffer << _calibrations.calibMpa(); iobuffer << _calibrations.pedCem(); iobuffer << _calibrations.pedCha(); iobuffer << _calibrations.pedWha(); iobuffer << _calibrations.pedPpr(); iobuffer << _calibrations.pedPem(); iobuffer << _calibrations.pedPha(); iobuffer << _calibrations.pedMpa(); int n_items = this->size(); iobuffer << n_items ; CalData::Iterator end = this->end(); for(CalData::Iterator iter= this->begin(); iter != end; ++iter) { CalTower* t = iter.tower(); iobuffer << iter->iEta(); iobuffer << iter->iPhi(); iobuffer << iter->validCode(); t->writeToBuffer(iobuffer,current_version); } } iobuffer.SetByteCount(byte_count, kTRUE) ; } else { ERRLOG(ELerror,"CalData: ") << " (): NOTHING DONE" << endmsg; } } // // Access and manipulation // int CalData::size() const { // the ++ operator takes a long time=> try this for the moment until we have // something better int nTowers = 0; for (int ieta=0; ieta< TOWER_NETA; ieta++) { for (int iphi=0; iphi() const{ return (*_dataptr)[_iEta][_iPhi]; } CalTower& CalData::ConstIterator::operator*() const { return *operator->(); } bool CalData::ConstIterator::operator==(const ConstIterator& rhs) const{ if (this == &rhs) return true; return (_iEta == rhs._iEta && _iPhi == rhs._iPhi && _dataptr == rhs._dataptr); } bool CalData::ConstIterator::operator!=(const ConstIterator& it) const { return !operator==(it); } CalData::ConstIterator& CalData::ConstIterator::operator=(const ConstIterator& iter) { _iEta=iter._iEta; _iPhi=iter._iPhi; _dataptr=iter._dataptr; return *this; } // The non-const Iterator implementation CalData::Iterator::Iterator():_iEta(0),_iPhi(0),_dataptr(0) { } CalData::Iterator::Iterator(TowerData& td,UChar_t iEta=0, UChar_t iPhi=0):_iEta(iEta),_iPhi(iPhi),_dataptr(&td) { } CalData::Iterator& CalData::Iterator::operator++(){ bool first = true; while(((*_dataptr)[_iEta][_iPhi] == 0 || first) && !(_iPhi ==47 && _iEta ==51)){ first = false; ++_iPhi; if(_iPhi == TOWER_MAX_NPHI){ ++_iEta; _iPhi=0; } } return *this; } CalData::Iterator& CalData::Iterator::operator--(){ bool first = true; while(((*_dataptr)[_iEta][_iPhi] == 0 || first) && !(_iPhi ==0 && _iEta ==0)){ first = false; if(_iPhi== 0) { --_iEta; _iPhi = TOWER_MAX_NPHI;} --_iPhi; } return *this; } CalTower* CalData::Iterator::operator->() { return (*_dataptr)[_iEta][_iPhi]; } CalTower& CalData::Iterator::operator*() { return *operator->(); } bool CalData::Iterator::operator==(const Iterator& rhs) const { if (this == &rhs) return true; return (_iEta == rhs._iEta && _iPhi == rhs._iPhi && _dataptr == rhs._dataptr); } bool CalData::Iterator::operator!=(const Iterator& it) const { return !operator==(it); } CalData::Iterator& CalData::Iterator::operator=(const Iterator& iter) { _iEta=iter._iEta; _iPhi=iter._iPhi; _dataptr=iter._dataptr; return *this; } void CalData::totalEnergies(float& emSum, float& hadSum) const{ int intow = 0; emSum=0; hadSum=0; CalData::ConstIterator end = this->end(); for(CalData::ConstIterator iter= this->begin(); iter != end; ++iter){ CalTower* t = iter.tower(); intow++; emSum += t->emEnergy(); hadSum += t->hadEnergy(); } } // // Printing // void CalData::printSummary() const{ int intow = 0; float emSum=0; float hadSum=0; CalData::ConstIterator end = this->end(); for(CalData::ConstIterator iter= this->begin(); iter != end; ++iter){ CalTower* t = iter.tower(); intow++; emSum += t->emEnergy(); hadSum += t->hadEnergy(); } std::cout << "CalData contains " << intow << " towers:" << " total EM energy " << emSum << " total HAD energy " << hadSum << " TOTAL energy " << emSum+hadSum << std::endl; } void CalData::storeCalibrations(Calib& dbCalib) { _calibrations = CalDataCalib(dbCalib.detCem(), dbCalib.detCha(), dbCalib.detWha(), dbCalib.detPpr(), dbCalib.detPem(), dbCalib.detPha(), dbCalib.detMpa(), dbCalib.pedCem(), dbCalib.pedCha(), dbCalib.pedWha(), dbCalib.pedPpr(), dbCalib.pedPem(), dbCalib.pedPha(), dbCalib.pedMpa()); } bool CalData::puff() const{ if( !_isPuffed ){ // LER calibration arrays float cemCal[TENETA][TENPHI]; float pemCal[TENETA][TENPHI]; float pprCal[TENETA][TENPHI]; float chaCal[TENETA][TENPHI]; float phaCal[TENETA][TENPHI]; float whaCal[TENETA][TENPHI]; float mpaOffset[NMPSIDE][NMPTOW]; float mpaSlope[NMPSIDE][NMPTOW]; memset(cemCal,0,TENETA*TENPHI*sizeof(float)); memset(pemCal,0,TENETA*TENPHI*sizeof(float)); memset(pprCal,0,TENETA*TENPHI*sizeof(float)); memset(chaCal,0,TENETA*TENPHI*sizeof(float)); memset(whaCal,0,TENETA*TENPHI*sizeof(float)); memset(phaCal,0,TENETA*TENPHI*sizeof(float)); memset(mpaOffset,0,NMPSIDE*NMPTOW*sizeof(float)); memset(mpaSlope,0,NMPSIDE*NMPTOW*sizeof(float)); // Get LER collections from begin run baggie std::string DetString( " " ); bool noLer[] = { false, false, false, false, false, false, false}; enum { dCEM=0, dPEM, dPPR, dCHA, dWHA, dPHA, dMPA}; AbsEvent* aRun = AbsEnv::theRunRecord(); bool oldcollection=false; ConstEventIter cemI( aRun, "CEMTowerCorrColl" ); if ( cemI.is_valid() ) { ConstHandle collHandle( cemI ); const CEMTowerCorrColl::TowerCorrVector cont = collHandle->contents(); for ( CEMTowerCorrColl::const_iterator it = cont.begin(); it != cont.end(); ++it) { int ieta( it->iEta() ); int iphi( it->iPhi() ); cemCal[ieta][iphi] = it->correction(); } } else { DetString += "CEM "; noLer[dCEM] = true; } ConstEventIter pemI( aRun, "PEMTowerCorrColl" ); if ( pemI.is_valid() ) { ConstHandle collHandle( pemI ); const PEMTowerCorrColl::TowerCorrVector cont = collHandle->contents(); for ( PEMTowerCorrColl::const_iterator it = cont.begin(); it != cont.end(); ++it) { int ieta( it->iEta() ); int iphi( it->iPhi() ); pemCal[ieta][iphi] = it->correction(); } } else { DetString += "PEM "; noLer[dPEM] = true; } ConstEventIter pprI( aRun, "PPRTowerCorrColl" ); if ( pprI.is_valid() ) { ConstHandle collHandle( pprI ); const PPRTowerCorrColl::TowerCorrVector cont = collHandle->contents(); for ( PPRTowerCorrColl::const_iterator it = cont.begin(); it != cont.end(); ++it) { int ieta( it->iEta() ); int iphi( it->iPhi() ); pprCal[ieta][iphi] = it->correction(); } } else { DetString += "PPR "; noLer[dPPR] = true ; } ConstEventIter chaI( aRun, "CHATowerCorrColl" ); if ( chaI.is_valid() ) { ConstHandle collHandle( chaI ); const CHATowerCorrColl::TowerCorrVector cont = collHandle->contents(); for ( CHATowerCorrColl::const_iterator it = cont.begin(); it != cont.end(); ++it) { int ieta( it->iEta() ); int iphi( it->iPhi() ); chaCal[ieta][iphi] = it->correction(); } } else { DetString += "CHA "; noLer[dCHA] = true; } ConstEventIter whaI( aRun, "WHATowerCorrColl" ); if ( whaI.is_valid() ) { ConstHandle collHandle( whaI ); const WHATowerCorrColl::TowerCorrVector cont = collHandle->contents(); for ( WHATowerCorrColl::const_iterator it = cont.begin(); it != cont.end(); ++it) { int ieta( it->iEta() ); int iphi( it->iPhi() ); whaCal[ieta][iphi] = it->correction(); } } else { DetString += "WHA "; noLer[dWHA] = true; } ConstEventIter phaI( aRun, "PHATowerCorrColl" ); if ( phaI.is_valid() ) { ConstHandle collHandle( phaI ); const PHATowerCorrColl::TowerCorrVector cont = collHandle->contents(); for ( PHATowerCorrColl::const_iterator it = cont.begin(); it != cont.end(); ++it) { int ieta( it->iEta() ); int iphi( it->iPhi() ); phaCal[ieta][iphi] = it->correction(); } } else { DetString += "PHA "; noLer[dPHA] = true; } ConstEventIter mpaI( aRun, "MPATowerCorrColl" ); if ( mpaI.is_valid() ) { ConstHandle collHandle( mpaI ); const MPATowerCorrColl::TowerCorrVector cont = collHandle->contents(); for ( MPATowerCorrColl::const_iterator it = cont.begin(); it != cont.end(); ++it) { int is( it->iEta() ); int itow( it->iPhi() ); if (is < 2) mpaOffset[is][itow] = it->correction(); else mpaSlope[is-2][itow] = it->correction(); } } else { noLer[dMPA] = true; } if ( mpaOffset[0][0] == -9999) noLer[dMPA] = true; if ( DetString != " " ) { // if the new collections don't exist we use the old // one (TowerCorrectionColl): e.g. to read back 4.11.2 data (B.H.) oldcollection=true; const TowerCorrectionColl *TowCorr = NULL; AbsEvent* aRun = AbsEnv::theRunRecord(); EventRecord::ConstIterator tcorr(aRun,"TowerCorrectionColl"); if (tcorr.is_valid()) { TowerCorrectionColl_ch handle(tcorr); TowCorr = &*handle; for(TowerCorrectionColl::const_iterator towc = TowCorr->contents().begin(); towc != TowCorr->contents().end();++towc) { int ieta=int(towc->iEta()); int iphi=int(towc->iPhi()); if (TOWER_TYPE[ieta]<3){ cemCal[ieta][iphi]=towc->emcorrection(); } else { pemCal[ieta][iphi]=towc->emcorrection(); } float corrcha=1; float corrwha=1; float corrpha=1; if (TOWER_TYPE[ieta]==1) { int tempcha=int(towc->hadcorrection()); if ((tempcha & 0x1)==0) { corrcha=1+float( (tempcha>>1)&0xFF)/1000; } else { corrcha=1-float( (tempcha>>1)&0xFF)/1000; } if (((tempcha>>10) & 0x1)==0) { corrwha=1+float( (tempcha>>11)&0xFF)/1000; } else { corrwha=1-float( (tempcha>>11)&0xFF)/1000; } chaCal[ieta][iphi]=corrcha; whaCal[ieta][iphi]=corrwha; } else if (TOWER_TYPE[ieta]==4) { int temppha=int(towc->hadcorrection()); if ((temppha & 0x1)==0) { corrpha=1+float( (temppha>>1)&0xFF)/1000; } else { corrpha=1-float( (temppha>>1)&0xFF)/1000; } if (((temppha>>10) & 0x1)==0) { corrwha=1+float( (temppha>>11)&0xFF)/1000; } else { corrwha=1-float( (temppha>>11)&0xFF)/1000; } phaCal[ieta][iphi]=corrpha; whaCal[ieta][iphi]=corrwha; } else if (TOWER_TYPE[ieta]==0) { chaCal[ieta][iphi]=towc->hadcorrection(); } else if (TOWER_TYPE[ieta]==2 ||TOWER_TYPE[ieta]==3) { whaCal[ieta][iphi]=towc->hadcorrection(); } else if (TOWER_TYPE[ieta]>4) { phaCal[ieta][iphi]=towc->hadcorrection(); } } noLer[dCEM] = false; noLer[dCHA] = false; noLer[dPEM] = false; noLer[dPPR] = false; noLer[dWHA] = false; noLer[dPHA] = false; } else { ERRLOG(ELwarning,"CalData puff: ") << "No offline LER coll for: " << DetString << " => CalorimetryModule should be rerun" << endmsg; for (int iphi=0;iphiend(); if ( end.iEta()==0 && end.iPhi()==0 ) { ERRLOG(ELwarning,"CalData puff: ") << " empty event" << endmsg; } for(CalData::ConstIterator iter= this->begin(); iter != end; ++iter){ int teta( iter.iEta() ); // TOWE indices int tphi( iter.iPhi() ); float cal[]={1.0,1.0, 1.0,1.0, 1.0,1.0, 1.0,1.0, 1.0,1.0, 1.0,1.0, 1.0}; // Map : cem0,1 pem0,1 cha0,1 wha0,1 pha0,1 ppr0,1 , mpa // int TType( TOWER_TYPE[teta] ); if ( TType < 5 ) { int iphi0( 2*tphi ); if ( !noLer[dCEM] ) { cal[ 0] = cemCal[teta][iphi0 ]; cal[ 1] = cemCal[teta][iphi0+1]; if (oldcollection) { cal[ 0] = cemCal[teta][tphi ]; cal[ 1] = cemCal[teta][tphi ]; } } if ( !noLer[dCHA] ) { cal[ 4] = chaCal[teta][iphi0 ]; cal[ 5] = chaCal[teta][iphi0+1]; if (oldcollection) { cal[ 4] = chaCal[teta][tphi ]; cal[ 5] = chaCal[teta][tphi ]; } } if ( !noLer[dWHA] ) { cal[ 6] = whaCal[teta][iphi0 ]; cal[ 7] = whaCal[teta][iphi0+1]; if (oldcollection) { cal[ 6] = whaCal[teta][tphi ]; cal[ 7] = whaCal[teta][tphi ]; } } if ( !noLer[dPEM] ) { cal[ 2] = pemCal[teta][iphi0 ]; cal[ 3] = pemCal[teta][iphi0+1]; if (oldcollection) { cal[ 2] = pemCal[teta][tphi ]; cal[ 3] = pemCal[teta][tphi ]; } } if ( !noLer[dPHA] ) { cal[ 8] = phaCal[teta][iphi0 ]; cal[ 9] = phaCal[teta][iphi0+1]; if (oldcollection) { cal[ 8] = phaCal[teta][tphi ]; cal[ 9] = phaCal[teta][tphi ]; } } if ( !noLer[dPPR] ) { cal[10] = pprCal[teta][iphi0 ]; cal[11] = pprCal[teta][iphi0+1]; if (oldcollection) { cal[10] = pprCal[teta][tphi ]; cal[11] = pprCal[teta][tphi ]; } } } else { int iphi0( ( TType==5 ) ? tphi : 2*tphi ); if ( !noLer[dPEM] ) cal[ 2] = pemCal[teta][iphi0]; if ( !noLer[dPHA] ) cal[ 8] = phaCal[teta][iphi0]; if ( !noLer[dPPR] ) cal[10] = pprCal[teta][iphi0]; if (oldcollection) { cal[ 2] = pemCal[teta][tphi]; cal[ 8] = phaCal[teta][tphi]; cal[10] = pprCal[teta][tphi]; } } //MiniPlug if ( TType >= 8 ) { if ( !noLer[dMPA] ) { CalTower* t = iter.tower(); int itow(t->iTower() ); int is = 0; int layer = teta; if (teta > 25) { is = 1; layer = 51 - teta; } float mpCorr = (mpaOffset[is][itow] + mpaSlope[is][itow]*ilum) /(MC_EXP1_NEW[layer]); mpCorr = mpCorr*TOW2DEP_CORR[itow%14]; if (mpCorr < 0.) mpCorr = 0.; cal[12] = mpCorr; } else cal[12] = -1.; } // Regenerate calData pmtEnergy with the SCL/LERs CalTower* t = iter.tower(); t->puffTower(&_calibrations, cal); t->fillCalTower(-1,_paramVersion); // this prevents the validation flag from changing } } return true; } void CalData::cleanup(int skcut, float EtMin) { if(_locs == 0) _locs = new Locations(); CalData_ch cal_hndl = CalData_ch(this); CalData::Iterator end = this->end(); if(end.iEta()==0 && end.iPhi()==0) std::cout << "warning: empty event" << std::endl; // loop over all towers and remove those with Etbegin(); iter != end; ++iter){ CalTower* t = iter.tower(); t->setIeta(iter.iEta()); t->setIphi(iter.iPhi()); size_t ieta=t->iEta(); size_t iphi=t->iPhi(); int twrType = TOWER_TYPE[ieta]; int iTileMax = (twrType == 3 || twrType == 4) ? 2 : 1; // kill dead/hot towers in the plug if ( twrType > 2 && twrType < 8 ) { for ( int itile = 0; itile < iTileMax; ++itile ) { if (t && ( (itile == 0 && t->isBad(PEMPMT0BAD)) || (itile == 1 && t->isBad(PEMPMT1BAD))) ) { CellKey cellKey = CellKey( ieta, iphi,PEM); CalorKey calrKey = cellKey.makeCalorKey( cellKey, itile ); if (cellKey.isValid()) { float eTile = -1.*t->pmtEnergy( cellKey, itile ); // Zero out energy uint2 iData = _calibrations.pedPem(); t->addPmtEnergy( calrKey.detector(), itile, eTile, iData ); } } if (t && ( (itile == 0 && t->isBad(PHAPMT0BAD)) || (itile == 1 && t->isBad(PHAPMT1BAD))) ) { CellKey cellKey = CellKey( ieta, iphi,PHA); CalorKey calrKey = cellKey.makeCalorKey( cellKey, itile ); if (cellKey.isValid()) { float eTile = -1.*t->pmtEnergy( cellKey, itile ); // Zero out energy uint2 iData = _calibrations.pedPha(); t->addPmtEnergy ( calrKey.detector(), itile, eTile, iData ); } } } } t->fillCalTower(skcut,_paramVersion); // remove towers with EtemEnergy() || t->hadEnergy()>0) { // Kill low Et towers float Etem= t->emEnergy() * _locs->emSinTheta(ieta,iphi); float Ethad=t->hadEnergy()* _locs->hadSinTheta(ieta,iphi); float Ettot=Etem+Ethad; if (Ettotdetectors(dl); // Look for "spikes" in the plug region const bool pSpike = true; // Plug spike killer on const float ePSpikeEmin = 50.0; // Min. tower energy, GeV const float ePSpikeFmin = 0.02; // Min. spike fraction if ( pSpike && ( twrType > 2 && twrType < 8 ) ) { for ( int itile = 0; itile < iTileMax; ++itile ) { Detector pDet[3] = { PEM, PHA, PPR }; // Detector list for ( int idet = 0; idet < 3; ++idet ) { float eTow; // Energy in target tower float eSum; // Energy about target int nTow; // Tower count in eSum Detector iDet = pDet[idet]; bool validTwr = plugSpike(cal_hndl, ieta, iphi, itile, iDet, eTow, eSum, nTow); if ( validTwr ) { float fspike = eSum / ( (eTow + eSum) > 0.001 ? eTow + eSum : 0.001 ); if (eTow > ePSpikeEmin && fspike < ePSpikeFmin) { CellKey cellKey = CellKey( ieta, iphi, iDet ); CalorKey calrKey = cellKey.makeCalorKey( cellKey, itile ); float eTile = -eTow; // Zero out energy uint2 iData = ( idet == 0 ) ? _calibrations.pedPem() : ( ( idet == 1 ) ? _calibrations.pedPha() : _calibrations.pedPpr() ); t->addPmtEnergy( calrKey.detector(), itile, eTile, iData ); if (idet == 0) t->setBad(PEMSPIKE); if (idet == 1) t->setBad(PHASPIKE); if (idet == 2) t->setBad(PPRSPIKE); t->fillCalTower(-1,_paramVersion); // this prevents the validation flag from changing } } } } } } // ----- } _isPuffed = true; } CalData::Error CalData::find(CalData_ch& theHandle){ AbsEvent* theEvent = AbsEnv::theEvent(); EventRecord::ConstIterator calDataIter(theEvent,"CalData" ); if(calDataIter.is_invalid()) return ERROR; theHandle = CalData_ch(calDataIter); return OK; } // Ntuplizer related methods void CalData::attach_ntuplizer(CalDataNtuplizer* p_ntuplizer) { if (_p_ntuplizer != 0) { ERRLOG( ELsevere, "Ntuplizer already attached" ) << "@SUB=CalData::attach_ntuplizer" << "CalDataNtuplizer previously set" << endmsg; return; } _p_ntuplizer = p_ntuplizer; } void CalData::ntuplize() const { if (_p_ntuplizer) _p_ntuplizer->capture(*this); } // } // namespace calor CdfClassImp(CalData)