CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/DQM/SiStripMonitorSummary/src/SiStripApvGainsDQM.cc

Go to the documentation of this file.
00001 #include "DQM/SiStripMonitorSummary/interface/SiStripApvGainsDQM.h"
00002 
00003 
00004 #include "DQMServices/Core/interface/MonitorElement.h"
00005 #include "TCanvas.h"
00006 
00007 // -----
00008 SiStripApvGainsDQM::SiStripApvGainsDQM(const edm::EventSetup & eSetup,
00009                                        edm::ParameterSet const& hPSet,
00010                                        edm::ParameterSet const& fPSet):SiStripBaseCondObjDQM(eSetup,hPSet, fPSet){
00011 
00012   // Build the Histo_TkMap:
00013   if(HistoMaps_On_ ) Tk_HM_ = new TkHistoMap("SiStrip/Histo_Map","MeanApvGain_TkMap",0.);
00014 
00015 }
00016 // -----
00017 
00018 // -----
00019 SiStripApvGainsDQM::~SiStripApvGainsDQM(){}
00020 // -----
00021 
00022 
00023 // -----
00024 void SiStripApvGainsDQM::getActiveDetIds(const edm::EventSetup & eSetup){
00025 
00026   getConditionObject(eSetup);
00027   gainHandle_->getDetIds(activeDetIds);
00028 
00029 }
00030 // -----
00031 
00032 
00033 
00034 
00035 // -----
00036 void SiStripApvGainsDQM::fillModMEs(const std::vector<uint32_t> & selectedDetIds, const edm::EventSetup& es){
00037 
00038   //Retrieve tracker topology from geometry
00039   edm::ESHandle<TrackerTopology> tTopoHandle;
00040   es.get<IdealGeometryRecord>().get(tTopoHandle);
00041   const TrackerTopology* const tTopo = tTopoHandle.product();
00042 
00043   ModMEs CondObj_ME;
00044 
00045   for(std::vector<uint32_t>::const_iterator detIter_ =selectedDetIds.begin();
00046       detIter_!=selectedDetIds.end();++detIter_){
00047     fillMEsForDet(CondObj_ME,*detIter_,tTopo);
00048   }  
00049 }  
00050 
00051   
00052 // -----
00053 void SiStripApvGainsDQM::fillMEsForDet(const ModMEs& _selModME_, uint32_t selDetId_, const TrackerTopology* tTopo){
00054   ModMEs selModME_ = _selModME_;
00055   std::vector<uint32_t> DetIds;
00056   gainHandle_->getDetIds(DetIds);
00057 
00058   SiStripApvGain::Range gainRange = gainHandle_->getRange(selDetId_);
00059   
00060   int nApv =  reader->getNumberOfApvsAndStripLength(selDetId_).first;
00061     
00062   getModMEs(selModME_,selDetId_, tTopo);
00063  
00064   for( int iapv=0;iapv<nApv;++iapv){
00065       if( CondObj_fillId_ =="onlyProfile" || CondObj_fillId_ =="ProfileAndCumul"){
00066         selModME_.ProfileDistr->Fill(iapv+1,gainHandle_->getApvGain(iapv,gainRange));
00067       }
00068       if( CondObj_fillId_ =="onlyCumul" || CondObj_fillId_ =="ProfileAndCumul"){
00069         selModME_.CumulDistr  ->Fill(gainHandle_->getApvGain(iapv,gainRange));
00070       }
00071 
00072     // Fill the TkMap
00073     if(fPSet_.getParameter<bool>("TkMap_On") || hPSet_.getParameter<bool>("TkMap_On")){
00074       fillTkMap(selDetId_, gainHandle_->getApvGain(iapv,gainRange));
00075     }
00076 
00077   }
00078 }
00079 
00080 // -----
00081 void SiStripApvGainsDQM::fillSummaryMEs(const std::vector<uint32_t> & selectedDetIds, const edm::EventSetup& es){
00082   
00083   //Retrieve tracker topology from geometry
00084   edm::ESHandle<TrackerTopology> tTopoHandle;
00085   es.get<IdealGeometryRecord>().get(tTopoHandle);
00086   const TrackerTopology* const tTopo = tTopoHandle.product();
00087 
00088   for(std::vector<uint32_t>::const_iterator detIter_ = selectedDetIds.begin();
00089       detIter_!= selectedDetIds.end();detIter_++){
00090     fillMEsForLayer(/*SummaryMEsMap_,*/ *detIter_, tTopo);
00091   }
00092 
00093   for (std::map<uint32_t, ModMEs>::iterator iter=SummaryMEsMap_.begin(); iter!=SummaryMEsMap_.end(); iter++){
00094 
00095     ModMEs selME;
00096     selME = iter->second;
00097 
00098     if(hPSet_.getParameter<bool>("FillSummaryProfileAtLayerLevel") && fPSet_.getParameter<bool>("OutputSummaryProfileAtLayerLevelAsImage")){
00099 
00100       TCanvas c1("c1");
00101       selME.SummaryOfProfileDistr->getTProfile()->Draw();
00102       std::string name (selME.SummaryOfProfileDistr->getTProfile()->GetTitle());
00103       name+=".png";
00104       c1.Print(name.c_str());
00105     }
00106     if(hPSet_.getParameter<bool>("FillSummaryAtLayerLevel") && fPSet_.getParameter<bool>("OutputSummaryAtLayerLevelAsImage")){
00107 
00108       TCanvas c1("c1");
00109       selME.SummaryDistr->getTH1()->Draw();
00110       std::string name (selME.SummaryDistr->getTH1()->GetTitle());
00111       name+=".png";
00112       c1.Print(name.c_str());
00113     }
00114   }
00115 
00116 }  
00117 
00118 // -----
00119 void SiStripApvGainsDQM::fillMEsForLayer( /*std::map<uint32_t, ModMEs> selMEsMap_, */uint32_t selDetId_, const TrackerTopology* tTopo){
00120     
00121   int subdetectorId_ = ((selDetId_>>25)&0x7);
00122   
00123   if( subdetectorId_<3 ||subdetectorId_>6 ){ 
00124     edm::LogError("SiStripApvGainsDQM")
00125       << "[SiStripApvGainsDQM::fillMEsForLayer] WRONG INPUT : no such subdetector type : "
00126       << subdetectorId_ << " no folder set!" 
00127       << std::endl;
00128     return;
00129   }
00130   // ----
00131          
00132   std::map<uint32_t, ModMEs>::iterator selMEsMapIter_  = SummaryMEsMap_.find(getLayerNameAndId(selDetId_,tTopo).second);
00133   ModMEs selME_;
00134   if ( selMEsMapIter_ != SummaryMEsMap_.end())
00135   selME_ =selMEsMapIter_->second;
00136   getSummaryMEs(selME_,selDetId_,tTopo);
00137   
00138   SiStripApvGain::Range gainRange = gainHandle_->getRange(selDetId_);
00139   int nApv =  reader->getNumberOfApvsAndStripLength(selDetId_).first;
00140   
00141   float meanApvGain=0;
00142 
00143   SiStripHistoId hidmanager;
00144 
00145   if(hPSet_.getParameter<bool>("FillSummaryProfileAtLayerLevel")){
00146 
00147     // --> profile summary    
00148     std::string hSummaryOfProfile_description;
00149     hSummaryOfProfile_description  = hPSet_.getParameter<std::string>("SummaryOfProfile_description");
00150   
00151     std::string hSummaryOfProfile_name; 
00152     hSummaryOfProfile_name = hidmanager.createHistoLayer(hSummaryOfProfile_description, 
00153                                                          "layer", 
00154                                                          getLayerNameAndId(selDetId_,tTopo).first, "") ;
00155   
00156     for( int iapv=0;iapv<nApv;++iapv){
00157     
00158         meanApvGain = meanApvGain +gainHandle_ ->getApvGain(iapv,gainRange);
00159         selME_.SummaryOfProfileDistr->Fill(iapv+1,gainHandle_->getApvGain(iapv,gainRange));
00160 
00161     // Fill the TkMap
00162     if(fPSet_.getParameter<bool>("TkMap_On") || hPSet_.getParameter<bool>("TkMap_On")){
00163       fillTkMap(selDetId_, gainHandle_->getApvGain(iapv,gainRange));
00164     }
00165 
00166     }// iapv
00167 
00168     meanApvGain  = meanApvGain/nApv;
00169 
00170     // Fill the TkHistoMap with meanApvgain:
00171     if(HistoMaps_On_ ) Tk_HM_->setBinContent(selDetId_, meanApvGain);
00172 
00173   }//if Fill ...
00174 
00175 
00176   if(hPSet_.getParameter<bool>("FillSummaryAtLayerLevel")){
00177   
00178     // -->  summary    
00179     std::string hSummary_description;
00180     hSummary_description  = hPSet_.getParameter<std::string>("Summary_description");
00181   
00182     std::string hSummary_name; 
00183     hSummary_name = hidmanager.createHistoLayer(hSummary_description, 
00184                                                 "layer", 
00185                                                 getLayerNameAndId(selDetId_,tTopo).first, 
00186                                                 "") ;
00187 
00188 
00189     // get detIds belonging to same layer to fill X-axis with detId-number
00190   
00191     std::vector<uint32_t> sameLayerDetIds_;
00192   
00193     sameLayerDetIds_.clear();
00194 
00195     sameLayerDetIds_=GetSameLayerDetId(activeDetIds,selDetId_,tTopo);
00196   
00197     unsigned int iBin=0;
00198     for(unsigned int i=0;i<sameLayerDetIds_.size();i++){
00199       if(sameLayerDetIds_[i]==selDetId_){iBin=i+1;}
00200     }
00201 
00202     for( int iapv=0;iapv<nApv;++iapv){
00203         meanApvGain = meanApvGain +gainHandle_ ->getApvGain(iapv,gainRange);
00204         selME_.SummaryDistr->Fill(iBin,gainHandle_->getApvGain(iapv,gainRange));
00205     }//iapv
00206     meanApvGain  = meanApvGain/nApv;
00207 
00208     // Fill the TkHistoMap with meanApvgain:
00209     //    if(HistoMaps_On_ ) Tk_HM_->setBinContent(selDetId_, meanApvGain);
00210 
00211   }//if Fill ...
00212 }  
00213 // -----
00214 
00215 
00216 
00217 
00218 
00219