// class CBNT_CaloCell // make ntuple for CaloCell // for LArRec tutorial, Dec 2000 // H.Ma Nov 2000 // Using StoreGate now. // // 23 April 2004: add simple detector information, J.Tanaka #include "CaloRec/CBNTAA_CaloCell.h" #include "CaloEvent/CaloCellContainer.h" #include "GaudiKernel/ISvcLocator.h" #include "GaudiKernel/StatusCode.h" #include "GaudiKernel/MsgStream.h" #include "StoreGate/StoreGateSvc.h" #include "CaloIdentifier/CaloID.h" #include "CLHEP/Units/SystemOfUnits.h" #include "CaloUtils/ICaloBadChannelTool.h" #include "CaloDetDescr/CaloBadChannel.h" CBNTAA_CaloCell::CBNTAA_CaloCell(const std::string& name, ISvcLocator* pSvcLocator) : CBNT_AthenaAwareBase(name, pSvcLocator), m_cellsName("AllCalo"),m_maxNCells(0),m_cellEnergyThreshold(0.),m_saveDetInfo(false),m_saveTimeInfo(false),m_saveQInfo(false),m_suffix("") { // string property for Cell container declareProperty("CellsName",m_cellsName); // list of calo to treat declareProperty("CaloNums",m_caloNums); // string property for Cell container declareProperty("MaxNCells",m_maxNCells); // declareProperty("ThresholdGeVCells",m_thresholdGeVCells); // m_thresholdGeVCells --> m_cellEnergyThreshold declareProperty("CellEnergyThreshold",m_cellEnergyThreshold); // suffix for all the variables declareProperty("Suffix",m_suffix); // m_NtupleLocID="/FILE1/CALO/168"; declareProperty("SaveDetInfo",m_saveDetInfo); declareProperty("SaveTimeInfo",m_saveTimeInfo); declareProperty("SaveQualityInfo",m_saveQInfo); } CBNTAA_CaloCell::~CBNTAA_CaloCell() { } StatusCode CBNTAA_CaloCell::CBNT_initialize() { MsgStream log(messageService(), name()); log << MSG::INFO << " in CBNT_initialize" << endreq; log << MSG::INFO << " reading CaloCellContainer " << m_cellsName << endreq ; if (m_maxNCells<=0) { log << MSG::INFO << " no detailed cell info " << endreq ; }else{ log << MSG::INFO << " detailed cell info up to " << m_maxNCells << " cells " << endreq ; log << MSG::INFO << " ....applying threshold " << m_cellEnergyThreshold << endreq ; if (m_saveDetInfo) { log << MSG::INFO << " ...with pseudo identifier variable " << endreq ; } else{ log << MSG::INFO << " ...without pseudo identifier variable " << endreq ; } } StatusCode sc ; addBranch ("nhit"+m_suffix,m_nhit,"nhit"+m_suffix+"/I"); if ( sc == StatusCode::FAILURE ) { log<0) { addBranch ("NCells"+m_suffix,m_nCells,"NCells"+m_suffix+"/I"); addBranch ("ECells"+m_suffix,m_eCells); addBranch ("EtaCells"+m_suffix,m_etaCells); addBranch ("PhiCells"+m_suffix,m_phiCells); addBranch ("QCells"+m_suffix,m_fitQCells); addBranch ("GainCells"+m_suffix,m_gainCells); // Added LH addBranch("XCells"+m_suffix,m_xCells); addBranch("YCells"+m_suffix,m_yCells); addBranch("IDCells"+m_suffix,m_idCells); if (m_saveDetInfo) addBranch ("DetCells"+m_suffix,m_detCells); if (m_saveTimeInfo) addBranch ("TimeCells"+m_suffix,m_timeCells); if (m_saveQInfo) addBranch ("BadCells"+m_suffix,m_qCells); } // get StoreGate // Find the detector store service. StoreGateSvc* detStore; sc = service("DetectorStore",detStore); if (sc.isFailure()) { log << MSG::ERROR << "Unable to get pointer to Detector Store Service" << endreq; return sc; } sc = detStore->retrieve(m_emid); if (sc.isFailure()) { log << MSG::ERROR << "Unable to retrieve LArEM_ID helper from DetectorStore" << endreq; return sc; } sc = detStore->retrieve(m_fcalid); if (sc.isFailure()) { log << MSG::ERROR << "Unable to retrieve LArFCAL_ID helper from DetectorStore" << endreq; return sc; } sc = detStore->retrieve(m_hecid); if (sc.isFailure()) { log << MSG::ERROR << "Unable to retrieve LArHEC_ID helper from DetectorStore" << endreq; return sc; } sc = detStore->retrieve(m_tileid); if (sc.isFailure()) { log << MSG::ERROR << "Unable to retrieve TileID helper from DetectorStore" << endreq; return sc; } sc = service("StoreGateSvc", m_storeGate); if ( sc == StatusCode::FAILURE ) { log<retrieveTool("LArBadChannelTool",tool); if(sc.isFailure()) { log << MSG::ERROR << "Cannot get LArBadChannelTool"<< endreq; m_pb_tool = 0; } else { log << MSG::INFO << "Did get LArBadChannelTool"<< endreq; m_pb_tool =dynamic_cast(tool); } } unsigned int nSubCalo=static_cast(CaloCell_ID::NSUBCALO) ; //check calo number specified m_caloSelection = false ; if (m_caloNums.size()==0) { log << MSG::INFO << " No calorimeter selection " << endreq; return StatusCode::SUCCESS; } else if (m_caloNums.size()>nSubCalo ) { log << MSG::ERROR << " More than " << nSubCalo << " calo specified. Must be wrong. Stop." << endreq; return StatusCode::FAILURE; } else { m_caloSelection = true ; for (unsigned int index=0; index < m_caloNums.size() ; ++index) { if (m_caloNums[index]>=nSubCalo ) { log << MSG::ERROR << "Invalid calo specification:" << m_caloNums[index] << "Stop." << endreq ; return StatusCode::FAILURE; } else { log << MSG::INFO << " Select calorimeter " << m_caloNums[index] << endreq ; } } } return StatusCode::SUCCESS; } StatusCode CBNTAA_CaloCell::CBNT_finalize() { return StatusCode::SUCCESS; } StatusCode CBNTAA_CaloCell::CBNT_execute() { MsgStream log( messageService(), name() ); log << MSG::DEBUG << " in CBNT_execute" << endreq; // typedef ObjectVector CONTAINER; typedef CaloCellContainer CONTAINER; const CONTAINER* cellcoll ; StatusCode sc = m_storeGate->retrieve(cellcoll, m_cellsName) ; if(StatusCode::SUCCESS != sc ) { log<begin(); //CaloCellContainer::iterator l_cell = cellcoll->end(); CONTAINER::const_iterator f_cell = cellcoll->begin(); CONTAINER::const_iterator l_cell = cellcoll->end(); m_nhit = 0; int index = 0 ; for ( ; f_cell!=l_cell; ++f_cell) { const CaloCell* cell = (*f_cell) ; if (m_caloSelection) { unsigned int iCaloNum = static_cast(cell->caloDDE()->getSubCalo()); // keep only cells from desired calorimeter std::vector::const_iterator theFound = find (m_caloNums.begin(),m_caloNums.end(),iCaloNum); if (theFound==m_caloNums.end()) continue ; } ++m_nhit ; float e = cell->energy() ; m_eCell +=e; //fill cell by cell ntuple if required if (m_maxNCells>0) { if ( index < m_maxNCells ) { sc = this->record(cell,index); // log << MSG::VERBOSE << "Recording the cell index " << index << endreq ; Identifier id = cell->ID(); float th = m_cellEnergyThreshold ; double epsilon=0.001 ; if (std::abs(th)>epsilon) { if (th > 0.) { if (! (e>th)) continue ; } else if (th < 0.) { if (! (std::abs(e)>std::abs(th))) continue ; } } unsigned CombBit = 0; if (m_saveDetInfo) { CombBit = CaloCell_GetDetectorInfo(id,*m_emid,*m_fcalid, *m_hecid,*m_tileid); } //log << MSG::WARNING << "Energy unit " << e << " " << m_cellEnergyThreshold << " " << th << endreq; m_eCells->push_back(e) ; m_etaCells->push_back(cell->eta()) ; m_phiCells->push_back(cell->phi()) ; // Added LH m_xCells->push_back(cell->x()) ; m_yCells->push_back(cell->y()) ; m_idCells->push_back((long) id); m_fitQCells->push_back(cell->quality()); m_gainCells->push_back(cell->gain()); if (m_saveTimeInfo) m_timeCells->push_back(cell->time()); if (m_saveDetInfo) m_detCells->push_back(CombBit) ; if (m_saveQInfo) { CaloBadChannel* pb = m_pb_tool->ChannelProblem(id); if (pb) { int bittedword = pb->bittedWord (); m_qCells->push_back(bittedword); } else m_qCells->push_back(0); } ++index; }else{ if (m_maxNCells==index) { log << MSG::WARNING << " Too many cells. Save only " << m_maxNCells << endreq ; break ; } } } } if (m_maxNCells>0) m_nCells = index ; return sc; } unsigned CBNTAA_CaloCell::CaloCell_GetDetectorInfo(Identifier &cellID, const LArEM_ID &emid, const LArFCAL_ID &fcalid, const LArHEC_ID &hecid, const TileID &tileid) { // AtlasID bit (4) // 1 : lar_em // 2 : lar_hec // 3 : lar_fcal // 4 : tile unsigned ATbit1 = emid.is_lar_em(cellID) ? (1<<0) : 0; unsigned ATbit2 = hecid.is_lar_hec(cellID) ? (1<<1) : 0; unsigned ATbit3 = fcalid.is_lar_fcal(cellID) ? (1<<2) : 0; unsigned ATbit4 = tileid.is_tile(cellID) ? (1<<3) : 0; unsigned ATbit = (ATbit1 | ATbit2 | ATbit3 | ATbit4); //std::cout << "ATLAS Calo(EM,HEC,FCal,Tile) : " << ATbit1 << " " << ATbit2 << " " << ATbit3 << " " << ATbit4 << std::endl; // EM bit (5) // 1-2 : sampling // 0,1,2,3 // 0 presampler // 1,2,3 each layer // 3 : barrel // 4 : endcap_inner // 5 : endcap_outer unsigned EMbit1 = 0; unsigned EMbit3 = 0; unsigned EMbit4 = 0; unsigned EMbit5 = 0; if (ATbit1) { EMbit1 = unsigned(emid.sampling(cellID)); EMbit3 = emid.is_em_barrel(cellID) ? (1<<2) : 0; EMbit4 = emid.is_em_endcap_inner(cellID) ? (1<<3) : 0; EMbit5 = emid.is_em_endcap_outer(cellID) ? (1<<4) : 0; } unsigned EMbit = (EMbit1 | EMbit3 | EMbit4 | EMbit5); //std::cout << "EM : " << EMbit1 << " " << EMbit3 << " " << EMbit4 << " " << EMbit5 << std::endl; // HEC (2) // 1-2: sampling // 0,1 = first wheel // 2,3 = second wheel unsigned HCbit1 = 0; if (ATbit2) { HCbit1 = unsigned(hecid.sampling(cellID)); } unsigned HCbit = HCbit1; //std::cout << "HEC : " << HCbit1 << std::endl; // FCal (2) // 1-2 : module // 1,2,3 // 1 EM // 2,3 Hadronic // unsigned FCbit1 = 0; if (ATbit3) { FCbit1 = unsigned(fcalid.module(cellID)); } unsigned FCbit = FCbit1; //std::cout << "FCal : " << FCbit1 << std::endl; // Tile bit (8) // 1-3 : sample // 0 = SAMP_A // 1 = SAMP_B, SAMP_BC, SAMP_C // 2 = SAMP_D // 3 = SAMP_E // 4 = SAMP_X // 4 : barrel // 5 : extbarrel // 6 : gap // 7 : gapscin unsigned TLbit1 = 0; unsigned TLbit4 = 0; unsigned TLbit5 = 0; unsigned TLbit6 = 0; unsigned TLbit7 = 0; if (ATbit4) { TLbit1 = unsigned(tileid.sample(cellID)); TLbit4 = tileid.is_tile_barrel(cellID) ? (1<<3) : 0; TLbit5 = tileid.is_tile_extbarrel(cellID) ? (1<<4) : 0; TLbit6 = tileid.is_tile_gap(cellID) ? (1<<5) : 0; TLbit7 = tileid.is_tile_gapscin(cellID) ? (1<<6) : 0; } unsigned TLbit = (TLbit1 | TLbit4 | TLbit5 | TLbit6 | TLbit7); //std::cout << "Tile : " << TLbit1 << " " << TLbit4 << " " << TLbit5 << " " << TLbit6 << " " << TLbit7 << std::endl; unsigned CombBit = (ATbit | (EMbit<<4) | (HCbit<<9) | (FCbit<<11) | (TLbit<<13)); return CombBit; } StatusCode CBNTAA_CaloCell::CBNT_clear() { MsgStream log( messageService(), name() ); log << MSG::DEBUG << " in CBNT_clear" << endreq; m_nhit=0 ; m_eCell=0 ; if (m_maxNCells>0) { m_eCells->clear() ; m_etaCells->clear() ; m_phiCells->clear() ; m_fitQCells->clear() ; m_gainCells->clear() ; //Added LH m_xCells->clear(); m_yCells->clear(); m_idCells->clear(); if (m_saveDetInfo) m_detCells->clear() ; if (m_saveTimeInfo) m_timeCells->clear() ; if (m_saveQInfo) m_qCells->clear() ; } if (m_maxNCells>0) m_nCells = 0 ; return StatusCode::SUCCESS; }