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