CMS 3D CMS Logo

HcalPedestalWidthsCheck.cc

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   // get fake pedestals from file ("new pedestals")
00022   edm::ESHandle<HcalPedestalWidths> newPeds;
00023   es.get<HcalPedestalWidthsRcd>().get("update",newPeds);
00024   const HcalPedestalWidths* myNewPeds = newPeds.product();
00025 
00026   // get DB pedestals from Frontier/OrcoX ("reference")
00027   edm::ESHandle<HcalPedestalWidths> refPeds;
00028   es.get<HcalPedestalWidthsRcd>().get("reference",refPeds);
00029   const HcalPedestalWidths* myRefPeds = refPeds.product();
00030 
00031   // get e-map from reference
00032   edm::ESHandle<HcalElectronicsMap> refEMap;
00033   es.get<HcalElectronicsMapRcd>().get("reference",refEMap);
00034   const HcalElectronicsMap* myRefEMap = refEMap.product();
00035 
00036 
00037    // dump pedestals:
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     // first get the list of all channels from the update
00049     std::vector<DetId> listNewChan = myNewPeds->getAllChannels();
00050     
00051     // go through list of valid channels from reference, look up if pedestals exist for update
00052     // push back into new vector the corresponding updated pedestals,
00053     // or if it doesn't exist, the reference
00054     HcalPedestalWidths *resultPeds = new HcalPedestalWidths();
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()) // not present in new list, take old pedestals
00064           {
00065                 throw cms::Exception("DataDoesNotMatch")<<"Value not found in reference" << std::endl;
00066           }
00067         else // present in new list, take new pedestals
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);  // fix 25.02.08
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()) // not present in new list, take old pedestals
00091           {
00092                 throw cms::Exception("DataDoesNotMatch")<<"Value not found in reference" << std::endl;
00093           }
00094         else // present in new list, take new pedestals
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);  // fix 25.02.08
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()) // not present in new list, take old pedestals
00114           {
00115             const HcalPedestalWidth* mywidth = myRefPeds->getValues( mydetid );
00116             std::cout << "o";
00117             resultPeds->addValues( *mywidth );
00118           }
00119         else // present in new list, take new pedestals
00120           {
00121             const HcalPedestalWidth* mywidth = myNewPeds->getValues( mydetid );
00122             std::cout << "n";
00123             resultPeds->addValues( *mywidth );
00124 
00125             listNewChan.erase(cell);  // fix 25.02.08
00126           }
00127       }
00128 
00129     for (std::vector<DetId>::iterator it = listNewChan.begin(); it != listNewChan.end(); it++)  // fix 25.02.08
00130       {
00131         DetId mydetid = *it;
00132         const HcalPedestalWidth* mywidth = myNewPeds->getValues( mydetid );
00133         std::cout << "N";
00134         resultPeds->addValues( *mywidth );
00135       }
00136     // dump the resulting list of pedestals into a file
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     // get the e-map list of channels
00148     std::vector<HcalGenericDetId> listEMap = myRefEMap->allPrecisionId();
00149     // look up if emap channels are all present in pedestals, if not then cerr
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 //vecDetId HcalPedestalWidthsCheck::getMissingDetIds(vector<HcalPedestalWidths> & myPedestalWidths)
00164 //{
00165 //  HcalGeometry myHcalGeometry;
00166 //  // get the valid detid from the various subdetectors
00167 //  vecDetId validHB = myHcalGeometry.getValidDetIds(Hcal,HcalBarrel);  // check these numbers
00168 //  vecDetId validHE = myHcalGeometry.getValidDetIds(Hcal,HcalEndcap);
00169 //  vecDetId validHF = myHcalGeometry.getValidDetIds(Hcal,HcalForward);
00170 //  vecDetId validHO = myHcalGeometry.getValidDetIds(Hcal,HcalOuter);
00171 //  vecDetId validZDC = myHcalGeometry.getValidDetIds(Calo,2);
00172 //
00173 //  // check if everything is there in pedestals
00174 //
00175 //
00176 //}
00177 
00178 
00179 DEFINE_FWK_MODULE(HcalPedestalWidthsCheck);

Generated on Tue Jun 9 17:26:54 2009 for CMSSW by  doxygen 1.5.4