CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/EventFilter/Cosmics/src/EcalMIPRecHitFilter.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    EcalMIPRecHitFilter
00004 // Class:      EcalMIPRecHitFilter
00005 // 
00013 //
00014 // Original Author:  Giovanni FRANZONI
00015 //         Created:  Wed Sep 19 16:21:29 CEST 2007
00016 // $Id: EcalMIPRecHitFilter.cc,v 1.6 2010/02/03 03:12:45 wmtan Exp $
00017 //
00018 //
00019 
00020 
00021 // system include files
00022 #include <memory>
00023 #include <vector>
00024 
00025 // user include files
00026 #include "FWCore/Framework/interface/Frameworkfwd.h"
00027 #include "HLTrigger/HLTcore/interface/HLTFilter.h"
00028 
00029 #include "FWCore/Framework/interface/Event.h"
00030 #include "FWCore/Framework/interface/MakerMacros.h"
00031 #include "FWCore/Framework/interface/ESHandle.h"
00032 
00033 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00034 
00035 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
00036 #include "DataFormats/EcalRecHit/interface/EcalUncalibratedRecHit.h"
00037 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00038 
00039 #include "DataFormats/DetId/interface/DetId.h"
00040 #include "Geometry/CaloTopology/interface/CaloTopology.h"
00041 #include "Geometry/CaloEventSetup/interface/CaloTopologyRecord.h"
00042 
00043 #include "CondFormats/EcalObjects/interface/EcalIntercalibConstants.h"
00044 #include "CondFormats/DataRecord/interface/EcalIntercalibConstantsRcd.h"
00045 #include "CalibCalorimetry/EcalLaserCorrection/interface/EcalLaserDbService.h"
00046 #include "CalibCalorimetry/EcalLaserCorrection/interface/EcalLaserDbRecord.h"
00047 
00048 #include "CondFormats/EcalObjects/interface/EcalADCToGeVConstant.h"
00049 #include "CondFormats/DataRecord/interface/EcalADCToGeVConstantRcd.h"
00050 
00051 //
00052 // class declaration
00053 //
00054 
00055 class EcalMIPRecHitFilter : public HLTFilter {
00056    public:
00057       explicit EcalMIPRecHitFilter(const edm::ParameterSet&);
00058       ~EcalMIPRecHitFilter();
00059 
00060    private:
00061       virtual void beginJob() ;
00062       virtual bool filter(edm::Event&, const edm::EventSetup&);
00063       virtual void endJob() ;
00064       
00065       // ----------member data ---------------------------
00066 
00067   edm::InputTag EcalRecHitCollection_;
00068   double minAmp1_;
00069   double minAmp2_;
00070   double minSingleAmp_;
00071   std::vector<int> maskedList_;
00072   int side_;
00073 
00074 };
00075 
00076 //
00077 // constructors and destructor
00078 //
00079 EcalMIPRecHitFilter::EcalMIPRecHitFilter(const edm::ParameterSet& iConfig)
00080 {
00081    //now do what ever initialization is needed
00082   minSingleAmp_     = iConfig.getUntrackedParameter<double>("SingleAmpMin", 0.108);
00083   minAmp1_     = iConfig.getUntrackedParameter<double>("AmpMinSeed", 0.063);
00084   minAmp2_     = iConfig.getUntrackedParameter<double>("AmpMin2", 0.045); 
00085   maskedList_ = iConfig.getUntrackedParameter<std::vector<int> >("maskedChannels", maskedList_); //this is using the ashed index
00086   EcalRecHitCollection_ = iConfig.getParameter<edm::InputTag>("EcalRecHitCollection");
00087   side_ = iConfig.getUntrackedParameter<int>("side", 3);  
00088 }
00089 
00090 
00091 EcalMIPRecHitFilter::~EcalMIPRecHitFilter()
00092 {
00093  
00094    // do anything here that needs to be done at desctruction time
00095    // (e.g. close files, deallocate resources etc.)
00096 
00097 }
00098 
00099 
00100 //
00101 // member functions
00102 //
00103 
00104 // ------------ method called on each new Event  ------------
00105 bool
00106 EcalMIPRecHitFilter::filter(edm::Event& iEvent, const edm::EventSetup& iSetup)
00107 {
00108    using namespace edm;
00109 
00110    // getting very basic uncalRH
00111    Handle<EcalRecHitCollection> recHits;
00112    //try {
00113    //  iEvent.getByLabel(EcalRecHitCollection_, recHits);
00114    //} catch ( std::exception& ex) {
00115    //  LogWarning("EcalMIPRecHitFilter") << EcalRecHitCollection_ << " not available";
00116    //}
00117    iEvent.getByLabel(EcalRecHitCollection_, recHits);
00118    if (!recHits.isValid()){
00119       LogWarning("EcalMIPRecHitFilter") << EcalRecHitCollection_ << " not available";
00120    }
00121 
00122    ESHandle<CaloTopology> caloTopo;
00123    iSetup.get<CaloTopologyRecord>().get(caloTopo);
00124 
00125    // Intercalib constants
00126    edm::ESHandle<EcalIntercalibConstants> pIcal;
00127    iSetup.get<EcalIntercalibConstantsRcd>().get(pIcal);
00128    const EcalIntercalibConstants* ical = pIcal.product();
00129    const EcalIntercalibConstantMap& icalMap=ical->getMap();
00130    
00131    edm::ESHandle<EcalLaserDbService> pLaser;
00132    iSetup.get<EcalLaserDbRecord>().get( pLaser );
00133    
00134    edm::ESHandle<EcalADCToGeVConstant> pAgc;
00135    iSetup.get<EcalADCToGeVConstantRcd>().get(pAgc);
00136    const EcalADCToGeVConstant* agc = pAgc.product();
00137    //std::cout << "Global EB ADC->GeV scale: " << agc->getEBValue() << " GeV/ADC count" ;
00138    float adcconst = agc->getEBValue();
00139    
00140    bool thereIsSignal = false;  
00141    // loop on  rechits
00142    for ( EcalRecHitCollection::const_iterator hitItr = recHits->begin(); hitItr != recHits->end(); ++hitItr ) {
00143      
00144      EcalRecHit hit = (*hitItr);
00145      
00146      // masking noisy channels //KEEP this for now, just in case a few show up
00147      std::vector<int>::iterator result;
00148      result = find( maskedList_.begin(), maskedList_.end(), EBDetId(hit.id()).hashedIndex() );    
00149      if  (result != maskedList_.end()) 
00150        // LogWarning("EcalFilter") << "skipping uncalRecHit for channel: " << ic << " with amplitude " << ampli_ ;
00151        continue; 
00152      
00153      float ampli_ = hit.energy();
00154      EBDetId ebDet = hit.id();
00155          
00156          // find intercalib constant for this xtal
00157          EcalIntercalibConstantMap::const_iterator icalit=icalMap.find(ebDet);
00158          EcalIntercalibConstant icalconst = 1.;
00159          if( icalit!=icalMap.end() ){
00160            icalconst = (*icalit);
00161            //      LogDebug("EcalRecHitDebug") << "Found intercalib for xtal " << EBDetId(it->id()).ic() << " " << icalconst ;
00162          } else {
00163            //edm::LogError("EcalRecHitError") << "No intercalib const found for xtal " << EBDetId(ebDet) << "! something wrong with EcalIntercalibConstants in your DB? " ;
00164          }
00165          float lasercalib = pLaser->getLaserCorrection( EBDetId(ebDet), iEvent.time() );
00166 
00167          ampli_ /= (icalconst * lasercalib * adcconst);
00168      // seeking channels with signal and displaced jitter
00169      if (ampli_ >= minSingleAmp_  ) 
00170        {
00171          //std::cout << " THIS AMPLITUDE WORKS " << ampli_ << std::endl;
00172          thereIsSignal = true;
00173          // LogWarning("EcalFilter")  << "at evet: " << iEvent.id().event() 
00174          //                                    << " and run: " << iEvent.id().run() 
00175          //                                    << " there is OUT OF TIME signal at chanel: " << ic 
00176          //                                    << " with amplitude " << ampli_  << " and max at: " << jitter_;
00177          break;
00178        }
00179 
00180      //Check for more robust selection other than just single crystal cosmics
00181      if (ampli_ >= minAmp1_)
00182        {
00183          //std::cout << " THIS AMPLITUDE WORKS " << ampli_ << std::endl;
00184           std::vector<DetId> neighbors = caloTopo->getWindow(ebDet,side_,side_);
00185           float secondMin = 0.;
00186           for(std::vector<DetId>::const_iterator detitr = neighbors.begin(); detitr != neighbors.end(); ++detitr)
00187             {
00188               EcalRecHitCollection::const_iterator thishit = recHits->find((*detitr));
00189               if (thishit == recHits->end()) 
00190                 {
00191                   //LogWarning("EcalMIPRecHitFilter") << "No RecHit available, for "<< EBDetId(*detitr);
00192                   continue;
00193                 }
00194              if ((*thishit).id() != ebDet)
00195                 {
00196                   float thisamp = (*thishit).energy();
00197                                   // find intercalib constant for this xtal
00198                                   EcalIntercalibConstantMap::const_iterator icalit2=icalMap.find((*thishit).id());
00199                                   EcalIntercalibConstant icalconst2 = 1.;
00200                       if( icalit2!=icalMap.end() ){
00201                          icalconst2 = (*icalit2);
00202                       //           LogDebug("EcalRecHitDebug") << "Found intercalib for xtal " << EBDetId(it->id()).ic() << " " << icalconst ;
00203                       } else {
00204                       //edm::LogError("EcalRecHitError") << "No intercalib const found for xtal " << EBDetId(ebDet) << "! something wrong with EcalIntercalibConstants in your DB? " ;
00205                       }
00206                       float lasercalib2 = pLaser->getLaserCorrection( EBDetId((*thishit).id()), iEvent.time() );
00207                                   thisamp /= (icalconst2 * lasercalib2 * adcconst);
00208                   if (thisamp > secondMin) secondMin = thisamp;
00209                 } 
00210             }
00211             
00212           if (secondMin > minAmp2_ ) 
00213             {
00214                thereIsSignal = true;
00215                break;
00216             }    
00217        }
00218    }
00219    //std::cout << " Ok is There one of THEM " << thereIsSignal << std::endl;
00220    return thereIsSignal;
00221 }
00222 
00223 // ------------ method called once each job just before starting event loop  ------------
00224 void 
00225 EcalMIPRecHitFilter::beginJob()
00226 {
00227 }
00228 
00229 // ------------ method called once each job just after ending the event loop  ------------
00230 void 
00231 EcalMIPRecHitFilter::endJob() {
00232 }
00233 
00234 //define this as a plug-in
00235 DEFINE_FWK_MODULE(EcalMIPRecHitFilter);