CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/DQMOffline/CalibTracker/plugins/SiStripQualityHotStripIdentifierRoot.cc

Go to the documentation of this file.
00001 #include "DQMOffline/CalibTracker/plugins/SiStripQualityHotStripIdentifierRoot.h"
00002 
00003 #include "CalibFormats/SiStripObjects/interface/SiStripQuality.h"
00004 
00005 #include "DataFormats/TrackerRecHit2D/interface/SiStripRecHit2D.h"
00006 #include "DataFormats/TrackerRecHit2D/interface/ProjectedSiStripRecHit2D.h"
00007 #include "DataFormats/TrackerRecHit2D/interface/SiStripMatchedRecHit2D.h"
00008 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00009 #include "DataFormats/TrackReco/interface/Track.h"
00010 #include "DataFormats/TrackingRecHit/interface/TrackingRecHit.h"
00011 
00012 #include <iostream>
00013 #include <fstream>
00014 #include <sstream>
00015 
00016 //Insert here the include to the algos
00017 #include "CalibTracker/SiStripQuality/interface/SiStripHotStripAlgorithmFromClusterOccupancy.h"
00018 #include "CalibTracker/SiStripQuality/interface/SiStripBadAPVAlgorithmFromClusterOccupancy.h"
00019 #include "CalibTracker/SiStripQuality/interface/SiStripBadAPVandHotStripAlgorithmFromClusterOccupancy.h"
00020 
00021 
00022 SiStripQualityHotStripIdentifierRoot::SiStripQualityHotStripIdentifierRoot(const edm::ParameterSet& iConfig) : ConditionDBWriter<SiStripBadStrip>(iConfig),
00023   m_cacheID_(0), 
00024   dataLabel_(iConfig.getUntrackedParameter<std::string>("dataLabel","")),
00025   UseInputDB_(iConfig.getUntrackedParameter<bool>("UseInputDB",false)),
00026   conf_(iConfig),
00027   fp_(iConfig.getUntrackedParameter<edm::FileInPath>("file",edm::FileInPath("CalibTracker/SiStripCommon/data/SiStripDetInfo.dat"))),
00028   filename(iConfig.getUntrackedParameter<std::string>("rootFilename","CondDB_TKCC_20X_v3_hlt_50822.root")),
00029   dirpath(iConfig.getUntrackedParameter<std::string>("rootDirPath",""))
00030 {
00031   reader = new SiStripDetInfoFileReader(fp_.fullPath());  
00032   
00033   dqmStore_ = edm::Service<DQMStore>().operator->(); 
00034   dqmStore_->setVerbose(iConfig.getUntrackedParameter<uint32_t>("verbosity",0)); 
00035 
00036   if(filename!=""){
00037     edm::LogInfo("SiStripQualityHotStripIdentifierRoot") << " before opening file " << filename.c_str();  
00038     dqmStore_->open(filename.c_str(), false); 
00039     edm::LogInfo("SiStripQualityHotStripIdentifierRoot") << " after opening file ";  
00040   }
00041 }
00042 
00043 
00044 SiStripQualityHotStripIdentifierRoot::~SiStripQualityHotStripIdentifierRoot(){
00045 }
00046 
00047 SiStripBadStrip* SiStripQualityHotStripIdentifierRoot::getNewObject(){
00048 
00049   edm::LogInfo("SiStripQualityHotStripIdentifierRoot") <<"SiStripQualityHotStripIdentifierRoot::getNewObject called"<<std::endl;
00050 
00051   SiStripBadStrip* obj=new SiStripBadStrip();
00052   
00053   edm::ParameterSet parameters=conf_.getParameter<edm::ParameterSet>("AlgoParameters");
00054   std::string AlgoName = parameters.getParameter<std::string>("AlgoName");
00055 
00056   if (AlgoName=="SiStripHotStripAlgorithmFromClusterOccupancy")
00057     {
00058     
00059       edm::LogInfo("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::getNewObject] call to SiStripHotStripAlgorithmFromClusterOccupancy"<<std::endl;
00060 
00061       theIdentifier= new SiStripHotStripAlgorithmFromClusterOccupancy(conf_);
00062       theIdentifier->setProbabilityThreshold(parameters.getUntrackedParameter<double>("ProbabilityThreshold",1.E-7));
00063       theIdentifier->setMinNumEntries(parameters.getUntrackedParameter<uint32_t>("MinNumEntries",100));
00064       theIdentifier->setMinNumEntriesPerStrip(parameters.getUntrackedParameter<uint32_t>("MinNumEntriesPerStrip",5));
00065       theIdentifier->setOccupancyThreshold(parameters.getUntrackedParameter<double>("OccupancyThreshold",1.E-5));
00066       theIdentifier->setNumberOfEvents(parameters.getUntrackedParameter<uint32_t>("NumberOfEvents",0));
00067       theIdentifier->setOutputFileName(conf_.getUntrackedParameter<std::string>("OccupancyRootFile","Occupancy.root"),conf_.getUntrackedParameter<bool>("WriteOccupancyRootFile",false));
00068       theIdentifier->setTrackerGeometry(_tracker);
00069 
00070       bookHistos();
00071   
00072       SiStripQuality* qobj = new SiStripQuality();
00073       theIdentifier->extractBadStrips(qobj,ClusterPositionHistoMap,SiStripQuality_);//here I insert SiStripQuality as input and get qobj as output
00074     
00075       //----------
00076 
00077       edm::LogInfo("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::getNewObject] copy SiStripObject in SiStripBadStrip"<<std::endl;
00078 
00079       std::stringstream ss;  
00080   
00081       SiStripBadStrip::RegistryIterator rIter=qobj->getRegistryVectorBegin();
00082       SiStripBadStrip::RegistryIterator rIterEnd=qobj->getRegistryVectorEnd();
00083       for(;rIter!=rIterEnd;++rIter){
00084         SiStripBadStrip::Range range(qobj->getDataVectorBegin()+rIter->ibegin,qobj->getDataVectorBegin()+rIter->iend);
00085         if ( ! obj->put(rIter->detid,range) )
00086           edm::LogError("SiStripQualityHotStripIdentifierRoot")<<"[SiStripQualityHotStripIdentifierRoot::getNewObject] detid already exists"<<std::endl;
00087       }
00088       edm::LogInfo("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::getNewObject] " << ss.str() << std::endl;
00089     }
00090   else if (AlgoName=="SiStripBadAPVAlgorithmFromClusterOccupancy")
00091     {
00092 
00093       edm::LogInfo("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::getNewObject] call to SiStripBadAPVAlgorithmFromClusterOccupancy"<<std::endl;
00094 
00095       theIdentifier2 = new SiStripBadAPVAlgorithmFromClusterOccupancy(conf_);
00096       theIdentifier2->setLowOccupancyThreshold(parameters.getUntrackedParameter<double>("LowOccupancyThreshold",5));
00097       theIdentifier2->setHighOccupancyThreshold(parameters.getUntrackedParameter<double>("HighOccupancyThreshold",10));
00098       theIdentifier2->setAbsoluteLowThreshold(parameters.getUntrackedParameter<double>("AbsoluteLowThreshold",0));
00099       theIdentifier2->setNumberIterations(parameters.getUntrackedParameter<uint32_t>("NumberIterations",2));
00100       theIdentifier2->setAbsoluteOccupancyThreshold(parameters.getUntrackedParameter<double>("OccupancyThreshold",1.E-5));
00101       theIdentifier2->setNumberOfEvents(parameters.getUntrackedParameter<uint32_t>("NumberOfEvents",0));
00102       theIdentifier2->setMinNumOfEvents();
00103       theIdentifier2->setOutputFileName(conf_.getUntrackedParameter<std::string>("OccupancyRootFile","Occupancy.root"),conf_.getUntrackedParameter<bool>("WriteOccupancyRootFile",false));
00104       theIdentifier2->setTrackerGeometry(_tracker);
00105 
00106       bookHistos();
00107   
00108       SiStripQuality* qobj = new SiStripQuality();
00109       theIdentifier2->extractBadAPVs(qobj,ClusterPositionHistoMap,SiStripQuality_);
00110     
00111       //----------
00112 
00113       edm::LogInfo("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::getNewObject] copy SiStripObject in SiStripBadStrip"<<std::endl;
00114 
00115       std::stringstream ss;  
00116   
00117       SiStripBadStrip::RegistryIterator rIter=qobj->getRegistryVectorBegin();
00118       SiStripBadStrip::RegistryIterator rIterEnd=qobj->getRegistryVectorEnd();
00119       for(;rIter!=rIterEnd;++rIter){
00120         SiStripBadStrip::Range range(qobj->getDataVectorBegin()+rIter->ibegin,qobj->getDataVectorBegin()+rIter->iend);
00121         if ( ! obj->put(rIter->detid,range) )
00122           edm::LogError("SiStripQualityHotStripIdentifierRoot")<<"[SiStripQualityHotStripIdentifierRoot::getNewObject] detid already exists"<<std::endl;
00123       }
00124       edm::LogInfo("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::getNewObject] " << ss.str() << std::endl;
00125 
00126     
00127     }
00128   else if (AlgoName=="SiStripBadAPVandHotStripAlgorithmFromClusterOccupancy")
00129     {
00130     
00131       edm::LogInfo("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::getNewObject] call to SiStripBadAPVandHotStripAlgorithmFromClusterOccupancy"<<std::endl;
00132 
00133       theIdentifier3= new SiStripBadAPVandHotStripAlgorithmFromClusterOccupancy(conf_);
00134       theIdentifier3->setProbabilityThreshold(parameters.getUntrackedParameter<double>("ProbabilityThreshold",1.E-7));
00135       theIdentifier3->setMinNumEntries(parameters.getUntrackedParameter<uint32_t>("MinNumEntries",100));
00136       theIdentifier3->setMinNumEntriesPerStrip(parameters.getUntrackedParameter<uint32_t>("MinNumEntriesPerStrip",5));
00137       theIdentifier3->setNumberOfEvents(parameters.getUntrackedParameter<uint32_t>("NumberOfEvents",0));
00138       theIdentifier3->setOutputFileName(conf_.getUntrackedParameter<std::string>("OccupancyRootFile","Occupancy.root"),conf_.getUntrackedParameter<bool>("WriteOccupancyRootFile",false));
00139       theIdentifier3->setTrackerGeometry(_tracker);
00140       theIdentifier3->setLowOccupancyThreshold(parameters.getUntrackedParameter<double>("LowOccupancyThreshold",5));
00141       theIdentifier3->setHighOccupancyThreshold(parameters.getUntrackedParameter<double>("HighOccupancyThreshold",10));
00142       theIdentifier3->setAbsoluteLowThreshold(parameters.getUntrackedParameter<double>("AbsoluteLowThreshold",0));
00143       theIdentifier3->setNumberIterations(parameters.getUntrackedParameter<uint32_t>("NumberIterations",2));
00144       theIdentifier3->setAbsoluteOccupancyThreshold(parameters.getUntrackedParameter<double>("OccupancyThreshold",1.E-5));
00145       theIdentifier3->setMinNumOfEvents();
00146 
00147       bookHistos();
00148   
00149       SiStripQuality* qobj = new SiStripQuality();
00150       theIdentifier3->extractBadAPVSandStrips(qobj,ClusterPositionHistoMap,SiStripQuality_);//here I insert SiStripQuality as input and get qobj as output
00151     
00152       //----------
00153 
00154       edm::LogInfo("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::getNewObject] copy SiStripObject in SiStripBadStrip"<<std::endl;
00155 
00156       std::stringstream ss;  
00157   
00158       SiStripBadStrip::RegistryIterator rIter=qobj->getRegistryVectorBegin();
00159       SiStripBadStrip::RegistryIterator rIterEnd=qobj->getRegistryVectorEnd();
00160       for(;rIter!=rIterEnd;++rIter){
00161         SiStripBadStrip::Range range(qobj->getDataVectorBegin()+rIter->ibegin,qobj->getDataVectorBegin()+rIter->iend);
00162         if ( ! obj->put(rIter->detid,range) )
00163           edm::LogError("SiStripQualityHotStripIdentifierRoot")<<"[SiStripQualityHotStripIdentifierRoot::getNewObject] detid already exists"<<std::endl;
00164       }
00165       edm::LogInfo("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::getNewObject] " << ss.str() << std::endl;
00166     }
00167   else
00168     {
00169       edm::LogError("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::getNewObject] call for a unknow HotStrip identification algoritm"<<std::endl;
00170       
00171       std::vector<uint32_t> a;
00172       SiStripBadStrip::Range range(a.begin(),a.end());
00173       if ( ! obj->put(0xFFFFFFFF,range) )
00174         edm::LogError("SiStripQualityHotStripIdentifierRoot")<<"[SiStripQualityHotStripIdentifierRoot::getNewObject] detid already exists"<<std::endl;
00175     }
00176 
00177   return obj;
00178 }
00179 
00180 void SiStripQualityHotStripIdentifierRoot::algoBeginRun(const edm::Run& iRun,const edm::EventSetup& iSetup){
00181   iSetup.get<TrackerDigiGeometryRecord> ().get (theTrackerGeom);
00182   _tracker=&(* theTrackerGeom);
00183 
00184   if(UseInputDB_){
00185     unsigned long long cacheID = iSetup.get<SiStripQualityRcd>().cacheIdentifier();
00186     
00187     if (m_cacheID_ == cacheID) 
00188       return;
00189     
00190     m_cacheID_ = cacheID; 
00191     
00192     iSetup.get<SiStripQualityRcd>().get(dataLabel_,SiStripQuality_);
00193   }
00194 }
00195 
00196 void SiStripQualityHotStripIdentifierRoot::algoEndJob(){
00197   //Clear map
00198   ClusterPositionHistoMap.clear();
00199 }
00200 
00201 
00202 void SiStripQualityHotStripIdentifierRoot::bookHistos(){
00203   edm::LogInfo("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::bookHistos] " << dirpath << std::endl;
00204   std::vector<MonitorElement*> MEs = dqmStore_->getAllContents(dirpath);
00205                                                                //"DQMData/Run 50908/SiStrip/MechanicalView");
00206     //                                                         "/DQMData/Run 50908/SiStrip/Run summary/MechanicalView/TID/side_2/wheel_3/ring_2/mono_modules/module_402676874");
00207   edm::LogInfo("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::bookHistos] vector size " << MEs.size()<< std::endl;
00208 
00209   std::vector<MonitorElement*>::const_iterator iter=MEs.begin();
00210   std::vector<MonitorElement*>::const_iterator iterEnd=MEs.end();
00211 
00212   edm::ParameterSet parameters=conf_.getParameter<edm::ParameterSet>("AlgoParameters");
00213   bool gotNentries=true;
00214   double TotNumberOfEvents;
00215   if( parameters.getUntrackedParameter<uint32_t>("NumberOfEvents",0)==0 && parameters.getUntrackedParameter<double>("OccupancyThreshold",0)!=0)
00216     gotNentries=false;
00217   edm::LogInfo("SiStripQualityHotStripIdentifierRoot")<< "[SiStripQualityHotStripIdentifierRoot::bookHistos]  gotNentries flag " << gotNentries 
00218                                                       << " number of " << parameters.getUntrackedParameter<uint32_t>("NumberOfEvents",0)
00219                                                       << " occup " << parameters.getUntrackedParameter<double>("OccupancyThreshold",0)
00220                                                       << " OccupancyHisto" << parameters.getUntrackedParameter<std::string>("OccupancyHisto") << std::endl;
00221   
00222   for (; iter!=iterEnd;++iter) {
00223     std::string me_name = (*iter)->getName();
00224     
00225     if (!gotNentries && strstr(me_name.c_str(),"TotalNumberOfCluster__T")!=NULL && strstr(me_name.c_str(),"Profile")==NULL ){
00226 
00227       TotNumberOfEvents = ((TH1F*)(*iter)->getTH1F())->GetEntries();
00228       edm::LogInfo("SiStripQualityHotStripIdentifierRoot")<< "Total Number of Events: " << TotNumberOfEvents << std::endl;
00229 
00230       if (parameters.getParameter<std::string>("AlgoName")=="SiStripHotStripAlgorithmFromClusterOccupancy")            {theIdentifier->setNumberOfEvents(TotNumberOfEvents);}
00231       if (parameters.getParameter<std::string>("AlgoName")=="SiStripBadAPVAlgorithmFromClusterOccupancy")              {theIdentifier2->setNumberOfEvents(TotNumberOfEvents); theIdentifier2->setMinNumOfEvents();}
00232       if (parameters.getParameter<std::string>("AlgoName")=="SiStripBadAPVandHotStripAlgorithmFromClusterOccupancy")   {theIdentifier3->setNumberOfEvents(TotNumberOfEvents); theIdentifier3->setMinNumOfEvents();}
00233 
00234       gotNentries=true;
00235       edm::LogInfo("SiStripQualityHotStripIdentifierRoot")<< "[SiStripQualityHotStripIdentifierRoot::bookHistos]  gotNentries flag " << gotNentries << std::endl;
00236     }
00237 
00238     if (strstr(me_name.c_str(),(parameters.getUntrackedParameter<std::string>("OccupancyHisto")).c_str())==NULL)
00239       continue;
00240 
00241     unsigned int detid=0;
00242     char title[128];
00243     sprintf(title,"%s",me_name.c_str());
00244     char *ptr=strtok(title,"__");
00245     int c=0;
00246     while (ptr!=NULL){
00247       if (c==2){
00248         detid=atol(ptr);
00249         break;
00250       }
00251       ptr=strtok(NULL,"_");
00252       c++;
00253     }
00254     LogDebug("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::bookHistos] detid " << detid<< std::endl;
00255 
00256     ClusterPositionHistoMap[detid]=boost::shared_ptr<TH1F>(new TH1F(*(*iter)->getTH1F()));
00257     
00258   }
00259   
00260 }
00261