Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-11-07 23:57:52

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