CMS 3D CMS Logo

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