CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/DQM/SiStripMonitorDigi/src/SiStripMonitorDigi.cc

Go to the documentation of this file.
00001 // -*- c++ -*-
00004 // Original Author:  Dorian Kcira
00005 //         Created:  Sat Feb  4 20:49:10 CET 2006
00006 // $Id: SiStripMonitorDigi.cc,v 1.75 2013/01/03 19:14:38 wmtan Exp $
00007 #include<fstream>
00008 #include "TNamed.h"
00009 #include "FWCore/Framework/interface/ESHandle.h"
00010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00011 #include "FWCore/ServiceRegistry/interface/Service.h"
00012 #include "CalibTracker/Records/interface/SiStripDetCablingRcd.h"
00013 #include "CalibFormats/SiStripObjects/interface/SiStripDetCabling.h"
00014 #include "DataFormats/Common/interface/DetSetNew.h"
00015 #include "DataFormats/Common/interface/DetSetVectorNew.h"
00016 #include "DataFormats/Common/interface/DetSetVector.h"
00017 #include "DataFormats/Common/interface/Handle.h"
00018 #include "DataFormats/SiStripDetId/interface/SiStripSubStructure.h"
00019 #include "DataFormats/SiStripDigi/interface/SiStripDigi.h"
00020 #include "DQM/SiStripCommon/interface/SiStripFolderOrganizer.h"
00021 #include "DQM/SiStripCommon/interface/SiStripHistoId.h"
00022 #include "DQM/SiStripMonitorDigi/interface/SiStripMonitorDigi.h"
00023 #include "DQMServices/Core/interface/DQMStore.h"
00024 #include "DQMServices/Core/interface/MonitorElement.h"
00025 #include "DPGAnalysis/SiStripTools/interface/APVCyclePhaseCollection.h"
00026 #include "DPGAnalysis/SiStripTools/interface/EventWithHistory.h"
00027 #include "CalibTracker/SiStripCommon/interface/SiStripDCSStatus.h"
00028 
00029 #include "CondFormats/SiStripObjects/interface/FedChannelConnection.h"
00030 #include "DataFormats/SiStripCommon/interface/SiStripConstants.h"
00031 
00032 #include "TMath.h"
00033 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
00034 
00035 #include "iostream"
00036 
00037 #include "DataFormats/Scalers/interface/DcsStatus.h"
00038 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerEvmReadoutRecord.h"
00039 #include "DataFormats/L1GlobalTrigger/interface/L1GtFdlWord.h"
00040 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h"
00041 #include "CondFormats/RunInfo/interface/RunInfo.h"
00042 
00043 //--------------------------------------------------------------------------------------------
00044 SiStripMonitorDigi::SiStripMonitorDigi(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(true), reset_each_run(false), folder_organizer(), m_cacheID_(0) 
00045 {
00046   firstEvent = -1;
00047   eventNb = 0;
00048 
00049   // Detector Partitions
00050   SubDetPhasePartMap["TIB"]        = "TI";
00051   SubDetPhasePartMap["TID__side__1"] = "TI";
00052   SubDetPhasePartMap["TID__side__2"] = "TI";
00053   SubDetPhasePartMap["TOB"]        = "TO";
00054   SubDetPhasePartMap["TEC__side__1"] = "TM";
00055   SubDetPhasePartMap["TEC__side__2"] = "TP";
00056 
00057   // get Digi Producer List   
00058   digiProducerList = conf_.getParameter<std::vector<edm::InputTag> >("DigiProducersList");
00059 
00060   //get on/off option for every cluster from cfi
00061   edm::ParameterSet ParametersNumberOfDigis =  conf_.getParameter<edm::ParameterSet>("TH1NumberOfDigis");
00062   layerswitchnumdigison = ParametersNumberOfDigis.getParameter<bool>("layerswitchon");
00063   moduleswitchnumdigison = ParametersNumberOfDigis.getParameter<bool>("moduleswitchon");
00064   
00065   edm::ParameterSet ParametersNumberOfDigisPerStrip =  conf_.getParameter<edm::ParameterSet>("TH1NumberOfDigisPerStrip");
00066   moduleswitchnumdigispstripon = ParametersNumberOfDigisPerStrip.getParameter<bool>("moduleswitchon");
00067 
00068   edm::ParameterSet ParametersADCsHottestStrip =  conf_.getParameter<edm::ParameterSet>("TH1ADCsHottestStrip");
00069   layerswitchadchotteston = ParametersADCsHottestStrip.getParameter<bool>("layerswitchon");
00070   moduleswitchadchotteston = ParametersADCsHottestStrip.getParameter<bool>("moduleswitchon");
00071   
00072   edm::ParameterSet ParametersADCsCoolestStrip =  conf_.getParameter<edm::ParameterSet>("TH1ADCsCoolestStrip");
00073   layerswitchadccooleston = ParametersADCsCoolestStrip.getParameter<bool>("layerswitchon");
00074   moduleswitchadccooleston = ParametersADCsCoolestStrip.getParameter<bool>("moduleswitchon");
00075   
00076   edm::ParameterSet ParametersDigiADCs =  conf_.getParameter<edm::ParameterSet>("TH1DigiADCs");
00077   layerswitchdigiadcson = ParametersDigiADCs.getParameter<bool>("layerswitchon");
00078   moduleswitchdigiadcson = ParametersDigiADCs.getParameter<bool>("moduleswitchon");
00079    
00080   edm::ParameterSet ParametersStripOccupancy =  conf_.getParameter<edm::ParameterSet>("TH1StripOccupancy");
00081   layerswitchstripoccupancyon = ParametersStripOccupancy.getParameter<bool>("layerswitchon");
00082   moduleswitchstripoccupancyon = ParametersStripOccupancy.getParameter<bool>("moduleswitchon");
00083 
00084   edm::ParameterSet ParametersDigiProf = conf_.getParameter<edm::ParameterSet>("TProfNumberOfDigi");
00085   layerswitchnumdigisprofon = ParametersDigiProf.getParameter<bool>("layerswitchon");
00086 
00087   edm::ParameterSet ParametersDigiADC = conf_.getParameter<edm::ParameterSet>("TProfDigiADC");
00088   layerswitchdigiadcprofon = ParametersDigiProf.getParameter<bool>("layerswitchon");
00089 
00090   edm::ParameterSet ParametersTotDigiProf = conf_.getParameter<edm::ParameterSet>("TProfTotalNumberOfDigis");
00091   subdetswitchtotdigiprofon = ParametersTotDigiProf.getParameter<bool>("subdetswitchon");
00092 
00093   edm::ParameterSet ParametersTotDigisProfVsLS = conf_.getParameter<edm::ParameterSet>("TProfTotalNumberOfDigisVsLS");
00094   subdetswitchtotdigiproflson = ParametersTotDigisProfVsLS.getParameter<bool>("subdetswitchon");
00095 
00096   edm::ParameterSet ParametersTotDigiFailure = conf_.getParameter<edm::ParameterSet>("TotalNumberOfDigisFailure");
00097   subdetswitchtotdigifailureon = ParametersTotDigiFailure.getParameter<bool>("subdetswitchon");
00098 
00099   edm::ParameterSet ParametersDigiApvProf = conf_.getParameter<edm::ParameterSet>("TProfDigiApvCycle");
00100   subdetswitchapvcycleprofon = ParametersDigiApvProf.getParameter<bool>("subdetswitchon");
00101 
00102   edm::ParameterSet ParametersDigiApvTH2 = conf_.getParameter<edm::ParameterSet>("TH2DigiApvCycle");
00103   subdetswitchapvcycleth2on = ParametersDigiApvTH2.getParameter<bool>("subdetswitchon");
00104 
00105   edm::ParameterSet ParametersNApvShots = conf_.getParameter<edm::ParameterSet>("TH1NApvShots");
00106   subdetswitchnapvshotson = ParametersNApvShots.getParameter<bool>("subdetswitchon");
00107 
00108   edm::ParameterSet ParametersNStripApvShots = conf_.getParameter<edm::ParameterSet>("TH1NStripsApvShots");
00109   subdetswitchnstripsapvshotson = ParametersNStripApvShots.getParameter<bool>("subdetswitchon");
00110   
00111   edm::ParameterSet ParametersChargeMedianApvShots = conf_.getParameter<edm::ParameterSet>("TH1ChargeMedianApvShots");
00112   subdetswitchchargemedianapvshotson = ParametersChargeMedianApvShots.getParameter<bool>("subdetswitchon");
00113 
00114   edm::ParameterSet ParametersApvNumberApvShots = conf_.getParameter<edm::ParameterSet>("TH1ApvNumApvShots");
00115   subdetswitchapvshotsApvon = ParametersChargeMedianApvShots.getParameter<bool>("subdetswitchon");
00116 
00117   edm::ParameterSet ParametersNApvShotsProf = conf_.getParameter<edm::ParameterSet>("TProfNShotsVsTime");
00118   subdetswitchapvshotsonprof = ParametersNApvShotsProf.getParameter<bool>("subdetswitchon");
00119 
00120   //Global Histograms
00121 
00122   edm::ParameterSet ParametersGlobalNApvShots = conf_.getParameter<edm::ParameterSet>("TH1NApvShots");
00123   globalswitchnapvshotson = ParametersGlobalNApvShots.getParameter<bool>("globalswitchon");
00124 
00125   edm::ParameterSet ParametersGlobalNApvShotsProf = conf_.getParameter<edm::ParameterSet>("TProfGlobalNShots");
00126   globalsummaryapvshotson = ParametersGlobalNApvShotsProf.getParameter<bool>("globalswitchon");
00127 
00128   edm::ParameterSet ParametersGlobalNStripApvShots = conf_.getParameter<edm::ParameterSet>("TH1NStripsApvShots");
00129   globalswitchnstripsapvshotson = ParametersGlobalNStripApvShots.getParameter<bool>("globalswitchon");
00130 
00131   edm::ParameterSet ParametersGlobalApvNumApvShots = conf_.getParameter<edm::ParameterSet>("TH1ApvNumApvShots");
00132   globalswitchapvshotsApvon = ParametersGlobalApvNumApvShots.getParameter<bool>("globalswitchon");
00133 
00134   edm::ParameterSet ParametersGlobalChargeMedianApvShots = conf_.getParameter<edm::ParameterSet>("TH1ChargeMedianApvShots");
00135   globalswitchchargemedianapvshotson = ParametersGlobalChargeMedianApvShots.getParameter<bool>("globalswitchon");
00136 
00137   edm::ParameterSet ParametersGlobalNApvShotsTimeProf = conf_.getParameter<edm::ParameterSet>("TProfNShotsVsTime");
00138   globalswitchapvshotsonprof = ParametersGlobalNApvShotsTimeProf.getParameter<bool>("globalswitchon");
00139 
00140   //Digi and APV Shots Maps
00141 
00142   digitkhistomapon = conf_.getParameter<bool>("TkHistoMap_On"); 
00143   
00144   shotshistomapon= conf_.getParameter<bool>("TkHistoMapNApvShots_On"); 
00145   shotsstripshistomapon= conf_.getParameter<bool>("TkHistoMapNStripApvShots_On"); 
00146   shotschargehistomapon= conf_.getParameter<bool>("TkHistoMapMedianChargeApvShots_On"); 
00147 
00148   createTrendMEs = conf_.getParameter<bool>("CreateTrendMEs");
00149   Mod_On_ = conf_.getParameter<bool>("Mod_On");
00150   xLumiProf = conf_.getParameter<int>("xLumiProf");
00151   // Event History Producer
00152   historyProducer_ = conf_.getParameter<edm::InputTag>("HistoryProducer");
00153 
00154   // Apv Phase Producer
00155   apvPhaseProducer_ = conf_.getParameter<edm::InputTag>("ApvPhaseProducer");
00156 
00157   // Create DCS Status
00158   bool checkDCS    = conf_.getParameter<bool>("UseDCSFiltering");
00159   if (checkDCS) dcsStatus_ = new SiStripDCSStatus();
00160   else dcsStatus_ = 0; 
00161 
00162   //initialize boolean for the data-presence check (needed for TotalNumberOfDigisFailure histogram)
00163   isStableBeams = false;
00164 }
00165 //------------------------------------------------------------------------------------------
00166 
00167 SiStripMonitorDigi::~SiStripMonitorDigi() { 
00168   if (dcsStatus_) delete dcsStatus_;
00169 }
00170 
00171 //--------------------------------------------------------------------------------------------
00172 void SiStripMonitorDigi::beginRun(const edm::Run& run, const edm::EventSetup& es){
00173 
00174   if (show_mechanical_structure_view) {
00175     unsigned long long cacheID = es.get<SiStripDetCablingRcd>().cacheIdentifier();
00176     if (m_cacheID_ != cacheID) {
00177       m_cacheID_ = cacheID;       
00178       edm::LogInfo("SiStripMonitorDigi") <<"SiStripMonitorDigi::beginRun: " 
00179                                          << " Creating MEs for new Cabling ";     
00180       createMEs(es);
00181     } 
00182   } else if (reset_each_run) {
00183     edm::LogInfo("SiStripMonitorDigi") <<"SiStripMonitorDigi::beginRun: " 
00184                                        << " Resetting MEs ";        
00185     for (std::map<uint32_t, ModMEs >::const_iterator idet = DigiMEs.begin() ; idet!=DigiMEs.end() ; idet++) {
00186       ResetModuleMEs(idet->first);
00187     }
00188   }
00189   
00190   if (subdetswitchtotdigifailureon) {
00191     //get FED cabling to know if SiStrip is in DAQ or no
00192     unsigned long long cacheID = es.get<SiStripDetCablingRcd>().cacheIdentifier();
00193     if (m_cacheID_ != cacheID) {
00194       m_cacheID_ = cacheID;       
00195     }
00196     edm::ESHandle< SiStripDetCabling > detCabling_;
00197     es.get<SiStripDetCablingRcd>().get(detCabling_);
00198     
00199     nFEDConnected = 0;
00200     const int siStripFedIdMin = FEDNumbering::MINSiStripFEDID;
00201     const int siStripFedIdMax = FEDNumbering::MAXSiStripFEDID; 
00202     
00203     edm::eventsetup::EventSetupRecordKey recordKey(edm::eventsetup::EventSetupRecordKey::TypeTag::findType("RunInfoRcd"));
00204     if( es.find( recordKey ) != 0) {
00205       
00206       edm::ESHandle<RunInfo> sumFED;
00207       es.get<RunInfoRcd>().get(sumFED);    
00208       
00209       if ( sumFED.isValid() ) {
00210         std::vector<int> FedsInIds= sumFED->m_fed_in;   
00211         for(unsigned int it = 0; it < FedsInIds.size(); ++it) {
00212           int fedID = FedsInIds[it];     
00213           if(fedID>=siStripFedIdMin &&  fedID<=siStripFedIdMax)  ++nFEDConnected;
00214         }
00215       }
00216     }
00217   }
00218 
00219 }
00220 
00221 //--------------------------------------------------------------------------------------------
00222 void SiStripMonitorDigi::endRun(const edm::Run&, const edm::EventSetup&){
00223 }
00224 
00225 //--------------------------------------------------------------------------------------------
00226 void SiStripMonitorDigi::beginLuminosityBlock(const edm::LuminosityBlock& lb, const edm::EventSetup& es){
00227   if (subdetswitchtotdigiproflson){
00228     if (digiFailureMEs.SubDetTotDigiProfLS) digiFailureMEs.SubDetTotDigiProfLS->Reset();
00229   }
00230   if (subdetswitchtotdigifailureon) 
00231     isStableBeams = false;
00232 }
00233 
00234 //--------------------------------------------------------------------------------------------
00235 void SiStripMonitorDigi::endLuminosityBlock(const edm::LuminosityBlock& lb, const edm::EventSetup& es) {
00236 
00237   if (subdetswitchtotdigifailureon){
00238     MonitorElement * me = dqmStore_->get("SiStrip/MechanicalView/NumberOfDigisInLastLS");     
00239     if (me) {
00240       
00241       for (int ibin = 1; ibin<7;ibin++){
00242         
00243         float value = me->getBinContent(ibin);
00244         if ( isStableBeams && nFEDConnected > 100 && value < 50. ){
00245           digiFailureMEs.SubDetDigiFailures2D -> Fill(lb.id().luminosityBlock() , ibin-1 , 0.01);
00246         }
00247         else{
00248           digiFailureMEs.SubDetDigiFailures2D -> Fill(lb.id().luminosityBlock() , ibin-1 , 1);
00249         }
00250       }
00251     }
00252   }
00253 }
00254 //--------------------------------------------------------------------------------------------
00255 void SiStripMonitorDigi::beginJob(){
00256 }
00257 
00258 
00259 //--------------------------------------------------------------------------------------------
00260 void SiStripMonitorDigi::createMEs(const edm::EventSetup& es){
00261 
00262   if ( show_mechanical_structure_view ){
00263 
00264     //Retrieve tracker topology from geometry
00265     edm::ESHandle<TrackerTopology> tTopoHandle;
00266     es.get<IdealGeometryRecord>().get(tTopoHandle);
00267     const TrackerTopology* const tTopo = tTopoHandle.product();
00268 
00269     // take from eventSetup the SiStripDetCabling object - here will use SiStripDetControl later on
00270     es.get<SiStripDetCablingRcd>().get(SiStripDetCabling_);
00271     
00272     // get list of active detectors from SiStripDetCabling
00273     std::vector<uint32_t> activeDets; 
00274     activeDets.clear(); // just in case
00275     SiStripDetCabling_->addActiveDetectorsRawIds(activeDets);
00276 
00277     SiStripSubStructure substructure;
00278 
00279     // remove any eventual zero elements - there should be none, but just in case
00280     for(std::vector<uint32_t>::iterator idets = activeDets.begin(); idets != activeDets.end(); idets++){
00281       if(*idets == 0) activeDets.erase(idets);
00282     }
00283     
00284     // create SiStripFolderOrganizer
00285     SiStripFolderOrganizer folder_organizer;
00286 
00287     // Create TkHistoMap for Digi and APV shots properies
00288     
00289     if (digitkhistomapon) tkmapdigi = new TkHistoMap("SiStrip/TkHisto","TkHMap_NumberOfDigi",0.0,1);
00290     if (shotshistomapon)  tkmapNApvshots = new TkHistoMap("SiStrip/TkHisto","TkHMap_NApvShots",0.0,1);
00291     if (shotsstripshistomapon) tkmapNstripApvshot= new TkHistoMap("SiStrip/TkHisto","TkHMap_NStripApvShots",0.0,1);
00292     if (shotschargehistomapon) tkmapMedianChargeApvshots= new TkHistoMap("SiStrip/TkHisto","TkHMap_MedianChargeApvShots",0.0,1);
00293     
00294     std::vector<uint32_t> tibDetIds;
00295     
00296     // loop over detectors and book MEs
00297     edm::LogInfo("SiStripTkDQM|SiStripMonitorDigi")<<"nr. of activeDets:  "<<activeDets.size();
00298     for(std::vector<uint32_t>::const_iterator detid_iterator = activeDets.begin(); detid_iterator!=activeDets.end(); detid_iterator++){
00299 
00300       uint32_t detid = (*detid_iterator);
00301 
00302       ModMEs local_modmes;
00303       
00304       local_modmes.NumberOfDigis = 0;
00305       local_modmes.NumberOfDigisPerStrip = 0;
00306       local_modmes.ADCsHottestStrip = 0;
00307       local_modmes.ADCsCoolestStrip = 0;
00308       local_modmes.DigiADCs = 0;
00309       local_modmes.StripOccupancy = 0;
00310 
00311       if (Mod_On_) {
00312 
00313         // set appropriate folder using SiStripFolderOrganizer
00314         folder_organizer.setDetectorFolder(detid, tTopo); // pass the detid to this method
00315         if (reset_each_run) ResetModuleMEs(detid);
00316         createModuleMEs(local_modmes, detid);
00317 
00318         // append to DigiMEs
00319         DigiMEs.insert( std::make_pair(detid, local_modmes));
00320       }
00321 
00322       // Create Layer Level MEs if they are not created already
00323       std::pair<std::string,int32_t> det_layer_pair = folder_organizer.GetSubDetAndLayer(detid, tTopo);
00324       SiStripHistoId hidmanager;
00325       std::string label = hidmanager.getSubdetid(detid,tTopo,false);
00326       
00327       // get detids for the layer
00328       std::map<std::string, LayerMEs>::iterator iLayerME  = LayerMEsMap.find(label);
00329 
00330       if(iLayerME==LayerMEsMap.end()) {
00331         int32_t lnumber = det_layer_pair.second;
00332         std::vector<uint32_t> layerDetIds;
00333         if (det_layer_pair.first == "TIB") {
00334           substructure.getTIBDetectors(activeDets,layerDetIds,lnumber,0,0,0);
00335         } else if (det_layer_pair.first == "TOB") {
00336           substructure.getTOBDetectors(activeDets,layerDetIds,lnumber,0,0);
00337         } else if (det_layer_pair.first == "TID" && lnumber > 0) {
00338           substructure.getTIDDetectors(activeDets,layerDetIds,2,abs(lnumber),0,0);
00339         } else if (det_layer_pair.first == "TID" && lnumber < 0) {
00340           substructure.getTIDDetectors(activeDets,layerDetIds,1,abs(lnumber),0,0);
00341         } else if (det_layer_pair.first == "TEC" && lnumber > 0) {
00342           substructure.getTECDetectors(activeDets,layerDetIds,2,abs(lnumber),0,0,0,0);
00343         } else if (det_layer_pair.first == "TEC" && lnumber < 0) {
00344           substructure.getTECDetectors(activeDets,layerDetIds,1,abs(lnumber),0,0,0,0);
00345         }
00346 
00347         LayerDetMap[label] = layerDetIds;
00348 
00349         // book Layer plots      
00350         folder_organizer.setLayerFolder(detid,tTopo,det_layer_pair.second); 
00351         createLayerMEs(label, layerDetIds.size());
00352       }
00353       
00354       // book sub-detector plots
00355       std::pair<std::string,std::string> sdet_pair = folder_organizer.getSubDetFolderAndTag(detid, tTopo);
00356       if (SubDetMEsMap.find(sdet_pair.second) == SubDetMEsMap.end()){
00357         dqmStore_->setCurrentFolder(sdet_pair.first);
00358         createSubDetMEs(sdet_pair.second);        
00359       }
00360 
00361     }//end of loop over detectors
00362 
00363     //book some Summary histograms on APV shots in the MechanicalView
00364 
00365     dqmStore_->setCurrentFolder("SiStrip/MechanicalView/");
00366 
00367     if (globalsummaryapvshotson) {
00368       const char* HistoName = "Summary Mean Apv shots for SubDets";
00369       NApvShotsGlobalProf= dqmStore_->bookProfile(HistoName, HistoName,
00370                                               6,0.5,6.5,
00371                                               100, 0., 0., "" );
00372       NApvShotsGlobalProf->setBinLabel(1, std::string("TECB"));
00373       NApvShotsGlobalProf->setBinLabel(2, std::string("TECF"));
00374       NApvShotsGlobalProf->setBinLabel(3, std::string("TIB"));
00375       NApvShotsGlobalProf->setBinLabel(4, std::string("TIDB"));
00376       NApvShotsGlobalProf->setBinLabel(5, std::string("TIDF"));
00377       NApvShotsGlobalProf->setBinLabel(6, std::string("TOB"));
00378       NApvShotsGlobalProf->setAxisTitle(" mean APV shots # / evt",2);
00379     }
00380 
00381     //cumulative number of APV shots Vs Time
00382     if (globalswitchapvshotsonprof){
00383       edm::ParameterSet Parameters =  conf_.getParameter<edm::ParameterSet>("TProfNShotsVsTime");
00384       const char* HistoName = "NApv_Shots_vs_Time";
00385       ShotsVsTimeApvShotsGlobal=dqmStore_->bookProfile(HistoName,HistoName,
00386                                                            Parameters.getParameter<int32_t>("Nbins"),
00387                                                            Parameters.getParameter<double>("xmin"),
00388                                                            Parameters.getParameter<double>("xmax"),
00389                                                            200, //that parameter should not be there !?
00390                                                            Parameters.getParameter<double>("ymin"),
00391                                                            Parameters.getParameter<double>("ymax"),
00392                                                            "" );
00393       ShotsVsTimeApvShotsGlobal->setAxisTitle("Time (s)",1);
00394       ShotsVsTimeApvShotsGlobal->setAxisTitle("# Apv Shots",2);
00395       if (ShotsVsTimeApvShotsGlobal->kind() == MonitorElement::DQM_KIND_TPROFILE) ShotsVsTimeApvShotsGlobal->getTH1()->SetBit(TH1::kCanRebin);
00396     }
00397 
00398     //cumulative number of Strips in APV shots
00399     if (globalswitchnstripsapvshotson){
00400       edm::ParameterSet Parameters =  conf_.getParameter<edm::ParameterSet>("TH1NStripsApvShots");
00401       const char* HistoName = "Number_of_Strips_in_Apv_Shots";
00402       StripMultiplicityApvShotsGlobal=dqmStore_->book1D(HistoName,HistoName,
00403                                                            Parameters.getParameter<int32_t>("Nbins"),
00404                                                            Parameters.getParameter<double>("xmin"),
00405                                                            Parameters.getParameter<double>("xmax"));
00406       StripMultiplicityApvShotsGlobal->setAxisTitle("# strips in Apv Shots",1);
00407     }
00408 
00409     //cumulative number of APV shots
00410     if (globalswitchnapvshotson){
00411         edm::ParameterSet Parameters =  conf_.getParameter<edm::ParameterSet>("TH1NApvShots");
00412         const char* HistoName = "Number_of_Apv_Shots";
00413         NApvShotsGlobal=dqmStore_->book1D(HistoName,HistoName,
00414                                                        Parameters.getParameter<int32_t>("Nbins"),
00415                                                        Parameters.getParameter<double>("xmin"),
00416                                                        Parameters.getParameter<double>("xmax"));
00417         NApvShotsGlobal->setAxisTitle("# Apv Shots",1);
00418     }
00419 
00420     //cumulative Median Charge in APV shots
00421     if (globalswitchchargemedianapvshotson){
00422       edm::ParameterSet Parameters =  conf_.getParameter<edm::ParameterSet>("TH1ChargeMedianApvShots");
00423       //dqmStore_->setCurrentFolder("SiStrip/MechanicalView/"+label);
00424       const char* HistoName = "Apv_Shots_Charge_Median";
00425       MedianChargeApvShotsGlobal=dqmStore_->book1D(HistoName,HistoName,
00426                                                                 Parameters.getParameter<int32_t>("Nbins"),
00427                                                                 Parameters.getParameter<double>("xmin"),
00428                                                                 Parameters.getParameter<double>("xmax"));
00429       MedianChargeApvShotsGlobal->setAxisTitle("Apv Shots Charge Median (ADC)",1);
00430     }
00431 
00432     //cmulative APV number with shots
00433     if (globalswitchapvshotsApvon){
00434       edm::ParameterSet Parameters =  conf_.getParameter<edm::ParameterSet>("TH1ApvNumApvShots");
00435       //dqmStore_->setCurrentFolder("SiStrip/MechanicalView/"+label);
00436       const char* HistoName = "Apv_Shots_Apv_Number";
00437       NApvApvShotsGlobal=dqmStore_->book1D(HistoName,HistoName,
00438                                                          Parameters.getParameter<int32_t>("Nbins"),
00439                                                          Parameters.getParameter<double>("xmin"),
00440                                                          Parameters.getParameter<double>("xmax"));
00441       NApvApvShotsGlobal->setAxisTitle("Apv Number",1);
00442     }
00443 
00444     //
00445     // Book new histogram to monitor digi in last LS
00446     //
00447 
00448     digiFailureMEs.SubDetTotDigiProfLS = 0;
00449     digiFailureMEs.SubDetDigiFailures2D  = 0;
00450 
00451     std::stringstream ss;
00452 
00453     folder_organizer.getLayerFolderName(ss, 0, tTopo);
00454     dqmStore_->setCurrentFolder(ss.str().c_str());
00455 
00456     if (subdetswitchtotdigiproflson) {
00457       const char* HistoName = "NumberOfDigisInLastLS";
00458       digiFailureMEs.SubDetTotDigiProfLS= dqmStore_->bookProfile(HistoName, HistoName,
00459                                                                6,0.5,6.5,
00460                                           100, 0., 10000., "" );
00461       digiFailureMEs.SubDetTotDigiProfLS->setBinLabel(1, std::string("TECB"));
00462       digiFailureMEs.SubDetTotDigiProfLS->setBinLabel(2, std::string("TECF"));
00463       digiFailureMEs.SubDetTotDigiProfLS->setBinLabel(3, std::string("TIB"));
00464       digiFailureMEs.SubDetTotDigiProfLS->setBinLabel(4, std::string("TIDB"));
00465       digiFailureMEs.SubDetTotDigiProfLS->setBinLabel(5, std::string("TIDF"));
00466       digiFailureMEs.SubDetTotDigiProfLS->setBinLabel(6, std::string("TOB"));
00467     }
00468 
00469     if (subdetswitchtotdigifailureon) {
00470       std::string HistoName = "DataPresentInLS";
00471       edm::ParameterSet Parameters =  conf_.getParameter<edm::ParameterSet>("TotalNumberOfDigisFailure");
00472 
00473       digiFailureMEs.SubDetDigiFailures2D = dqmStore_->book2D(HistoName,HistoName,
00474                                                               Parameters.getParameter<int32_t>("Nbins"), //bins X
00475                                                               1, //xmin
00476                                                               Parameters.getParameter<int32_t>("Nbins") + 1, //xmax
00477                                                               6, //bins Y
00478                                                               0, //ymin
00479                                                               6); //ymax
00480 
00481       digiFailureMEs.SubDetDigiFailures2D->setBinLabel(1, std::string("TEC-") , 2 );
00482       digiFailureMEs.SubDetDigiFailures2D->setBinLabel(2, std::string("TEC+") , 2 );
00483       digiFailureMEs.SubDetDigiFailures2D->setBinLabel(3, std::string("TIB")  , 2 );
00484       digiFailureMEs.SubDetDigiFailures2D->setBinLabel(4, std::string("TID-") , 2 );
00485       digiFailureMEs.SubDetDigiFailures2D->setBinLabel(5, std::string("TID+") , 2 );
00486       digiFailureMEs.SubDetDigiFailures2D->setBinLabel(6, std::string("TOB")  , 2 );
00487       digiFailureMEs.SubDetDigiFailures2D->setAxisTitle("Luminosity Section");
00488     }
00489   }//end of if
00490 
00491 }//end of method
00492 
00493 //--------------------------------------------------------------------------------------------
00494 void SiStripMonitorDigi::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup){
00495 
00496   // Filter out events if DCS Event if requested
00497   if (dcsStatus_ && !dcsStatus_->getStatus(iEvent, iSetup)) return;
00498 
00499   //Retrieve tracker topology from geometry
00500   edm::ESHandle<TrackerTopology> tTopoHandle;
00501   iSetup.get<IdealGeometryRecord>().get(tTopoHandle);
00502   const TrackerTopology* const tTopo = tTopoHandle.product();
00503 
00504   TotalNShots=0;
00505 
00506   runNb   = iEvent.id().run();
00507   eventNb++;
00508 
00509   float iOrbitSec      = iEvent.orbitNumber()/11223.0;
00510 
00511   digi_detset_handles.clear();
00512   for(std::vector<edm::InputTag>::iterator itDigiProducerList = digiProducerList.begin();
00513      itDigiProducerList != digiProducerList.end(); ++itDigiProducerList ) {
00514 
00515     edm::Handle< edm::DetSetVector<SiStripDigi> > digi_handle;
00516 
00517     iEvent.getByLabel((*itDigiProducerList),digi_handle);
00518 
00519     if (digi_handle.isValid()) digi_detset_handles.push_back(digi_handle.product());
00520   }    
00521 
00522   // initialise # of clusters to zero
00523   for (std::map<std::string, SubDetMEs>::iterator iSubdet  = SubDetMEsMap.begin();
00524        iSubdet != SubDetMEsMap.end(); iSubdet++) {
00525     iSubdet->second.totNDigis = 0;
00526     iSubdet->second.SubDetApvShots.clear();
00527   }
00528 
00529   for (std::map<std::string, std::vector< uint32_t > >::const_iterator iterLayer = LayerDetMap.begin();
00530        iterLayer != LayerDetMap.end(); iterLayer++) {
00531     
00532     std::string layer_label = iterLayer->first;
00533     
00534     std::vector< uint32_t > layer_dets = iterLayer->second;
00535     std::map<std::string, LayerMEs>::iterator iLayerME = LayerMEsMap.find(layer_label);
00536       
00537     //get Layer MEs 
00538     LayerMEs local_layermes;
00539 
00540     if(iLayerME == LayerMEsMap.end()) continue;
00541     else local_layermes = iLayerME->second; 
00542 
00543     int largest_adc_layer= 0;
00544     int smallest_adc_layer= 99999;
00545 
00546     int ndigi_layer = 0;
00547 
00548     uint16_t iDet = 0;
00549 
00550     std::string subdet_label = ""; 
00551 
00552     // loop over all modules in the layer
00553     for (std::vector< uint32_t >::const_iterator iterDets = layer_dets.begin() ; 
00554          iterDets != layer_dets.end() ; iterDets++) {
00555       iDet++;
00556       
00557       // detid and type of ME
00558       uint32_t detid = (*iterDets);
00559         
00560       // Get SubDet label once
00561       if (subdet_label.size() == 0) subdet_label = folder_organizer.getSubDetFolderAndTag(detid, tTopo).second;
00562 
00563       // DetId and corresponding set of MEs
00564 
00565       std::map<uint32_t, ModMEs >::iterator pos = DigiMEs.find(detid);
00566       ModMEs local_modmes = pos->second;
00567         
00568       // search  digis of detid
00569       int loc = getDigiSourceIndex(detid); 
00570       
00571       int ndigi_det = 0;
00572       
00573       if (loc > -1) {   
00574         ndigi_det = (*(digi_detset_handles[loc]))[detid].size();
00575         APVShotFinder theShotFinder = APVShotFinder((*(digi_detset_handles[loc]))[detid]);
00576         const std::vector<APVShot>& shots = theShotFinder.getShots();
00577         AddApvShotsToSubDet(shots,SubDetMEsMap[subdet_label].SubDetApvShots);
00578         if (shotshistomapon) tkmapNApvshots->fill(detid,shots.size());
00579         if (shotsstripshistomapon) FillApvShotsMap(tkmapNstripApvshot,shots,detid,1);
00580         if (shotschargehistomapon) FillApvShotsMap(tkmapMedianChargeApvshots,shots,detid,2);
00581       }
00582 
00583       if(Mod_On_ && moduleswitchnumdigison && (local_modmes.NumberOfDigis != NULL))
00584         (local_modmes.NumberOfDigis)->Fill(ndigi_det); 
00585       
00586       if (layerswitchnumdigisprofon) 
00587         local_layermes.LayerNumberOfDigisProfile->Fill(iDet*1.0,ndigi_det);
00588 
00589       if (digitkhistomapon) tkmapdigi->fill(detid,ndigi_det);
00590 
00591       if (ndigi_det == 0) continue; // no digis for this detid => jump to next step of loop
00592      
00593       const edm::DetSet<SiStripDigi> & digi_detset = (*(digi_detset_handles[loc]))[detid]; 
00594 
00595       ndigi_layer += ndigi_det;         
00596 
00597       // ADCs
00598       int largest_adc=(digi_detset.data.begin())->adc();
00599       int smallest_adc=(digi_detset.data.begin())->adc();
00600       
00601 
00602       // Check if these parameters are really needed
00603       float det_occupancy = 0.0;
00604       
00605       for(edm::DetSet<SiStripDigi>::const_iterator digiIter = digi_detset.data.begin(); 
00606           digiIter!= digi_detset.data.end(); digiIter++ ){
00607         
00608         int this_adc = digiIter->adc();
00609         
00610         if (this_adc > 0.0) det_occupancy++;
00611         
00612         if(this_adc>largest_adc) largest_adc  = this_adc; 
00613         if(this_adc<smallest_adc) smallest_adc  = this_adc; 
00614 
00615         if(Mod_On_ && moduleswitchnumdigispstripon && (local_modmes.NumberOfDigisPerStrip != NULL) && (this_adc > 0.0) )
00616           (local_modmes.NumberOfDigisPerStrip)->Fill(digiIter->strip());
00617 
00618         if(Mod_On_ && moduleswitchdigiadcson && (local_modmes.DigiADCs != NULL) )
00619           (local_modmes.DigiADCs)->Fill(static_cast<float>(this_adc));
00620         
00621         //Fill #ADCs for this digi at layer level
00622         if(layerswitchdigiadcson) {
00623           fillME(local_layermes.LayerDigiADCs , this_adc);
00624           if (createTrendMEs) fillTrend(local_layermes.LayerDigiADCsTrend, this_adc, iOrbitSec);
00625         }
00626         
00627         if (layerswitchdigiadcprofon) 
00628           local_layermes.LayerDigiADCProfile->Fill(iDet*1.0,this_adc);
00629         
00630       }//end of loop over digis in this det
00631       
00632       // Occupancy
00633       short nstrips = SiStripDetCabling_->nApvPairs(detid) * 2 * 128;
00634       if (nstrips > 0 && det_occupancy > 0 ) {
00635         det_occupancy = det_occupancy/nstrips;
00636         if (Mod_On_ && moduleswitchstripoccupancyon && (local_modmes.StripOccupancy != NULL))
00637           (local_modmes.StripOccupancy)->Fill(det_occupancy);
00638         if (layerswitchstripoccupancyon) {
00639           fillME(local_layermes.LayerStripOccupancy, det_occupancy);
00640           if (createTrendMEs) fillTrend(local_layermes.LayerStripOccupancyTrend, det_occupancy, iOrbitSec);
00641         }
00642       }
00643       
00644       if  (largest_adc > largest_adc_layer) largest_adc_layer = largest_adc;
00645       if  (smallest_adc < smallest_adc_layer) smallest_adc_layer = smallest_adc;
00646       
00647       // nr. of adcs for hottest strip
00648       if( Mod_On_ && moduleswitchadchotteston && (local_modmes.ADCsHottestStrip != NULL)) 
00649         (local_modmes.ADCsHottestStrip)->Fill(static_cast<float>(largest_adc));
00650       
00651       // nr. of adcs for coolest strip  
00652       if(Mod_On_ && moduleswitchadccooleston && (local_modmes.ADCsCoolestStrip != NULL)) 
00653         (local_modmes.ADCsCoolestStrip)->Fill(static_cast<float>(smallest_adc));
00654       
00655     }//end of loop over DetIds
00656     
00657     if(layerswitchnumdigison) {
00658       fillME(local_layermes.LayerNumberOfDigis,ndigi_layer);
00659       if (createTrendMEs) fillTrend(local_layermes.LayerNumberOfDigisTrend, ndigi_layer, iOrbitSec);
00660     }
00661     if(layerswitchadchotteston) {
00662       fillME(local_layermes.LayerADCsHottestStrip,largest_adc_layer);
00663       if (createTrendMEs) fillTrend(local_layermes.LayerADCsHottestStripTrend, largest_adc_layer, iOrbitSec);
00664     }
00665     if(layerswitchadccooleston) {
00666       fillME(local_layermes.LayerADCsCoolestStrip ,smallest_adc_layer);
00667       if (createTrendMEs) fillTrend(local_layermes.LayerADCsCoolestStripTrend, smallest_adc_layer, iOrbitSec);
00668     }
00669 
00670     std::map<std::string, SubDetMEs>::iterator iSubdet  = SubDetMEsMap.find(subdet_label);
00671     if(iSubdet != SubDetMEsMap.end()) {
00672       iSubdet->second.totNDigis += ndigi_layer;  
00673       //std::cout << " totDigis" <<  iSubdet->second.totNDigis << " in "  << subdet_label << std::endl;    
00674     }
00675   }
00676   
00677   if (subdetswitchtotdigifailureon) {
00678 
00679     //check Stable beams bit
00680     edm::Handle<L1GlobalTriggerEvmReadoutRecord> gtEvm_handle;
00681     iEvent.getByLabel("gtEvmDigis", gtEvm_handle);
00682     L1GlobalTriggerEvmReadoutRecord const* gtevm = gtEvm_handle.product();
00683     
00684     L1GtfeExtWord gtfeEvmExtWord;
00685     if (gtevm)
00686       {
00687         gtfeEvmExtWord = gtevm->gtfeWord();
00688       }
00689     else
00690       edm::LogInfo("DQMProvInfo") << " gtfeEvmWord inaccessible" ;
00691     
00692     if ( gtfeEvmExtWord.beamMode() == 11 )
00693       isStableBeams = true;
00694   }
00695 
00696   for (std::map<std::string, SubDetMEs>::iterator it = SubDetMEsMap.begin();
00697        it != SubDetMEsMap.end(); it++) {
00698 
00699       if (subdetswitchtotdigiproflson) {
00700         if (strcmp(it->first.c_str(),"TEC__side__1")==0){
00701           digiFailureMEs.SubDetTotDigiProfLS->Fill(1, it->second.totNDigis);
00702         }else if (strcmp(it->first.c_str(),"TEC__side__2")==0){
00703           digiFailureMEs.SubDetTotDigiProfLS->Fill(2, it->second.totNDigis);
00704         }else if (strcmp(it->first.c_str(),"TIB")==0){
00705           digiFailureMEs.SubDetTotDigiProfLS->Fill(3, it->second.totNDigis);
00706         }else if (strcmp(it->first.c_str(),"TID__side__1")==0){
00707           digiFailureMEs.SubDetTotDigiProfLS->Fill(4, it->second.totNDigis);
00708         }else if (strcmp(it->first.c_str(),"TID__side__2")==0){
00709           digiFailureMEs.SubDetTotDigiProfLS->Fill(5, it->second.totNDigis);
00710         }else if (strcmp(it->first.c_str(),"TOB")==0){
00711           digiFailureMEs.SubDetTotDigiProfLS->Fill(6, it->second.totNDigis);      
00712         }
00713       }
00714 
00715       if (globalsummaryapvshotson) {
00716         if (strcmp(it->first.c_str(),"TEC__side__1")==0){
00717           NApvShotsGlobalProf->Fill(1,it->second.SubDetApvShots.size());
00718         }else if (strcmp(it->first.c_str(),"TEC__side__2")==0){
00719           NApvShotsGlobalProf->Fill(2,it->second.SubDetApvShots.size());
00720         }else if (strcmp(it->first.c_str(),"TIB")==0){
00721           NApvShotsGlobalProf->Fill(3,it->second.SubDetApvShots.size());
00722         }else if (strcmp(it->first.c_str(),"TID__side__1")==0){
00723           NApvShotsGlobalProf->Fill(4,it->second.SubDetApvShots.size());
00724         }else if (strcmp(it->first.c_str(),"TID__side__2")==0){
00725           NApvShotsGlobalProf->Fill(5,it->second.SubDetApvShots.size());
00726         }else if (strcmp(it->first.c_str(),"TOB")==0){
00727           NApvShotsGlobalProf->Fill(6,it->second.SubDetApvShots.size());
00728         }
00729       }
00730 
00731       SubDetMEs subdetmes= it->second;
00732       std::string subdet = it->first;
00733 
00734       // Fill APV shots histograms for SubDet
00735 
00736       uint ShotsSize=subdetmes.SubDetApvShots.size();
00737       TotalNShots+=ShotsSize; //Counter for total Shots in the SiStrip Tracker
00738 
00739       if (subdetswitchnapvshotson ) subdetmes.SubDetNApvShotsTH1->Fill(ShotsSize);// N shots
00740       if (subdetswitchapvshotsonprof) subdetmes.SubDetNApvShotsProf ->Fill(iOrbitSec,ShotsSize); //N shots vs time
00741 
00742       for (uint i=0; i< ShotsSize; ++i){ // Strip multiplicity, charge median and APV number distributions for APV shots
00743         
00744         if (subdetswitchapvshotsApvon) subdetmes.SubDetNApvShotsNApvTH1->Fill((subdetmes.SubDetApvShots[i].apvNumber()+1));//APV are defined by 0 to 5 I want 1 to 6
00745         if (globalswitchapvshotsApvon)  NApvApvShotsGlobal->Fill((subdetmes.SubDetApvShots[i].apvNumber()+1));
00746 
00747         if (subdetswitchnstripsapvshotson) subdetmes.SubDetNStripsApvShotsTH1->Fill(subdetmes.SubDetApvShots[i].nStrips());
00748         if (globalswitchnstripsapvshotson) StripMultiplicityApvShotsGlobal->Fill(subdetmes.SubDetApvShots[i].nStrips());
00749 
00750         if (subdetswitchchargemedianapvshotson) subdetmes.SubDetChargeMedianApvShotsTH1->Fill(subdetmes.SubDetApvShots[i].median());
00751         if (globalswitchchargemedianapvshotson)  MedianChargeApvShotsGlobal->Fill(subdetmes.SubDetApvShots[i].median());
00752         
00753       }
00754       
00755       if (subdetswitchtotdigiprofon)subdetmes.SubDetTotDigiProf->Fill(iOrbitSec,subdetmes.totNDigis);
00756   }
00757 
00758   if (globalswitchnapvshotson) NApvShotsGlobal->Fill(TotalNShots);
00759   if (globalswitchapvshotsonprof) ShotsVsTimeApvShotsGlobal->Fill(iOrbitSec,TotalNShots);
00760 
00761   // get EventHistory 
00762 
00763   edm::Handle<EventWithHistory> event_history;
00764   iEvent.getByLabel(historyProducer_,event_history);  
00765 
00766   // get Phase of APV
00767   edm::Handle<APVCyclePhaseCollection> apv_phase_collection;
00768   iEvent.getByLabel(apvPhaseProducer_,apv_phase_collection);
00769 
00770   if (event_history.isValid() 
00771       && !event_history.failedToGet()
00772       && apv_phase_collection.isValid() 
00773       && !apv_phase_collection.failedToGet()) {
00774 
00775     
00776     long long tbx = event_history->absoluteBX();
00777 
00778 
00779     for (std::map<std::string, SubDetMEs>::iterator it = SubDetMEsMap.begin();
00780          it != SubDetMEsMap.end(); it++) {
00781 
00782       SubDetMEs subdetmes;
00783       std::string subdet = it->first;
00784       subdetmes = it->second;
00785  
00786       int the_phase = APVCyclePhaseCollection::invalid;
00787       long long tbx_corr = tbx;
00788 
00789       if (SubDetPhasePartMap.find(subdet) != SubDetPhasePartMap.end()) the_phase = apv_phase_collection->getPhase(SubDetPhasePartMap[subdet]);
00790       if(the_phase==APVCyclePhaseCollection::nopartition ||
00791          the_phase==APVCyclePhaseCollection::multiphase ||
00792          the_phase==APVCyclePhaseCollection::invalid) the_phase=30;
00793       tbx_corr  -= the_phase;
00794       
00795       if (subdetswitchapvcycleprofon)subdetmes.SubDetDigiApvProf->Fill(tbx_corr%70,subdetmes.totNDigis);
00796       if (subdetswitchapvcycleth2on) subdetmes.SubDetDigiApvTH2->Fill(tbx_corr%70,subdetmes.totNDigis); 
00797     }
00798   }
00799 }//end of method analyze
00800 //--------------------------------------------------------------------------------------------
00801 
00802 void SiStripMonitorDigi::endJob(void){
00803   bool outputMEsInRootFile = conf_.getParameter<bool>("OutputMEsInRootFile");
00804   std::string outputFileName = conf_.getParameter<std::string>("OutputFileName");
00805 
00806   // save histograms in a file
00807   if(outputMEsInRootFile)     dqmStore_->save(outputFileName);
00808   
00809 }//end of method
00810 //--------------------------------------------------------------------------------------------
00811 void SiStripMonitorDigi::ResetModuleMEs(uint32_t idet){
00812   std::map<uint32_t, ModMEs >::iterator pos = DigiMEs.find(idet);
00813   ModMEs mod_me = pos->second;
00814 
00815   if(Mod_On_ && moduleswitchnumdigison) mod_me.NumberOfDigis->Reset();
00816   if(Mod_On_ && moduleswitchnumdigispstripon) mod_me.NumberOfDigisPerStrip ->Reset();
00817   if(Mod_On_ && moduleswitchadchotteston) mod_me.ADCsHottestStrip->Reset();
00818   if(Mod_On_ && moduleswitchadccooleston) mod_me.ADCsCoolestStrip->Reset();
00819   if(Mod_On_ && moduleswitchdigiadcson) mod_me.DigiADCs->Reset();
00820   if(Mod_On_ && moduleswitchstripoccupancyon) mod_me.StripOccupancy->Reset();
00821 
00822 }
00823 //------------------------------------------------------------------------------------------
00824 MonitorElement* SiStripMonitorDigi::bookMETrend(const char* ParameterSetLabel, const char* HistoName)
00825 {
00826   edm::ParameterSet ParametersTrend =  conf_.getParameter<edm::ParameterSet>("Trending");
00827   MonitorElement* me = dqmStore_->bookProfile(HistoName,HistoName,
00828                                               ParametersTrend.getParameter<int32_t>("Nbins"),
00829                                               //                                              0,
00830                                               ParametersTrend.getParameter<double>("xmin"),
00831                                               ParametersTrend.getParameter<double>("xmax"),
00832                                               //                                              ParametersTrend.getParameter<int32_t>("Nbins"),
00833                                               100, //that parameter should not be there !?
00834                                               ParametersTrend.getParameter<double>("ymin"),
00835                                               ParametersTrend.getParameter<double>("ymax"),
00836                                               "" );
00837   if(!me) return me;
00838 
00839   me->setAxisTitle("Event Time in Seconds",1);
00840   if (me->kind() == MonitorElement::DQM_KIND_TPROFILE) me->getTH1()->SetBit(TH1::kCanRebin);
00841   return me;
00842 }
00843 
00844 //------------------------------------------------------------------------------------------
00845 MonitorElement* SiStripMonitorDigi::bookME1D(const char* ParameterSetLabel, const char* HistoName)
00846 {
00847   edm::ParameterSet Parameters =  conf_.getParameter<edm::ParameterSet>(ParameterSetLabel);
00848   return dqmStore_->book1D(HistoName,HistoName,
00849                            Parameters.getParameter<int32_t>("Nbinx"),
00850                            Parameters.getParameter<double>("xmin"),
00851                            Parameters.getParameter<double>("xmax")
00852                            );
00853 }
00854 
00855 //--------------------------------------------------------------------------------
00856 void SiStripMonitorDigi::fillTrend(MonitorElement* me ,float value, float timeinorbit)
00857 {
00858   if(!me) return;
00859   me->Fill(timeinorbit,value);
00860 }
00861 
00862 //
00863 // -- Create Module Level MEs
00864 //
00865 void SiStripMonitorDigi::createModuleMEs(ModMEs& mod_single, uint32_t detid) {
00866 
00867   // use SistripHistoId for producing histogram id (and title)
00868   SiStripHistoId hidmanager;
00869   std::string hid;
00870   
00871   //nr. of digis per module
00872   if(moduleswitchnumdigison) {
00873     hid = hidmanager.createHistoId("NumberOfDigis","det",detid);
00874     mod_single.NumberOfDigis = dqmStore_->book1D(hid, hid, 21, -0.5, 20.5);
00875     dqmStore_->tag(mod_single.NumberOfDigis, detid);
00876     mod_single.NumberOfDigis->setAxisTitle("number of digis in one detector module");
00877     mod_single.NumberOfDigis->getTH1()->StatOverflows(kTRUE);  // over/underflows in Mean calculation
00878   }
00879   
00880   //nr. of digis per strip in module
00881   if(moduleswitchnumdigispstripon){
00882     hid = hidmanager.createHistoId("NumberOfDigisPerStrip","det",detid);
00883     short nstrips = SiStripDetCabling_->nApvPairs(detid) * 2 * 128; 
00884     mod_single.NumberOfDigisPerStrip = dqmStore_->book1D(hid, hid, nstrips, -0.5, nstrips+0.5);
00885     dqmStore_->tag(mod_single.NumberOfDigisPerStrip, detid);
00886     mod_single.NumberOfDigisPerStrip->setAxisTitle("number of (digis > 0) per strip");
00887     mod_single.NumberOfDigisPerStrip->getTH1()->StatOverflows(kTRUE);  // over/underflows in Mean calculation
00888   }
00889   //#ADCs for hottest strip
00890   if(moduleswitchadchotteston) {
00891     hid = hidmanager.createHistoId("ADCsHottestStrip","det",detid);
00892     mod_single.ADCsHottestStrip = bookME1D("TH1ADCsHottestStrip", hid.c_str());
00893     dqmStore_->tag(mod_single.ADCsHottestStrip, detid); // 6 APVs -> 768 strips
00894     mod_single.ADCsHottestStrip->setAxisTitle("number of ADCs for hottest strip");
00895   }
00896   
00897   //#ADCs for coolest strip
00898   if(moduleswitchadccooleston) {
00899     hid = hidmanager.createHistoId("ADCsCoolestStrip","det",detid);
00900     mod_single.ADCsCoolestStrip = bookME1D("TH1ADCsCoolestStrip", hid.c_str());
00901     dqmStore_->tag(mod_single.ADCsCoolestStrip, detid);
00902     mod_single.ADCsCoolestStrip->setAxisTitle("number of ADCs for coolest strip");
00903   }
00904   
00905   //#ADCs for each digi
00906   if(moduleswitchdigiadcson) {
00907     hid = hidmanager.createHistoId("DigiADCs","det",detid);
00908     mod_single.DigiADCs = bookME1D("TH1DigiADCs", hid.c_str());
00909     dqmStore_->tag(mod_single.DigiADCs, detid);
00910     mod_single.DigiADCs->setAxisTitle("number of ADCs for each digi");
00911   }
00912   
00913   //Strip occupancy
00914   if(moduleswitchstripoccupancyon) {
00915     hid = hidmanager.createHistoId("StripOccupancy","det",detid);
00916     mod_single.StripOccupancy = bookME1D("TH1StripOccupancy", hid.c_str());
00917     dqmStore_->tag(mod_single.StripOccupancy, detid);
00918     mod_single.StripOccupancy->setAxisTitle("strip occupancy");
00919   }
00920   
00921 }
00922   
00923 //
00924 // -- Create Module Level MEs
00925 //  
00926 
00927 void SiStripMonitorDigi::createLayerMEs(std::string label, int ndets) {
00928 
00929   std::map<std::string, LayerMEs>::iterator iLayerME  = LayerMEsMap.find(label);
00930   if(iLayerME==LayerMEsMap.end()){
00931     SiStripHistoId hidmanager;
00932     LayerMEs layerMEs; 
00933     layerMEs.LayerNumberOfDigis = 0;
00934     layerMEs.LayerNumberOfDigisTrend = 0;
00935     layerMEs.LayerADCsHottestStrip = 0;
00936     layerMEs.LayerADCsHottestStripTrend = 0;
00937     layerMEs.LayerADCsCoolestStrip = 0;
00938     layerMEs.LayerADCsCoolestStripTrend = 0;
00939     layerMEs.LayerDigiADCs = 0;
00940     layerMEs.LayerDigiADCsTrend = 0;
00941     layerMEs.LayerStripOccupancy = 0;
00942     layerMEs.LayerStripOccupancyTrend = 0;
00943     layerMEs.LayerNumberOfDigisProfile = 0;
00944     layerMEs.LayerDigiADCProfile = 0;
00945     
00946 
00947     //#Digis
00948     if(layerswitchnumdigison) {
00949       layerMEs.LayerNumberOfDigis=bookME1D("TH1NumberOfDigis", hidmanager.createHistoLayer("Summary_TotalNumberOfDigis","layer",label,"").c_str()); 
00950       if (createTrendMEs) layerMEs.LayerNumberOfDigisTrend=bookMETrend("TH1NumberOfDigis", hidmanager.createHistoLayer("Trend_NumberOfDigis","layer",label,"").c_str()); 
00951     }
00952 
00953     //#ADCs for hottest strip
00954     if(layerswitchadchotteston) {
00955       layerMEs.LayerADCsHottestStrip=bookME1D("TH1ADCsHottestStrip", hidmanager.createHistoLayer("Summary_ADCsHottestStrip","layer",label,"").c_str()); 
00956       if (createTrendMEs) layerMEs.LayerADCsHottestStripTrend=bookMETrend("TH1ADCsHottestStrip", hidmanager.createHistoLayer("Trend_ADCsHottestStrip","layer",label,"").c_str()); 
00957     }
00958 
00959     //#ADCs for coolest strip
00960     if(layerswitchadccooleston) {
00961       layerMEs.LayerADCsCoolestStrip=bookME1D("TH1ADCsCoolestStrip", hidmanager.createHistoLayer("Summary_ADCsCoolestStrip","layer",label,"").c_str());
00962       if (createTrendMEs) layerMEs.LayerADCsCoolestStripTrend=bookMETrend("TH1ADCsCoolestStrip", hidmanager.createHistoLayer("Trend_ADCsCoolestStrip","layer",label,"").c_str());
00963     }
00964 
00965     //#ADCs for each digi
00966     if(layerswitchdigiadcson) {
00967       layerMEs.LayerDigiADCs=bookME1D("TH1DigiADCs", hidmanager.createHistoLayer("Summary_DigiADCs","layer",label,"").c_str());
00968       if (createTrendMEs) layerMEs.LayerDigiADCsTrend=bookMETrend("TH1DigiADCs", hidmanager.createHistoLayer("Trend_DigiADCs","layer",label,"").c_str());
00969     }
00970 
00971     //Strip Occupancy
00972     if(layerswitchstripoccupancyon) {
00973       layerMEs.LayerStripOccupancy=bookME1D("TH1StripOccupancy", hidmanager.createHistoLayer("Summary_StripOccupancy","layer",label,"").c_str());  
00974       if (createTrendMEs) layerMEs.LayerStripOccupancyTrend=bookMETrend("TH1StripOccupancy", hidmanager.createHistoLayer("Trend_StripOccupancy","layer",label,"").c_str());  
00975       
00976     }
00977     // # of Digis 
00978     if(layerswitchnumdigisprofon) {
00979       std::string hid = hidmanager.createHistoLayer("NumberOfDigiProfile","layer",label,"");
00980       layerMEs.LayerNumberOfDigisProfile = dqmStore_->bookProfile(hid, hid, ndets, 0.5, ndets+0.5,21, -0.5, 200.5);
00981     }
00982 
00983     // # of Digis 
00984     if(layerswitchdigiadcprofon) {
00985       std::string hid = hidmanager.createHistoLayer("DigiADCProfile","layer",label,"");      
00986       layerMEs.LayerDigiADCProfile = dqmStore_->bookProfile(hid, hid, ndets, 0.5, ndets+0.5, 64, -0.5, 255.5);      
00987     }
00988 
00989     LayerMEsMap[label]=layerMEs;
00990   }
00991 }
00992 //
00993 // -- Create SubDetector MEs
00994 //
00995 void SiStripMonitorDigi::createSubDetMEs(std::string label) {
00996 
00997   SubDetMEs subdetMEs; 
00998   subdetMEs.totNDigis         = 0;
00999   subdetMEs.SubDetTotDigiProf = 0;
01000   subdetMEs.SubDetDigiApvProf = 0;
01001   subdetMEs.SubDetDigiApvTH2  = 0;
01002 
01003   subdetMEs.SubDetApvShots.clear();
01004   subdetMEs.SubDetNApvShotsTH1            = 0;
01005   subdetMEs.SubDetChargeMedianApvShotsTH1 = 0;
01006   subdetMEs.SubDetNStripsApvShotsTH1      = 0;
01007   subdetMEs.SubDetNApvShotsProf = 0;
01008 
01009   std::string HistoName;
01010   
01011   // Total Number of Digi - Profile
01012   if(subdetswitchtotdigiprofon){
01013     edm::ParameterSet Parameters =  conf_.getParameter<edm::ParameterSet>("TProfTotalNumberOfDigis");
01014     HistoName = "TotalNumberOfDigiProfile__" + label;
01015     subdetMEs.SubDetTotDigiProf=dqmStore_->bookProfile(HistoName,HistoName,
01016                                                        Parameters.getParameter<int32_t>("Nbins"),
01017                                                        Parameters.getParameter<double>("xmin"),
01018                                                        Parameters.getParameter<double>("xmax"),
01019                                                        100, //that parameter should not be there !?
01020                                                        Parameters.getParameter<double>("ymin"),
01021                                                        Parameters.getParameter<double>("ymax"),
01022                                                        "" );
01023     subdetMEs.SubDetTotDigiProf->setAxisTitle("Event Time in Seconds",1);
01024     if (subdetMEs.SubDetTotDigiProf->kind() == MonitorElement::DQM_KIND_TPROFILE) subdetMEs.SubDetTotDigiProf->getTH1()->SetBit(TH1::kCanRebin);
01025   }
01026   
01027   // Number of Digi vs Bx - Profile
01028   if(subdetswitchapvcycleprofon){
01029     edm::ParameterSet Parameters =  conf_.getParameter<edm::ParameterSet>("TProfDigiApvCycle");
01030     HistoName = "Digi_vs_ApvCycle__" + label;
01031     subdetMEs.SubDetDigiApvProf=dqmStore_->bookProfile(HistoName,HistoName,
01032                                                        Parameters.getParameter<int32_t>("Nbins"),
01033                                                        Parameters.getParameter<double>("xmin"),
01034                                                        Parameters.getParameter<double>("xmax"),
01035                                                        200, //that parameter should not be there !?
01036                                                        Parameters.getParameter<double>("ymin"),
01037                                                        Parameters.getParameter<double>("ymax"),
01038                                                        "" );
01039     subdetMEs.SubDetDigiApvProf->setAxisTitle("ApvCycle (Corrected Absolute Bx % 70)",1);
01040   }
01041   
01042   // Number of Digi vs Bx - TH2
01043   if(subdetswitchapvcycleth2on){
01044     edm::ParameterSet Parameters =  conf_.getParameter<edm::ParameterSet>("TH2DigiApvCycle");
01045     //dqmStore_->setCurrentFolder("SiStrip/MechanicalView/"+label);
01046     HistoName = "Digi_vs_ApvCycle_2D__" + label;
01047     // Adjusting the scale for 2D histogram
01048     double h2ymax = 9999.0;
01049     double yfact = Parameters.getParameter<double>("yfactor");
01050     if(label.find("TIB") != std::string::npos) h2ymax = (6984.*256.)*yfact;
01051     else if (label.find("TID") != std::string::npos) h2ymax = (2208.*256.)*yfact;
01052     else if (label.find("TOB") != std::string::npos) h2ymax = (12906.*256.)*yfact;
01053     else if (label.find("TEC") != std::string::npos) h2ymax = (7552.*2.*256.)*yfact;
01054     subdetMEs.SubDetDigiApvTH2=dqmStore_->book2D(HistoName,HistoName,
01055                                                  Parameters.getParameter<int32_t>("Nbins"),
01056                                                  Parameters.getParameter<double>("xmin"),
01057                                                  Parameters.getParameter<double>("xmax"),
01058                                                  Parameters.getParameter<int32_t>("Nbinsy"), //it was 100 that parameter should not be there !?
01059                                                  Parameters.getParameter<double>("ymin"),
01060                                                  h2ymax);
01061     subdetMEs.SubDetDigiApvTH2->setAxisTitle("absolute Bx mod(70)",1);
01062   }
01063 
01064   //Number of APV Shots
01065   if (subdetswitchnapvshotson){
01066     edm::ParameterSet Parameters =  conf_.getParameter<edm::ParameterSet>("TH1NApvShots");
01067     //dqmStore_->setCurrentFolder("SiStrip/MechanicalView/"+label);
01068     HistoName = "Number_of_Apv_Shots_" + label;
01069     subdetMEs.SubDetNApvShotsTH1=dqmStore_->book1D(HistoName,HistoName,
01070                                                    Parameters.getParameter<int32_t>("Nbins"),
01071                                                    Parameters.getParameter<double>("xmin"),
01072                                                    Parameters.getParameter<double>("xmax"));
01073     subdetMEs.SubDetNApvShotsTH1->setAxisTitle("# Apv Shots",1);
01074   }
01075 
01076   //Strip multiplicity of APV Shots
01077   if (subdetswitchnstripsapvshotson){
01078     edm::ParameterSet Parameters =  conf_.getParameter<edm::ParameterSet>("TH1NStripsApvShots");
01079     //dqmStore_->setCurrentFolder("SiStrip/MechanicalView/"+label);
01080     HistoName = "Number_of_Strips_in_Apv_Shots_" + label;
01081     subdetMEs.SubDetNStripsApvShotsTH1=dqmStore_->book1D(HistoName,HistoName,
01082                                                    Parameters.getParameter<int32_t>("Nbins"),
01083                                                    Parameters.getParameter<double>("xmin"),
01084                                                    Parameters.getParameter<double>("xmax"));
01085     subdetMEs.SubDetNStripsApvShotsTH1->setAxisTitle("# strips in Apv Shots",1);
01086   }
01087 
01088   //Charge median of APV Shots
01089   if (subdetswitchchargemedianapvshotson){
01090     edm::ParameterSet Parameters =  conf_.getParameter<edm::ParameterSet>("TH1ChargeMedianApvShots");
01091     //dqmStore_->setCurrentFolder("SiStrip/MechanicalView/"+label);
01092     HistoName = "Apv_Shots_Charge_Median_" + label;
01093     subdetMEs.SubDetChargeMedianApvShotsTH1=dqmStore_->book1D(HistoName,HistoName,
01094                                                    Parameters.getParameter<int32_t>("Nbins"),
01095                                                    Parameters.getParameter<double>("xmin"),
01096                                                    Parameters.getParameter<double>("xmax"));
01097     subdetMEs.SubDetChargeMedianApvShotsTH1->setAxisTitle("Apv Shots Charge Median (ADC)",1);
01098   }
01099 
01100 
01101   if (subdetswitchchargemedianapvshotson){
01102     edm::ParameterSet Parameters =  conf_.getParameter<edm::ParameterSet>("TH1ApvNumApvShots");
01103     //dqmStore_->setCurrentFolder("SiStrip/MechanicalView/"+label);
01104     HistoName = "Apv_Shots_Apv_Number_" + label;
01105     subdetMEs.SubDetNApvShotsNApvTH1=dqmStore_->book1D(HistoName,HistoName,
01106                                                               Parameters.getParameter<int32_t>("Nbins"),
01107                                                               Parameters.getParameter<double>("xmin"),
01108                                                               Parameters.getParameter<double>("xmax"));
01109     subdetMEs.SubDetNApvShotsNApvTH1->setAxisTitle("Apv Number",1);
01110   }
01111 
01112 
01113 
01114 
01115 
01116   //APV Shots number Vs time
01117   if(subdetswitchapvshotsonprof){
01118     edm::ParameterSet Parameters =  conf_.getParameter<edm::ParameterSet>("TProfNShotsVsTime");
01119     HistoName = "NApv_Shots_vs_Time_" + label;
01120     subdetMEs.SubDetNApvShotsProf=dqmStore_->bookProfile(HistoName,HistoName,
01121                                                        Parameters.getParameter<int32_t>("Nbins"),
01122                                                        Parameters.getParameter<double>("xmin"),
01123                                                        Parameters.getParameter<double>("xmax"),
01124                                                        200, //that parameter should not be there !?
01125                                                        Parameters.getParameter<double>("ymin"),
01126                                                        Parameters.getParameter<double>("ymax"),
01127                                                        "" );
01128     subdetMEs.SubDetNApvShotsProf->setAxisTitle("Time (s)",1);
01129     subdetMEs.SubDetNApvShotsProf->setAxisTitle("# Apv Shots",2);
01130     if (subdetMEs.SubDetNApvShotsProf->kind() == MonitorElement::DQM_KIND_TPROFILE) subdetMEs.SubDetNApvShotsProf->getTH1()->SetBit(TH1::kCanRebin);
01131   }
01132 
01133 
01134 
01135 
01136 
01137 
01138 
01139   SubDetMEsMap[label]=subdetMEs;
01140 }
01141 //
01142 // -- Get DetSet vector for a given Detector
01143 //
01144 int SiStripMonitorDigi::getDigiSourceIndex(uint32_t id) {
01145   int location = -1;
01146   for (unsigned int ival = 0; ival <  digi_detset_handles.size(); ++ival){
01147     edm::DetSetVector<SiStripDigi>::const_iterator isearch = digi_detset_handles[ival]->find(id); 
01148     if(isearch != digi_detset_handles[ival]->end()) {
01149       location = ival;
01150       break;
01151     }
01152   }
01153   return location;
01154 }
01155 
01156 void SiStripMonitorDigi::AddApvShotsToSubDet(const std::vector<APVShot> & moduleShots, std::vector<APVShot>  & subdetShots){
01157   
01158   for (uint i=0; i<moduleShots.size(); i++){
01159     subdetShots.push_back(moduleShots[i]);
01160   }
01161 }
01162 
01163 void SiStripMonitorDigi::FillApvShotsMap(TkHistoMap* the_map, const std::vector<APVShot> & shots, uint32_t id ,int mode){
01164   
01165   for (uint i=0; i<shots.size(); i++){
01166     if (mode==1) the_map->fill(id,shots[i].nStrips()); //mode == 1 fill with strip multiplicity
01167     if (mode==2) the_map->fill(id,shots[i].median()); // mode == 2 fill with charge median
01168   }
01169 }
01170 
01171 //define this as a plug-in
01172 DEFINE_FWK_MODULE(SiStripMonitorDigi);