Go to the documentation of this file.00001 #include "CondTools/Hcal/interface/HcalPedestalWidthsCheck.h"
00002
00003 HcalPedestalWidthsCheck::HcalPedestalWidthsCheck(edm::ParameterSet const& ps)
00004 {
00005 outfile = ps.getUntrackedParameter<std::string>("outFile","null");
00006 dumprefs = ps.getUntrackedParameter<std::string>("dumpRefWidthsTo","null");
00007 dumpupdate = ps.getUntrackedParameter<std::string>("dumpUpdateWidthsTo","null");
00008 checkemapflag = ps.getUntrackedParameter<bool>("checkEmap",false);
00009 validateflag = ps.getUntrackedParameter<bool>("validateWidths",false);
00010 epsilon = ps.getUntrackedParameter<double>("deltaW",0);
00011 }
00012
00013 HcalPedestalWidthsCheck::~HcalPedestalWidthsCheck()
00014 {
00015 }
00016
00017 void HcalPedestalWidthsCheck::analyze(const edm::Event& ev, const edm::EventSetup& es)
00018 {
00019 using namespace edm::eventsetup;
00020
00021
00022 edm::ESHandle<HcalPedestalWidths> newPeds;
00023 es.get<HcalPedestalWidthsRcd>().get("update",newPeds);
00024 const HcalPedestalWidths* myNewPeds = newPeds.product();
00025
00026
00027 edm::ESHandle<HcalPedestalWidths> refPeds;
00028 es.get<HcalPedestalWidthsRcd>().get("reference",refPeds);
00029 const HcalPedestalWidths* myRefPeds = refPeds.product();
00030
00031
00032 edm::ESHandle<HcalElectronicsMap> refEMap;
00033 es.get<HcalElectronicsMapRcd>().get("reference",refEMap);
00034 const HcalElectronicsMap* myRefEMap = refEMap.product();
00035
00036
00037
00038 if(dumpupdate.compare("null")!=0){
00039 std::ofstream outStream(dumpupdate.c_str());
00040 std::cout << "--- Dumping PedestalWidths - update ---" << std::endl;
00041 HcalDbASCIIIO::dumpObject (outStream, (*myNewPeds) );
00042 }
00043 if(dumprefs.compare("null")!=0){
00044 std::ofstream outStream2(dumprefs.c_str());
00045 std::cout << "--- Dumping PedestalWidths - reference ---" << std::endl;
00046 HcalDbASCIIIO::dumpObject (outStream2, (*myRefPeds) );
00047 }
00048
00049 std::vector<DetId> listNewChan = myNewPeds->getAllChannels();
00050
00051
00052
00053
00054 HcalPedestalWidths *resultPeds = new HcalPedestalWidths(myRefPeds->topo(), myRefPeds->isADC() );
00055 std::vector<DetId> listRefChan = myRefPeds->getAllChannels();
00056 std::vector<DetId>::iterator cell;
00057
00058 if(validateflag){
00059 for (std::vector<DetId>::iterator it = listRefChan.begin(); it != listRefChan.end(); it++)
00060 {
00061 DetId mydetid = *it;
00062 cell = std::find(listNewChan.begin(), listNewChan.end(), mydetid);
00063 if (cell == listNewChan.end())
00064 {
00065 throw cms::Exception("DataDoesNotMatch")<<"Value not found in reference" << std::endl;
00066 }
00067 else
00068 {
00069 const HcalPedestalWidth* first = myNewPeds->getValues( mydetid );
00070 const HcalPedestalWidth* second = myRefPeds->getValues( mydetid );
00071 const float* newwidth = first->getValues();
00072 const float* oldwidth = second->getValues();
00073 if( (*newwidth != *oldwidth) || (*(newwidth+1)!=*(oldwidth+1)) || (*(newwidth+2)!=*(oldwidth+2)) || (*(newwidth+3)!=*(oldwidth+3)) || (*(newwidth+4)!=*(oldwidth+4)) || (*(newwidth+5)!=*(oldwidth+5)) || (*(newwidth+6)!=*(oldwidth+6)) || (*(newwidth+7)!=*(oldwidth+7)) || (*(newwidth+8)!=*(oldwidth+8)) || (*(newwidth+9)!=*(oldwidth+9))){
00074 throw cms::Exception("DataDoesNotMatch") << "Values are not identical" << std::endl;
00075 }
00076 listNewChan.erase(cell);
00077 }
00078 }
00079 std::cout << "These are identical" << std::endl;
00080 }
00081
00082
00083
00084
00085 if(epsilon!=0){
00086 for (std::vector<DetId>::iterator it = listRefChan.begin(); it != listRefChan.end(); it++)
00087 {
00088 DetId mydetid = *it;
00089 cell = std::find(listNewChan.begin(), listNewChan.end(), mydetid);
00090 if (cell == listNewChan.end())
00091 {
00092 throw cms::Exception("DataDoesNotMatch")<<"Value not found in reference" << std::endl;
00093 }
00094 else
00095 {
00096 const HcalPedestalWidth* first = myNewPeds->getValues( mydetid );
00097 const HcalPedestalWidth* second = myRefPeds->getValues( mydetid );
00098 const float* newwidth = first->getValues();
00099 const float* oldwidth = second->getValues();
00100 if( fabs(*newwidth-*oldwidth)>epsilon || fabs(*(newwidth+1)-*(oldwidth+1))>epsilon || fabs(*(newwidth+2)-*(oldwidth+2))>epsilon || fabs(*(newwidth+3)-*(oldwidth+3))>epsilon || fabs(*(newwidth+4)-*(oldwidth+4))>epsilon || fabs(*(newwidth+5)-*(oldwidth+5))>epsilon || fabs(*(newwidth+6)-*(oldwidth+6))>epsilon || fabs(*(newwidth+7)-*(oldwidth+7))>epsilon || fabs(*(newwidth+8)-*(oldwidth+8))>epsilon || fabs(*(newwidth+9)-*(oldwidth+9))>epsilon){
00101 throw cms::Exception("DataDoesNotMatch") << "Values differ by more than deltaW" << std::endl;
00102 }
00103 listNewChan.erase(cell);
00104 }
00105 }
00106 std::cout << "These are identical" << std::endl;
00107 }
00108 if(outfile.compare("null")!=0){
00109 for (std::vector<DetId>::iterator it = listRefChan.begin(); it != listRefChan.end(); it++)
00110 {
00111 DetId mydetid = *it;
00112 cell = std::find(listNewChan.begin(), listNewChan.end(), mydetid);
00113 if (cell == listNewChan.end())
00114 {
00115 const HcalPedestalWidth* mywidth = myRefPeds->getValues( mydetid );
00116 std::cout << "o";
00117 resultPeds->addValues( *mywidth );
00118 }
00119 else
00120 {
00121 const HcalPedestalWidth* mywidth = myNewPeds->getValues( mydetid );
00122 std::cout << "n";
00123 resultPeds->addValues( *mywidth );
00124
00125 listNewChan.erase(cell);
00126 }
00127 }
00128
00129 for (std::vector<DetId>::iterator it = listNewChan.begin(); it != listNewChan.end(); it++)
00130 {
00131 DetId mydetid = *it;
00132 const HcalPedestalWidth* mywidth = myNewPeds->getValues( mydetid );
00133 std::cout << "N";
00134 resultPeds->addValues( *mywidth );
00135 }
00136
00137 std::ofstream outStream3(outfile.c_str());
00138 std::cout << "--- Dumping PedestalWidths - the combined ones ---" << std::endl;
00139 HcalDbASCIIIO::dumpObject (outStream3, (*resultPeds) );
00140
00141
00142
00143 }
00144 std::cout << std::endl;
00145 if(checkemapflag){
00146 std::vector<DetId> listResult = resultPeds->getAllChannels();
00147
00148 std::vector<HcalGenericDetId> listEMap = myRefEMap->allPrecisionId();
00149
00150 for (std::vector<HcalGenericDetId>::const_iterator it = listEMap.begin(); it != listEMap.end(); it++)
00151 {
00152 DetId mydetid = DetId(it->rawId());
00153 if (std::find(listResult.begin(), listResult.end(), mydetid ) == listResult.end() )
00154 {
00155 std::cout << "Conditions not found for DetId = " << HcalGenericDetId(it->rawId()) << std::endl;
00156 }
00157 }
00158 }
00159
00160 }
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179 DEFINE_FWK_MODULE(HcalPedestalWidthsCheck);