CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/SimCalorimetry/HcalZeroSuppressionProducers/src/HcalRealisticZS.cc

Go to the documentation of this file.
00001 #include "HcalRealisticZS.h"
00002 #include "DataFormats/HcalDigi/interface/HcalDigiCollections.h"
00003 #include "DataFormats/Common/interface/EDCollection.h"
00004 #include "DataFormats/Common/interface/Handle.h"
00005 #include "FWCore/Framework/interface/ESHandle.h"
00006 #include "FWCore/Framework/interface/EventSetup.h"
00007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00008 #include "FWCore/Utilities/interface/Exception.h"
00009 #include "CalibFormats/HcalObjects/interface/HcalDbRecord.h"
00010 
00011 using namespace std;
00012 
00013 #include <iostream>
00014 
00015 HcalRealisticZS::HcalRealisticZS(edm::ParameterSet const& conf):
00016   inputLabel_(conf.getParameter<edm::InputTag>("digiLabel"))
00017 {
00018   bool markAndPass=conf.getParameter<bool>("markAndPass");
00019 
00020 
00021   std::vector<int> tmp = conf.getParameter<std::vector<int> >("HBregion");
00022 
00023   if(tmp[0]<0 || tmp[0]>9 || tmp[1]<0 || tmp[1]>9 || tmp[0]>tmp[1]) {
00024     edm::LogError("HcalZeroSuppression") << "ZS(HB) region error: " 
00025                                          << tmp[0] << ":" <<tmp[1];
00026     tmp[0]=0; tmp[1]=9;
00027   }
00028 
00029   std::pair<int,int> HBsearchTS (tmp[0],tmp[1]);
00030   
00031   tmp = conf.getParameter<std::vector<int> >("HEregion");
00032   if(tmp[0]<0 || tmp[0]>9 || tmp[1]<0 || tmp[1]>9 || tmp[0]>tmp[1]) {
00033     edm::LogError("HcalZeroSuppression") << "ZS(HE) region error: " 
00034                                          << tmp[0] << ":" <<tmp[1];
00035     tmp[0]=0; tmp[1]=9;
00036   }
00037   std::pair<int,int> HEsearchTS (tmp[0],tmp[1]);
00038   
00039   tmp = conf.getParameter<std::vector<int> >("HOregion");
00040   if(tmp[0]<0 || tmp[0]>9 || tmp[1]<0 || tmp[1]>9 || tmp[0]>tmp[1]) {
00041     edm::LogError("HcalZeroSuppression") << "ZS(HO) region error: " 
00042                                          << tmp[0] << ":" <<tmp[1];
00043     tmp[0]=0; tmp[1]=9;
00044   }
00045   std::pair<int,int> HOsearchTS (tmp[0],tmp[1]);
00046   
00047   tmp = conf.getParameter<std::vector<int> >("HFregion");
00048   if(tmp[0]<0 || tmp[0]>9 || tmp[1]<0 || tmp[1]>9 || tmp[0]>tmp[1]) {
00049     edm::LogError("HcalZeroSuppression") << "ZS(HF) region error: " 
00050                                          << tmp[0] << ":" <<tmp[1];
00051     tmp[0]=0; tmp[1]=9;
00052   }
00053   std::pair<int,int> HFsearchTS (tmp[0],tmp[1]);
00054       
00055   
00056     //this constructor will be called if useConfigZSvalues is set to 1 in
00057     //HcalZeroSuppressionProducers/python/hcalDigisRealistic_cfi.py
00058     //which means that channel-by-channel ZS thresholds from DB will NOT be used
00059     if ( conf.getParameter<int>("useConfigZSvalues") ) {
00060 
00061       algo_=std::auto_ptr<HcalZSAlgoRealistic>
00062         (new HcalZSAlgoRealistic (markAndPass,
00063                                   conf.getParameter<int>("HBlevel"),
00064                                   conf.getParameter<int>("HElevel"),
00065                                   conf.getParameter<int>("HOlevel"),
00066                                   conf.getParameter<int>("HFlevel"), 
00067                                   HBsearchTS,
00068                                   HEsearchTS,
00069                                   HOsearchTS,
00070                                   HFsearchTS
00071                                   ));
00072       
00073     }
00074     else {
00075 
00076       algo_=std::auto_ptr<HcalZSAlgoRealistic>
00077         (new HcalZSAlgoRealistic(markAndPass,                             
00078                                  HBsearchTS,
00079                                  HEsearchTS,
00080                                  HOsearchTS,
00081                                  HFsearchTS));    
00082     }
00083 
00084     produces<HBHEDigiCollection>();
00085     produces<HODigiCollection>();
00086     produces<HFDigiCollection>();
00087     
00088 }
00089     
00090 HcalRealisticZS::~HcalRealisticZS() {
00091   algo_->clearDbService();
00092 }
00093     
00094 void HcalRealisticZS::produce(edm::Event& e, const edm::EventSetup& eventSetup)
00095 {
00096  
00097   edm::Handle<HBHEDigiCollection> hbhe;    
00098   edm::Handle<HODigiCollection> ho;    
00099   edm::Handle<HFDigiCollection> hf;    
00100 
00101   edm::ESHandle<HcalDbService> conditions;
00102   eventSetup.get<HcalDbRecord>().get(conditions);
00103   algo_->setDbService(conditions.product());
00104 
00105   e.getByLabel(inputLabel_,hbhe);
00106   
00107   // create empty output
00108   std::auto_ptr<HBHEDigiCollection> zs_hbhe(new HBHEDigiCollection);
00109   
00110   e.getByLabel(inputLabel_,ho);
00111   
00112   // create empty output
00113   std::auto_ptr<HODigiCollection> zs_ho(new HODigiCollection);
00114   
00115   e.getByLabel(inputLabel_,hf);
00116   
00117   // create empty output
00118   std::auto_ptr<HFDigiCollection> zs_hf(new HFDigiCollection);
00119   
00120   //run the algorithm
00121 
00122   algo_->suppress(*(hbhe.product()),*zs_hbhe);
00123   algo_->suppress(*(ho.product()),*zs_ho);
00124   algo_->suppress(*(hf.product()),*zs_hf);
00125 
00126   
00127   edm::LogInfo("HcalZeroSuppression") << "Suppression (HBHE) input " << hbhe->size() << " digis, output " << zs_hbhe->size() << " digis" 
00128                                       <<  " (HO) input " << ho->size() << " digis, output " << zs_ho->size() << " digis"
00129                                       <<  " (HF) input " << hf->size() << " digis, output " << zs_hf->size() << " digis";
00130   
00131 
00132     // return result
00133     e.put(zs_hbhe);
00134     e.put(zs_ho);
00135     e.put(zs_hf);
00136 
00137 }