CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_8_patch3/src/DQM/SiStripMonitorSummary/src/SiStripBaseCondObjDQM.cc

Go to the documentation of this file.
00001 #include "DQM/SiStripMonitorSummary/interface/SiStripBaseCondObjDQM.h"
00002 
00003 #include "TCanvas.h"
00004 
00005 // -----
00006 
00007 
00008 
00009 SiStripBaseCondObjDQM::SiStripBaseCondObjDQM(const edm::EventSetup & eSetup,
00010                                              edm::ParameterSet const& hPSet,
00011                                              edm::ParameterSet const& fPSet ):
00012   eSetup_(eSetup),
00013   hPSet_(hPSet),
00014   fPSet_(fPSet),
00015   cacheID_memory(0),
00016   dqmStore_(edm::Service<DQMStore>().operator->()){
00017 
00018   reader = new SiStripDetInfoFileReader(edm::FileInPath(std::string("CalibTracker/SiStripCommon/data/SiStripDetInfo.dat") ).fullPath());
00019   
00020   Mod_On_                  = fPSet_.getParameter<bool>("Mod_On");
00021   HistoMaps_On_            = fPSet_.getParameter<bool>("HistoMaps_On");
00022   SummaryOnLayerLevel_On_  = fPSet_.getParameter<bool>("SummaryOnLayerLevel_On");
00023   SummaryOnStringLevel_On_ = fPSet_.getParameter<bool>("SummaryOnStringLevel_On");
00024 
00025   GrandSummary_On_         = fPSet_.getParameter<bool>("GrandSummary_On");
00026 
00027   CondObj_fillId_    = hPSet_.getParameter<std::string>("CondObj_fillId");
00028   CondObj_name_      = hPSet_.getParameter<std::string>("CondObj_name");
00029  
00030 
00031   //Warning message from wrong input:
00032   if(SummaryOnLayerLevel_On_ && SummaryOnStringLevel_On_){
00033     edm::LogWarning("SiStripBaseCondObjDQM") 
00034        << "[SiStripBaseCondObjDQM::SiStripBaseCondObjDQMs] PLEASE CHECK : String and layer level options can not be activated together"
00035        << std::endl; 
00036   }
00037 
00038   //The OR of the two conditions allow to switch on this feature for all the components (if the FillConditions_PSet has the TkMap_On =true) or for single MEs (if the PSet for a ME has the TkMap_On =true)
00039   if(fPSet_.getParameter<bool>("TkMap_On") || hPSet_.getParameter<bool>("TkMap_On")) bookTkMap(hPSet_.getParameter<std::string>("TkMapName"));
00040 
00041 
00042   minValue=hPSet_.getParameter<double>("minValue");
00043   maxValue=hPSet_.getParameter<double>("maxValue");
00044 
00045 }
00046 // -----
00047 
00048 
00049 //======================================
00050 // -----
00051 void SiStripBaseCondObjDQM::analysis(const edm::EventSetup & eSetup_){
00052  
00053   cacheID_current=  getCache(eSetup_);
00054   
00055   if (cacheID_memory == cacheID_current) return;
00056   
00057   getConditionObject(eSetup_);
00058 
00059   //The OR of the two conditions allows to switch on this feature for all the components (if the FillConditions_PSet has the ActiveDetIds_On =true) or for single MEs (if the PSet for a ME has the ActiveDetIds_On =true)
00060   if(fPSet_.getParameter<bool>("ActiveDetIds_On") || hPSet_.getParameter<bool>("ActiveDetIds_On"))
00061     getActiveDetIds(eSetup_);
00062   else
00063     activeDetIds=reader->getAllDetIds();
00064 
00065   selectModules(activeDetIds);
00066 
00067   if(Mod_On_ )                                            { fillModMEs(activeDetIds); }
00068   if(SummaryOnLayerLevel_On_ || SummaryOnStringLevel_On_ ){ fillSummaryMEs(activeDetIds);}
00069 
00070   std::string filename = hPSet_.getParameter<std::string>("TkMapName");
00071   if (filename!=""){
00072     char sRun[128];
00073     sprintf(sRun,"_Run_%d",eSetup_.iovSyncValue().eventID().run());
00074     filename.insert(filename.find("."),sRun);
00075     
00076     saveTkMap(filename.c_str(), minValue, maxValue);
00077   }
00078 }
00079 // -----
00080 
00081 
00082 //=====================================
00083 // -----
00084 void SiStripBaseCondObjDQM::analysisOnDemand(const edm::EventSetup & eSetup_, 
00085                                             std::string requestedSubDetector, 
00086                                             uint32_t requestedSide, 
00087                                             uint32_t requestedLayer){
00088   
00089   getConditionObject(eSetup_);
00090   getActiveDetIds(eSetup_);
00091    
00092   std::vector<uint32_t> requestedDetIds_;
00093   requestedDetIds_.clear();
00094   
00095   SiStripSubStructure substructure_;
00096   
00097   if(requestedSubDetector=="TIB"){ 
00098       substructure_.getTIBDetectors( activeDetIds, requestedDetIds_, requestedLayer,0,0,0);
00099   }
00100   else if(requestedSubDetector=="TID"){ 
00101       substructure_.getTIDDetectors( activeDetIds, requestedDetIds_, requestedSide,requestedLayer,0,0);
00102   }
00103   else if(requestedSubDetector=="TOB"){  
00104       substructure_.getTOBDetectors( activeDetIds, requestedDetIds_, requestedLayer,0,0);
00105   }
00106   else if(requestedSubDetector=="TEC"){  
00107       substructure_.getTECDetectors( activeDetIds, requestedDetIds_, requestedSide,requestedLayer,0,0,0,0);
00108   } 
00109 
00110   analysisOnDemand(eSetup_,requestedDetIds_);
00111  
00112 }
00113 // -----
00114 
00115 //===========================================
00116 // -----
00117 void SiStripBaseCondObjDQM::analysisOnDemand(const edm::EventSetup & eSetup_, uint32_t  detIdOnDemand){
00118  
00119   unsigned long long cacheID_current=  getCache(eSetup_);
00120   
00121   if (cacheID_memory == cacheID_current) return;
00122   
00123   getConditionObject(eSetup_);
00124   
00125   std::vector<uint32_t> vdetIdsOnDemand_;
00126   vdetIdsOnDemand_.push_back(detIdOnDemand); // fillModMEs needs a vector 
00127 
00128   fillModMEs(vdetIdsOnDemand_); 
00129   
00130 }
00131 // -----
00132 //===============================================
00133 // -----
00134 void SiStripBaseCondObjDQM::analysisOnDemand(const edm::EventSetup & eSetup_, std::vector<uint32_t>  detIdsOnDemand){
00135  
00136   unsigned long long cacheID_current=  getCache(eSetup_);
00137   
00138   if (cacheID_memory == cacheID_current) return;
00139   
00140   getConditionObject(eSetup_);
00141   
00142 
00143   fillSummaryMEs(detIdsOnDemand); 
00144   
00145 }
00146 // -----
00147 //====================================
00148 // -----
00149 std::vector<uint32_t> SiStripBaseCondObjDQM::getCabledModules() {     
00150  
00151   std::vector<uint32_t> cabledDetIds_;  
00152   eSetup_.get<SiStripDetCablingRcd>().get(detCablingHandle_);
00153   detCablingHandle_->addActiveDetectorsRawIds(cabledDetIds_);
00154 
00155   return cabledDetIds_;  
00156 
00157 }
00158 // -----
00159 
00160 
00161 //=========================================================
00162 // -----
00163 
00164 //#FIXME : very long method. please factorize it
00165  
00166 void SiStripBaseCondObjDQM::selectModules(std::vector<uint32_t> & detIds_){
00167    
00168   ModulesToBeExcluded_     = fPSet_.getParameter< std::vector<unsigned int> >("ModulesToBeExcluded");
00169   ModulesToBeIncluded_     = fPSet_.getParameter< std::vector<unsigned int> >("ModulesToBeIncluded");
00170   SubDetectorsToBeExcluded_= fPSet_.getParameter< std::vector<std::string> >("SubDetectorsToBeExcluded");  
00171  
00172   if(fPSet_.getParameter<bool>("restrictModules") 
00173      && ModulesToBeExcluded_.size()==0 
00174      && ModulesToBeIncluded_.size()==0 ){
00175     edm::LogWarning("SiStripBaseCondObjDQM") 
00176        << "[SiStripBaseCondObjDQM::selectModules] PLEASE CHECK : no modules to be exclude/included in your cfg"
00177        << std::endl; 
00178   }
00179 
00180  
00181  
00182   
00183   // --> detIds to start with
00184 
00185   if( fPSet_.getParameter<bool>("restrictModules")){
00186       
00187     if( ModulesToBeIncluded_.size()>0 ){
00188      std::vector<uint32_t> tmp;
00189      tmp.clear();
00190      set_intersection( detIds_.begin(), detIds_.end(),  
00191                        ModulesToBeIncluded_.begin(), ModulesToBeIncluded_.end(),
00192                        inserter(tmp,tmp.begin()));
00193      swap(detIds_,tmp);
00194    }
00195     
00196   }
00197 
00198   
00199 
00200   // -----
00201   // *** exclude modules ***
00202   
00203   if( fPSet_.getParameter<bool>("restrictModules") ){
00204     
00205     std::sort(detIds_.begin(),detIds_.end());
00206 
00207     for( std::vector<uint32_t>::const_iterator modIter_  = ModulesToBeExcluded_.begin(); 
00208                                                modIter_ != ModulesToBeExcluded_.end(); modIter_++){
00209       
00210       std::vector<uint32_t>::iterator detIter_=std::lower_bound(detIds_.begin(),detIds_.end(),*modIter_);
00211       detIds_.erase(detIter_);
00212       detIter_--;
00213      
00214     }
00215   
00216   }
00217   // *** exclude modules ***
00218   // -----
00219    
00220 
00221   // -----
00222   // *** restrict to a particular subdetector ***
00223    
00224   if( *(SubDetectorsToBeExcluded_.begin()) !="none" ){
00225     
00226     std::vector<uint32_t> tmp;
00227 
00228     SiStripSubStructure substructure_;
00229     
00230     for( std::vector<std::string>::const_iterator modIter_  = SubDetectorsToBeExcluded_.begin(); 
00231                                                  modIter_ != SubDetectorsToBeExcluded_.end(); modIter_++){
00232       tmp.clear();
00233 
00234       if (*modIter_=="TIB")     { substructure_.getTIBDetectors(detIds_, tmp, 0,0,0,0);}
00235       else if (*modIter_=="TOB") { substructure_.getTOBDetectors(detIds_, tmp, 0,0,0);}
00236       else if (*modIter_=="TID") { substructure_.getTIDDetectors(detIds_, tmp, 0,0,0,0);}
00237       else if (*modIter_=="TEC") { substructure_.getTECDetectors(detIds_, tmp, 0,0,0,0,0,0);}
00238       else {
00239         edm::LogWarning("SiStripBaseCondObjDQM") 
00240        << "[SiStripBaseCondObjDQM::selectModules] PLEASE CHECK : no correct (name) subdetector to be excluded in your cfg"
00241        << std::endl; 
00242       }
00243 
00244       std::vector<uint32_t>::iterator iterBegin_=std::lower_bound(detIds_.begin(),
00245                                                                   detIds_.end(),
00246                                                                   *min_element(tmp.begin(), tmp.end()));
00247                                                                   
00248       std::vector<uint32_t>::iterator iterEnd_=std::lower_bound(detIds_.begin(),
00249                                                                 detIds_.end(),
00250                                                                 *max_element(tmp.begin(), tmp.end()));
00251                                                                 
00252       for(std::vector<uint32_t>::iterator detIter_ = iterEnd_;
00253                                          detIter_!= iterBegin_-1;detIter_--){
00254           detIds_.erase(detIter_);
00255       } 
00256 
00257     } // loop SubDetectorsToBeExcluded_
00258   }
00259 
00260   
00261   // -----
00262   // *** fill only one Module per layer ***
00263 
00264   if(fPSet_.getParameter<std::string>("ModulesToBeFilled") == "onlyOneModulePerLayer"){
00265    
00266     std::vector<uint32_t> tmp;
00267     std::vector<uint32_t> layerDetIds;
00268 
00269     SiStripSubStructure substructure_;
00270     
00271     for(unsigned int i=1; i<5 ; i++){
00272       tmp.clear();
00273       substructure_.getTIBDetectors(detIds_, tmp, i,0,0,0);
00274       if(tmp.size() !=0) { layerDetIds.push_back(*(tmp.begin()));}
00275     }
00276     for(unsigned int i=1; i<7 ; i++){
00277       tmp.clear();
00278       substructure_.getTOBDetectors(detIds_, tmp, i,0,0);
00279       if(tmp.size() !=0) { layerDetIds.push_back(*(tmp.begin()));}
00280     }
00281     for(unsigned int i=1; i<4 ; i++){
00282       tmp.clear();
00283       substructure_.getTIDDetectors(detIds_, tmp, 1,i,0,0);
00284       if(tmp.size() !=0) { layerDetIds.push_back(*(tmp.begin()));}
00285       substructure_.getTIDDetectors(detIds_, tmp, 2,i,0,0);
00286       if(tmp.size() !=0) { layerDetIds.push_back(*(tmp.begin()));}
00287     }  
00288     for(unsigned int i=1; i<10 ; i++){
00289       tmp.clear();
00290       substructure_.getTECDetectors(detIds_, tmp, 1,i,0,0,0,0);
00291       if(tmp.size() !=0) { layerDetIds.push_back(*(tmp.begin()));}
00292       substructure_.getTECDetectors(detIds_, tmp, 2,i,0,0,0,0);
00293       if(tmp.size() !=0) { layerDetIds.push_back(*(tmp.begin()));}
00294     }
00295     
00296     detIds_.clear();
00297     detIds_=layerDetIds;
00298 
00299   }
00300   // -----
00301 
00302    
00303 } //selectModules
00304 // -----
00305 
00306 
00307 //=================================================
00308 // -----
00309 void SiStripBaseCondObjDQM::getModMEs(ModMEs& CondObj_ME, const uint32_t& detId_){
00310   
00311   std::map< uint32_t, ModMEs >::const_iterator ModMEsMap_iter = ModMEsMap_.find(detId_);
00312 
00313   if (ModMEsMap_iter != ModMEsMap_.end()){ 
00314   
00315     CondObj_ME=ModMEsMap_iter->second;
00316   
00317     if( ( CondObj_fillId_ =="ProfileAndCumul" || CondObj_fillId_ =="onlyProfile") && CondObj_ME.ProfileDistr ) { 
00318       CondObj_ME.ProfileDistr ->Reset();    
00319     }
00320        
00321     if( (CondObj_fillId_ =="ProfileAndCumul" || CondObj_fillId_ =="onlyCumul" ) &&  CondObj_ME.CumulDistr ){
00322       CondObj_ME.CumulDistr ->Reset();
00323     }
00324     else {
00325       edm::LogWarning("SiStripBaseCondObjDQM") 
00326         << "[SiStripBaseCondObjDQM::getModMEs] PLEASE CHECK : CondObj_fillId option mispelled";
00327     }
00328     return; 
00329 
00330   }
00331   
00332   // --> profile defined for all CondData
00333   if ( (CondObj_fillId_ =="ProfileAndCumul" || CondObj_fillId_ =="onlyProfile")) {
00334     bookProfileMEs(CondObj_ME,detId_);
00335   }  
00336   
00337   // --> cumul currently only defined for noise and apvgain
00338   if( (CondObj_fillId_ =="ProfileAndCumul" || CondObj_fillId_ =="onlyCumul" )
00339       &&(CondObj_name_ == "noise" || CondObj_name_ == "apvgain")          ) bookCumulMEs(CondObj_ME,detId_);
00340   
00341  
00342   ModMEsMap_.insert( std::make_pair(detId_,CondObj_ME) );
00343   
00344 }
00345 // ---- 
00346 
00347 //===============================================
00348 // -----
00349 //%FIXME: very long method, factorize
00350 void SiStripBaseCondObjDQM::getSummaryMEs(ModMEs& CondObj_ME, const uint32_t& detId_){
00351 
00352   std::map<uint32_t, ModMEs>::const_iterator SummaryMEsMap_iter;
00353 
00354   if(CondObj_name_ == "lorentzangle" && SummaryOnStringLevel_On_ ){
00355     SummaryMEsMap_iter = SummaryMEsMap_.find(getStringNameAndId(detId_).second);
00356   }
00357   else {
00358     SummaryMEsMap_iter = SummaryMEsMap_.find(getLayerNameAndId(detId_).second);
00359   }
00360    
00361   if (SummaryMEsMap_iter != SummaryMEsMap_.end()){ return;}
00362 
00363   //FIXME t's not good that the base class has to know about which derived class shoudl exist.
00364   // please modify this part. implement virtual functions, esplicited in the derived classes
00365   // --> currently only profile summary defined for all condition objects except quality
00366   if(  (CondObj_fillId_ =="ProfileAndCumul" || CondObj_fillId_ =="onlyProfile" ) &&
00367      (
00368       CondObj_name_ == "pedestal"     || 
00369       CondObj_name_ == "noise"         || 
00370       CondObj_name_ == "lowthreshold"  || 
00371       CondObj_name_ == "highthreshold" || 
00372       CondObj_name_ == "apvgain"       || 
00373       CondObj_name_ == "lorentzangle") ) {
00374     if(hPSet_.getParameter<bool>("FillSummaryProfileAtLayerLevel"))     
00375       if (!CondObj_ME.SummaryOfProfileDistr) { bookSummaryProfileMEs(CondObj_ME,detId_); }
00376   }    
00377     
00378   // --> currently only genuine cumul LA
00379   if(   (CondObj_fillId_ =="ProfileAndCumul" || CondObj_fillId_ =="onlyCumul" ) &&
00380         (
00381          CondObj_name_ == "lorentzangle" ||  
00382          CondObj_name_ == "noise")  ) {
00383     if(hPSet_.getParameter<bool>("FillCumulativeSummaryAtLayerLevel"))
00384       if (!CondObj_ME.SummaryOfCumulDistr) { bookSummaryCumulMEs(CondObj_ME,detId_); } 
00385   } 
00386                           
00387   // --> currently only summary as a function of detId for noise, pedestal and apvgain 
00388   if(      CondObj_name_ == "noise"         ||
00389            CondObj_name_ == "lowthreshold"  || 
00390            CondObj_name_ == "highthreshold" || 
00391            CondObj_name_ == "apvgain"       || 
00392            CondObj_name_ == "pedestal"      || 
00393            CondObj_name_ == "quality"           ) {
00394     if(hPSet_.getParameter<bool>("FillSummaryAtLayerLevel"))          
00395       if (!CondObj_ME.SummaryDistr) { bookSummaryMEs(CondObj_ME,detId_); } 
00396     
00397   } 
00398                           
00399   if(CondObj_name_ == "lorentzangle" && SummaryOnStringLevel_On_) {
00400     //FIXME getStringNameandId takes time. not need to call it every timne. put the call at the beginning of the method and caache the string 
00401     SummaryMEsMap_.insert( std::make_pair(getStringNameAndId(detId_).second,CondObj_ME) );
00402   }
00403   else {
00404     SummaryMEsMap_.insert( std::make_pair(getLayerNameAndId(detId_).second,CondObj_ME) );
00405   }
00406 
00407 }
00408 // ---- 
00409 
00410 //====================================================
00411 // -----
00412 void SiStripBaseCondObjDQM::bookProfileMEs(SiStripBaseCondObjDQM::ModMEs& CondObj_ME, const uint32_t& detId_){
00413      
00414   int   hProfile_NchX  = 0;
00415   double hProfile_LowX  = 0;
00416   double hProfile_HighX = 0;
00417   
00418   std::string hProfile_description;
00419   hProfile_description   = hPSet_.getParameter<std::string>("Profile_description");
00420       
00421   std::string hProfile_xTitle, hProfile_yTitle;
00422   hProfile_xTitle          = hPSet_.getParameter<std::string>("Profile_xTitle");
00423   hProfile_yTitle          = hPSet_.getParameter<std::string>("Profile_yTitle");
00424             
00425   if( CondObj_name_!= "apvgain" ){
00426     
00427     int nStrip      = reader->getNumberOfApvsAndStripLength(detId_).first*128;
00428         
00429     hProfile_NchX           = nStrip;
00430     hProfile_LowX           = 0.5;
00431     hProfile_HighX          = nStrip+0.5;
00432   }
00433   else {
00434         
00435     int nApv      = reader->getNumberOfApvsAndStripLength(detId_).first;
00436         
00437     hProfile_NchX           = nApv;
00438     hProfile_LowX           = 0.5;
00439     hProfile_HighX          = nApv+0.5;
00440   }
00441       
00442   folder_organizer.setDetectorFolder(detId_); 
00443       
00444   std::string hProfile_Name; 
00445   hProfile_Name = hidmanager.createHistoId(hProfile_description, "det", detId_);
00446       
00447   std::string hProfile;
00448   hProfile = hProfile_Name ;
00449     
00450   CondObj_ME.ProfileDistr = dqmStore_->book1D(hProfile_Name, hProfile, hProfile_NchX, hProfile_LowX, hProfile_HighX);
00451   CondObj_ME.ProfileDistr->setAxisTitle(hProfile_xTitle,1);
00452   CondObj_ME.ProfileDistr->setAxisTitle(hProfile_yTitle,2);
00453   dqmStore_->tag(CondObj_ME.ProfileDistr, detId_);
00454   
00455 }
00456 // -----
00457 
00458 
00459 //=============================================      
00460 // -----
00461 void SiStripBaseCondObjDQM::bookCumulMEs(SiStripBaseCondObjDQM::ModMEs& CondObj_ME, const uint32_t& detId_){
00462 
00463   int    hCumul_NchX    = 0;
00464   double hCumul_LowX    = 0;
00465   double hCumul_HighX   = 0;
00466      
00467   std::string hCumul_description;
00468   hCumul_description   = hPSet_.getParameter<std::string>("Cumul_description");
00469       
00470   std::string hCumul_xTitle, hCumul_yTitle;
00471   hCumul_xTitle        = hPSet_.getParameter<std::string>("Cumul_xTitle");
00472   hCumul_yTitle        = hPSet_.getParameter<std::string>("Cumul_yTitle");
00473       
00474   hCumul_NchX          = hPSet_.getParameter<int>("Cumul_NchX");
00475   hCumul_LowX          = hPSet_.getParameter<double>("Cumul_LowX");
00476   hCumul_HighX         = hPSet_.getParameter<double>("Cumul_HighX");
00477       
00478   folder_organizer.setDetectorFolder(detId_); 
00479       
00480   std::string hCumul_name; 
00481   hCumul_name   = hidmanager.createHistoId(hCumul_description  , "det", detId_); ;
00482       
00483   std::string hCumul_title;
00484   hCumul_title   = hCumul_name ;
00485       
00486   CondObj_ME.CumulDistr = dqmStore_->book1D(hCumul_name, 
00487                                             hCumul_title, 
00488                                             hCumul_NchX, 
00489                                             hCumul_LowX, 
00490                                             hCumul_HighX);
00491   CondObj_ME.CumulDistr->setAxisTitle(hCumul_xTitle,1);
00492   CondObj_ME.CumulDistr->setAxisTitle(hCumul_yTitle,2);
00493   dqmStore_->tag(CondObj_ME.CumulDistr, detId_);
00494       
00495 } 
00496 // ---- 
00497 
00498 
00499 //===========================================
00500 // -----
00501 //#FIXME: same comments: factorize, and remove any reference to derived classes
00502 void SiStripBaseCondObjDQM::bookSummaryProfileMEs(SiStripBaseCondObjDQM::ModMEs& CondObj_ME, const uint32_t& detId_){
00503   
00504   std::vector<uint32_t> sameLayerDetIds_;
00505 
00506   int   hSummaryOfProfile_NchX    = 0;
00507   double hSummaryOfProfile_LowX    = 0;
00508   double hSummaryOfProfile_HighX   = 0;
00509      
00510   std::string hSummaryOfProfile_description;
00511   hSummaryOfProfile_description  = hPSet_.getParameter<std::string>("SummaryOfProfile_description");
00512       
00513   std::string hSummaryOfProfile_xTitle, hSummaryOfProfile_yTitle;
00514   hSummaryOfProfile_xTitle        = hPSet_.getParameter<std::string>("SummaryOfProfile_xTitle");
00515   hSummaryOfProfile_yTitle        = hPSet_.getParameter<std::string>("SummaryOfProfile_yTitle");
00516   
00517   int hSummaryOfProfile_NchY;
00518   double hSummaryOfProfile_LowY, hSummaryOfProfile_HighY;
00519   hSummaryOfProfile_NchY          = hPSet_.getParameter<int>("SummaryOfProfile_NchY");
00520   hSummaryOfProfile_LowY          = hPSet_.getParameter<double>("SummaryOfProfile_LowY");
00521   hSummaryOfProfile_HighY         = hPSet_.getParameter<double>("SummaryOfProfile_HighY");
00522   
00523   int nStrip, nApv, layerId_;    
00524   
00525   if(CondObj_name_ == "lorentzangle" && SummaryOnStringLevel_On_) { layerId_= getStringNameAndId(detId_).second;}
00526   else                                                          { layerId_= getLayerNameAndId(detId_).second;}
00527 
00528 
00529   if( CondObj_name_ == "pedestal" || CondObj_name_ == "noise"|| CondObj_name_ == "lowthreshold" || CondObj_name_ == "highthreshold" ){ // plot in strip number
00530     
00531     if( (layerId_ > 610 && layerId_ < 620) || // TID & TEC have 768 strips at maximum
00532         (layerId_ > 620 && layerId_ < 630) ||
00533         (layerId_ > 410 && layerId_ < 414) ||
00534         (layerId_ > 420 && layerId_ < 424) ){ nStrip =768;} 
00535     else { nStrip      = reader->getNumberOfApvsAndStripLength(detId_).first*128;}
00536     
00537     hSummaryOfProfile_NchX           = nStrip;
00538     hSummaryOfProfile_LowX           = 0.5;
00539     hSummaryOfProfile_HighX          = nStrip+0.5;
00540   
00541   }  
00542   else if( (CondObj_name_ == "lorentzangle" && SummaryOnLayerLevel_On_) || CondObj_name_ == "quality"){ // plot in detId-number
00543 
00544     // -----
00545     // get detIds belonging to same layer to fill X-axis with detId-number
00546                                            
00547     uint32_t subDetId_ =  ((detId_>>25)&0x7);
00548     SiStripSubStructure substructure_;
00549   
00550     sameLayerDetIds_.clear();
00551   
00552     if(subDetId_==3){  //  TIB
00553       substructure_.getTIBDetectors(activeDetIds, sameLayerDetIds_,TIBDetId(detId_).layerNumber(),0,0,TIBDetId(detId_).stringNumber());  
00554     }
00555     else if(subDetId_==4){  // TID
00556       substructure_.getTIDDetectors(activeDetIds, sameLayerDetIds_,0,0,0,0);
00557     }
00558     else if(subDetId_==5){  // TOB
00559       substructure_.getTOBDetectors(activeDetIds, sameLayerDetIds_, TOBDetId(detId_).layerNumber(),0,0);
00560     }
00561     else if(subDetId_==6){  // TEC
00562       substructure_.getTECDetectors(activeDetIds, sameLayerDetIds_, 0,0,0,0,0,0);
00563     }
00564 
00565     hSummaryOfProfile_NchX           = sameLayerDetIds_.size(); 
00566     hSummaryOfProfile_LowX           = 0.5;
00567     hSummaryOfProfile_HighX          = sameLayerDetIds_.size()+0.5;
00568  
00569   } 
00570   else if( CondObj_name_ == "lorentzangle" && SummaryOnStringLevel_On_){ // plot in detId-number
00571 
00572     // -----
00573     // get detIds belonging to same string to fill X-axis with detId-number
00574                                            
00575     uint32_t subDetId_ =  ((detId_>>25)&0x7);
00576     SiStripSubStructure substructure_;
00577     
00578     sameLayerDetIds_.clear(); 
00579     
00580     if(subDetId_==3){  //  TIB    
00581       if(TIBDetId(detId_).isInternalString()){
00582         substructure_.getTIBDetectors(activeDetIds, sameLayerDetIds_, TIBDetId(detId_).layerNumber(),0,1,TIBDetId(detId_).stringNumber()); }
00583       else if(TIBDetId(detId_).isExternalString()){
00584         substructure_.getTIBDetectors(activeDetIds, sameLayerDetIds_, TIBDetId(detId_).layerNumber(),0,2,TIBDetId(detId_).stringNumber()); }
00585     }
00586     else if(subDetId_==4){  // TID
00587       substructure_.getTIDDetectors(activeDetIds, sameLayerDetIds_, 0,0,0,0);
00588     }
00589     else if(subDetId_==5){  // TOB
00590       substructure_.getTOBDetectors(activeDetIds, sameLayerDetIds_, TOBDetId(detId_).layerNumber(),0,TOBDetId(detId_).rodNumber());
00591     }
00592     else if(subDetId_==6){  // TEC
00593       substructure_.getTECDetectors(activeDetIds, sameLayerDetIds_, 0,0,0,0,0,0);
00594     }
00595 
00596 
00597     hSummaryOfProfile_NchX           = sameLayerDetIds_.size(); 
00598     hSummaryOfProfile_LowX           = 0.5;
00599     hSummaryOfProfile_HighX          = sameLayerDetIds_.size()+0.5;
00600  
00601   } 
00602   else if( CondObj_name_ == "apvgain"){
00603  
00604     if( (layerId_ > 610 && layerId_ < 620) || // TID & TEC have 6 apvs at maximum
00605         (layerId_ > 620 && layerId_ < 630) ||
00606         (layerId_ > 410 && layerId_ < 414) ||
00607         (layerId_ > 420 && layerId_ < 424) ){ nApv =6;} 
00608     else { nApv     = reader->getNumberOfApvsAndStripLength(detId_).first;}
00609     
00610     hSummaryOfProfile_NchX           = nApv;
00611     hSummaryOfProfile_LowX           = 0.5;
00612     hSummaryOfProfile_HighX          = nApv+0.5;
00613  
00614   }
00615   else {
00616     edm::LogWarning("SiStripBaseCondObjDQM") 
00617        << "[SiStripBaseCondObjDQM::bookSummaryProfileMEs] PLEASE CHECK : x-axis label in your cfg"
00618        << std::endl; 
00619   }
00620   
00621   uint32_t layer_=0;
00622       
00623   layer_ = folder_organizer.GetSubDetAndLayer(detId_).second;
00624       
00625   folder_organizer.setLayerFolder(detId_,layer_); 
00626       
00627   std::string hSummaryOfProfile_name; 
00628   
00629   // ---
00630   int subdetectorId_ = ((detId_>>25)&0x7);
00631   
00632  
00633   if( subdetectorId_<3 ||subdetectorId_>6 ){ 
00634     edm::LogError("SiStripBaseCondObjDQM")
00635        << "[SiStripBaseCondObjDQM::bookSummaryProfileMEs] WRONG INPUT : no such subdetector type : "
00636        << subdetectorId_ << " no folder set!" 
00637        << std::endl;
00638     return;
00639   }
00640   // ---
00641   
00642   if(CondObj_name_ == "lorentzangle" && SummaryOnStringLevel_On_) { 
00643     hSummaryOfProfile_name = hidmanager.createHistoLayer(hSummaryOfProfile_description, "layer" , getStringNameAndId(detId_).first,"") ;
00644   }
00645   else {
00646     hSummaryOfProfile_name = hidmanager.createHistoLayer(hSummaryOfProfile_description, "layer" , getLayerNameAndId(detId_).first,"") ;
00647   }
00648       
00649   std::string hSummaryOfProfile_title;
00650   hSummaryOfProfile_title   = hSummaryOfProfile_name ;
00651            
00652   CondObj_ME.SummaryOfProfileDistr = dqmStore_->bookProfile(hSummaryOfProfile_name, 
00653                                                             hSummaryOfProfile_title, 
00654                                                             hSummaryOfProfile_NchX, 
00655                                                             hSummaryOfProfile_LowX, 
00656                                                             hSummaryOfProfile_HighX, 
00657                                                             hSummaryOfProfile_NchY, 
00658                                                             0., 
00659                                                             0.);
00660   //                                                        hSummaryOfProfile_LowY, 
00661   //                                                        hSummaryOfProfile_HighY);
00662   CondObj_ME.SummaryOfProfileDistr->setAxisTitle(hSummaryOfProfile_xTitle,1);
00663   CondObj_ME.SummaryOfProfileDistr->setAxisTitle(hSummaryOfProfile_yTitle,2);
00664   CondObj_ME.SummaryOfProfileDistr->setAxisRange(hSummaryOfProfile_LowY, hSummaryOfProfile_HighY,2);
00665  
00666   // -----
00667   // in order to get the right detId-number labelled in right bin of x-axis
00668   
00669   if( CondObj_name_ == "quality" ){
00670     
00671     unsigned int iBin=0;
00672     
00673     for(unsigned int i=0;i< sameLayerDetIds_.size(); i++){
00674     
00675       iBin++;
00676       char sameLayerDetIds_Name[1024];
00677       sprintf(sameLayerDetIds_Name,"%u",sameLayerDetIds_[i]);
00678       CondObj_ME.SummaryOfProfileDistr->setBinLabel(iBin, sameLayerDetIds_Name);
00679     
00680     }
00681   } 
00682   if( CondObj_name_ == "lorentzangle"){
00683 
00684     // Put the detIds for the -z side as following the geometrical order:
00685       reverse(sameLayerDetIds_.begin(), sameLayerDetIds_.begin()+sameLayerDetIds_.size()/2);
00686 
00687       unsigned int iBin=0;
00688        for(unsigned int i=0;i< sameLayerDetIds_.size(); i++){ 
00689          iBin++;
00690          if (!SummaryOnStringLevel_On_){
00691            // remove the label for detIds:
00692              CondObj_ME.SummaryOfProfileDistr->setBinLabel(iBin, "");
00693          }  
00694      
00695          if (SummaryOnStringLevel_On_){
00696       // Label with module position instead of detIds:
00697            char sameLayerDetIds_Name[1024];
00698            if(subdetectorId_==3){//re-abelling for TIB
00699              if(TIBDetId(sameLayerDetIds_[i]).isZPlusSide()){
00700                sprintf(sameLayerDetIds_Name,"%i",TIBDetId(sameLayerDetIds_[i]).module());}
00701              else if(TIBDetId(sameLayerDetIds_[i]).isZMinusSide()){
00702                sprintf(sameLayerDetIds_Name,"%i",-TIBDetId(sameLayerDetIds_[i]).module());}
00703              CondObj_ME.SummaryOfProfileDistr->setBinLabel(iBin, sameLayerDetIds_Name);
00704            }
00705            else if(subdetectorId_==5){//re-abelling for TOB
00706              if(TOBDetId(sameLayerDetIds_[i]).isZPlusSide())      { sprintf(sameLayerDetIds_Name,"%i",TOBDetId(sameLayerDetIds_[i]).module());}
00707              else if(TOBDetId(sameLayerDetIds_[i]).isZMinusSide()) { sprintf(sameLayerDetIds_Name,"%i",-TOBDetId(sameLayerDetIds_[i]).module());}
00708              CondObj_ME.SummaryOfProfileDistr->setBinLabel(iBin, sameLayerDetIds_Name);
00709            }
00710          }
00711        } 
00712  
00713        
00714 
00715 
00716   // -----
00717       
00718   dqmStore_->tag(CondObj_ME.SummaryOfProfileDistr, layer_);
00719       
00720   } // if "lorentzangle"
00721 
00722 }
00723 // ---- 
00724 
00725 
00726 //=============================================================
00727 // -----
00728 void SiStripBaseCondObjDQM::bookSummaryCumulMEs(SiStripBaseCondObjDQM::ModMEs& CondObj_ME, const uint32_t& detId_){
00729     
00730   int   hSummaryOfCumul_NchX    = 0;
00731   double hSummaryOfCumul_LowX    = 0;
00732   double hSummaryOfCumul_HighX   = 0;
00733         
00734   std::string hSummaryOfCumul_description;
00735   hSummaryOfCumul_description  = hPSet_.getParameter<std::string>("SummaryOfCumul_description");
00736         
00737   std::string hSummaryOfCumul_xTitle, hSummaryOfCumul_yTitle;
00738   hSummaryOfCumul_xTitle        = hPSet_.getParameter<std::string>("SummaryOfCumul_xTitle");
00739   hSummaryOfCumul_yTitle        = hPSet_.getParameter<std::string>("SummaryOfCumul_yTitle");
00740         
00741   hSummaryOfCumul_NchX          = hPSet_.getParameter<int>("SummaryOfCumul_NchX");
00742   hSummaryOfCumul_LowX          = hPSet_.getParameter<double>("SummaryOfCumul_LowX");
00743   hSummaryOfCumul_HighX         = hPSet_.getParameter<double>("SummaryOfCumul_HighX");
00744         
00745   uint32_t layer_=0;
00746         
00747   layer_ = folder_organizer.GetSubDetAndLayer(detId_).second;
00748         
00749   folder_organizer.setLayerFolder(detId_,layer_); 
00750         
00751   std::string hSummaryOfCumul_name; 
00752   
00753   // ---
00754   int subdetectorId_ = ((detId_>>25)&0x7);
00755   
00756   if( subdetectorId_<3 || subdetectorId_>6 ){ 
00757     edm::LogError("SiStripBaseCondObjDQM")
00758        << "[SiStripBaseCondObjDQM::bookSummaryCumulMEs] WRONG INPUT : no such subdetector type : "
00759        << subdetectorId_ << " no folder set!" 
00760        << std::endl;
00761     return;
00762   }
00763   // ---
00764   
00765   // LA Histos are plotted for each string:
00766   if(CondObj_name_ == "lorentzangle" && SummaryOnStringLevel_On_) { 
00767     hSummaryOfCumul_name = hidmanager.createHistoLayer(hSummaryOfCumul_description, "layer" , getStringNameAndId(detId_).first, "") ;
00768   }
00769   else {  
00770     hSummaryOfCumul_name = hidmanager.createHistoLayer(hSummaryOfCumul_description, "layer" , getLayerNameAndId(detId_).first, "") ;
00771   }
00772 
00773         
00774   std::string hSummaryOfCumul_title;
00775   hSummaryOfCumul_title   = hSummaryOfCumul_name ;
00776         
00777   CondObj_ME.SummaryOfCumulDistr = dqmStore_->book1D(hSummaryOfCumul_name, 
00778                                                      hSummaryOfCumul_title, 
00779                                                      hSummaryOfCumul_NchX, 
00780                                                      hSummaryOfCumul_LowX, 
00781                                                      hSummaryOfCumul_HighX);
00782 
00783   CondObj_ME.SummaryOfCumulDistr->setAxisTitle(hSummaryOfCumul_xTitle,1);
00784   CondObj_ME.SummaryOfCumulDistr->setAxisTitle(hSummaryOfCumul_yTitle,2);
00785         
00786   dqmStore_->tag(CondObj_ME.SummaryOfCumulDistr, layer_);
00787         
00788 }
00789 // -----
00790 
00791 //================================================
00792 // -----
00793 //FIXME same as before: factorize
00794 void SiStripBaseCondObjDQM::bookSummaryMEs(SiStripBaseCondObjDQM::ModMEs& CondObj_ME, const uint32_t& detId_){
00795   
00796   std::vector<uint32_t> sameLayerDetIds_;
00797 
00798   int   hSummary_NchX    = 0;
00799   double hSummary_LowX    = 0;
00800   double hSummary_HighX   = 0;
00801      
00802   std::string hSummary_description;
00803   hSummary_description  = hPSet_.getParameter<std::string>("Summary_description");
00804       
00805   std::string hSummary_xTitle, hSummary_yTitle;
00806   hSummary_xTitle        = hPSet_.getParameter<std::string>("Summary_xTitle");
00807   hSummary_yTitle        = hPSet_.getParameter<std::string>("Summary_yTitle");
00808   
00809   int hSummary_NchY;
00810   double hSummary_LowY, hSummary_HighY;
00811   hSummary_NchY          = hPSet_.getParameter<int>("Summary_NchY");
00812   hSummary_LowY          = hPSet_.getParameter<double>("Summary_LowY");
00813   hSummary_HighY         = hPSet_.getParameter<double>("Summary_HighY");
00814        
00815 
00816   // -----
00817   // get detIds belonging to same layer to fill X-axis with detId-number
00818                                            
00819   
00820   sameLayerDetIds_.clear();
00821    
00822   sameLayerDetIds_=GetSameLayerDetId(activeDetIds,detId_);
00823 
00824   hSummary_NchX           = sameLayerDetIds_.size(); 
00825   hSummary_LowX           = 0.5;
00826   hSummary_HighX          = sameLayerDetIds_.size()+0.5;
00827   
00828   uint32_t layer_=0;
00829       
00830   layer_ = folder_organizer.GetSubDetAndLayer(detId_).second;
00831       
00832   folder_organizer.setLayerFolder(detId_,layer_); 
00833       
00834   std::string hSummary_name; 
00835   
00836   // ---
00837   int subdetectorId_ = ((detId_>>25)&0x7);
00838   
00839  
00840   if( subdetectorId_<3 ||subdetectorId_>6 ){ 
00841     edm::LogError("SiStripBaseCondObjDQM")
00842        << "[SiStripBaseCondObjDQM::bookSummaryMEs] WRONG INPUT : no such subdetector type : "
00843        << subdetectorId_ << " no folder set!" 
00844        << std::endl;
00845     return;
00846   }
00847   // ---
00848   
00849   hSummary_name = hidmanager.createHistoLayer(hSummary_description, 
00850                                                        "layer" , 
00851                                                         getLayerNameAndId(detId_).first,
00852                                                         "") ;
00853       
00854   std::string hSummary_title;
00855   hSummary_title   = hSummary_name ;
00856            
00857   CondObj_ME.SummaryDistr = dqmStore_->bookProfile(hSummary_name, 
00858                                                    hSummary_title, 
00859                                                    hSummary_NchX, 
00860                                                    hSummary_LowX, 
00861                                                    hSummary_HighX, 
00862                                                    hSummary_NchY, 
00863                                                    0., 
00864                                                    0.);
00865   //                                               hSummary_LowY, 
00866   //                                               hSummary_HighY);
00867   CondObj_ME.SummaryDistr->setAxisTitle(hSummary_xTitle,1);
00868   CondObj_ME.SummaryDistr->setAxisTitle(hSummary_yTitle,2);
00869   CondObj_ME.SummaryDistr->setAxisRange(hSummary_LowY, hSummary_HighY,2);
00870  
00871   // -----
00872   // in order to get the right detId-number labelled in right bin of x-axis
00873   unsigned int iBin=0;
00874     
00875   for(unsigned int i=0;i< sameLayerDetIds_.size(); i++){
00876     
00877     iBin++;
00878     char sameLayerDetIds_Name[1024];
00879     sprintf(sameLayerDetIds_Name,"%u",sameLayerDetIds_[i]);
00880     if(iBin%100==0)
00881       CondObj_ME.SummaryDistr->setBinLabel(iBin, sameLayerDetIds_Name);
00882     
00883   }
00884   // -----
00885       
00886   dqmStore_->tag(CondObj_ME.SummaryDistr, layer_);
00887       
00888 } 
00889 
00890 
00891 //==========================================================
00892 // -----
00893 std::pair<std::string,uint32_t> SiStripBaseCondObjDQM::getLayerNameAndId(const uint32_t& detId_){
00894 
00895   int subdetectorId_ = ((detId_>>25)&0x7);
00896   int layerId_=0;
00897 
00898   std::stringstream layerName;
00899   
00900   if( subdetectorId_ == 3 ){ //TIB
00901 
00902     for( unsigned int i = 1; i < 5; i++ ){
00903       if( TIBDetId( detId_ ).layer() ==i ){ 
00904         layerName << "TIB__layer__" << i;
00905         layerId_ = 300 + i;
00906       }
00907     }
00908     
00909   }
00910 
00911   else if( subdetectorId_ == 4 ){ //TIDD
00912     
00913     if( TIDDetId( detId_ ).side() == 1 ) { // TIDD side 1
00914       
00915       for( unsigned int i = 1; i < 4; i++ ){
00916         if(TIDDetId(detId_).wheel()==i){ 
00917           layerName << "TID__side__1__wheel__" << i;
00918           layerId_ = 410 + i;
00919         }
00920       }
00921       
00922     }
00923 
00924     else if( TIDDetId( detId_ ).side() == 2 ) { // TIDD side 2
00925       
00926       for( unsigned int i = 1; i < 4; i++ ) {
00927         if(TIDDetId(detId_).wheel()==i){ 
00928           layerName << "TID__side__2__wheel__" << i;
00929           layerId_ = 420 + i;
00930         }
00931       }
00932 
00933     }
00934 
00935   }
00936 
00937 
00938   else if( subdetectorId_ == 5 ){ // TOB
00939     
00940     for( unsigned int i = 1; i < 7; i++ ) {
00941       if( TOBDetId( detId_ ).layer() == i ) { 
00942         layerName << "TOB__layer__" << i;
00943         layerId_ = 500 + i;
00944       }
00945     }
00946     
00947   }
00948 
00949   else if( subdetectorId_ == 6 ){ // TEC
00950     
00951     if( TECDetId( detId_ ).side() == 1) { // TEC side 1
00952       
00953       for( unsigned int i = 1; i < 10; i++ ) {
00954         if( TECDetId( detId_ ).wheel() == i ) { 
00955           layerName << "TEC__side__1__wheel__" << i;
00956           layerId_ = 610 + i;
00957         }
00958       }
00959 
00960     }
00961 
00962     else if( TECDetId( detId_ ).side() == 2 ) { // TEC side 2
00963       
00964       for( unsigned int i = 1; i < 10; i++ ) {
00965         if( TECDetId( detId_ ).wheel() == i ) { 
00966           layerName << "TEC__side__2__wheel__" << i;
00967           layerId_ = 620 + i;
00968         }
00969       }
00970 
00971      }
00972   }
00973   
00974   return std::make_pair( layerName.str(), layerId_ );
00975 
00976 }
00977 
00978 //=================================================
00979 //---------------
00980 
00981 
00982 std::pair<std::string,uint32_t> SiStripBaseCondObjDQM::getStringNameAndId(const uint32_t& detId_){
00983 
00984   int subdetectorId_ = ((detId_>>25)&0x7);
00985   int layerStringId_=0;
00986   
00987   std::stringstream layerStringName;
00988   
00989   if( subdetectorId_==3 ){ //TIB
00990     if(TIBDetId(detId_).layer()==1 && TIBDetId(detId_).isInternalString()){ //1st layer int
00991       for( unsigned int i=1; i < 27 ;i++){
00992         if(TIBDetId(detId_).stringNumber()==i){  
00993           layerStringName << "TIB_L1_Int_Str_" << i;
00994           layerStringId_ = 30110+i; 
00995         }
00996       }      
00997     }
00998     else  if(TIBDetId(detId_).layer()==1 && TIBDetId(detId_).isExternalString()){ //1st layer ext
00999       for( unsigned int i=1; i < 31 ;i++){
01000         if(TIBDetId(detId_).stringNumber()==i){  
01001           layerStringName << "TIB_L1_Ext_Str_" << i;
01002           layerStringId_ = 301200+i; 
01003         }
01004       }      
01005     }
01006     else if(TIBDetId(detId_).layer()==2 && TIBDetId(detId_).isInternalString()){ //2nd layer int
01007       for( unsigned int i=1; i < 35 ;i++){
01008         if(TIBDetId(detId_).stringNumber()==i){  
01009           layerStringName << "TIB_L2_Int_Str_" << i;
01010           layerStringId_ = 302100+i; 
01011         }
01012       }      
01013     }
01014     else if(TIBDetId(detId_).layer()==2 && TIBDetId(detId_).isExternalString()){ //2nd layer ext
01015       for( unsigned int i=1; i < 39 ;i++){
01016         if(TIBDetId(detId_).stringNumber()==i){  
01017           layerStringName << "TIB_L2_Ext_Str_" << i;
01018           layerStringId_ = 302200+i; 
01019         }
01020       }      
01021     }
01022     else if(TIBDetId(detId_).layer()==3 && TIBDetId(detId_).isInternalString()){ //3rd layer int
01023       for( unsigned int i=1; i < 45 ;i++){
01024         if(TIBDetId(detId_).stringNumber()==i){  
01025           layerStringName << "TIB_L3_Int_Str_" << i;
01026           layerStringId_ = 303100+i; 
01027         }
01028       }      
01029     }
01030     else if(TIBDetId(detId_).layer()==3 && TIBDetId(detId_).isExternalString()){ //3rd layer ext
01031       for( unsigned int i=1; i < 47 ;i++){
01032         if(TIBDetId(detId_).stringNumber()==i){  
01033           layerStringName << "TIB_L3_Ext_Str_" << i;
01034           layerStringId_ = 303200+i; 
01035         }
01036       }      
01037     }
01038     else if(TIBDetId(detId_).layer()==4 && TIBDetId(detId_).isInternalString()){ //4th layer int
01039       for( unsigned int i=1; i < 53 ;i++){
01040         if(TIBDetId(detId_).stringNumber()==i){  
01041           layerStringName << "TIB_L4_Int_Str_" << i;
01042           layerStringId_ = 304100+i; 
01043         }
01044       }      
01045     }
01046     else if(TIBDetId(detId_).layer()==4 && TIBDetId(detId_).isExternalString()){ //4th layer ext
01047       for( unsigned int i=1; i < 57 ;i++){
01048         if(TIBDetId(detId_).stringNumber()==i){  
01049           layerStringName << "TIB_L4_Ext_Str_" << i;
01050           layerStringId_ = 304200+i; 
01051         }
01052       }      
01053     }
01054   } //TIB
01055 
01056 
01057   else if( subdetectorId_==5 ){ // TOB
01058     if(TOBDetId(detId_).layer()==1){ //1st layer
01059       for( unsigned int i=1; i < 43 ;i++){
01060         if(TOBDetId(detId_).rodNumber()==i){  
01061           layerStringName << "TOB_L1_Rod_" << i;
01062           layerStringId_ = 50100+i;
01063         }
01064       }      
01065     }
01066     else if(TOBDetId(detId_).layer()==2){ //2nd layer
01067       for( unsigned int i=1; i < 49 ;i++){
01068         if(TOBDetId(detId_).rodNumber()==i){  
01069           layerStringName << "TOB_L2_Rod_" << i;
01070           layerStringId_ = 50200+i; 
01071         }
01072       }      
01073     }
01074     else if(TOBDetId(detId_).layer()==3){ //3rd layer
01075       for( unsigned int i=1; i < 55 ;i++){
01076         if(TOBDetId(detId_).rodNumber()==i){  
01077           layerStringName << "TOB_L3_Rod_" << i;
01078           layerStringId_ = 50300+i; 
01079         }
01080       }      
01081     }
01082     else if(TOBDetId(detId_).layer()==4){ //4th layer
01083       for( unsigned int i=1; i < 61 ;i++){
01084         if(TOBDetId(detId_).rodNumber()==i){  
01085           layerStringName << "TOB_L4_Rod_" << i;
01086           layerStringId_ = 50400+i; 
01087         }
01088       }      
01089     }
01090     else if(TOBDetId(detId_).layer()==5){ //5th layer
01091       for( unsigned int i=1; i < 67 ;i++){
01092         if(TOBDetId(detId_).rodNumber()==i){  
01093           layerStringName << "TOB_L5_Rod_" << i;
01094           layerStringId_ = 50500+i; 
01095         }
01096       }      
01097     }
01098     else if(TOBDetId(detId_).layer()==6){ //6st layer
01099       for( unsigned int i=1; i < 75 ;i++){
01100         if(TOBDetId(detId_).rodNumber()==i){  
01101           layerStringName << "TOB_L6_Rod_" << i;
01102           layerStringId_ = 50600+i; 
01103         }
01104       }      
01105     }
01106   }//TOB
01107 
01108   return std::make_pair( layerStringName.str(), layerStringId_ );
01109 
01110 }
01111 
01112 
01113 
01114     
01115 //========================
01116 std::vector<uint32_t> SiStripBaseCondObjDQM::GetSameLayerDetId(std::vector<uint32_t> activeDetIds,uint32_t selDetId ){
01117  
01118   std::vector<uint32_t> sameLayerDetIds;
01119   sameLayerDetIds.clear();
01120 
01121   SiStripSubStructure substructure_;
01122   
01123   uint32_t subselDetId_ =  ((selDetId>>25)&0x7);
01124 
01125   if(subselDetId_==3){  //  TIB
01126     substructure_.getTIBDetectors(activeDetIds, sameLayerDetIds, TIBDetId(selDetId).layer(),0,0,0);  
01127   }
01128   else if(subselDetId_==4){  // TID
01129     substructure_.getTIDDetectors(activeDetIds, sameLayerDetIds, TIDDetId(selDetId).side(),TIDDetId(selDetId).wheel(),0,0);
01130   }
01131   else if(subselDetId_==5){  // TOB
01132     substructure_.getTOBDetectors(activeDetIds, sameLayerDetIds, TOBDetId(selDetId).layer(),0,0);
01133   }
01134   else if(subselDetId_==6){  // TEC
01135     substructure_.getTECDetectors(activeDetIds, sameLayerDetIds, TECDetId(selDetId).side(),TECDetId(selDetId).wheel(),0,0,0,0);
01136   }
01137 
01138   return sameLayerDetIds;
01139   
01140 }
01141 
01142 
01143 //==========================
01144 void SiStripBaseCondObjDQM::bookTkMap(const std::string& TkMapname){
01145   tkMap= new TrackerMap(TkMapname.c_str());
01146 }
01147 
01148 //==========================
01149 void SiStripBaseCondObjDQM::fillTkMap(const uint32_t& detid, const float& value){
01150   tkMap->fill(detid,value);
01151 }
01152 
01153 //==========================
01154 void SiStripBaseCondObjDQM::saveTkMap(const std::string& TkMapname, double minValue, double maxValue){
01155   if(tkMapScaler.size()!=0){
01156     //check that saturation is below x%  below minValue and above minValue, and in case re-arrange.
01157     float th=hPSet_.getParameter<double>("saturatedFraction");
01158 
01159     size_t imin=0,imax=0;
01160     float entries=0 ;
01161     for(size_t i=0;i<tkMapScaler.size();++i)
01162       entries+=tkMapScaler[i];
01163 
01164     float min=0 ;
01165     for(size_t i=0;(i<tkMapScaler.size()) && (min<th);++i){
01166       min+=tkMapScaler[i]/entries;
01167       imin=i;
01168     }
01169 
01170     float max=0;
01171     // for(size_t i=tkMapScaler.size()-1;(i>=0) && (max<th);--i){ // Wrong
01172     // Since i is unsigned, i >= 0 is always true,
01173     // and the loop termination condition is never reached.
01174     // We offset the loop index by one to fix this.
01175     for(size_t j=tkMapScaler.size();(j>0) && (max<th);--j){ 
01176       size_t i = j - 1;
01177       max+=tkMapScaler[i]/entries;
01178       imax=i;
01179     }
01180     
01181     //reset maxValue;
01182     if(maxValue<imax){
01183       edm::LogInfo("")<< "Resetting TkMap maxValue from " << maxValue << " to " << imax;
01184       maxValue=imax;
01185     }
01186     //reset minValue;
01187     if(minValue>imin){
01188       edm::LogInfo("")<< "Resetting TkMap minValue from " << minValue << " to " << imin;
01189       minValue=imin;
01190     }
01191   }
01192 
01193   tkMap->save(false, minValue, maxValue, TkMapname.c_str());
01194   tkMap->setPalette(1); tkMap->showPalette(true);
01195 
01196 }
01197 
01198 
01199 //==========================
01200 void SiStripBaseCondObjDQM::end(){
01201   edm::LogInfo("SiStripBaseCondObjDQM") 
01202     << "SiStripBase::end"
01203     << std::endl; 
01204 }
01205 
01206 //==========================
01207 void SiStripBaseCondObjDQM::fillModMEs(const std::vector<uint32_t> & selectedDetIds){
01208   ModMEs CondObj_ME;
01209  
01210   for(std::vector<uint32_t>::const_iterator detIter_=selectedDetIds.begin();
01211                                            detIter_!=selectedDetIds.end();++detIter_){
01212     fillMEsForDet(CondObj_ME,*detIter_);
01213   }
01214 }
01215 
01216 //==========================
01217 void SiStripBaseCondObjDQM::fillSummaryMEs(const std::vector<uint32_t> & selectedDetIds){
01218   
01219   for(std::vector<uint32_t>::const_iterator detIter_ = selectedDetIds.begin();
01220       detIter_!= selectedDetIds.end();detIter_++){
01221     fillMEsForLayer(/*SummaryMEsMap_,*/ *detIter_);    
01222   }
01223 
01224   for (std::map<uint32_t, ModMEs>::iterator iter=SummaryMEsMap_.begin(); iter!=SummaryMEsMap_.end(); iter++){
01225 
01226     ModMEs selME;
01227     selME = iter->second;
01228 
01229     if(hPSet_.getParameter<bool>("FillSummaryProfileAtLayerLevel") && fPSet_.getParameter<bool>("OutputSummaryProfileAtLayerLevelAsImage")){
01230 
01231       if( CondObj_fillId_ =="onlyProfile" || CondObj_fillId_ =="ProfileAndCumul"){
01232 
01233         TCanvas c1("c1");
01234         selME.SummaryOfProfileDistr->getTProfile()->Draw();
01235         std::string name (selME.SummaryOfProfileDistr->getTProfile()->GetTitle());
01236         name+=".png";
01237         c1.Print(name.c_str());
01238       }
01239     }
01240     if(hPSet_.getParameter<bool>("FillSummaryAtLayerLevel") && fPSet_.getParameter<bool>("OutputSummaryAtLayerLevelAsImage")){
01241 
01242       TCanvas c1("c1");
01243       selME.SummaryDistr->getTH1()->Draw();
01244       std::string name (selME.SummaryDistr->getTH1()->GetTitle());
01245       name+=".png";
01246       c1.Print(name.c_str());
01247     }
01248     if(hPSet_.getParameter<bool>("FillCumulativeSummaryAtLayerLevel") && fPSet_.getParameter<bool>("OutputCumulativeSummaryAtLayerLevelAsImage")){
01249 
01250       if( CondObj_fillId_ =="onlyCumul" || CondObj_fillId_ =="ProfileAndCumul"){
01251 
01252         TCanvas c1("c1");
01253         selME.SummaryOfCumulDistr->getTH1()->Draw();
01254         std::string name (selME.SummaryOfCumulDistr->getTH1()->GetTitle());
01255         name+=".png";
01256         c1.Print(name.c_str());
01257       }
01258     }
01259 
01260   }
01261  
01262 }