CMS 3D CMS Logo

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