CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/RecoLocalCalo/EcalDeadChannelRecoveryProducers/src/EcalDeadChannelRecoveryProducers.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    EcalDeadChannelRecoveryProducers
00004 // Class:      EcalDeadChannelRecoveryProducers
00005 // 
00013 //
00014 // Original Author:  Georgios Daskalakis
00015 //         Created:  Thu Apr 12 17:01:03 CEST 2007
00016 // $Id: EcalDeadChannelRecoveryProducers.cc,v 1.7 2011/05/22 23:08:19 eulisse Exp $
00017 //
00018 //
00019 
00020 
00021 // system include files
00022 #include <memory>
00023 
00024 
00025 
00026 // Geometry
00027 #include "Geometry/CaloEventSetup/interface/CaloTopologyRecord.h"
00028 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
00029 #include "Geometry/CaloTopology/interface/CaloTopology.h"
00030 
00031 // Reconstruction Classes
00032 #include "DataFormats/EcalRecHit/interface/EcalRecHit.h"
00033 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00034 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00035 
00036 #include "RecoLocalCalo/EcalDeadChannelRecoveryProducers/interface/EcalDeadChannelRecoveryProducers.h"
00037 #include "RecoLocalCalo/EcalDeadChannelRecoveryAlgos/interface/EcalDeadChannelRecoveryAlgos.h"
00038 
00039 
00040 #include <string>
00041 #include <cstdio>
00042 
00043 using namespace cms;
00044 using namespace std;
00045 
00046 
00047 
00048 //
00049 // constants, enums and typedefs
00050 //
00051 
00052 //
00053 // static data member definitions
00054 //
00055 
00056 //
00057 // constructors and destructor
00058 //
00059 EcalDeadChannelRecoveryProducers::EcalDeadChannelRecoveryProducers(const edm::ParameterSet& ps)
00060 {
00061 
00062    //now do what ever other initialization is needed
00063   CorrectDeadCells_     = ps.getParameter<bool>("CorrectDeadCells");
00064   CorrectionMethod_     = ps.getParameter<std::string>("CorrectionMethod");
00065   hitProducer_          = ps.getParameter<std::string>("hitProducer");
00066   hitCollection_        = ps.getParameter<std::string>("hitCollection");
00067   reducedHitCollection_ = ps.getParameter<std::string>("reducedHitCollection");
00068   DeadChannelFileName_ = ps.getParameter<std::string>("DeadChannelsFile");
00069   Sum8GeVThreshold_= ps.getParameter<double>("Sum8GeVThreshold");
00070 
00071    produces< EcalRecHitCollection >(reducedHitCollection_);
00072 }
00073 
00074 
00075 EcalDeadChannelRecoveryProducers::~EcalDeadChannelRecoveryProducers()
00076 {
00077  
00078    // do anything here that needs to be done at desctruction time
00079    // (e.g. close files, deallocate resources etc.)
00080 
00081 }
00082 
00083 
00084 //
00085 // member functions
00086 //
00087 
00088 // ------------ method called to produce the data  ------------
00089 void
00090 EcalDeadChannelRecoveryProducers::produce(edm::Event& evt, const edm::EventSetup& iSetup)
00091 {
00092   using namespace edm;
00093   
00094   edm::ESHandle<CaloTopology> theCaloTopology;
00095   iSetup.get<CaloTopologyRecord>().get(theCaloTopology);
00096   
00097   // get the hit collection from the event:
00098   edm::Handle<EcalRecHitCollection> rhcHandle;
00099   evt.getByLabel(hitProducer_, hitCollection_, rhcHandle);
00100   if (!(rhcHandle.isValid())) 
00101     {
00102       std::cout << "could not get a handle on the EcalRecHitCollection!" << std::endl;
00103       return;
00104     }
00105   const EcalRecHitCollection* hit_collection = rhcHandle.product();
00106   
00107   // create an auto_ptr to a EcalRecHitCollection, copy the RecHits into it and put it in the Event:
00108   std::auto_ptr< EcalRecHitCollection > redCollection(new EcalRecHitCollection);
00109   
00110   EcalDeadChannelRecoveryAlgos *DeadChannelCorrector = new EcalDeadChannelRecoveryAlgos(theCaloTopology.product());
00111   
00112   //Dead Cells are read from a text file
00113   std::vector<EBDetId>::const_iterator DeadCell;
00114 
00115   //
00116   //This should work only if we REMOVE the DC RecHit from the reduced RecHit collection 
00117   //
00118   for(EcalRecHitCollection::const_iterator it = hit_collection->begin(); it != hit_collection->end(); ++it) {     
00119     std::vector<EBDetId>::const_iterator CheckDead = ChannelsDeadID.begin();
00120     bool OverADeadRecHit=false;
00121     while(CheckDead<ChannelsDeadID.end()){
00122       if(it->detid()==*CheckDead){OverADeadRecHit=true;break;}
00123       CheckDead++;
00124     }
00125     if(!OverADeadRecHit)redCollection->push_back( *it );
00126   }
00127   for(DeadCell=ChannelsDeadID.begin();DeadCell<ChannelsDeadID.end();DeadCell++){
00128     EcalRecHit NewRecHit = DeadChannelCorrector->Correct(*DeadCell,hit_collection,CorrectionMethod_,Sum8GeVThreshold_);
00129     redCollection->push_back( NewRecHit );
00130   }
00131 
00132 
00133 
00134   
00135   delete DeadChannelCorrector ;
00136   
00137   evt.put(redCollection, reducedHitCollection_);
00138   
00139 }
00140 
00141 
00142 
00143 // ------------ method called once each job just before starting event loop  ------------
00144 void 
00145 EcalDeadChannelRecoveryProducers::beginJob()
00146 {
00147     FILE* DeadCha;
00148     printf("Dead Channels FILE: %s\n",DeadChannelFileName_.c_str());
00149     DeadCha = fopen(DeadChannelFileName_.c_str(),"r");
00150 
00151     int fileStatus=0;
00152     int ieta=-10000;
00153     int iphi=-10000;
00154     while(fileStatus != EOF) {
00155     fileStatus = fscanf(DeadCha,"%d %d\n",&ieta,&iphi);
00156     //    std::cout<<" ieta "<<ieta<<" iphi "<<iphi<<std::endl;
00157     if(ieta==-10000||iphi==-10000){std::cout << "Problem reading Dead Channels file "<<std::endl;break;}
00158     EBDetId cell(ieta,iphi);
00159     ChannelsDeadID.push_back(cell);
00160     } //end while           
00161     fclose(DeadCha);
00162     //  std::cout<<" Read "<<ChannelsDeadID.size()<<" dead channels "<<std::endl;
00163   
00164 }
00165 
00166 // ------------ method called once each job just after ending the event loop  ------------
00167 void 
00168 EcalDeadChannelRecoveryProducers::endJob() {
00169 }
00170 
00171 //define this as a plug-in
00172 DEFINE_FWK_MODULE(EcalDeadChannelRecoveryProducers);