CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/RecoCaloTools/EcalChannelKiller/src/EcalChannelKiller.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    EcalChannelKiller
00004 // Class:      EcalChannelKiller
00005 // 
00013 //
00014 // Original Author:  Georgios Daskalakis
00015 //         Created:  Tue Apr 24 17:21:31 CEST 2007
00016 // $Id: EcalChannelKiller.cc,v 1.8 2012/01/10 18:22:10 eulisse Exp $
00017 //
00018 //
00019 
00020 
00021 
00022 
00023 // Geometry
00024 #include "Geometry/Records/interface/IdealGeometryRecord.h"
00025 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
00026 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
00027 #include "Geometry/CaloTopology/interface/EcalEndcapTopology.h"
00028 #include "Geometry/CaloTopology/interface/EcalBarrelTopology.h"
00029 #include "Geometry/CaloTopology/interface/EcalBarrelHardcodedTopology.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 
00037 #include "RecoCaloTools/EcalChannelKiller/interface/EcalChannelKiller.h"
00038 
00039 #include <string>
00040 #include <cstdio>
00041 using namespace cms;
00042 using namespace std;
00043 
00044 
00045 //
00046 // constructors and destructor
00047 //
00048 EcalChannelKiller::EcalChannelKiller(const edm::ParameterSet& ps)
00049 {
00050 
00051    hitProducer_          = ps.getParameter<std::string>("hitProducer");
00052    hitCollection_        = ps.getParameter<std::string>("hitCollection");
00053    reducedHitCollection_ = ps.getParameter<std::string>("reducedHitCollection");
00054    DeadChannelFileName_  = ps.getParameter<std::string>("DeadChannelsFile");
00055 
00056    produces< EcalRecHitCollection >(reducedHitCollection_);
00057 
00058 
00059 }
00060 
00061 
00062 EcalChannelKiller::~EcalChannelKiller()
00063 {
00064  
00065    // do anything here that needs to be done at desctruction time
00066    // (e.g. close files, deallocate resources etc.)
00067 
00068 }
00069 
00070 
00071 //
00072 // member functions
00073 //
00074 
00075 // ------------ method called to produce the data  ------------
00076 void
00077 EcalChannelKiller::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00078 {
00079    using namespace edm;
00080 
00081    // get the hit collection from the event:
00082    edm::Handle<EcalRecHitCollection> rhcHandle;
00083    iEvent.getByLabel(hitProducer_, hitCollection_, rhcHandle);
00084    if (!(rhcHandle.isValid())) 
00085      {
00086        //       std::cout << "could not get a handle on the EcalRecHitCollection!" << std::endl;
00087        return;
00088      }
00089    const EcalRecHitCollection* hit_collection = rhcHandle.product();
00090  
00091    int nRed = 0;
00092    
00093    // create an auto_ptr to a EcalRecHitCollection, copy the RecHits into it and put in the Event:
00094    std::auto_ptr< EcalRecHitCollection > redCollection(new EcalRecHitCollection);
00095    
00096    
00097    for(EcalRecHitCollection::const_iterator it = hit_collection->begin(); it != hit_collection->end(); ++it) {
00098      
00099      double NewEnergy =it->energy();
00100      bool ItIsDead=false;
00101      //Dead Cells are read from text files
00102      std::vector<EBDetId>::const_iterator DeadCell;
00103      for(DeadCell=ChannelsDeadID.begin();DeadCell<ChannelsDeadID.end();DeadCell++){
00104        if(it->detid()==*DeadCell){
00105          ItIsDead=true;
00106          NewEnergy =0.;
00107          nRed++;
00108          
00109        }
00110      }//End looping on vector of Dead Cells
00111 
00112      // Make a new RecHit
00113      //
00114      // TODO what will be the it->time() for D.C. ?
00115      // Could we use it for "correction" identification?
00116      //
00117      if(!ItIsDead){
00118        EcalRecHit NewHit(it->id(),NewEnergy,it->time());
00119        redCollection->push_back( NewHit );
00120      }
00121    }
00122    //   std::cout << "total # hits: " << nTot << "  #hits with E = " << 0 << " GeV : " << nRed << std::endl;
00123    
00124    iEvent.put(redCollection, reducedHitCollection_);
00125    
00126 }
00127 
00128 
00129 
00130 
00131 // ------------ method called once each job just before starting event loop  ------------
00132 void 
00133 EcalChannelKiller::beginJob()
00134 {
00135 
00136   //Open the DeadChannel file, read it.
00137   FILE* DeadCha;
00138   printf("Dead Channels FILE: %s\n",DeadChannelFileName_.c_str());
00139   DeadCha = fopen(DeadChannelFileName_.c_str(),"r");
00140 
00141   int fileStatus=0;
00142   int ieta=-10000;
00143   int iphi=-10000;
00144   while(fileStatus != EOF) {
00145     fileStatus = fscanf(DeadCha,"%d %d\n",&ieta,&iphi);
00146     //    std::cout<<" ieta "<<ieta<<" iphi "<<iphi<<std::endl;
00147     if(ieta==-10000||iphi==-10000){/*std::cout << "Problem reading Dead Channels file "<<std::endl;*/break;}
00148     EBDetId cell(ieta,iphi);
00149     ChannelsDeadID.push_back(cell);
00150   } //end while     
00151   fclose(DeadCha);
00152   //  std::cout<<" Read "<<ChannelsDeadID.size()<<" dead channels "<<std::endl;
00153   
00154 }
00155 
00156 
00157 
00158 // ------------ method called once each job just after ending the event loop  ------------
00159 void 
00160 EcalChannelKiller::endJob() {
00161 }
00162 
00163 //define this as a plug-in
00164 DEFINE_FWK_MODULE(EcalChannelKiller);