Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-07 04:35:40

0001 #ifndef SiStripDeDx2DBuilder_H
0002 #define SiStripDeDx2DBuilder_H
0003 
0004 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0005 #include "CondFormats/PhysicsToolsObjects/interface/Histogram2D.h"
0006 #include "FWCore/Framework/interface/ESHandle.h"
0007 #include "FWCore/Framework/interface/Event.h"
0008 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0011 #include "FWCore/ServiceRegistry/interface/Service.h"
0012 #include "FWCore/Utilities/interface/Exception.h"
0013 //#include "FWCore/Utilities/interface/FileInPath.h"
0014 
0015 #include <iostream>
0016 #include <fstream>
0017 //#include "CLHEP/Random/RandFlat.h"
0018 //#include "CLHEP/Random/RandGauss.h"
0019 
0020 class SiStripDeDx2DBuilder : public edm::one::EDAnalyzer<> {
0021 public:
0022   explicit SiStripDeDx2DBuilder(const edm::ParameterSet& iConfig);
0023 
0024   ~SiStripDeDx2DBuilder() {}
0025 
0026   virtual void analyze(const edm::Event&, const edm::EventSetup&);
0027 
0028 private:
0029   //edm::FileInPath fp_;
0030   bool printdebug_;
0031 };
0032 
0033 SiStripDeDx2DBuilder::SiStripDeDx2DBuilder(const edm::ParameterSet& iConfig) {}
0034 //  fp_(iConfig.getUntrackedParameter<edm::FileInPath>("file",edm::FileInPath("CalibTracker/SiStripCommon/data/SiStripDetInfo.dat"))),
0035 //  printdebug_(iConfig.getUntrackedParameter<uint32_t>("printDebug",1)){}
0036 
0037 void SiStripDeDx2DBuilder::analyze(const edm::Event& evt, const edm::EventSetup& iSetup) {
0038   unsigned int run = evt.id().run();
0039 
0040   edm::LogInfo("SiStripDeDx2DBuilder")
0041       << "... creating dummy PhysicsToolsObjects::Calibration::HistogramD2D Data for Run " << run << "\n " << std::endl;
0042 
0043   //  PhysicsToolsObjects::Calibration::HistogramD2D* obj = new PhysicsTools::Calibration::HistogramD2D(300, 0., 3., 1000,0.,1000.);
0044   PhysicsTools::Calibration::VHistogramD2D obj;
0045 
0046   for (int ih = 0; ih < 3; ih++) {
0047     PhysicsTools::Calibration::HistogramD2D myhist(300, 0., 3., 1000, 0., 1000.);
0048     for (int ix = 0; ix < 300; ix++) {
0049       for (int iy = 0; iy < 1000; iy++) {
0050         myhist.setBinContent(ix, iy, iy / 999.);
0051       }
0052     }
0053 
0054     (obj.vHist).push_back(myhist);
0055     (obj.vValues).push_back(ih);
0056   }
0057 
0058   //  SiStripDetInfoFileReader reader(fp_.fullPath());
0059   //  const std::map<uint32_t, SiStripDetInfoFileReader::DetInfo > DetInfos  = reader.getAllData();
0060 
0061   //  int count=-1;
0062   //  for(std::map<uint32_t, SiStripDetInfoFileReader::DetInfo >::const_iterator it = DetInfos.begin(); it != DetInfos.end(); it++){
0063   //   count++;
0064   //Generate Gain for det detid
0065   //  std::vector<float> theSiStripVector;
0066   //  for(unsigned short j=0; j<it->second.nApvs; j++){
0067   //   float gain= (j+1)*1000+ (RandFlat::shoot(1.)*100);
0068   //   if (count<printdebug_)
0069   //    edm::LogInfo("PhysicsToolsObjects::Calibration::HistogramD2DBuilder") << "detid " << it->first << " \t"
0070   //                          << " apv " << j << " \t"
0071   //                          << gain    << " \t"
0072   //                          << std::endl;
0073   //       theSiStripVector.push_back(gain);
0074   //     }
0075 
0076   //     PhysicsToolsObjects::Calibration::HistogramD2D::Range range(theSiStripVector.begin(),theSiStripVector.end());
0077   //     if ( ! obj.put(it->first,range) )
0078 
0079   //      edm::LogError("PhysicsToolsObjects::Calibration::HistogramD2DBuilder")<<"[PhysicsToolsObjects::Calibration::HistogramD2DBuilder::analyze] detid already exists"<<std::endl;
0080   //  }
0081 
0082   //End now write sistripnoises data in DB
0083   edm::Service<cond::service::PoolDBOutputService> mydbservice;
0084 
0085   if (mydbservice.isAvailable()) {
0086     if (mydbservice->isNewTagRequest("SiStripDeDxProton_2D_Rcd")) {
0087       mydbservice->createOneIOV<PhysicsTools::Calibration::VHistogramD2D>(
0088           obj, mydbservice->beginOfTime(), "SiStripDeDxProton_2D_Rcd");
0089     } else {
0090       mydbservice->appendOneIOV<PhysicsTools::Calibration::VHistogramD2D>(
0091           obj, mydbservice->currentTime(), "SiStripDeDxProton_2D_Rcd");
0092     }
0093   } else {
0094     edm::LogError("SiStripDeDx2DBuilder") << "Service is unavailable" << std::endl;
0095   }
0096 }
0097 
0098 #include "FWCore/PluginManager/interface/ModuleDef.h"
0099 #include "FWCore/Framework/interface/MakerMacros.h"
0100 
0101 DEFINE_FWK_MODULE(SiStripDeDx2DBuilder);
0102 
0103 #endif