CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/DQM/SiStripMonitorCluster/src/SiStripMonitorCluster.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 // Package:    SiStripMonitorCluster
00003 // Class:      SiStripMonitorCluster
00006 // Original Author:  Dorian Kcira
00007 //         Created:  Wed Feb  1 16:42:34 CET 2006
00008 // $Id: SiStripMonitorCluster.cc,v 1.81 2012/04/17 18:50:30 threus Exp $
00009 #include <vector>
00010 #include <numeric>
00011 #include <fstream>
00012 #include <math.h>
00013 #include "TNamed.h"
00014 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00015 #include "FWCore/ServiceRegistry/interface/Service.h"
00016 
00017 #include "CalibTracker/Records/interface/SiStripDetCablingRcd.h"
00018 #include "CalibFormats/SiStripObjects/interface/SiStripDetCabling.h"
00019 #include "CondFormats/DataRecord/interface/SiStripCondDataRecords.h"
00020 #include "CondFormats/SiStripObjects/interface/SiStripNoises.h"
00021 #include "CalibFormats/SiStripObjects/interface/SiStripGain.h"
00022 #include "CalibFormats/SiStripObjects/interface/SiStripQuality.h"
00023 #include "DataFormats/SiStripCluster/interface/SiStripClusterCollection.h"
00024 #include "DataFormats/Common/interface/DetSetVector.h"
00025 #include "DataFormats/Common/interface/DetSetVectorNew.h"
00026 #include "DataFormats/SiStripCluster/interface/SiStripCluster.h"
00027 #include "DQM/SiStripCommon/interface/SiStripFolderOrganizer.h"
00028 #include "DQM/SiStripCommon/interface/SiStripHistoId.h"
00029 #include "DQM/SiStripMonitorCluster/interface/SiStripMonitorCluster.h"
00030 #include "DQMServices/Core/interface/DQMStore.h"
00031 #include "DQMServices/Core/interface/MonitorElement.h"
00032 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
00033 #include "DataFormats/SiStripDetId/interface/SiStripSubStructure.h"
00034 #include "DataFormats/SiStripDetId/interface/TECDetId.h"
00035 #include "DataFormats/SiStripDetId/interface/TIBDetId.h"
00036 #include "DataFormats/SiStripDetId/interface/TIDDetId.h"
00037 #include "DataFormats/SiStripDetId/interface/TOBDetId.h"
00038 #include "CalibTracker/SiStripCommon/interface/SiStripDCSStatus.h"
00039 #include "DataFormats/SiPixelCluster/interface/SiPixelCluster.h"
00040 
00041 #include "DPGAnalysis/SiStripTools/interface/APVCyclePhaseCollection.h"
00042 #include "DPGAnalysis/SiStripTools/interface/EventWithHistory.h"
00043 
00044 
00045 #include "TMath.h"
00046 #include <iostream>
00047 
00048 //--------------------------------------------------------------------------------------------
00049 SiStripMonitorCluster::SiStripMonitorCluster(const edm::ParameterSet& iConfig) : dqmStore_(edm::Service<DQMStore>().operator->()), conf_(iConfig), show_mechanical_structure_view(true), show_readout_view(false), show_control_view(false), select_all_detectors(false), reset_each_run(false), m_cacheID_(0)
00050 {
00051 
00052   firstEvent = -1;
00053   eventNb = 0;
00054 
00055   // Detector Partitions
00056   SubDetPhasePartMap["TIB"]        = "TI";
00057   SubDetPhasePartMap["TID__side__1"] = "TI";
00058   SubDetPhasePartMap["TID__side__2"] = "TI";
00059   SubDetPhasePartMap["TOB"]        = "TO";
00060   SubDetPhasePartMap["TEC__side__1"] = "TM";
00061   SubDetPhasePartMap["TEC__side__2"] = "TP";
00062 
00063   //get on/off option for every cluster from cfi
00064   edm::ParameterSet ParametersnClusters =  conf_.getParameter<edm::ParameterSet>("TH1nClusters");
00065   layerswitchncluson = ParametersnClusters.getParameter<bool>("layerswitchon");
00066   moduleswitchncluson = ParametersnClusters.getParameter<bool>("moduleswitchon");
00067   
00068   edm::ParameterSet ParametersClusterCharge =  conf_.getParameter<edm::ParameterSet>("TH1ClusterCharge");
00069   layerswitchcluschargeon = ParametersClusterCharge.getParameter<bool>("layerswitchon");
00070   moduleswitchcluschargeon = ParametersClusterCharge.getParameter<bool>("moduleswitchon");
00071   
00072   edm::ParameterSet ParametersClusterStoN =  conf_.getParameter<edm::ParameterSet>("TH1ClusterStoN");
00073   layerswitchclusstonon = ParametersClusterStoN.getParameter<bool>("layerswitchon");
00074   moduleswitchclusstonon = ParametersClusterStoN.getParameter<bool>("moduleswitchon");
00075 
00076   edm::ParameterSet ParametersClusterStoNVsPos =  conf_.getParameter<edm::ParameterSet>("TH1ClusterStoNVsPos");
00077   layerswitchclusstonVsposon = ParametersClusterStoNVsPos.getParameter<bool>("layerswitchon");
00078   moduleswitchclusstonVsposon = ParametersClusterStoNVsPos.getParameter<bool>("moduleswitchon");
00079   
00080   edm::ParameterSet ParametersClusterPos =  conf_.getParameter<edm::ParameterSet>("TH1ClusterPos");
00081   layerswitchclusposon = ParametersClusterPos.getParameter<bool>("layerswitchon");
00082   moduleswitchclusposon = ParametersClusterPos.getParameter<bool>("moduleswitchon");
00083 
00084   edm::ParameterSet ParametersClusterDigiPos =  conf_.getParameter<edm::ParameterSet>("TH1ClusterDigiPos");
00085   layerswitchclusdigiposon = ParametersClusterDigiPos.getParameter<bool>("layerswitchon");
00086   moduleswitchclusdigiposon = ParametersClusterDigiPos.getParameter<bool>("moduleswitchon");
00087   
00088   edm::ParameterSet ParametersClusterNoise =  conf_.getParameter<edm::ParameterSet>("TH1ClusterNoise");
00089   layerswitchclusnoiseon = ParametersClusterNoise.getParameter<bool>("layerswitchon");
00090   moduleswitchclusnoiseon = ParametersClusterNoise.getParameter<bool>("moduleswitchon");
00091   
00092   edm::ParameterSet ParametersClusterWidth =  conf_.getParameter<edm::ParameterSet>("TH1ClusterWidth");
00093   layerswitchcluswidthon = ParametersClusterWidth.getParameter<bool>("layerswitchon");
00094   moduleswitchcluswidthon = ParametersClusterWidth.getParameter<bool>("moduleswitchon");
00095   
00096   edm::ParameterSet ParametersModuleLocalOccupancy =  conf_.getParameter<edm::ParameterSet>("TH1ModuleLocalOccupancy");
00097   layerswitchlocaloccupancy = ParametersModuleLocalOccupancy.getParameter<bool>("layerswitchon");
00098   moduleswitchlocaloccupancy = ParametersModuleLocalOccupancy.getParameter<bool>("moduleswitchon");
00099 
00100   edm::ParameterSet ParametersNrOfClusterizedStrips =  conf_.getParameter<edm::ParameterSet>("TH1NrOfClusterizedStrips");
00101   layerswitchnrclusterizedstrip = ParametersNrOfClusterizedStrips.getParameter<bool>("layerswitchon");
00102   moduleswitchnrclusterizedstrip = ParametersNrOfClusterizedStrips.getParameter<bool>("moduleswitchon");
00103 
00104   edm::ParameterSet ParametersClusterProf = conf_.getParameter<edm::ParameterSet>("TProfNumberOfCluster");
00105   layerswitchnumclusterprofon = ParametersClusterProf.getParameter<bool>("layerswitchon");
00106 
00107   edm::ParameterSet ParametersClusterWidthProf = conf_.getParameter<edm::ParameterSet>("TProfClusterWidth");
00108   layerswitchclusterwidthprofon = ParametersClusterWidthProf.getParameter<bool>("layerswitchon");
00109 
00110   edm::ParameterSet ParametersTotClusterProf = conf_.getParameter<edm::ParameterSet>("TProfTotalNumberOfClusters");
00111   subdetswitchtotclusprofon = ParametersTotClusterProf.getParameter<bool>("subdetswitchon");
00112 
00113   edm::ParameterSet ParametersTotClusterTH1 = conf_.getParameter<edm::ParameterSet>("TH1TotalNumberOfClusters");
00114   subdetswitchtotclusth1on = ParametersTotClusterTH1.getParameter<bool>("subdetswitchon");
00115 
00116   edm::ParameterSet ParametersClusterApvProf = conf_.getParameter<edm::ParameterSet>("TProfClustersApvCycle");
00117   subdetswitchapvcycleprofon = ParametersClusterApvProf.getParameter<bool>("subdetswitchon");
00118 
00119   edm::ParameterSet ParametersClustersApvTH2 = conf_.getParameter<edm::ParameterSet>("TH2ClustersApvCycle");
00120   subdetswitchapvcycleth2on = ParametersClustersApvTH2.getParameter<bool>("subdetswitchon");
00121 
00122   edm::ParameterSet ParametersApvCycleDBxProf2 = conf_.getParameter<edm::ParameterSet>("TProf2ApvCycleVsDBx");
00123   subdetswitchapvcycledbxprof2on = ParametersApvCycleDBxProf2.getParameter<bool>("subdetswitchon");
00124 
00125   edm::ParameterSet ParametersDBxCycleProf = conf_.getParameter<edm::ParameterSet>("TProfClustersVsDBxCycle");
00126   subdetswitchdbxcycleprofon = ParametersDBxCycleProf.getParameter<bool>("subdetswitchon");
00127 
00128   edm::ParameterSet ParametersCStripVsCPix = conf_.getParameter<edm::ParameterSet>("TH2CStripVsCpixel");
00129   globalswitchcstripvscpix = ParametersCStripVsCPix.getParameter<bool>("globalswitchon");
00130 
00131   edm::ParameterSet ParametersMultiplicityRegionsTH1 = conf_.getParameter<edm::ParameterSet>("TH1MultiplicityRegions");
00132   globalswitchMultiRegions =  ParametersMultiplicityRegionsTH1.getParameter<bool>("globalswitchon");
00133 
00134   edm::ParameterSet ParametersApvCycleVsDBxGlobalTH2 = conf_.getParameter<edm::ParameterSet>("TH2ApvCycleVsDBxGlobal");
00135   globalswitchapvcycledbxth2on = ParametersApvCycleVsDBxGlobalTH2.getParameter<bool>("globalswitchon");
00136 
00137   edm::ParameterSet ParametersNoiseStrip2ApvCycle = conf_.getParameter<edm::ParameterSet>("TH1StripNoise2ApvCycle");
00138   globalswitchstripnoise2apvcycle = ParametersNoiseStrip2ApvCycle.getParameter<bool>("globalswitchon");
00139 
00140   edm::ParameterSet ParametersNoiseStrip3ApvCycle = conf_.getParameter<edm::ParameterSet>("TH1StripNoise3ApvCycle");
00141   globalswitchstripnoise3apvcycle = ParametersNoiseStrip3ApvCycle.getParameter<bool>("globalswitchon");
00142 
00143   edm::ParameterSet ParametersMainDiagonalPosition = conf_.getParameter<edm::ParameterSet>("TH1MainDiagonalPosition");
00144   globalswitchmaindiagonalposition= ParametersMainDiagonalPosition.getParameter<bool>("globalswitchon");
00145 
00146   edm::ParameterSet ClusterMultiplicityRegions = conf_.getParameter<edm::ParameterSet>("MultiplicityRegions");
00147   k0 = ClusterMultiplicityRegions.getParameter<double>("k0");
00148   q0 = ClusterMultiplicityRegions.getParameter<double>("q0");
00149   dk0 = ClusterMultiplicityRegions.getParameter<double>("dk0");
00150   maxClus = ClusterMultiplicityRegions.getParameter<double>("MaxClus");
00151   minPix = ClusterMultiplicityRegions.getParameter<double>("MinPix");
00152 
00153   clustertkhistomapon = conf_.getParameter<bool>("TkHistoMap_On");
00154   createTrendMEs = conf_.getParameter<bool>("CreateTrendMEs");
00155   Mod_On_ = conf_.getParameter<bool>("Mod_On");
00156   ClusterHisto_ = conf_.getParameter<bool>("ClusterHisto");
00157 
00158   topFolderName_ = conf_.getParameter<std::string>("TopFolderName");
00159 
00160 
00161   // Poducer name of input StripClusterCollection
00162   clusterProducerStrip_ = conf_.getParameter<edm::InputTag>("ClusterProducerStrip");
00163   clusterProducerPix_ = conf_.getParameter<edm::InputTag>("ClusterProducerPix");
00164   // SiStrip Quality Label
00165   qualityLabel_  = conf_.getParameter<std::string>("StripQualityLabel");
00166   // cluster quality conditions 
00167   edm::ParameterSet cluster_condition = conf_.getParameter<edm::ParameterSet>("ClusterConditions");
00168   applyClusterQuality_ = cluster_condition.getParameter<bool>("On");
00169   sToNLowerLimit_      = cluster_condition.getParameter<double>("minStoN");
00170   sToNUpperLimit_      = cluster_condition.getParameter<double>("maxStoN");
00171   widthLowerLimit_     = cluster_condition.getParameter<double>("minWidth"); 
00172   widthUpperLimit_     = cluster_condition.getParameter<double>("maxWidth"); 
00173 
00174   // Event History Producer
00175   historyProducer_ = conf_.getParameter<edm::InputTag>("HistoryProducer");
00176   // Apv Phase Producer
00177   apvPhaseProducer_ = conf_.getParameter<edm::InputTag>("ApvPhaseProducer");
00178 
00179   // Create DCS Status
00180   bool checkDCS    = conf_.getParameter<bool>("UseDCSFiltering");
00181   if (checkDCS) dcsStatus_ = new SiStripDCSStatus();
00182   else dcsStatus_ = 0; 
00183 
00184 } 
00185 
00186 SiStripMonitorCluster::~SiStripMonitorCluster() { 
00187   if (dcsStatus_) delete dcsStatus_;
00188 }
00189 
00190 //--------------------------------------------------------------------------------------------
00191 void SiStripMonitorCluster::beginRun(const edm::Run& run, const edm::EventSetup& es){
00192 
00193   if (show_mechanical_structure_view) {
00194     unsigned long long cacheID = es.get<SiStripDetCablingRcd>().cacheIdentifier();
00195     if (m_cacheID_ != cacheID) {
00196       m_cacheID_ = cacheID;       
00197      edm::LogInfo("SiStripMonitorCluster") <<"SiStripMonitorCluster::beginRun: " 
00198                                             << " Creating MEs for new Cabling ";     
00199 
00200       createMEs(es);
00201     } 
00202   } else if (reset_each_run) {
00203     edm::LogInfo("SiStripMonitorCluster") <<"SiStripMonitorCluster::beginRun: " 
00204                                           << " Resetting MEs ";        
00205     for (std::map<uint32_t, ModMEs >::const_iterator idet = ModuleMEsMap.begin() ; idet!=ModuleMEsMap.end() ; idet++) {
00206       ResetModuleMEs(idet->first);
00207     }
00208   }
00209 }
00210 
00211 //--------------------------------------------------------------------------------------------
00212 void SiStripMonitorCluster::createMEs(const edm::EventSetup& es){
00213 
00214   if ( show_mechanical_structure_view ){
00215     // take from eventSetup the SiStripDetCabling object - here will use SiStripDetControl later on
00216     es.get<SiStripDetCablingRcd>().get(SiStripDetCabling_);
00217     
00218     // get list of active detectors from SiStripDetCabling 
00219     std::vector<uint32_t> activeDets;
00220     SiStripDetCabling_->addActiveDetectorsRawIds(activeDets);
00221     
00222     SiStripSubStructure substructure;
00223 
00224     SiStripFolderOrganizer folder_organizer;
00225     folder_organizer.setSiStripFolderName(topFolderName_);
00226     folder_organizer.setSiStripFolder();
00227 
00228 
00229     // Create TkHistoMap for Cluster
00230     if (clustertkhistomapon) {
00231       if (topFolderName_ == "SiStrip") tkmapcluster = new TkHistoMap("SiStrip/TkHistoMap","TkHMap_NumberOfCluster",0.,1);
00232       else tkmapcluster = new TkHistoMap(topFolderName_+"/TkHistoMap","TkHMap_NumberOfCluster",0.,0);
00233     }    
00234 
00235     // loop over detectors and book MEs
00236     edm::LogInfo("SiStripTkDQM|SiStripMonitorCluster")<<"nr. of activeDets:  "<<activeDets.size();
00237     for(std::vector<uint32_t>::iterator detid_iterator = activeDets.begin(); detid_iterator!=activeDets.end(); detid_iterator++){
00238       uint32_t detid = (*detid_iterator);
00239       // remove any eventual zero elements - there should be none, but just in case
00240       if(detid == 0) {
00241         activeDets.erase(detid_iterator);
00242         continue;
00243       }
00244       
00245       if (Mod_On_) {
00246         ModMEs mod_single;
00247         mod_single.NumberOfClusters = 0;
00248         mod_single.ClusterPosition = 0;
00249         mod_single.ClusterDigiPosition = 0;
00250         mod_single.ClusterWidth = 0;
00251         mod_single.ClusterCharge = 0;
00252         mod_single.ClusterNoise = 0;
00253         mod_single.ClusterSignalOverNoise = 0;
00254         mod_single.ClusterSignalOverNoiseVsPos = 0;
00255         mod_single.ModuleLocalOccupancy = 0;
00256         mod_single.NrOfClusterizedStrips = 0; 
00257         
00258         // set appropriate folder using SiStripFolderOrganizer
00259         folder_organizer.setDetectorFolder(detid); // pass the detid to this method
00260         if (reset_each_run) ResetModuleMEs(detid);
00261         createModuleMEs(mod_single, detid);
00262         // append to ModuleMEsMap
00263         ModuleMEsMap.insert( std::make_pair(detid, mod_single));
00264       }
00265       
00266       // Create Layer Level MEs if they are not created already
00267       std::pair<std::string,int32_t> det_layer_pair = folder_organizer.GetSubDetAndLayer(detid);
00268       SiStripHistoId hidmanager;
00269       std::string label = hidmanager.getSubdetid(detid,false);
00270       
00271       std::map<std::string, LayerMEs>::iterator iLayerME  = LayerMEsMap.find(label);
00272       if(iLayerME==LayerMEsMap.end()) {
00273         
00274         // get detids for the layer
00275         int32_t lnumber = det_layer_pair.second;
00276         std::vector<uint32_t> layerDetIds;        
00277         if (det_layer_pair.first == "TIB") {
00278           substructure.getTIBDetectors(activeDets,layerDetIds,lnumber,0,0,0);
00279         } else if (det_layer_pair.first == "TOB") {
00280           substructure.getTOBDetectors(activeDets,layerDetIds,lnumber,0,0);
00281         } else if (det_layer_pair.first == "TID" && lnumber > 0) {
00282           substructure.getTIDDetectors(activeDets,layerDetIds,2,abs(lnumber),0,0);
00283         } else if (det_layer_pair.first == "TID" && lnumber < 0) {
00284           substructure.getTIDDetectors(activeDets,layerDetIds,1,abs(lnumber),0,0);
00285         } else if (det_layer_pair.first == "TEC" && lnumber > 0) {
00286           substructure.getTECDetectors(activeDets,layerDetIds,2,abs(lnumber),0,0,0,0);
00287         } else if (det_layer_pair.first == "TEC" && lnumber < 0) {
00288           substructure.getTECDetectors(activeDets,layerDetIds,1,abs(lnumber),0,0,0,0);
00289         }
00290         LayerDetMap[label] = layerDetIds;
00291 
00292         // book Layer MEs 
00293         folder_organizer.setLayerFolder(detid,det_layer_pair.second);
00294         createLayerMEs(label, layerDetIds.size());
00295       }
00296       // book sub-detector plots
00297       std::pair<std::string,std::string> sdet_pair = folder_organizer.getSubDetFolderAndTag(detid);
00298       if (SubDetMEsMap.find(sdet_pair.second) == SubDetMEsMap.end()){
00299         dqmStore_->setCurrentFolder(sdet_pair.first);
00300         createSubDetMEs(sdet_pair.second);        
00301       }
00302     }//end of loop over detectors
00303 
00304     // Create Global Histogram
00305     if (globalswitchapvcycledbxth2on) {
00306       dqmStore_->setCurrentFolder(topFolderName_+"/MechanicalView/");
00307       edm::ParameterSet GlobalTH2Parameters =  conf_.getParameter<edm::ParameterSet>("TH2ApvCycleVsDBxGlobal");
00308       std::string HistoName = "DeltaBx_vs_ApvCycle";
00309       GlobalApvCycleDBxTH2 = dqmStore_->book2D(HistoName,HistoName,
00310                                                GlobalTH2Parameters.getParameter<int32_t>("Nbinsx"),
00311                                                GlobalTH2Parameters.getParameter<double>("xmin"),
00312                                                GlobalTH2Parameters.getParameter<double>("xmax"),
00313                                                GlobalTH2Parameters.getParameter<int32_t>("Nbinsy"),
00314                                                GlobalTH2Parameters.getParameter<double>("ymin"),
00315                                                GlobalTH2Parameters.getParameter<double>("ymax"));
00316       GlobalApvCycleDBxTH2->setAxisTitle("APV Cycle (Corrected Absolute Bx % 70)",1);
00317       GlobalApvCycleDBxTH2->setAxisTitle("Delta Bunch Crossing Cycle",2);
00318     }
00319 
00320     if (globalswitchcstripvscpix) {
00321       dqmStore_->setCurrentFolder(topFolderName_+"/MechanicalView/");
00322       edm::ParameterSet GlobalTH2Parameters =  conf_.getParameter<edm::ParameterSet>("TH2CStripVsCpixel");
00323       std::string HistoName = "StripClusVsPixClus";
00324       GlobalCStripVsCpix = dqmStore_->book2D(HistoName,HistoName,
00325                                                GlobalTH2Parameters.getParameter<int32_t>("Nbinsx"),
00326                                                GlobalTH2Parameters.getParameter<double>("xmin"),
00327                                                GlobalTH2Parameters.getParameter<double>("xmax"),
00328                                                GlobalTH2Parameters.getParameter<int32_t>("Nbinsy"),
00329                                                GlobalTH2Parameters.getParameter<double>("ymin"),
00330                                                GlobalTH2Parameters.getParameter<double>("ymax"));
00331       GlobalCStripVsCpix->setAxisTitle("Strip Clusters",1);
00332       GlobalCStripVsCpix->setAxisTitle("Pix Clusters",2);
00333     }
00334     
00335     if (globalswitchMultiRegions){
00336       dqmStore_->setCurrentFolder(topFolderName_+"/MechanicalView/");
00337       edm::ParameterSet GlobalTH2Parameters =  conf_.getParameter<edm::ParameterSet>("TH1MultiplicityRegions");
00338       std::string HistoName = "ClusterMultiplicityRegions";
00339       PixVsStripMultiplicityRegions = dqmStore_->book1D(HistoName,HistoName,
00340                                                GlobalTH2Parameters.getParameter<int32_t>("Nbinx"),
00341                                                GlobalTH2Parameters.getParameter<double>("xmin"),
00342                                                GlobalTH2Parameters.getParameter<double>("xmax"));
00343       PixVsStripMultiplicityRegions->setAxisTitle("");
00344       PixVsStripMultiplicityRegions->setBinLabel(1,"Main Diagonal");
00345       PixVsStripMultiplicityRegions->setBinLabel(2,"Strip Noise");
00346       PixVsStripMultiplicityRegions->setBinLabel(3,"High Strip Noise");
00347       PixVsStripMultiplicityRegions->setBinLabel(4,"Beam Background");
00348       PixVsStripMultiplicityRegions->setBinLabel(5,"No Strip Clusters");
00349     } 
00350 
00351     if (globalswitchmaindiagonalposition){
00352       dqmStore_->setCurrentFolder(topFolderName_+"/MechanicalView/");
00353       edm::ParameterSet GlobalTH1Parameters =  conf_.getParameter<edm::ParameterSet>("TH1MainDiagonalPosition");
00354       std::string HistoName = "MainDiagonal Position";
00355       GlobalMainDiagonalPosition = dqmStore_->book1D(HistoName,HistoName,
00356                                              GlobalTH1Parameters.getParameter<int32_t>("Nbinsx"),
00357                                              GlobalTH1Parameters.getParameter<double>("xmin"),
00358                                              GlobalTH1Parameters.getParameter<double>("xmax"));
00359       GlobalMainDiagonalPosition->setAxisTitle("atan(NPix/(k*NStrip))");
00360     }
00361 
00362 
00363     if (globalswitchstripnoise2apvcycle){
00364       dqmStore_->setCurrentFolder(topFolderName_+"/MechanicalView/");
00365       edm::ParameterSet GlobalTH1Parameters =  conf_.getParameter<edm::ParameterSet>("TH1StripNoise2ApvCycle");
00366       std::string HistoName = "StripNoise_ApvCycle";
00367       StripNoise2Cycle = dqmStore_->book1D(HistoName,HistoName,
00368                                              GlobalTH1Parameters.getParameter<int32_t>("Nbinsx"),
00369                                              GlobalTH1Parameters.getParameter<double>("xmin"),
00370                                              GlobalTH1Parameters.getParameter<double>("xmax"));
00371       StripNoise2Cycle->setAxisTitle("APV Cycle");
00372     }
00373 
00374     if (globalswitchstripnoise3apvcycle){
00375       dqmStore_->setCurrentFolder(topFolderName_+"/MechanicalView/");
00376       edm::ParameterSet GlobalTH1Parameters =  conf_.getParameter<edm::ParameterSet>("TH1StripNoise3ApvCycle");
00377       std::string HistoName = "HighStripNoise_ApvCycle";
00378       StripNoise3Cycle = dqmStore_->book1D(HistoName,HistoName,
00379                                              GlobalTH1Parameters.getParameter<int32_t>("Nbinsx"),
00380                                              GlobalTH1Parameters.getParameter<double>("xmin"),
00381                                              GlobalTH1Parameters.getParameter<double>("xmax"));
00382       StripNoise3Cycle->setAxisTitle("APV Cycle");
00383     }
00384 
00385     if (ClusterHisto_){
00386       dqmStore_->setCurrentFolder(topFolderName_+"/MechanicalView/");
00387       edm::ParameterSet PixelCluster =  conf_.getParameter<edm::ParameterSet>("TH1NClusPx");
00388       std::string HistoName = "NumberOfClustersInPixel";
00389       NumberOfPixelClus = dqmStore_->book1D(HistoName, HistoName, 
00390                                             PixelCluster.getParameter<int32_t>("Nbinsx"),
00391                                             PixelCluster.getParameter<double>("xmin"),
00392                                             PixelCluster.getParameter<double>("xmax"));
00393       NumberOfPixelClus->setAxisTitle("# of Clusters in Pixel", 1);
00394       NumberOfPixelClus->setAxisTitle("Number of Events", 2);
00395       //
00396       edm::ParameterSet StripCluster =  conf_.getParameter<edm::ParameterSet>("TH1NClusStrip");
00397       HistoName = "NumberOfClustersInStrip";
00398       NumberOfStripClus = dqmStore_->book1D(HistoName, HistoName, 
00399                                             StripCluster.getParameter<int32_t>("Nbinsx"),
00400                                             StripCluster.getParameter<double>("xmin"),
00401                                             StripCluster.getParameter<double>("xmax"));
00402       NumberOfStripClus->setAxisTitle("# of Clusters in Strip", 1);
00403       NumberOfStripClus->setAxisTitle("Number of Events", 2);
00404     }
00405 
00406  
00407   }//end of if
00408 }//end of method
00409 
00410 //--------------------------------------------------------------------------------------------
00411 void SiStripMonitorCluster::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00412 {
00413   // Filter out events if DCS Event if requested
00414   if (dcsStatus_ && !dcsStatus_->getStatus(iEvent,iSetup)) return;
00415 
00416   runNb   = iEvent.id().run();
00417   eventNb++;
00418   float iOrbitSec      = iEvent.orbitNumber()/11223.0;
00419 
00420   int NPixClusters=0, NStripClusters=0, MultiplicityRegion=0;
00421   bool isPixValid=false;
00422 
00423   edm::ESHandle<SiStripNoises> noiseHandle;
00424   iSetup.get<SiStripNoisesRcd>().get(noiseHandle);
00425 
00426   edm::ESHandle<SiStripGain> gainHandle;
00427   iSetup.get<SiStripGainRcd>().get(gainHandle);
00428 
00429   edm::ESHandle<SiStripQuality> qualityHandle;
00430   iSetup.get<SiStripQualityRcd>().get(qualityLabel_,qualityHandle);
00431 
00432   iSetup.get<SiStripDetCablingRcd>().get(SiStripDetCabling_);
00433 
00434   // get collection of DetSetVector of clusters from Event
00435   edm::Handle< edmNew::DetSetVector<SiStripCluster> > cluster_detsetvektor;
00436   iEvent.getByLabel(clusterProducerStrip_, cluster_detsetvektor);
00437 
00438   //get pixel clusters
00439   edm::Handle< edmNew::DetSetVector<SiPixelCluster> > cluster_detsetvektor_pix;
00440   iEvent.getByLabel(clusterProducerPix_, cluster_detsetvektor_pix);
00441 
00442   if (!cluster_detsetvektor.isValid()) return;
00443   
00444   const edmNew::DetSetVector<SiStripCluster> * StrC= cluster_detsetvektor.product();
00445   NStripClusters= StrC->data().size(); 
00446   
00447   if (cluster_detsetvektor_pix.isValid()){
00448     const edmNew::DetSetVector<SiPixelCluster> * PixC= cluster_detsetvektor_pix.product();
00449     NPixClusters= PixC->data().size();
00450     isPixValid=true;
00451     MultiplicityRegion=FindRegion(NStripClusters,NPixClusters);  
00452     if (globalswitchcstripvscpix) GlobalCStripVsCpix->Fill(NStripClusters,NPixClusters);
00453     if (globalswitchmaindiagonalposition && NStripClusters > 0) GlobalMainDiagonalPosition->Fill(atan(NPixClusters/(k0*NStripClusters)));
00454     if (globalswitchMultiRegions) PixVsStripMultiplicityRegions->Fill(MultiplicityRegion);
00455    
00456     if (ClusterHisto_){
00457       NumberOfPixelClus->Fill(NPixClusters);
00458       NumberOfStripClus->Fill(NStripClusters);
00459     }
00460   }
00461   // initialise # of clusters to zero
00462   for (std::map<std::string, SubDetMEs>::iterator iSubdet  = SubDetMEsMap.begin();
00463        iSubdet != SubDetMEsMap.end(); iSubdet++) {
00464     iSubdet->second.totNClusters = 0;
00465   }
00466 
00467   SiStripFolderOrganizer folder_organizer;
00468   bool found_layer_me = false;
00469   for (std::map<std::string, std::vector< uint32_t > >::const_iterator iterLayer = LayerDetMap.begin();
00470        iterLayer != LayerDetMap.end(); iterLayer++) {
00471     
00472     std::string layer_label = iterLayer->first;
00473     
00474     int ncluster_layer = 0;
00475     std::map<std::string, LayerMEs>::iterator iLayerME = LayerMEsMap.find(layer_label);
00476     
00477     //get Layer MEs 
00478     LayerMEs layer_single;
00479     if(iLayerME != LayerMEsMap.end()) {
00480        layer_single = iLayerME->second; 
00481        found_layer_me = true;
00482      } 
00483 
00484     bool found_module_me = false;
00485     uint16_t iDet = 0;
00486     std::string subdet_label = ""; 
00487     // loop over all modules in the layer
00488     for (std::vector< uint32_t >::const_iterator iterDets = iterLayer->second.begin() ; 
00489          iterDets != iterLayer->second.end() ; iterDets++) {
00490       iDet++;
00491       // detid and type of ME
00492       uint32_t detid = (*iterDets);
00493 
00494       // Get SubDet label once
00495       if (subdet_label.size() == 0) subdet_label = folder_organizer.getSubDetFolderAndTag(detid).second;
00496 
00497       // DetId and corresponding set of MEs
00498       ModMEs mod_single;
00499       if (Mod_On_) {
00500         std::map<uint32_t, ModMEs >::iterator imodME = ModuleMEsMap.find(detid);
00501         if (imodME != ModuleMEsMap.end()) {
00502           mod_single = imodME->second;
00503           found_module_me = true;
00504         } 
00505       } else found_module_me = false;
00506 
00507       edmNew::DetSetVector<SiStripCluster>::const_iterator isearch = cluster_detsetvektor->find(detid); // search  clusters of detid
00508     
00509       if(isearch==cluster_detsetvektor->end()){
00510         if(found_module_me && moduleswitchncluson && (mod_single.NumberOfClusters)){
00511           (mod_single.NumberOfClusters)->Fill(0.); // no clusters for this detector module,fill histogram with 0
00512         }
00513         if(clustertkhistomapon) tkmapcluster->fill(detid,0.);
00514         if (found_layer_me && layerswitchnumclusterprofon) layer_single.LayerNumberOfClusterProfile->Fill(iDet, 0.0);
00515         continue; // no clusters for this detid => jump to next step of loop
00516       }
00517       
00518       //cluster_detset is a structure, cluster_detset.data is a std::vector<SiStripCluster>, cluster_detset.id is uint32_t
00519       edmNew::DetSet<SiStripCluster> cluster_detset = (*cluster_detsetvektor)[detid]; // the statement above makes sure there exists an element with 'detid'
00520       
00521       // Filling TkHistoMap with number of clusters for each module 
00522       if(clustertkhistomapon) {
00523         tkmapcluster->fill(detid,static_cast<float>(cluster_detset.size()));
00524       }
00525 
00526       if(moduleswitchncluson && found_module_me && (mod_single.NumberOfClusters != NULL)){ // nr. of clusters per module
00527         (mod_single.NumberOfClusters)->Fill(static_cast<float>(cluster_detset.size()));
00528       }
00529 
00530       if (found_layer_me && layerswitchnumclusterprofon) 
00531         layer_single.LayerNumberOfClusterProfile->Fill(iDet, static_cast<float>(cluster_detset.size()));
00532       ncluster_layer +=  cluster_detset.size();
00533       
00534       short total_clusterized_strips = 0;
00535       
00536       SiStripNoises::Range detNoiseRange = noiseHandle->getRange(detid);
00537       SiStripApvGain::Range detGainRange = gainHandle->getRange(detid); 
00538       SiStripQuality::Range qualityRange = qualityHandle->getRange(detid);
00539       
00540       for(edmNew::DetSet<SiStripCluster>::const_iterator clusterIter = cluster_detset.begin(); clusterIter!= cluster_detset.end(); clusterIter++){
00541 
00542         const std::vector<uint8_t>& ampls = clusterIter->amplitudes();
00543         // cluster position
00544         float cluster_position = clusterIter->barycenter();
00545         // start defined as nr. of first strip beloning to the cluster
00546         short cluster_start    = clusterIter->firstStrip();
00547         // width defined as nr. of strips that belong to cluster
00548         short cluster_width    = ampls.size(); 
00549         // add nr of strips of this cluster to total nr. of clusterized strips
00550         total_clusterized_strips = total_clusterized_strips + cluster_width; 
00551         
00552         // cluster signal and noise from the amplitudes
00553         float cluster_signal = 0.0;
00554         float cluster_noise  = 0.0;
00555         int nrnonzeroamplitudes = 0;
00556         float noise2 = 0.0;
00557         float noise  = 0.0;
00558         for(uint iamp=0; iamp<ampls.size(); iamp++){
00559           if(ampls[iamp]>0){ // nonzero amplitude
00560             cluster_signal += ampls[iamp];
00561             if(!qualityHandle->IsStripBad(qualityRange, clusterIter->firstStrip()+iamp)){
00562               noise = noiseHandle->getNoise(clusterIter->firstStrip()+iamp,detNoiseRange)/gainHandle->getStripGain(clusterIter->firstStrip()+iamp, detGainRange);
00563             }
00564             noise2 += noise*noise;
00565             nrnonzeroamplitudes++;
00566           }
00567         } // End loop over cluster amplitude
00568         
00569         if (nrnonzeroamplitudes > 0) cluster_noise = sqrt(noise2/nrnonzeroamplitudes);
00570         
00571         if( applyClusterQuality_ &&
00572             (cluster_signal/cluster_noise < sToNLowerLimit_ ||
00573              cluster_signal/cluster_noise > sToNUpperLimit_ ||
00574              cluster_width < widthLowerLimit_ ||
00575              cluster_width > widthUpperLimit_) ) continue;  
00576         
00577         ClusterProperties cluster_properties;
00578         cluster_properties.charge    = cluster_signal;
00579         cluster_properties.position  = cluster_position;
00580         cluster_properties.start     = cluster_start;
00581         cluster_properties.width     = cluster_width;
00582         cluster_properties.noise     = cluster_noise;
00583         
00584         // Fill Module Level MEs
00585         if (found_module_me) fillModuleMEs(mod_single, cluster_properties);
00586         
00587         // Fill Layer Level MEs
00588         if (found_layer_me) {
00589           fillLayerMEs(layer_single, cluster_properties, iOrbitSec);
00590           if (layerswitchclusterwidthprofon) 
00591             layer_single.LayerClusterWidthProfile->Fill(iDet, cluster_width);
00592         }
00593       } // end loop over clusters
00594       
00595       short total_nr_strips = SiStripDetCabling_->nApvPairs(detid) * 2 * 128; // get correct # of avp pairs
00596       float local_occupancy = static_cast<float>(total_clusterized_strips)/static_cast<float>(total_nr_strips);
00597       if (found_module_me) {
00598         if(moduleswitchnrclusterizedstrip && mod_single.NrOfClusterizedStrips ){ // nr of clusterized strips
00599           mod_single.NrOfClusterizedStrips->Fill(static_cast<float>(total_clusterized_strips));
00600         }
00601         
00602         if(moduleswitchlocaloccupancy && mod_single.ModuleLocalOccupancy ){ // Occupancy
00603           mod_single.ModuleLocalOccupancy->Fill(local_occupancy);
00604         }
00605       }
00606       if (layerswitchlocaloccupancy && found_layer_me && layer_single.LayerLocalOccupancy) {
00607         fillME(layer_single.LayerLocalOccupancy,local_occupancy);
00608         if (createTrendMEs) fillME(layer_single.LayerLocalOccupancyTrend,iOrbitSec,local_occupancy);
00609       }
00610     }
00611     std::map<std::string, SubDetMEs>::iterator iSubdet  = SubDetMEsMap.find(subdet_label);
00612     if(iSubdet != SubDetMEsMap.end()) iSubdet->second.totNClusters += ncluster_layer; 
00613   }
00614   
00615   //  EventHistory 
00616   edm::Handle<EventWithHistory> event_history;
00617   iEvent.getByLabel(historyProducer_,event_history);
00618   
00619   // Phase of APV
00620   edm::Handle<APVCyclePhaseCollection> apv_phase_collection;
00621   iEvent.getByLabel(apvPhaseProducer_,apv_phase_collection);
00622 
00623   if (event_history.isValid() 
00624         && !event_history.failedToGet()
00625         && apv_phase_collection.isValid() 
00626         && !apv_phase_collection.failedToGet()) {
00627 
00628 
00629     long long dbx        = event_history->deltaBX();
00630     long long tbx        = event_history->absoluteBX();    
00631 
00632     bool global_histo_filled = false;
00633     bool MultiplicityRegion_Vs_APVcycle_filled=false;
00634 
00635     for (std::map<std::string, SubDetMEs>::iterator it = SubDetMEsMap.begin();
00636        it != SubDetMEsMap.end(); it++) {
00637       std::string sdet = it->first;
00638       //std::string sdet = sdet_tag.substr(0,sdet_tag.find_first_of("_"));
00639       SubDetMEs sdetmes = it->second;
00640 
00641       int the_phase = APVCyclePhaseCollection::invalid;
00642       long long tbx_corr = tbx;
00643 
00644       if (SubDetPhasePartMap.find(sdet) != SubDetPhasePartMap.end()) the_phase = apv_phase_collection->getPhase(SubDetPhasePartMap[sdet]);
00645       if(the_phase==APVCyclePhaseCollection::nopartition ||
00646          the_phase==APVCyclePhaseCollection::multiphase ||
00647          the_phase==APVCyclePhaseCollection::invalid) {
00648         the_phase=30;
00649         //std::cout << " subdet " << it->first << " not valid" << " MR " << MultiplicityRegion <<std::endl;
00650       }
00651       tbx_corr  -= the_phase;
00652       long long dbxincycle = event_history->deltaBXinCycle(the_phase);
00653       if (globalswitchapvcycledbxth2on && !global_histo_filled) { 
00654         GlobalApvCycleDBxTH2->Fill(tbx_corr%70,dbx);
00655         global_histo_filled = true;
00656       }
00657 
00658       if (isPixValid && !MultiplicityRegion_Vs_APVcycle_filled){        
00659         if (globalswitchstripnoise2apvcycle && MultiplicityRegion==2) {StripNoise2Cycle->Fill(tbx_corr%70);}
00660         if (globalswitchstripnoise3apvcycle && MultiplicityRegion==3) {StripNoise3Cycle->Fill(tbx_corr%70);}
00661         MultiplicityRegion_Vs_APVcycle_filled=true;
00662       }
00663 
00664       if (subdetswitchtotclusth1on) sdetmes.SubDetTotClusterTH1->Fill(sdetmes.totNClusters);
00665       if (subdetswitchtotclusprofon) sdetmes.SubDetTotClusterProf->Fill(iOrbitSec,sdetmes.totNClusters);
00666       if (subdetswitchapvcycleprofon) sdetmes.SubDetClusterApvProf->Fill(tbx_corr%70,sdetmes.totNClusters);
00667       if (subdetswitchapvcycleth2on) sdetmes.SubDetClusterApvTH2->Fill(tbx_corr%70,sdetmes.totNClusters);
00668       if (subdetswitchdbxcycleprofon) sdetmes.SubDetClusterDBxCycleProf->Fill(dbxincycle,sdetmes.totNClusters);
00669       if (subdetswitchapvcycledbxprof2on) sdetmes.SubDetApvDBxProf2->Fill(tbx_corr%70,dbx,sdetmes.totNClusters);
00670     }
00671   }
00672 }
00673 //
00674 // -- EndJob
00675 //
00676 void SiStripMonitorCluster::endJob(void){
00677   bool outputMEsInRootFile = conf_.getParameter<bool>("OutputMEsInRootFile");
00678   std::string outputFileName = conf_.getParameter<std::string>("OutputFileName");
00679  
00680   // save histos in a file
00681   if(outputMEsInRootFile) dqmStore_->save(outputFileName);
00682 }
00683 //
00684 // -- Reset MEs
00685 //------------------------------------------------------------------------------
00686 void SiStripMonitorCluster::ResetModuleMEs(uint32_t idet){
00687   std::map<uint32_t, ModMEs >::iterator pos = ModuleMEsMap.find(idet);
00688   ModMEs mod_me = pos->second;
00689 
00690   if (moduleswitchncluson)            mod_me.NumberOfClusters->Reset();
00691   if (moduleswitchclusposon)          mod_me.ClusterPosition->Reset();
00692   if (moduleswitchclusdigiposon)      mod_me.ClusterDigiPosition->Reset();
00693   if (moduleswitchclusstonVsposon)    mod_me.ClusterSignalOverNoiseVsPos->Reset();
00694   if (moduleswitchcluswidthon)        mod_me.ClusterWidth->Reset();
00695   if (moduleswitchcluschargeon)       mod_me.ClusterCharge->Reset();
00696   if (moduleswitchclusnoiseon)        mod_me.ClusterNoise->Reset();
00697   if (moduleswitchclusstonon)         mod_me.ClusterSignalOverNoise->Reset();
00698   if (moduleswitchlocaloccupancy)     mod_me.ModuleLocalOccupancy->Reset();
00699   if (moduleswitchnrclusterizedstrip) mod_me.NrOfClusterizedStrips->Reset(); 
00700 }
00701 //
00702 // -- Create Module Level MEs
00703 //
00704 void SiStripMonitorCluster::createModuleMEs(ModMEs& mod_single, uint32_t detid) {
00705 
00706   // use SistripHistoId for producing histogram id (and title)
00707   SiStripHistoId hidmanager;
00708   std::string hid;
00709   
00710   //nr. of clusters per module
00711   if(moduleswitchncluson) {
00712     hid = hidmanager.createHistoId("NumberOfClusters","det",detid);
00713     mod_single.NumberOfClusters = bookME1D("TH1nClusters", hid.c_str());
00714     dqmStore_->tag(mod_single.NumberOfClusters, detid);
00715     mod_single.NumberOfClusters->setAxisTitle("number of clusters in one detector module");
00716     mod_single.NumberOfClusters->getTH1()->StatOverflows(kTRUE);  // over/underflows in Mean calculation
00717   }
00718   
00719   //ClusterPosition
00720   if(moduleswitchclusposon) {
00721     short total_nr_strips = SiStripDetCabling_->nApvPairs(detid) * 2 * 128; // get correct # of avp pairs    
00722     hid = hidmanager.createHistoId("ClusterPosition","det",detid);
00723     mod_single.ClusterPosition = dqmStore_->book1D(hid, hid, total_nr_strips, 0.5, total_nr_strips+0.5);
00724     dqmStore_->tag(mod_single.ClusterPosition, detid);
00725     mod_single.ClusterPosition->setAxisTitle("cluster position [strip number +0.5]");
00726   }
00727 
00728   //ClusterDigiPosition
00729   if(moduleswitchclusdigiposon) {
00730     short total_nr_strips = SiStripDetCabling_->nApvPairs(detid) * 2 * 128; // get correct # of avp pairs    
00731     hid = hidmanager.createHistoId("ClusterDigiPosition","det",detid);
00732     mod_single.ClusterDigiPosition = dqmStore_->book1D(hid, hid, total_nr_strips, 0.5, total_nr_strips+0.5);
00733     dqmStore_->tag(mod_single.ClusterDigiPosition, detid);
00734     mod_single.ClusterDigiPosition->setAxisTitle("digi in cluster position [strip number +0.5]");
00735   }
00736   
00737   //ClusterWidth
00738   if(moduleswitchcluswidthon) {
00739     hid = hidmanager.createHistoId("ClusterWidth","det",detid);
00740     mod_single.ClusterWidth = bookME1D("TH1ClusterWidth", hid.c_str());
00741     dqmStore_->tag(mod_single.ClusterWidth, detid);
00742     mod_single.ClusterWidth->setAxisTitle("cluster width [nr strips]");
00743   }
00744   
00745   //ClusterCharge
00746   if(moduleswitchcluschargeon) {
00747     hid = hidmanager.createHistoId("ClusterCharge","det",detid);
00748     mod_single.ClusterCharge = bookME1D("TH1ClusterCharge", hid.c_str());
00749     dqmStore_->tag(mod_single.ClusterCharge, detid);
00750     mod_single.ClusterCharge->setAxisTitle("cluster charge [ADC]");
00751   }
00752   
00753   //ClusterNoise
00754   if(moduleswitchclusnoiseon) {
00755     hid = hidmanager.createHistoId("ClusterNoise","det",detid);
00756     mod_single.ClusterNoise = bookME1D("TH1ClusterNoise", hid.c_str());
00757     dqmStore_->tag(mod_single.ClusterNoise, detid);
00758     mod_single.ClusterNoise->setAxisTitle("cluster noise");
00759   }
00760   
00761   //ClusterSignalOverNoise
00762   if(moduleswitchclusstonon) {
00763     hid = hidmanager.createHistoId("ClusterSignalOverNoise","det",detid);
00764     mod_single.ClusterSignalOverNoise = bookME1D("TH1ClusterStoN", hid.c_str());
00765     dqmStore_->tag(mod_single.ClusterSignalOverNoise, detid);
00766     mod_single.ClusterSignalOverNoise->setAxisTitle("ratio of signal to noise for each cluster");
00767   }
00768 
00769   //ClusterSignalOverNoiseVsPos
00770   if(moduleswitchclusstonVsposon) {
00771     hid = hidmanager.createHistoId("ClusterSignalOverNoiseVsPos","det",detid);
00772     Parameters =  conf_.getParameter<edm::ParameterSet>("TH1ClusterStoNVsPos");
00773     mod_single.ClusterSignalOverNoiseVsPos= dqmStore_->bookProfile(hid.c_str(),hid.c_str(),
00774                                                                    Parameters.getParameter<int32_t>("Nbinx"),
00775                                                                    Parameters.getParameter<double>("xmin"),
00776                                                                    Parameters.getParameter<double>("xmax"),
00777                                                                    Parameters.getParameter<int32_t>("Nbiny"),
00778                                                                    Parameters.getParameter<double>("ymin"),
00779                                                                    Parameters.getParameter<double>("ymax")
00780                                                                    );
00781     dqmStore_->tag(mod_single.ClusterSignalOverNoiseVsPos, detid);
00782     mod_single.ClusterSignalOverNoiseVsPos->setAxisTitle("pos");
00783   }
00784   
00785   //ModuleLocalOccupancy
00786   if (moduleswitchlocaloccupancy) {
00787     hid = hidmanager.createHistoId("ClusterLocalOccupancy","det",detid);
00788     mod_single.ModuleLocalOccupancy = bookME1D("TH1ModuleLocalOccupancy", hid.c_str());
00789     dqmStore_->tag(mod_single.ModuleLocalOccupancy, detid);
00790     mod_single.ModuleLocalOccupancy->setAxisTitle("module local occupancy [% of clusterized strips]");
00791   }
00792   
00793   //NrOfClusterizedStrips
00794   if (moduleswitchnrclusterizedstrip) {
00795     hid = hidmanager.createHistoId("NrOfClusterizedStrips","det",detid);
00796     mod_single.NrOfClusterizedStrips = bookME1D("TH1NrOfClusterizedStrips", hid.c_str());
00797     dqmStore_->tag(mod_single.NrOfClusterizedStrips, detid);
00798     mod_single.NrOfClusterizedStrips->setAxisTitle("number of clusterized strips");
00799   }
00800 }  
00801 //
00802 // -- Create Module Level MEs
00803 //  
00804 void SiStripMonitorCluster::createLayerMEs(std::string label, int ndets) {
00805 
00806   SiStripHistoId hidmanager;
00807   
00808   LayerMEs layerMEs; 
00809   layerMEs.LayerClusterStoN = 0;
00810   layerMEs.LayerClusterStoNTrend = 0;
00811   layerMEs.LayerClusterCharge = 0;
00812   layerMEs.LayerClusterChargeTrend = 0;
00813   layerMEs.LayerClusterNoise = 0;
00814   layerMEs.LayerClusterNoiseTrend = 0;
00815   layerMEs.LayerClusterWidth = 0;
00816   layerMEs.LayerClusterWidthTrend = 0;
00817   layerMEs.LayerLocalOccupancy = 0;
00818   layerMEs.LayerLocalOccupancyTrend = 0;
00819   layerMEs.LayerNumberOfClusterProfile = 0;
00820   layerMEs.LayerClusterWidthProfile = 0;
00821   
00822   //Cluster Width
00823   if(layerswitchcluswidthon) {
00824     layerMEs.LayerClusterWidth=bookME1D("TH1ClusterWidth", hidmanager.createHistoLayer("Summary_ClusterWidth","layer",label,"").c_str()); 
00825     if (createTrendMEs) layerMEs.LayerClusterWidthTrend=bookMETrend("TH1ClusterWidth", hidmanager.createHistoLayer("Trend_ClusterWidth","layer",label,"").c_str()); 
00826   }
00827   
00828   //Cluster Noise
00829   if(layerswitchclusnoiseon) {
00830     layerMEs.LayerClusterNoise=bookME1D("TH1ClusterNoise", hidmanager.createHistoLayer("Summary_ClusterNoise","layer",label,"").c_str()); 
00831     if (createTrendMEs) layerMEs.LayerClusterNoiseTrend=bookMETrend("TH1ClusterNoise", hidmanager.createHistoLayer("Trend_ClusterNoise","layer",label,"").c_str()); 
00832   }
00833   
00834   //Cluster Charge
00835   if(layerswitchcluschargeon) {
00836     layerMEs.LayerClusterCharge=bookME1D("TH1ClusterCharge", hidmanager.createHistoLayer("Summary_ClusterCharge","layer",label,"").c_str());
00837     if (createTrendMEs) layerMEs.LayerClusterChargeTrend=bookMETrend("TH1ClusterCharge", hidmanager.createHistoLayer("Trend_ClusterCharge","layer",label,"").c_str());
00838   }
00839   
00840   //Cluster StoN
00841   if(layerswitchclusstonon) {
00842     layerMEs.LayerClusterStoN=bookME1D("TH1ClusterStoN", hidmanager.createHistoLayer("Summary_ClusterSignalOverNoise","layer",label,"").c_str());
00843     if (createTrendMEs) layerMEs.LayerClusterStoNTrend=bookMETrend("TH1ClusterStoN", hidmanager.createHistoLayer("Trend_ClusterSignalOverNoise","layer",label,"").c_str());
00844   }
00845   
00846   //Cluster Occupancy
00847   if(layerswitchlocaloccupancy) {
00848     layerMEs.LayerLocalOccupancy=bookME1D("TH1ModuleLocalOccupancy", hidmanager.createHistoLayer("Summary_ClusterLocalOccupancy","layer",label,"").c_str());  
00849     if (createTrendMEs) layerMEs.LayerLocalOccupancyTrend=bookMETrend("TH1ModuleLocalOccupancy", hidmanager.createHistoLayer("Trend_ClusterLocalOccupancy","layer",label,"").c_str());  
00850     
00851   }
00852   
00853   // # of Cluster Profile 
00854   if(layerswitchnumclusterprofon) {
00855     std::string hid = hidmanager.createHistoLayer("NumberOfClusterProfile","layer",label,"");
00856     layerMEs.LayerNumberOfClusterProfile = dqmStore_->bookProfile(hid, hid, ndets, 0.5, ndets+0.5,21, -0.5, 20.5);      
00857   }
00858   
00859   // Cluster Width Profile 
00860   if(layerswitchclusterwidthprofon) {
00861     std::string hid = hidmanager.createHistoLayer("ClusterWidthProfile","layer",label,"");      
00862     layerMEs.LayerClusterWidthProfile = dqmStore_->bookProfile(hid, hid, ndets, 0.5, ndets+0.5, 20, -0.5, 19.5);      
00863   }
00864 
00865   LayerMEsMap[label]=layerMEs;
00866 }
00867 //
00868 // -- Create SubDetector MEs
00869 //
00870 void SiStripMonitorCluster::createSubDetMEs(std::string label) {
00871 
00872   SubDetMEs subdetMEs;
00873   subdetMEs.totNClusters              = 0;
00874   subdetMEs.SubDetTotClusterTH1       = 0;
00875   subdetMEs.SubDetTotClusterProf      = 0;
00876   subdetMEs.SubDetClusterApvProf      = 0;
00877   subdetMEs.SubDetClusterApvTH2       = 0;
00878   subdetMEs.SubDetClusterDBxCycleProf = 0;
00879   subdetMEs.SubDetApvDBxProf2         = 0;
00880   
00881   std::string HistoName;
00882   // Total Number of Cluster - 1D 
00883   if (subdetswitchtotclusth1on){
00884     HistoName = "TotalNumberOfCluster__" + label;
00885     subdetMEs.SubDetTotClusterTH1 = bookME1D("TH1TotalNumberOfClusters",HistoName.c_str());
00886     subdetMEs.SubDetTotClusterTH1->setAxisTitle("Total number of clusters in subdetector");
00887     subdetMEs.SubDetTotClusterTH1->getTH1()->StatOverflows(kTRUE);  // over/underflows in Mean calculation
00888   }
00889   // Total Number of Cluster vs Time - Profile
00890   if (subdetswitchtotclusprofon){
00891     edm::ParameterSet Parameters =  conf_.getParameter<edm::ParameterSet>("TProfTotalNumberOfClusters");
00892     HistoName = "TotalNumberOfClusterProfile__" + label;
00893     subdetMEs.SubDetTotClusterProf = dqmStore_->bookProfile(HistoName,HistoName,
00894                                                             Parameters.getParameter<int32_t>("Nbins"),
00895                                                             Parameters.getParameter<double>("xmin"),
00896                                                             Parameters.getParameter<double>("xmax"),
00897                                                             100, //that parameter should not be there !?
00898                                                             Parameters.getParameter<double>("ymin"),
00899                                                             Parameters.getParameter<double>("ymax"),
00900                                                             "" );
00901     subdetMEs.SubDetTotClusterProf->setAxisTitle("Event Time (Seconds)",1);
00902     if (subdetMEs.SubDetTotClusterProf->kind() == MonitorElement::DQM_KIND_TPROFILE) subdetMEs.SubDetTotClusterProf->getTH1()->SetBit(TH1::kCanRebin);
00903   }
00904   // Total Number of Cluster vs APV cycle - Profile
00905   if(subdetswitchapvcycleprofon){
00906     edm::ParameterSet Parameters =  conf_.getParameter<edm::ParameterSet>("TProfClustersApvCycle");
00907     HistoName = "Cluster_vs_ApvCycle__" + label;
00908     subdetMEs.SubDetClusterApvProf=dqmStore_->bookProfile(HistoName,HistoName,
00909                                                           Parameters.getParameter<int32_t>("Nbins"),
00910                                                           Parameters.getParameter<double>("xmin"),
00911                                                           Parameters.getParameter<double>("xmax"),
00912                                                           200, //that parameter should not be there !?
00913                                                           Parameters.getParameter<double>("ymin"),
00914                                                           Parameters.getParameter<double>("ymax"),
00915                                                           "" );
00916     subdetMEs.SubDetClusterApvProf->setAxisTitle("Apv Cycle (Corrected Absolute Bx % 70)",1);
00917   }
00918   
00919   // Total Number of Clusters vs ApvCycle - 2D 
00920   if(subdetswitchapvcycleth2on){
00921     edm::ParameterSet Parameters =  conf_.getParameter<edm::ParameterSet>("TH2ClustersApvCycle");
00922     HistoName = "Cluster_vs_ApvCycle_2D__" + label;
00923     // Adjusting the scale for 2D histogram
00924     double h2ymax = 9999.0;     
00925     double yfact = Parameters.getParameter<double>("yfactor");
00926     if(label.find("TIB") != std::string::npos) h2ymax = (6984.*256.)*yfact;
00927     else if (label.find("TID") != std::string::npos) h2ymax = (2208.*256.)*yfact;
00928     else if (label.find("TOB") != std::string::npos) h2ymax = (12906.*256.)*yfact;
00929     else if (label.find("TEC") != std::string::npos) h2ymax = (7552.*2.*256.)*yfact;
00930     
00931     subdetMEs.SubDetClusterApvTH2=dqmStore_->book2D(HistoName,HistoName,
00932                                                     Parameters.getParameter<int32_t>("Nbinsx"),
00933                                                     Parameters.getParameter<double>("xmin"),
00934                                                     Parameters.getParameter<double>("xmax"),
00935                                                     Parameters.getParameter<int32_t>("Nbinsy"),
00936                                                     Parameters.getParameter<double>("ymin"),
00937                                                     h2ymax);
00938     subdetMEs.SubDetClusterApvTH2->setAxisTitle("Apv Cycle (Corrected Absolute Bx % 70))",1);
00939     subdetMEs.SubDetClusterApvTH2->setAxisTitle("Total # of Clusters",2);
00940    
00941   }
00942   // Total Number of Cluster vs DeltaBxCycle - Profile
00943   if(subdetswitchdbxcycleprofon){
00944     edm::ParameterSet Parameters =  conf_.getParameter<edm::ParameterSet>("TProfClustersVsDBxCycle");
00945     HistoName = "Cluster_vs_DeltaBxCycle__" + label;
00946     subdetMEs.SubDetClusterDBxCycleProf = dqmStore_->bookProfile(HistoName,HistoName,
00947                                                                  Parameters.getParameter<int32_t>("Nbins"),
00948                                                                  Parameters.getParameter<double>("xmin"),
00949                                                                  Parameters.getParameter<double>("xmax"),
00950                                                                  200, //that parameter should not be there !?
00951                                                                  Parameters.getParameter<double>("ymin"),
00952                                                                  Parameters.getParameter<double>("ymax"),
00953                                                                  "" );
00954     subdetMEs.SubDetClusterDBxCycleProf->setAxisTitle("Delta Bunch Crossing Cycle",1);
00955   }
00956   // DeltaBx vs ApvCycle - 2DProfile
00957   if(subdetswitchapvcycledbxprof2on){
00958     edm::ParameterSet Parameters =  conf_.getParameter<edm::ParameterSet>("TProf2ApvCycleVsDBx");
00959     HistoName = "DeltaBx_vs_ApvCycle__" + label;
00960     subdetMEs.SubDetApvDBxProf2 = dqmStore_->bookProfile2D(HistoName,HistoName,
00961                                                            Parameters.getParameter<int32_t>("Nbinsx"),
00962                                                            Parameters.getParameter<double>("xmin"),
00963                                                            Parameters.getParameter<double>("xmax"),
00964                                                            Parameters.getParameter<int32_t>("Nbinsy"),
00965                                                            Parameters.getParameter<double>("ymin"),
00966                                                            Parameters.getParameter<double>("ymax"),
00967                                                            Parameters.getParameter<double>("zmin"),
00968                                                            Parameters.getParameter<double>("zmax"),
00969                                                            "" );
00970     subdetMEs.SubDetApvDBxProf2->setAxisTitle("APV Cycle (Corrected Absolute Bx % 70)",1);
00971     subdetMEs.SubDetApvDBxProf2->setAxisTitle("Delta Bunch Crossing Cycle",2);
00972   }
00973   SubDetMEsMap[label]=subdetMEs;
00974 }
00975 
00976 //
00977 // -- Fill Module Level Histograms
00978 //
00979 void SiStripMonitorCluster::fillModuleMEs(ModMEs& mod_mes, ClusterProperties& cluster) {
00980   
00981   if(moduleswitchclusposon && (mod_mes.ClusterPosition)) // position of cluster
00982     (mod_mes.ClusterPosition)->Fill(cluster.position);
00983   
00984   // position of digis in cluster
00985   if(moduleswitchclusdigiposon && (mod_mes.ClusterDigiPosition)) {
00986     for(int ipos=cluster.start+1; ipos<=cluster.start+cluster.width; ipos++){
00987       (mod_mes.ClusterDigiPosition)->Fill(ipos);
00988     }
00989   }
00990 
00991   if(moduleswitchcluswidthon && (mod_mes.ClusterWidth)) // width of cluster
00992     (mod_mes.ClusterWidth)->Fill(static_cast<float>(cluster.width));
00993  
00994   if(moduleswitchclusstonon && (mod_mes.ClusterSignalOverNoise)) {// SignalToNoise
00995     if (cluster.noise > 0) 
00996       (mod_mes.ClusterSignalOverNoise)->Fill(cluster.charge/cluster.noise);
00997   }
00998 
00999   if(moduleswitchclusstonVsposon && (mod_mes.ClusterSignalOverNoiseVsPos)) {// SignalToNoise
01000     if (cluster.noise > 0) 
01001       (mod_mes.ClusterSignalOverNoiseVsPos)->Fill(cluster.position,cluster.charge/cluster.noise);
01002   }
01003 
01004   if(moduleswitchclusnoiseon && (mod_mes.ClusterNoise))  // Noise
01005     (mod_mes.ClusterNoise)->Fill(cluster.noise);
01006 
01007   if(moduleswitchcluschargeon && (mod_mes.ClusterCharge)) // charge of cluster
01008     (mod_mes.ClusterCharge)->Fill(cluster.charge);
01009   
01010 } 
01011 //
01012 // -- Fill Layer Level MEs
01013 //
01014 void SiStripMonitorCluster::fillLayerMEs(LayerMEs& layerMEs, ClusterProperties& cluster, float timeinorbit) { 
01015   if(layerswitchclusstonon) {
01016     fillME(layerMEs.LayerClusterStoN  ,cluster.charge/cluster.noise);
01017     if (createTrendMEs) fillME(layerMEs.LayerClusterStoNTrend,timeinorbit,cluster.charge/cluster.noise);
01018   }
01019   
01020   if(layerswitchcluschargeon) {
01021     fillME(layerMEs.LayerClusterCharge,cluster.charge);
01022     if (createTrendMEs) fillME(layerMEs.LayerClusterChargeTrend,timeinorbit,cluster.charge);
01023   }
01024   
01025   if(layerswitchclusnoiseon) {
01026     fillME(layerMEs.LayerClusterNoise ,cluster.noise);
01027     if (createTrendMEs) fillME(layerMEs.LayerClusterNoiseTrend,timeinorbit,cluster.noise);
01028   }
01029   
01030   if(layerswitchcluswidthon) {
01031     fillME(layerMEs.LayerClusterWidth ,cluster.width);
01032     if (createTrendMEs) fillME(layerMEs.LayerClusterWidthTrend,timeinorbit,cluster.width);
01033   }
01034   
01035 }
01036 //------------------------------------------------------------------------------------------
01037 MonitorElement* SiStripMonitorCluster::bookMETrend(const char* ParameterSetLabel, const char* HistoName)
01038 {
01039   Parameters =  conf_.getParameter<edm::ParameterSet>(ParameterSetLabel);
01040   edm::ParameterSet ParametersTrend =  conf_.getParameter<edm::ParameterSet>("Trending");
01041   MonitorElement* me = dqmStore_->bookProfile(HistoName,HistoName,
01042                                               ParametersTrend.getParameter<int32_t>("Nbins"),
01043                                               //                                              0,
01044                                               ParametersTrend.getParameter<double>("xmin"),
01045                                               ParametersTrend.getParameter<double>("xmax"),
01046                                               //                                              ParametersTrend.getParameter<int32_t>("Nbins"),
01047                                               100, //that parameter should not be there !?
01048                                               ParametersTrend.getParameter<double>("ymin"),
01049                                               ParametersTrend.getParameter<double>("ymax"),
01050                                               "" );
01051   if(!me) return me;
01052   me->setAxisTitle("Event Time in Seconds",1);
01053   if (me->kind() == MonitorElement::DQM_KIND_TPROFILE) me->getTH1()->SetBit(TH1::kCanRebin);
01054   return me;
01055 }
01056 
01057 //------------------------------------------------------------------------------------------
01058 MonitorElement* SiStripMonitorCluster::bookME1D(const char* ParameterSetLabel, const char* HistoName)
01059 {
01060   Parameters =  conf_.getParameter<edm::ParameterSet>(ParameterSetLabel);
01061   return dqmStore_->book1D(HistoName,HistoName,
01062                            Parameters.getParameter<int32_t>("Nbinx"),
01063                            Parameters.getParameter<double>("xmin"),
01064                            Parameters.getParameter<double>("xmax")
01065                            );
01066 }
01067 
01068 int SiStripMonitorCluster::FindRegion(int nstrip,int npix){
01069   
01070   double kplus= k0*(1+dk0/100);
01071   double kminus=k0*(1-dk0/100);
01072   int region=0;
01073   
01074   if (nstrip!=0 && npix >= (nstrip*kminus-q0) && npix <=(nstrip*kplus+q0)) region=1; 
01075   else if (nstrip!=0 && npix < (nstrip*kminus-q0) &&  nstrip <= maxClus) region=2;
01076   else if (nstrip!=0 && npix < (nstrip*kminus-q0) &&  nstrip > maxClus) region=3;
01077   else if (nstrip!=0 && npix > (nstrip*kplus+q0)) region=4;
01078   else if (npix > minPix && nstrip==0) region=5;
01079   return region;
01080 
01081 }
01082 
01083 
01084