Go to the documentation of this file.00001 #include "RecoLocalCalo/EcalRecProducers/plugins/EcalDetIdToBeRecoveredProducer.h"
00002
00003 #include "DataFormats/Common/interface/Handle.h"
00004 #include "FWCore/Framework/interface/ESHandle.h"
00005
00006 #include "DataFormats/EcalDetId/interface/EcalDetIdCollections.h"
00007 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
00008
00009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00010
00011 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00012 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00013
00014 #include "Geometry/EcalMapping/interface/EcalMappingRcd.h"
00015 #include "Geometry/Records/interface/IdealGeometryRecord.h"
00016 #include "CondFormats/DataRecord/interface/EcalChannelStatusRcd.h"
00017
00018 #include <set>
00019
00020 #include <sys/types.h>
00021 #include <signal.h>
00022
00023 EcalDetIdToBeRecoveredProducer::EcalDetIdToBeRecoveredProducer(const edm::ParameterSet& ps)
00024 {
00025
00026 ebSrFlagCollection_ = ps.getParameter<edm::InputTag>("ebSrFlagCollection");
00027 eeSrFlagCollection_ = ps.getParameter<edm::InputTag>("eeSrFlagCollection");
00028
00029
00030 ebIntegrityGainErrorsCollection_ = ps.getParameter<edm::InputTag>("ebIntegrityGainErrors");
00031 ebIntegrityGainSwitchErrorsCollection_ = ps.getParameter<edm::InputTag>("ebIntegrityGainSwitchErrors");
00032 ebIntegrityChIdErrorsCollection_ = ps.getParameter<edm::InputTag>("ebIntegrityChIdErrors");
00033
00034
00035 eeIntegrityGainErrorsCollection_ = ps.getParameter<edm::InputTag>("eeIntegrityGainErrors");
00036 eeIntegrityGainSwitchErrorsCollection_ = ps.getParameter<edm::InputTag>("eeIntegrityGainSwitchErrors");
00037 eeIntegrityChIdErrorsCollection_ = ps.getParameter<edm::InputTag>("eeIntegrityChIdErrors");
00038
00039
00040 integrityTTIdErrorsCollection_ = ps.getParameter<edm::InputTag>("integrityTTIdErrors");
00041 integrityBlockSizeErrorsCollection_ = ps.getParameter<edm::InputTag>("integrityBlockSizeErrors");
00042
00043
00044 ebDetIdCollection_ = ps.getParameter<std::string>("ebDetIdToBeRecovered");
00045 eeDetIdCollection_ = ps.getParameter<std::string>("eeDetIdToBeRecovered");
00046 ttDetIdCollection_ = ps.getParameter<std::string>("ebFEToBeRecovered");
00047 scDetIdCollection_ = ps.getParameter<std::string>("eeFEToBeRecovered");
00048
00049 produces< std::set<EBDetId> >( ebDetIdCollection_ );
00050 produces< std::set<EEDetId> >( eeDetIdCollection_ );
00051 produces< std::set<EcalTrigTowerDetId> >( ttDetIdCollection_ );
00052 produces< std::set<EcalScDetId> >( scDetIdCollection_ );
00053 }
00054
00055
00056 EcalDetIdToBeRecoveredProducer::~EcalDetIdToBeRecoveredProducer()
00057 {
00058 }
00059
00060
00061 void EcalDetIdToBeRecoveredProducer::beginRun(edm::Run & run, const edm::EventSetup& es)
00062 {
00063 edm::ESHandle< EcalElectronicsMapping > pEcalMapping;
00064 es.get<EcalMappingRcd>().get(pEcalMapping);
00065 ecalMapping_ = pEcalMapping.product();
00066
00067 edm::ESHandle< EcalChannelStatusMap > pChStatus;
00068 es.get<EcalChannelStatusRcd>().get(pChStatus);
00069 chStatus_ = pChStatus.product();
00070
00071 es.get<IdealGeometryRecord>().get(ttMap_);
00072 }
00073
00074
00075 template <typename CollT, typename ItemT>
00076 bool include(const CollT& coll, const ItemT& item)
00077 {
00078 typename CollT::const_iterator res = std::find( coll.begin(), coll.end(), item );
00079 return ( res != coll.end() );
00080 }
00081
00082 void EcalDetIdToBeRecoveredProducer::produce(edm::Event& ev, const edm::EventSetup& es)
00083 {
00084 std::vector< edm::Handle<EBDetIdCollection> > ebDetIdColls;
00085 std::vector< edm::Handle<EEDetIdCollection> > eeDetIdColls;
00086 std::vector< edm::Handle<EcalElectronicsIdCollection> > ttColls;
00087
00088 std::auto_ptr< std::set<EBDetId> > ebDetIdToRecover( new std::set<EBDetId> );
00089 std::auto_ptr< std::set<EEDetId> > eeDetIdToRecover( new std::set<EEDetId> );
00090 std::auto_ptr< std::set<EcalTrigTowerDetId> > ebTTDetIdToRecover( new std::set<EcalTrigTowerDetId> );
00091 std::auto_ptr< std::set<EcalScDetId> > eeSCDetIdToRecover( new std::set<EcalScDetId> );
00092
00093
00094
00095
00096
00097
00098 edm::Handle<EBSrFlagCollection> ebSrFlags;
00099 ev.getByLabel(ebSrFlagCollection_, ebSrFlags );
00100 if ( ! ebSrFlags.isValid() ) {
00101 edm::LogWarning("EcalDetIdToBeRecoveredProducer: -->") << ebSrFlagCollection_ << " not available";
00102 }
00103 edm::Handle<EESrFlagCollection> eeSrFlags;
00104 ev.getByLabel(eeSrFlagCollection_, eeSrFlags );
00105 if ( ! eeSrFlags.isValid() ) {
00106 edm::LogWarning("EcalDetIdToBeRecoveredProducer: -->") << eeSrFlagCollection_ << " not available";
00107 }
00108
00109
00110 edm::Handle<EBDetIdCollection> ebIntegrityGainErrors;
00111 ev.getByLabel( ebIntegrityGainErrorsCollection_, ebIntegrityGainErrors );
00112 if ( ebIntegrityGainErrors.isValid() ) {
00113 ebDetIdColls.push_back( ebIntegrityGainErrors );
00114 } else {
00115 edm::LogWarning("EcalDetIdToBeRecoveredProducer") << ebIntegrityGainErrorsCollection_ << " not available";
00116 }
00117 edm::Handle<EBDetIdCollection> ebIntegrityGainSwitchErrors;
00118 ev.getByLabel( ebIntegrityGainSwitchErrorsCollection_, ebIntegrityGainSwitchErrors );
00119 if ( ebIntegrityGainSwitchErrors.isValid() ) {
00120 ebDetIdColls.push_back( ebIntegrityGainSwitchErrors );
00121 } else {
00122 edm::LogWarning("EcalDetIdToBeRecoveredProducer") << ebIntegrityGainErrorsCollection_ << " not available";
00123 }
00124 edm::Handle<EBDetIdCollection> ebIntegrityChIdErrors;
00125 ev.getByLabel( ebIntegrityChIdErrorsCollection_, ebIntegrityChIdErrors );
00126 if ( ebIntegrityChIdErrors.isValid() ) {
00127 ebDetIdColls.push_back( ebIntegrityChIdErrors );
00128 } else {
00129 edm::LogWarning("EcalDetIdToBeRecoveredProducer") << ebIntegrityChIdErrorsCollection_ << " not available";
00130 }
00131
00132 edm::Handle<EEDetIdCollection> eeIntegrityGainErrors;
00133 ev.getByLabel( eeIntegrityGainErrorsCollection_, eeIntegrityGainErrors );
00134 if ( eeIntegrityGainErrors.isValid() ) {
00135 eeDetIdColls.push_back( eeIntegrityGainErrors );
00136 } else {
00137 edm::LogWarning("EcalDetIdToBeRecoveredProducer") << eeIntegrityGainErrorsCollection_ << " not available";
00138 }
00139 edm::Handle<EEDetIdCollection> eeIntegrityGainSwitchErrors;
00140 ev.getByLabel( eeIntegrityGainSwitchErrorsCollection_, eeIntegrityGainSwitchErrors );
00141 if ( eeIntegrityGainSwitchErrors.isValid() ) {
00142 eeDetIdColls.push_back( eeIntegrityGainSwitchErrors );
00143 } else {
00144 edm::LogWarning("EcalDetIdToBeRecoveredProducer") << eeIntegrityGainErrorsCollection_ << " not available";
00145 }
00146 edm::Handle<EEDetIdCollection> eeIntegrityChIdErrors;
00147 ev.getByLabel( eeIntegrityChIdErrorsCollection_, eeIntegrityChIdErrors );
00148 if ( eeIntegrityChIdErrors.isValid() ) {
00149 eeDetIdColls.push_back( eeIntegrityChIdErrors );
00150 } else {
00151 edm::LogWarning("EcalDetIdToBeRecoveredProducer") << eeIntegrityChIdErrorsCollection_ << " not available";
00152 }
00153
00154 edm::Handle<EcalElectronicsIdCollection> integrityTTIdErrors;
00155 ev.getByLabel( integrityTTIdErrorsCollection_, integrityTTIdErrors );
00156 if ( integrityTTIdErrors.isValid() ) {
00157 ttColls.push_back( integrityTTIdErrors );
00158 } else {
00159 edm::LogWarning("EcalDetIdToBeRecoveredProducer") << integrityTTIdErrorsCollection_ << " not available";
00160 }
00161 edm::Handle<EcalElectronicsIdCollection> integrityBlockSizeErrors;
00162 ev.getByLabel( integrityBlockSizeErrorsCollection_, integrityBlockSizeErrors );
00163 if ( integrityBlockSizeErrors.isValid() ) {
00164 ttColls.push_back( integrityBlockSizeErrors );
00165 } else {
00166 edm::LogWarning("EcalDetIdToBeRecoveredProducer") << integrityBlockSizeErrorsCollection_ << " not available";
00167 }
00168
00169
00170
00171
00172
00173 EBDetIdCollection ebSrpDetId;
00174 EcalTrigTowerDetIdCollection ebSrpTTDetId;
00175 for ( EBSrFlagCollection::const_iterator it = ebSrFlags->begin(); it != ebSrFlags->end(); ++it ) {
00176 const int flag = it->value();
00177 if ( flag == EcalSrFlag::SRF_FULL || ( flag == EcalSrFlag::SRF_FORCED_MASK) ) {
00178 const EcalTrigTowerDetId ttId = it->id();
00179 ebSrpTTDetId.push_back( ttId );
00180
00181 const std::vector<DetId> vid = ttMap_->constituentsOf( ttId );
00182
00183 for ( std::vector<DetId>::const_iterator itId = vid.begin(); itId != vid.end(); ++itId ) {
00184 ebSrpDetId.push_back( *itId );
00185 }
00186 }
00187 }
00188
00189 EEDetIdCollection eeSrpDetId;
00190
00191 for ( EESrFlagCollection::const_iterator it = eeSrFlags->begin(); it != eeSrFlags->end(); ++it ) {
00192 const int flag = it->value();
00193 if ( flag == EcalSrFlag::SRF_FULL || ( flag == EcalSrFlag::SRF_FORCED_MASK) ) {
00194
00195
00196 const EcalScDetId scId( it->id() );
00197
00199
00200 std::vector<DetId> vid;
00201 for(int dx=1; dx<=5; ++dx){
00202 for(int dy=1; dy<=5; ++dy){
00203 const int ix = (scId.ix()-1)*5 + dx;
00204 const int iy = (scId.iy()-1)*5 + dy;
00205 const int iz = scId.zside();
00206 if(EEDetId::validDetId(ix, iy, iz)){
00207 vid.push_back(EEDetId(ix, iy, iz));
00208 }
00209 }
00210 }
00212
00213 for ( std::vector<DetId>::const_iterator itId = vid.begin(); itId != vid.end(); ++itId ) {
00214 eeSrpDetId.push_back( *itId );
00215 }
00216 }
00217 }
00218
00219 if ( ebSrFlags->size() == 0 ) {
00220 }
00221
00222 if ( eeSrFlags->size() == 0 ) {
00223 }
00224
00225
00226
00227
00228
00229
00230
00231 for ( std::vector<edm::Handle<EBDetIdCollection> >::const_iterator it = ebDetIdColls.begin(); it != ebDetIdColls.end(); ++it )
00232 {
00233 const EBDetIdCollection * idc = it->product();
00234 for ( EBDetIdCollection::const_iterator jt = idc->begin(); jt != idc->end(); ++jt )
00235 if (include(ebSrpDetId, *jt))
00236 ebDetIdToRecover->insert( *jt );
00237 }
00238
00239 for ( std::vector<edm::Handle<EEDetIdCollection> >::const_iterator it = eeDetIdColls.begin(); it != eeDetIdColls.end(); ++it )
00240 {
00241 const EEDetIdCollection * idc = it->product();
00242 for ( EEDetIdCollection::const_iterator jt = idc->begin(); jt != idc->end(); ++jt )
00243 if (include(eeSrpDetId, *jt))
00244 eeDetIdToRecover->insert( *jt );
00245 }
00246
00247
00248
00249
00250
00251
00252
00253 for ( EBDetIdCollection::const_iterator itId = ebSrpDetId.begin(); itId != ebSrpDetId.end(); ++itId ) {
00254 EcalChannelStatusMap::const_iterator chit = chStatus_->find( *itId );
00255 if ( chit != chStatus_->end() ) {
00256 const int flag = (*chit).getStatusCode() & 0x001F;
00257 if ( flag >= 10 && flag <= 12) {
00258 ebDetIdToRecover->insert( *itId );
00259 } else if ( flag == 13 || flag == 14 ) {
00260 ebTTDetIdToRecover->insert( (*itId).tower() );
00261 }
00262 } else {
00263 edm::LogError("EcalDetIdToBeRecoveredProducer") << "No channel status found for xtal "
00264 << (*itId).rawId()
00265 << "! something wrong with EcalChannelStatus in your DB? ";
00266 }
00267 }
00268
00269 for ( EEDetIdCollection::const_iterator itId = eeSrpDetId.begin(); itId != eeSrpDetId.end(); ++itId ) {
00270 EcalChannelStatusMap::const_iterator chit = chStatus_->find( *itId );
00271 if ( chit != chStatus_->end() ) {
00272 int flag = (*chit).getStatusCode() & 0x001F;
00273 if ( flag >= 10 && flag <= 12) {
00274 eeDetIdToRecover->insert( *itId );
00275 } else if ( flag == 13 || flag == 14 ) {
00276 eeSCDetIdToRecover->insert( EcalScDetId(1+((*itId).ix()-1)/5,1+((*itId).iy()-1)/5,(*itId).zside()) );
00277 }
00278 } else {
00279 edm::LogError("EcalDetIdToBeRecoveredProducer") << "No channel status found for xtal "
00280 << (*itId).rawId()
00281 << "! something wrong with EcalChannelStatus in your DB? ";
00282 }
00283 }
00284
00285
00286
00287 for (size_t t = 0; t < ttColls.size(); ++t) {
00288 const EcalElectronicsIdCollection& coll = *(ttColls[t]);
00289
00290 for (size_t i = 0; i < coll.size(); ++i)
00291 {
00292 const EcalElectronicsId elId = coll[i];
00293 const EcalSubdetector subdet = elId.subdet();
00294 const DetId detId = ecalMapping_->getDetId(elId);
00295
00296 if (subdet == EcalBarrel) {
00297
00298 const EcalTrigTowerDetId ttId( ttMap_->towerOf(detId) );
00299 const std::vector<DetId>& vid = ttMap_->constituentsOf(ttId);
00300
00301 for (size_t j = 0; j < vid.size(); ++j) {
00302 const EBDetId ebdi(vid[j]);
00303 if (include(ebSrpDetId, ebdi)) {
00304 ebDetIdToRecover->insert(ebdi);
00305 ebTTDetIdToRecover->insert(ebdi.tower());
00306 }
00307 }
00308 }
00309 else if (subdet == EcalEndcap) {
00310
00311 const EcalScDetId scId(detId);
00312 std::vector<DetId> vid;
00313 for(int dx=1; dx<=5; ++dx) {
00314 for(int dy=1; dy<=5; ++dy) {
00315 const int ix = (scId.ix()-1)*5 + dx;
00316 const int iy = (scId.iy()-1)*5 + dy;
00317 const int iz = scId.zside();
00318 if(EEDetId::validDetId(ix, iy, iz))
00319 vid.push_back(EEDetId(ix, iy, iz));
00320 }
00321 }
00322
00323 for (size_t j = 0; j < vid.size(); ++j) {
00324 const EEDetId eedi(vid[i]);
00325 if (include(eeSrpDetId, eedi)) {
00326 eeDetIdToRecover->insert(eedi);
00327 eeSCDetIdToRecover->insert(EcalScDetId(eedi));
00328 }
00329 }
00330 }
00331 else
00332 edm::LogWarning("EcalDetIdToBeRecoveredProducer")
00333 << "Incorrect EcalSubdetector = " << subdet
00334 << " in EcalElectronicsIdCollection collection ";
00335 }
00336 }
00337
00338
00339 ev.put( ebDetIdToRecover, ebDetIdCollection_ );
00340 ev.put( eeDetIdToRecover, eeDetIdCollection_ );
00341 ev.put( ebTTDetIdToRecover, ttDetIdCollection_ );
00342 ev.put( eeSCDetIdToRecover, scDetIdCollection_ );
00343 }
00344
00345
00346 #include "FWCore/Framework/interface/MakerMacros.h"
00347 DEFINE_FWK_MODULE( EcalDetIdToBeRecoveredProducer );