CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/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.6 2010/08/06 20:24:55 wmtan 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 using namespace cms;
00042 using namespace std;
00043 
00044 
00045 
00046 //
00047 // constants, enums and typedefs
00048 //
00049 
00050 //
00051 // static data member definitions
00052 //
00053 
00054 //
00055 // constructors and destructor
00056 //
00057 EcalDeadChannelRecoveryProducers::EcalDeadChannelRecoveryProducers(const edm::ParameterSet& ps)
00058 {
00059 
00060    //now do what ever other initialization is needed
00061   CorrectDeadCells_     = ps.getParameter<bool>("CorrectDeadCells");
00062   CorrectionMethod_     = ps.getParameter<std::string>("CorrectionMethod");
00063   hitProducer_          = ps.getParameter<std::string>("hitProducer");
00064   hitCollection_        = ps.getParameter<std::string>("hitCollection");
00065   reducedHitCollection_ = ps.getParameter<std::string>("reducedHitCollection");
00066   DeadChannelFileName_ = ps.getParameter<std::string>("DeadChannelsFile");
00067   Sum8GeVThreshold_= ps.getParameter<double>("Sum8GeVThreshold");
00068 
00069    produces< EcalRecHitCollection >(reducedHitCollection_);
00070 }
00071 
00072 
00073 EcalDeadChannelRecoveryProducers::~EcalDeadChannelRecoveryProducers()
00074 {
00075  
00076    // do anything here that needs to be done at desctruction time
00077    // (e.g. close files, deallocate resources etc.)
00078 
00079 }
00080 
00081 
00082 //
00083 // member functions
00084 //
00085 
00086 // ------------ method called to produce the data  ------------
00087 void
00088 EcalDeadChannelRecoveryProducers::produce(edm::Event& evt, const edm::EventSetup& iSetup)
00089 {
00090   using namespace edm;
00091   
00092   edm::ESHandle<CaloTopology> theCaloTopology;
00093   iSetup.get<CaloTopologyRecord>().get(theCaloTopology);
00094   
00095   // get the hit collection from the event:
00096   edm::Handle<EcalRecHitCollection> rhcHandle;
00097   evt.getByLabel(hitProducer_, hitCollection_, rhcHandle);
00098   if (!(rhcHandle.isValid())) 
00099     {
00100       std::cout << "could not get a handle on the EcalRecHitCollection!" << std::endl;
00101       return;
00102     }
00103   const EcalRecHitCollection* hit_collection = rhcHandle.product();
00104   
00105   // create an auto_ptr to a EcalRecHitCollection, copy the RecHits into it and put it in the Event:
00106   std::auto_ptr< EcalRecHitCollection > redCollection(new EcalRecHitCollection);
00107   
00108   EcalDeadChannelRecoveryAlgos *DeadChannelCorrector = new EcalDeadChannelRecoveryAlgos(theCaloTopology.product());
00109   
00110   //Dead Cells are read from a text file
00111   std::vector<EBDetId>::const_iterator DeadCell;
00112 
00113   //
00114   //This should work only if we REMOVE the DC RecHit from the reduced RecHit collection 
00115   //
00116   for(EcalRecHitCollection::const_iterator it = hit_collection->begin(); it != hit_collection->end(); ++it) {     
00117     std::vector<EBDetId>::const_iterator CheckDead = ChannelsDeadID.begin();
00118     bool OverADeadRecHit=false;
00119     while(CheckDead<ChannelsDeadID.end()){
00120       if(it->detid()==*CheckDead){OverADeadRecHit=true;break;}
00121       CheckDead++;
00122     }
00123     if(!OverADeadRecHit)redCollection->push_back( *it );
00124   }
00125   for(DeadCell=ChannelsDeadID.begin();DeadCell<ChannelsDeadID.end();DeadCell++){
00126     EcalRecHit NewRecHit = DeadChannelCorrector->Correct(*DeadCell,hit_collection,CorrectionMethod_,Sum8GeVThreshold_);
00127     redCollection->push_back( NewRecHit );
00128   }
00129 
00130 
00131 
00132   
00133   delete DeadChannelCorrector ;
00134   
00135   evt.put(redCollection, reducedHitCollection_);
00136   
00137 }
00138 
00139 
00140 
00141 // ------------ method called once each job just before starting event loop  ------------
00142 void 
00143 EcalDeadChannelRecoveryProducers::beginJob()
00144 {
00145     FILE* DeadCha;
00146     printf("Dead Channels FILE: %s\n",DeadChannelFileName_.c_str());
00147     DeadCha = fopen(DeadChannelFileName_.c_str(),"r");
00148 
00149     int fileStatus=0;
00150     int ieta=-10000;
00151     int iphi=-10000;
00152     while(fileStatus != EOF) {
00153     fileStatus = fscanf(DeadCha,"%d %d\n",&ieta,&iphi);
00154     //    std::cout<<" ieta "<<ieta<<" iphi "<<iphi<<std::endl;
00155     if(ieta==-10000||iphi==-10000){std::cout << "Problem reading Dead Channels file "<<std::endl;break;}
00156     EBDetId cell(ieta,iphi);
00157     ChannelsDeadID.push_back(cell);
00158     } //end while           
00159     fclose(DeadCha);
00160     //  std::cout<<" Read "<<ChannelsDeadID.size()<<" dead channels "<<std::endl;
00161   
00162 }
00163 
00164 // ------------ method called once each job just after ending the event loop  ------------
00165 void 
00166 EcalDeadChannelRecoveryProducers::endJob() {
00167 }
00168 
00169 //define this as a plug-in
00170 DEFINE_FWK_MODULE(EcalDeadChannelRecoveryProducers);