CMS 3D CMS Logo

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