CMS 3D CMS Logo

/data/git/CMSSW_5_3_11_patch5/src/CondTools/Hcal/plugins/HcalAutoPedestalValidator.cc

Go to the documentation of this file.
00001 #include "CondTools/Hcal/interface/HcalAutoPedestalValidator.h"
00002 
00003 HcalAutoPedestalValidator::HcalAutoPedestalValidator(edm::ParameterSet const& ps)
00004 {
00005   outfile = ps.getUntrackedParameter<std::string>("outFile","changed.bool");
00006   epsilon = ps.getUntrackedParameter<double>("deltaP",.25);
00007 }
00008 
00009 HcalAutoPedestalValidator::~HcalAutoPedestalValidator()
00010 {
00011 }
00012 
00013 void HcalAutoPedestalValidator::analyze(const edm::Event& ev, const edm::EventSetup& es)
00014 {
00015   using namespace edm::eventsetup;
00016   // get fake pedestals from file ("new pedestals")
00017   edm::ESHandle<HcalPedestals> newPeds;
00018   es.get<HcalPedestalsRcd>().get("update",newPeds);
00019   const HcalPedestals* myNewPeds = newPeds.product();
00020 
00021   // get DB pedestals from Frontier/OrcoX ("reference")
00022   edm::ESHandle<HcalPedestals> refPeds;
00023   es.get<HcalPedestalsRcd>().get("reference",refPeds);
00024   const HcalPedestals* myRefPeds = refPeds.product();
00025 
00026   std::vector<DetId> listNewChan = myNewPeds->getAllChannels();
00027   std::vector<DetId> listRefChan = myRefPeds->getAllChannels();
00028   std::vector<DetId>::iterator cell;
00029   bool failflag = false;
00030   for (std::vector<DetId>::iterator it = listRefChan.begin(); it != listRefChan.end(); it++)
00031   {
00032      DetId mydetid = *it;
00033      cell = std::find(listNewChan.begin(), listNewChan.end(), mydetid);
00034      if (cell == listNewChan.end()) {continue;}
00035      else
00036      {
00037         const float* values = (myNewPeds->getValues( mydetid ))->getValues();
00038         const float* oldvalue = (myRefPeds->getValues( mydetid ))->getValues();
00039         if( (*values==0) &&(*(values+1)==0) && (*(values+2)==0) && (*(values+3)==0) )continue;
00040         if( (*oldvalue-*values) + (*(oldvalue+1)-*(values+1)) + (*(oldvalue+2)-*(values+2)) + (*(oldvalue+3)-*(values+3))/4 > epsilon)
00041         {
00042            std::cout << "Channel " << std::hex << mydetid.rawId() <<  " Values differ by " << std::dec << (*oldvalue-*values) << "  " << (*(oldvalue+1)-*(values+1)) << "  " << (*(oldvalue+2)-*(values+2)) << "  " << (*(oldvalue+3)-*(values+3)) << std::endl;
00043            failflag = true;
00044         }
00045      listNewChan.erase(cell);  // fix 25.02.08
00046      }
00047   }
00048 
00049   if(!failflag) std::cout << "These are identical to within deltaP" << std::endl;
00050   if(failflag)
00051   {
00052     // if changed, this creates the empty file changed.bool which the auto job uses as a flag
00053     std::ofstream outStream3(outfile.c_str());
00054     std::cout << "--- Pedestals changed! ---" << std::endl;
00055   }
00056 }
00057 
00058 DEFINE_FWK_MODULE(HcalAutoPedestalValidator);