CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/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.7 2010/08/06 20:24:49 wmtan 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          DetId itID = it->id();
00106          //      std::cout<<" +++++++++++ Old Energy "<<it->energy()<<" eta "<< itID.rawId()<<std::endl;
00107          ItIsDead=true;
00108          NewEnergy =0.;
00109          nRed++;
00110          
00111        }
00112      }//End looping on vector of Dead Cells
00113 
00114      // Make a new RecHit
00115      //
00116      // TODO what will be the it->time() for D.C. ?
00117      // Could we use it for "correction" identification?
00118      //
00119      if(!ItIsDead){
00120        EcalRecHit NewHit(it->id(),NewEnergy,it->time());
00121        redCollection->push_back( NewHit );
00122      }
00123    }
00124    //   std::cout << "total # hits: " << nTot << "  #hits with E = " << 0 << " GeV : " << nRed << std::endl;
00125    
00126    iEvent.put(redCollection, reducedHitCollection_);
00127    
00128 }
00129 
00130 
00131 
00132 
00133 // ------------ method called once each job just before starting event loop  ------------
00134 void 
00135 EcalChannelKiller::beginJob()
00136 {
00137 
00138   //Open the DeadChannel file, read it.
00139   FILE* DeadCha;
00140   printf("Dead Channels FILE: %s\n",DeadChannelFileName_.c_str());
00141   DeadCha = fopen(DeadChannelFileName_.c_str(),"r");
00142 
00143   int fileStatus=0;
00144   int ieta=-10000;
00145   int iphi=-10000;
00146   while(fileStatus != EOF) {
00147     fileStatus = fscanf(DeadCha,"%d %d\n",&ieta,&iphi);
00148     //    std::cout<<" ieta "<<ieta<<" iphi "<<iphi<<std::endl;
00149     if(ieta==-10000||iphi==-10000){/*std::cout << "Problem reading Dead Channels file "<<std::endl;*/break;}
00150     EBDetId cell(ieta,iphi);
00151     ChannelsDeadID.push_back(cell);
00152   } //end while     
00153   fclose(DeadCha);
00154   //  std::cout<<" Read "<<ChannelsDeadID.size()<<" dead channels "<<std::endl;
00155   
00156 }
00157 
00158 
00159 
00160 // ------------ method called once each job just after ending the event loop  ------------
00161 void 
00162 EcalChannelKiller::endJob() {
00163 }
00164 
00165 //define this as a plug-in
00166 DEFINE_FWK_MODULE(EcalChannelKiller);