CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_6/src/CondTools/SiStrip/plugins/SiStripNoisesBuilder.cc

Go to the documentation of this file.
00001 #include "CondTools/SiStrip/plugins/SiStripNoisesBuilder.h"
00002 #include "CalibTracker/SiStripCommon/interface/SiStripDetInfoFileReader.h"
00003 #include <iostream>
00004 #include <fstream>
00005 
00006 SiStripNoisesBuilder::SiStripNoisesBuilder( const edm::ParameterSet& iConfig ):
00007   fp_(iConfig.getUntrackedParameter<edm::FileInPath>("file",edm::FileInPath("CalibTracker/SiStripCommon/data/SiStripDetInfo.dat"))),
00008   printdebug_(iConfig.getUntrackedParameter<uint32_t>("printDebug",1)){}
00009 
00010 
00011 void SiStripNoisesBuilder::analyze(const edm::Event& evt, const edm::EventSetup& iSetup){
00012 
00013   unsigned int run=evt.id().run();
00014 
00015   edm::LogInfo("SiStripNoisesBuilder") << "... creating dummy SiStripNoises Data for Run " << run << "\n " << std::endl;
00016 
00017   SiStripNoises* obj = new SiStripNoises();
00018 
00019   SiStripDetInfoFileReader reader(fp_.fullPath());
00020   
00021   const std::map<uint32_t, SiStripDetInfoFileReader::DetInfo > DetInfos  = reader.getAllData();
00022 
00023   int count=-1;
00024   for(std::map<uint32_t, SiStripDetInfoFileReader::DetInfo >::const_iterator it = DetInfos.begin(); it != DetInfos.end(); it++){    
00025     count++;
00026     //Generate Noise for det detid
00027     SiStripNoises::InputVector theSiStripVector;
00028     for(int strip=0; strip<128*it->second.nApvs; ++strip){
00029 
00030       float MeanNoise = 5;
00031       float RmsNoise  = 1;
00032       float noise =  CLHEP::RandGauss::shoot(MeanNoise,RmsNoise);
00033       
00034       //double badStripProb = .5;
00035       //bool disable = (CLHEP::RandFlat::shoot(1.) < badStripProb ? true:false);
00036         
00037       obj->setData(noise,theSiStripVector);
00038       if (count<static_cast<int>(printdebug_))
00039         edm::LogInfo("SiStripNoisesBuilder") << "detid " << it->first << " \t"
00040                                              << " strip " << strip << " \t"
00041                                              << noise     << " \t" 
00042                                              << theSiStripVector.back()/10 << " \t" 
00043                                              << std::endl;          
00044     }    
00045       
00046     if ( ! obj->put(it->first,theSiStripVector) )
00047       edm::LogError("SiStripNoisesBuilder")<<"[SiStripNoisesBuilder::analyze] detid already exists"<<std::endl;
00048   }
00049 
00050 
00051   //End now write sistripnoises data in DB
00052   edm::Service<cond::service::PoolDBOutputService> mydbservice;
00053 
00054   if( mydbservice.isAvailable() ){
00055     if ( mydbservice->isNewTagRequest("SiStripNoisesRcd") ){
00056       mydbservice->createNewIOV<SiStripNoises>(obj,mydbservice->beginOfTime(),mydbservice->endOfTime(),"SiStripNoisesRcd");
00057     } else {  
00058       //mydbservice->createNewIOV<SiStripNoises>(obj,mydbservice->currentTime(),"SiStripNoisesRcd");      
00059       mydbservice->appendSinceTime<SiStripNoises>(obj,mydbservice->currentTime(),"SiStripNoisesRcd");      
00060     }
00061   }else{
00062     edm::LogError("SiStripNoisesBuilder")<<"Service is unavailable"<<std::endl;
00063   }
00064 }
00065