CMS 3D CMS Logo

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