CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/DQM/SiStripMonitorPedestals/src/SiStripMonitorPedestals.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    SiStripMonitorPedestals
00004 // Class:      SiStripMonitorPedestals
00005 // 
00013 //
00014 // Original Author:  Simone Gennai and Suchandra Dutta
00015 //         Created:  Sat Feb  4 20:49:10 CET 2006
00016 // $Id: SiStripMonitorPedestals.cc,v 1.36 2009/11/05 21:08:29 dutta Exp $
00017 //
00018 //
00019 
00020 #include "FWCore/ServiceRegistry/interface/Service.h"
00021 #include "DataFormats/Common/interface/Handle.h"
00022 
00023 #include "DQMServices/Core/interface/DQMStore.h"
00024 #include "DQMServices/Core/interface/MonitorElement.h"
00025 
00026 #include "DQM/SiStripCommon/interface/SiStripFolderOrganizer.h"
00027 #include "DQM/SiStripCommon/interface/SiStripHistoId.h"
00028 
00029 #include "CalibTracker/SiStripAPVAnalysis/interface/ApvAnalysisFactory.h"
00030 
00031 #include <FWCore/Framework/interface/EventSetup.h>
00032 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00033 
00034 #include "DQM/SiStripMonitorPedestals/interface/SiStripMonitorPedestals.h"
00035 #include "CondFormats/DataRecord/interface/SiStripPedestalsRcd.h"
00036 #include "CondFormats/DataRecord/interface/SiStripNoisesRcd.h"
00037 #include "CalibTracker/Records/interface/SiStripQualityRcd.h"
00038 #include "CondFormats/SiStripObjects/interface/SiStripPedestals.h"
00039 #include "CondFormats/SiStripObjects/interface/SiStripNoises.h"
00040 #include "CalibFormats/SiStripObjects/interface/SiStripQuality.h"
00041 
00042 #include "TProfile.h"
00043 // std
00044 #include <cstdlib>
00045 #include <cmath>
00046 #include <numeric>
00047 #include <algorithm>
00048 
00049 const std::string SiStripMonitorPedestals::RunMode1 = "ConDBPlotsOnly";
00050 const std::string SiStripMonitorPedestals::RunMode2 = "CalculatedPlotsOnly";
00051 const std::string SiStripMonitorPedestals::RunMode3 = "AllPlots";
00052 
00053 SiStripMonitorPedestals::SiStripMonitorPedestals(edm::ParameterSet const& iConfig):
00054   dqmStore_(edm::Service<DQMStore>().operator->()),
00055   conf_(iConfig),
00056   pedsPSet_(iConfig.getParameter<edm::ParameterSet>("PedestalsPSet")),
00057   analyzed(false),
00058   firstEvent(true),
00059   signalCutPeds_(4),
00060   nEvTot_(0),
00061   nIteration_(0),
00062   apvFactory_(0),
00063   m_cacheID_(0)
00064 {
00065   edm::LogInfo("SiStripMonitorPedestals") <<"SiStripMonitorPedestals  " 
00066                                           << " Constructing....... ";     
00067 }
00068 //
00069 // -- Destructor
00070 //
00071 SiStripMonitorPedestals::~SiStripMonitorPedestals()
00072 {
00073   edm::LogInfo("SiStripMonitorPedestals") <<"SiStripMonitorPedestals  " 
00074                                           << " Destructing...... ";     
00075   if (apvFactory_) {delete apvFactory_;} 
00076 }
00077 //
00078 // -- Begin Job
00079 //
00080 void SiStripMonitorPedestals::beginJob() {
00081   theEventInitNumber_ = pedsPSet_.getParameter<int>("NumberOfEventsForInit");
00082   theEventIterNumber_ = pedsPSet_.getParameter<int>("NumberOfEventsForIteration");
00083   NumCMstripsInGroup_ = pedsPSet_.getParameter<int>("NumCMstripsInGroup");
00084         runTypeFlag_  = conf_.getParameter<std::string>("RunTypeFlag");
00085 }
00086 //
00087 // -- BeginRun
00088 //
00089 void SiStripMonitorPedestals::beginRun(edm::Run const& run, edm::EventSetup const& eSetup) {
00090 
00091   unsigned long long cacheID = eSetup.get<SiStripDetCablingRcd>().cacheIdentifier();
00092   if (m_cacheID_ != cacheID) {
00093     m_cacheID_ = cacheID;       
00094     eSetup.get<SiStripDetCablingRcd>().get( detcabling );
00095     edm::LogInfo("SiStripMonitorPedestals") <<"SiStripMonitorPedestals::beginRun: " 
00096                                           << " Creating MEs for new Cabling ";     
00097     createMEs();
00098   } else {
00099     edm::LogInfo("SiStripMonitorPedestals") <<"SiStripMonitorPedestals::beginRun: " 
00100                                           << " Resetting MEs ";        
00101     for (std::map<uint32_t, ModMEs >::const_iterator idet = PedMEs.begin() ; idet!=PedMEs.end() ; idet++) {
00102       resetMEs(idet->first);
00103     }
00104   }
00105   if (runTypeFlag_ == RunMode1 || runTypeFlag_ == RunMode3 ) fillCondDBMEs(eSetup);
00106 }
00107 //
00108 // -- Create Monitor Elements
00109 //
00110 void SiStripMonitorPedestals::createMEs() {
00111   std::vector<uint32_t> SelectedDetIds;
00112   
00113   //ApvAnalysisFactory
00114   if (apvFactory_) {delete apvFactory_;} 
00115   apvFactory_ = new ApvAnalysisFactory(pedsPSet_);
00116   
00117   detcabling->addActiveDetectorsRawIds(SelectedDetIds);
00118   
00119   // use SistripHistoId for producing histogram id (and title)
00120   SiStripHistoId hidmanager;
00121   // create SiStripFolderOrganizer
00122   SiStripFolderOrganizer folder_organizer;
00123   
00124   edm::LogInfo("SiStripMonitorPedestals") <<"SiStripMonitorPedestals::createMEs: " 
00125           << "Number of Detector Present in cabling " << SelectedDetIds.size();
00126 
00127   for (std::vector<uint32_t>::const_iterator idetid=SelectedDetIds.begin(), iEnd=SelectedDetIds.end();idetid!=iEnd;++idetid){
00128     
00129     uint32_t detid = *idetid;
00130 
00131     // Check consistency in DetId
00132     if (detid == 0 || detid == 0xFFFFFFFF){
00133       edm::LogError("SiStripMonitorPedestals") <<"SiStripMonitorPedestals::createMEs: " 
00134         << "Wrong DetId !!!!!! " <<  detid << " Neglecting !!!!!! ";
00135       continue;
00136     }
00137 
00138     unsigned int apv_pairs = detcabling->nApvPairs(detid);
00139     
00140     // Check consistency in Apv numbers
00141     if (apv_pairs < 1 || apv_pairs > 3) {
00142       edm::LogError("SiStripMonitorPedestals") <<"SiStripMonitorPedestals::createMEs: Wrong APV Pairs  => detId "
00143                 << detid  << " APV pairs " << apv_pairs <<  " Neglecting !!!!!! ";
00144       continue;
00145     }
00146     unsigned int napvs = apv_pairs * 2;
00147     unsigned int nStrip  = napvs * 128;
00148 
00149     bool newDetId =   apvFactory_->instantiateApvs(detid,napvs);  
00150   
00151     if( newDetId ) {
00152       ModMEs local_modmes;
00153       local_modmes.PedsPerStrip = 0;
00154       local_modmes.PedsDistribution = 0;      
00155       local_modmes.PedsEvolution = 0;
00156       local_modmes.CMSubNoisePerStrip = 0;
00157       local_modmes.RawNoisePerStrip = 0;
00158       local_modmes.CMSubNoiseProfile = 0;
00159       local_modmes.RawNoiseProfile = 0;
00160       local_modmes.NoisyStrips = 0;
00161       local_modmes.NoisyStripDistribution = 0;
00162       local_modmes.CMDistribution = 0;
00163       local_modmes.CMSlopeDistribution = 0;
00164       local_modmes.PedsPerStripDB = 0;
00165       local_modmes.CMSubNoisePerStripDB = 0;
00166       local_modmes.BadStripsDB = 0;
00167 
00168       std::string hid;
00169       // set appropriate folder using SiStripFolderOrganizer
00170       folder_organizer.setDetectorFolder(detid); // pass the detid to this method
00171       
00172       // if the deid already exists in the map, then reset MEs otherwise create them
00173       resetMEs(detid);
00174       
00175       if (runTypeFlag_ == RunMode1 || runTypeFlag_ == RunMode3 ) {
00176         //Pedestals histos
00177         hid = hidmanager.createHistoId("PedestalFromCondDB","det", detid);
00178         local_modmes.PedsPerStripDB = dqmStore_->book1D(hid, hid, nStrip,0.5,nStrip+0.5); //to modify the size binning 
00179         dqmStore_->tag(local_modmes.PedsPerStripDB, detid);
00180         (local_modmes.PedsPerStripDB)->setAxisTitle("Pedestal from CondDB(ADC) vs Strip Number",1);
00181         
00182         hid = hidmanager.createHistoId("NoiseFromCondDB","det", detid);
00183         local_modmes.CMSubNoisePerStripDB = dqmStore_->book1D(hid, hid, nStrip,0.5,nStrip+0.5);
00184         dqmStore_->tag(local_modmes.CMSubNoisePerStripDB, detid);
00185         (local_modmes.CMSubNoisePerStripDB)->setAxisTitle("CMSubNoise from CondDB(ADC) vs Strip Number",1);
00186         
00187         hid = hidmanager.createHistoId("BadStripFlagCondDB","det", detid);
00188         local_modmes.BadStripsDB = dqmStore_->book2D(hid, hid, nStrip,0.5,nStrip+0.5,6,-0.5,5.5);
00189         dqmStore_->tag(local_modmes.BadStripsDB, detid);
00190         (local_modmes.BadStripsDB)->setAxisTitle("Strip Flag from CondDB(ADC) vs Strip Number",1);
00191       }
00192       if (runTypeFlag_ == RunMode2 || runTypeFlag_ == RunMode3 ) { 
00193         //Pedestals histos
00194         hid = hidmanager.createHistoId("PedsPerStrip","det", detid);
00195         local_modmes.PedsPerStrip = dqmStore_->book1D(hid, hid, nStrip,0.5,nStrip+0.5); //to modify the size binning 
00196         dqmStore_->tag(local_modmes.PedsPerStrip, detid);
00197         (local_modmes.PedsPerStrip)->setAxisTitle("Pedestal (ADC)  vs Strip Number ",1);
00198         
00199         hid = hidmanager.createHistoId("PedsDistribution","det", detid);
00200         local_modmes.PedsDistribution = dqmStore_->book2D(hid, hid, napvs,-0.5,napvs-0.5, 300, 200, 500); //to modify the size binning 
00201         dqmStore_->tag(local_modmes.PedsDistribution, detid);
00202         (local_modmes.PedsDistribution)->setAxisTitle("Apv Number",1);
00203         (local_modmes.PedsDistribution)->setAxisTitle("Mean Pedestal Value (ADC)",2);
00204         
00205         hid = hidmanager.createHistoId("PedsEvolution","det", detid);
00206         local_modmes.PedsEvolution = dqmStore_->book2D(hid, hid, napvs,-0.5,napvs-0.5, 50, 0., 50.); //to modify the size binning 
00207         dqmStore_->tag(local_modmes.PedsEvolution, detid);
00208         (local_modmes.PedsEvolution)->setAxisTitle("Apv Number",1);
00209         (local_modmes.PedsEvolution)->setAxisTitle("Iteration Number",2);
00210         
00211         //Noise histos
00212         hid = hidmanager.createHistoId("CMSubNoisePerStrip","det", detid);
00213         local_modmes.CMSubNoisePerStrip = dqmStore_->book1D(hid, hid, nStrip,0.5,nStrip+0.5);
00214         dqmStore_->tag(local_modmes.CMSubNoisePerStrip, detid);
00215         (local_modmes.CMSubNoisePerStrip)->setAxisTitle("CMSubNoise (ADC) vs Strip Number",1);
00216         
00217         hid = hidmanager.createHistoId("RawNoisePerStrip","det", detid);
00218         local_modmes.RawNoisePerStrip = dqmStore_->book1D(hid, hid, nStrip,0.5,nStrip+0.5);
00219         dqmStore_->tag(local_modmes.RawNoisePerStrip, detid);
00220         (local_modmes.RawNoisePerStrip)->setAxisTitle("RawNoise(ADC) vs Strip Number",1);
00221         
00222         hid = hidmanager.createHistoId("CMSubNoiseProfile","det", detid);
00223         local_modmes.CMSubNoiseProfile = dqmStore_->bookProfile(hid, hid, nStrip,0.5,nStrip+0.5, 100, 0., 100.);
00224         dqmStore_->tag(local_modmes.CMSubNoiseProfile, detid);
00225         (local_modmes.CMSubNoiseProfile)->setAxisTitle("Mean of CMSubNoise (ADC) vs Strip Number",1);
00226         
00227         hid = hidmanager.createHistoId("RawNoiseProfile","det", detid);
00228         local_modmes.RawNoiseProfile = dqmStore_->bookProfile(hid, hid, nStrip,0.5,nStrip+0.5, 100, 0., 100.);
00229         dqmStore_->tag(local_modmes.RawNoiseProfile, detid);
00230         (local_modmes.RawNoiseProfile)->setAxisTitle("Mean of RawNoise (ADC) vs Strip Number",1);
00231         
00232         hid = hidmanager.createHistoId("NoisyStrips","det", detid);
00233         local_modmes.NoisyStrips = dqmStore_->book2D(hid, hid, nStrip,0.5,nStrip+0.5,6,-0.5,5.5);
00234         dqmStore_->tag(local_modmes.NoisyStrips, detid);
00235         (local_modmes.NoisyStrips)->setAxisTitle("Strip Number",1);
00236         (local_modmes.NoisyStrips)->setAxisTitle("Flag Value",2);
00237         
00238         hid = hidmanager.createHistoId("NoisyStripDistribution","det", detid);
00239         local_modmes.NoisyStripDistribution = dqmStore_->book1D(hid, hid, 11, -0.5,10.5);
00240         dqmStore_->tag(local_modmes.NoisyStripDistribution, detid);
00241         (local_modmes.NoisyStripDistribution)->setAxisTitle("Flag Value",1);
00242         
00243         //Common Mode histos
00244         hid = hidmanager.createHistoId("CMDistribution","det", detid);
00245         local_modmes.CMDistribution = dqmStore_->book2D(hid, hid, napvs,-0.5,napvs-0.5, 150, -15., 15.); 
00246         dqmStore_->tag(local_modmes.CMDistribution, detid);
00247         (local_modmes.CMDistribution)->setAxisTitle("Common Mode (ADC) vs APV Number",1);
00248       
00249         hid = hidmanager.createHistoId("CMSlopeDistribution","det", detid);
00250         local_modmes.CMSlopeDistribution = dqmStore_->book2D(hid, hid, napvs,-0.5,napvs-0.5, 100, -0.05, 0.05); 
00251         dqmStore_->tag(local_modmes.CMSlopeDistribution, detid);
00252         (local_modmes.CMSlopeDistribution)->setAxisTitle("Common Mode Slope vs APV Number",1);
00253         
00254       }
00255       // data from CondDB
00256       // append to PedMEs
00257       PedMEs.insert( std::make_pair(detid, local_modmes));
00258     } //newDetId
00259           
00260   }
00261   edm::LogInfo("SiStripMonitorPedestals") <<"SiStripMonitorPedestals::createMEs: Number of DETS used "
00262                    <<PedMEs.size();
00263 }
00264 // ------------ method called to produce the data  ------------
00265 void SiStripMonitorPedestals::analyze(const edm::Event& iEvent, const edm::EventSetup& eSetup)
00266 {
00267 
00268   edm::LogInfo("SiStripMonitorPedestals") <<
00269                "SiStripMonitorPedestals::analyze: Run " << 
00270                iEvent.id().run()  << " Event " << iEvent.id().event();
00271 
00272   eSetup.get<SiStripDetCablingRcd>().get( detcabling );
00273 
00274   if (runTypeFlag_ != RunMode2 &&  runTypeFlag_ != RunMode3 ) return;
00275 
00276   //Increment # of Events
00277   nEvTot_++;
00278  
00279   // retrieve producer name of input StripDigiCollection
00280   std::string digiProducer = conf_.getParameter<std::string>("DigiProducer");
00281   // get DigiCollection object from Event
00282   edm::Handle< edm::DetSetVector<SiStripRawDigi> > digi_collection;
00283   std::string digiType = "VirginRaw";
00284   //you have a collection as there are all the digis for the event for every detector
00285   iEvent.getByLabel(digiProducer, digiType, digi_collection);
00286 
00287   //Increase the number of iterations ...
00288   if((nEvTot_ - theEventInitNumber_)%theEventIterNumber_ == 1) nIteration_++;
00289   
00290 
00291   // loop over all MEs
00292   for (std::map<uint32_t, ModMEs >::const_iterator i = PedMEs.begin() ; i!=PedMEs.end() ; i++) {
00293     uint32_t detid = i->first; ModMEs local_modmes = i->second;
00294     // get iterators for digis belonging to one DetId, it is an iterator, i.e. one element of the vector      
00295     std::vector< edm::DetSet<SiStripRawDigi> >::const_iterator digis = digi_collection->find( detid );
00296     if (digis == digi_collection->end() ||
00297         digis->data.size() == 0 || 
00298         digis->data.size() > 768) {
00299       if (digis == digi_collection->end()) {
00300         edm::LogError("SiStripMonitorPedestals") << " SiStripMonitorPedestals::analyze: Event " <<  nEvTot_ 
00301                << " DetId " <<  detid << " at the end of Digi Collection!!!"; 
00302       } else {
00303         edm::LogError("SiStripMonitorPedestals") << " [SiStripMonitorPedestals::analyze: Event " <<  nEvTot_ 
00304                << " DetId " <<  detid << " # of Digis " << digis->data.size() ;
00305       }
00306       std::vector<FedChannelConnection> fed_conns = detcabling->getConnections(detid);
00307       for (unsigned int  k = 0; k < fed_conns.size() ; k++) {
00308         if (k==0) edm::LogError("SiStripMonitorPedestals") <<" SiStripMonitorPedestals::analyze: Fed Id " <<
00309               fed_conns[k].fedId() << " Channel " << fed_conns[k].fedCh();
00310         else  edm::LogError("SiStripMonitorPedestals")  <<"  SiStripMonitorPedestals::analyze: Channel " <<
00311                             fed_conns[k].fedCh();
00312       }
00313       std::cout << std::endl;
00314       continue;
00315     }
00316 
00317     if ( digis->data.empty() ) { 
00318       edm::LogError("MonitorDigi_tmp") << "[SiStripRawDigiToRaw::createFedBuffers] Zero digis found!"; 
00319     } 
00320     uint32_t id  = detid;
00321     //    cout <<"Data size "<<digis->data.size()<<endl;
00322     apvFactory_->update(id, (*digis));
00323       
00324     if(nEvTot_ > theEventInitNumber_) {
00325       if(local_modmes.CMDistribution != NULL){ 
00326         std::vector<float> tmp;
00327         tmp.clear();
00328         apvFactory_->getCommonMode(id, tmp);
00329         //unpacking the info looking at the right topology
00330         int numberCMBlocks = int(128. / NumCMstripsInGroup_);
00331         int ibin=0;
00332         for (std::vector<float>::const_iterator iped=tmp.begin(); iped!=tmp.end();iped++) {
00333           int iapv = int (ibin/numberCMBlocks);
00334           (local_modmes.CMDistribution)->Fill(iapv,static_cast<float>(*iped));
00335           ibin++;
00336             
00337         }
00338       }
00339       if(local_modmes.CMSlopeDistribution != NULL){ 
00340         std::vector<float> tmp;
00341         tmp.clear();
00342         int iapv = 0;
00343         apvFactory_->getCommonModeSlope(id, tmp);
00344         for (std::vector<float>::const_iterator it=tmp.begin(); it!=tmp.end();it++) {
00345           (local_modmes.CMSlopeDistribution)->Fill(iapv,static_cast<float>(*it));
00346           iapv++;
00347         }
00348       }
00349     }
00350       
00351     //asking for the status
00352     if((nEvTot_ - theEventInitNumber_ - theEventIterNumber_)%theEventIterNumber_ == 1)
00353       {
00354               
00355         std::vector<float> tmp;
00356         tmp.clear();
00357         apvFactory_->getPedestal(id, tmp);
00358         if(local_modmes.PedsPerStrip != NULL){ 
00359           int numberOfApvs = int(tmp.size()/128.);
00360           for(int i=0; i<numberOfApvs;i++){
00361             std::vector<float> myPedPerApv;
00362             apvFactory_->getPedestal(id, i, myPedPerApv);
00363             float avarage = 0;
00364             avarage = accumulate(myPedPerApv.begin(), myPedPerApv.end(), avarage);
00365             avarage = avarage/128.;
00366             (local_modmes.PedsEvolution)->setBinContent(i+1,nIteration_,avarage);
00367               
00368           }
00369           int ibin=0;
00370           
00371           for (std::vector<float>::const_iterator iped=tmp.begin(); iped!=tmp.end();iped++) {
00372             int napv = int(ibin / 128.);
00373             ibin++;
00374             float last_value = (local_modmes.PedsPerStrip)->getBinContent(ibin);
00375             if(last_value != 0.){
00376               (local_modmes.PedsPerStrip)->setBinContent(ibin,(static_cast<float>(*iped) + last_value)/2.);
00377             }else{
00378               (local_modmes.PedsPerStrip)->setBinContent(ibin,static_cast<float>(*iped));
00379             }
00380             (local_modmes.PedsDistribution)->Fill(napv,static_cast<float>(*iped));
00381           }
00382         }
00383           
00384         if(local_modmes.CMSubNoisePerStrip != NULL && local_modmes.CMSubNoiseProfile != NULL){ 
00385           tmp.clear();
00386           apvFactory_->getNoise(id, tmp);
00387           int ibin=0;
00388           for (std::vector<float>::const_iterator iped=tmp.begin(); iped!=tmp.end();iped++) {
00389             ibin++;
00390             (local_modmes.CMSubNoiseProfile)->Fill(static_cast<double>(ibin*1.),static_cast<float>(*iped));
00391 
00392             float last_value = (local_modmes.CMSubNoisePerStrip)->getBinContent(ibin);
00393             if(last_value != 0.){
00394               (local_modmes.CMSubNoisePerStrip)->setBinContent(ibin,(static_cast<float>(*iped)+last_value)/2.);
00395             }else{
00396               (local_modmes.CMSubNoisePerStrip)->setBinContent(ibin,static_cast<float>(*iped));
00397             }
00398           }
00399         }
00400 
00401           
00402         if(local_modmes.RawNoisePerStrip != NULL && local_modmes.RawNoiseProfile != NULL){ 
00403           tmp.clear();
00404           apvFactory_->getRawNoise(id, tmp);
00405           int ibin=0;
00406           for (std::vector<float>::const_iterator iped=tmp.begin(); iped!=tmp.end();iped++) {
00407             ibin++;
00408             (local_modmes.RawNoiseProfile)->Fill(static_cast<double>(ibin*1.),static_cast<float>(*iped));
00409             float last_value = (local_modmes.RawNoisePerStrip)->getBinContent(ibin);
00410             if(last_value != 0.){
00411               (local_modmes.RawNoisePerStrip)->setBinContent(ibin,(static_cast<float>(*iped)+last_value)/2.);
00412             }else{
00413               (local_modmes.RawNoisePerStrip)->setBinContent(ibin,static_cast<float>(*iped));
00414             }
00415           }
00416         }
00417 
00418         if(local_modmes.NoisyStrips != NULL){ 
00419           TkApvMask::MaskType temp;
00420           apvFactory_->getMask(id, temp);
00421           int ibin=0;
00422           for (TkApvMask::MaskType::const_iterator iped=temp.begin(); iped!=temp.end();iped++) {
00423             ibin++;
00424               
00425             if(nIteration_ <2){
00426               if(*iped == 1)
00427                 (local_modmes.NoisyStrips)->Fill(ibin,3.);
00428               if(*iped == 2)
00429                 (local_modmes.NoisyStrips)->Fill(ibin,4.);
00430               if(*iped == 0)
00431                 (local_modmes.NoisyStrips)->Fill(ibin,0.);
00432             }else{
00433               (local_modmes.NoisyStrips)->Fill(ibin,static_cast<float>(*iped));
00434               (local_modmes.NoisyStripDistribution)->Fill(static_cast<float>(*iped));
00435             }
00436           }
00437         }
00438 
00439 
00440       }    
00441   }
00442   if (firstEvent) firstEvent=false;  
00443 }
00444 //
00445 // -- End Run
00446 //    
00447 void SiStripMonitorPedestals::endRun(edm::Run const& run, edm::EventSetup const& eSetup) {
00448   bool outputMEsInRootFile = conf_.getParameter<bool>("OutputMEsInRootFile");
00449   if (outputMEsInRootFile) {    
00450     std::string outPutFileName = conf_.getParameter<std::string>("OutPutFileName");
00451 //    dqmStore_->showDirStructure();
00452     dqmStore_->save(outPutFileName);
00453   }
00454 }
00455 //
00456 // -- End Job
00457 //    
00458 void SiStripMonitorPedestals::endJob(void){
00459   edm::LogInfo("SiStripMonitorPedestals") <<"SiStripMonitorPedestals::EndJob: " 
00460                                           << " Finishing!! ";        
00461 }
00462 //
00463 // -- Reset Monitor Elements corresponding to a detetor
00464 //    
00465 void SiStripMonitorPedestals::resetMEs(uint32_t idet){
00466   std::map<uint32_t, ModMEs >::iterator pos = PedMEs.find(idet);
00467   if (pos != PedMEs.end()) {
00468     ModMEs mod_me = pos->second;
00469 
00470     if (runTypeFlag_ == RunMode1 || runTypeFlag_ == RunMode3 ) { 
00471       mod_me.PedsPerStripDB->Reset();     
00472       mod_me.CMSubNoisePerStripDB->Reset();     
00473       mod_me.BadStripsDB->Reset();     
00474     }
00475     if (runTypeFlag_ == RunMode2 || runTypeFlag_ == RunMode3 ) { 
00476       mod_me.PedsPerStrip->Reset();      
00477       mod_me.PedsDistribution->Reset();      
00478       mod_me.PedsEvolution->Reset();      
00479       mod_me.CMSubNoisePerStrip->Reset();      
00480       mod_me.RawNoisePerStrip->Reset();      
00481       mod_me.CMSubNoiseProfile->Reset();      
00482       mod_me.RawNoiseProfile->Reset();      
00483       mod_me.NoisyStrips->Reset();      
00484       mod_me.CMDistribution->Reset();     
00485       mod_me.CMSlopeDistribution->Reset(); 
00486     }
00487   }
00488 }
00489 //
00490 // -- Fill CondDB Monitoring Elements
00491 //
00492 void SiStripMonitorPedestals::fillCondDBMEs(edm::EventSetup const& eSetup) {
00493   //get Pedestal and Noise  ES handle
00494   edm::ESHandle<SiStripPedestals> pedestalHandle;
00495   edm::ESHandle<SiStripNoises> noiseHandle;
00496   edm::ESHandle<SiStripQuality> qualityHandle;
00497   
00498   eSetup.get<SiStripPedestalsRcd>().get(pedestalHandle);
00499   eSetup.get<SiStripNoisesRcd>().get(noiseHandle);
00500   std::string quality_label = conf_.getParameter<std::string>("StripQualityLabel");
00501   eSetup.get<SiStripQualityRcd>().get(quality_label, qualityHandle);
00502 
00503   for (std::map<uint32_t, ModMEs >::const_iterator i = PedMEs.begin() ; i!=PedMEs.end() ; i++) {
00504     uint32_t detid = i->first; 
00505     ModMEs local_modmes = i->second;
00506     edm::LogInfo("SiStripMonitorPedestals") <<" SiStripMonitorPedestals::analyze: " <<
00507       " Get Ped/Noise/Bad Strips from CondDb for DetId " << detid;
00508     int nStrip  = detcabling->nApvPairs(detid) * 256;
00509     // Get range of pedestal and noise for the detid
00510     SiStripNoises::Range noiseRange = noiseHandle->getRange(detid);
00511     SiStripPedestals::Range pedRange = pedestalHandle->getRange(detid);
00512     SiStripQuality::Range qualityRange = qualityHandle->getRange(detid);
00513     
00514     for(int istrip=0;istrip<nStrip;++istrip){
00515       try{
00516         //Fill Pedestals
00517         (local_modmes.PedsPerStripDB)->Fill(istrip+1,pedestalHandle->getPed(istrip,pedRange));
00518       }
00519       catch(cms::Exception& e){
00520         edm::LogError("SiStripMonitorPedestals") << "[SiStripMonitorPedestals::analyze]  cms::Exception accessing SiStripPedestalsService_.getPedestal("<<detid<<","<<istrip<<") :  "  << " " << e.what() ;
00521       }
00522       try{
00523         //Fill Noises
00524         (local_modmes.CMSubNoisePerStripDB)->Fill(istrip+1,noiseHandle->getNoise(istrip,noiseRange));
00525         
00526       }
00527       catch(cms::Exception& e){
00528         edm::LogError("SiStripMonitorPedestals") << "[SiStripMonitorPedestals::analyze]  cms::Exception accessing SiStripNoiseService_.getNoise("<<detid<<","<<istrip<<") :  "  << " " << e.what() ;
00529       }
00530       try{
00531         //Fill BadStripsNoise
00532         (local_modmes.BadStripsDB)->Fill(istrip+1,qualityHandle->IsStripBad(qualityRange,istrip)?1.:0.);
00533         
00534         
00535       }
00536       catch(cms::Exception& e){
00537         edm::LogError("SiStripMonitorPedestals") << "[SiStripMonitorPedestals::analyze]  cms::Exception accessing SiStripNoiseService_.getDisable("<<detid<<","<<istrip<<") :  "  << " " << e.what() ;
00538       }
00539     }//close istrip loop
00540   }
00541 }
00542 DEFINE_FWK_MODULE(SiStripMonitorPedestals);