CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/DQM/HcalMonitorTasks/src/HcalBeamMonitor.cc

Go to the documentation of this file.
00001 #include "DQM/HcalMonitorTasks/interface/HcalBeamMonitor.h"
00002 #include "CondFormats/HcalObjects/interface/HcalChannelQuality.h"
00003 #include "CondFormats/DataRecord/interface/HcalChannelQualityRcd.h"
00004 #include "Geometry/HcalTowerAlgo/src/HcalHardcodeGeometryData.h"
00005 #include "FWCore/Framework/interface/EventSetup.h"
00006 #include "FWCore/Framework/interface/LuminosityBlock.h"
00007 #include "FWCore/Framework/interface/Run.h"
00008 
00009 #include <iomanip>
00010 #include <cmath>
00011 
00012 // define sizes of ieta arrays for each subdetector
00013 
00014 #define PI        3.1415926535897932
00015 #define HBETASIZE 34  // one more bin than needed, I think
00016 #define HEETASIZE 60  // ""
00017 #define HOETASIZE 32  // ""
00018 #define HFETASIZE 84  // ""
00019 
00020 /*  Task calculates various moments of Hcal recHits 
00021 
00022     v1.0
00023     16 August 2008
00024     by Jeff Temple
00025 
00026 */
00027 
00028 // constructor
00029 HcalBeamMonitor::HcalBeamMonitor(const edm::ParameterSet& ps):
00030   ETA_OFFSET_HB(16),
00031   ETA_OFFSET_HE(29),
00032   ETA_BOUND_HE(17),
00033   ETA_OFFSET_HO(15),
00034   ETA_OFFSET_HF(41),
00035   ETA_BOUND_HF(29)
00036 {
00037   Online_                = ps.getUntrackedParameter<bool>("online",false);
00038   mergeRuns_             = ps.getUntrackedParameter<bool>("mergeRuns",false);
00039   enableCleanup_         = ps.getUntrackedParameter<bool>("enableCleanup",false);
00040   debug_                 = ps.getUntrackedParameter<int>("debug",0);
00041   prefixME_              = ps.getUntrackedParameter<std::string>("subSystemFolder","Hcal/");
00042   if (prefixME_.substr(prefixME_.size()-1,prefixME_.size())!="/")
00043     prefixME_.append("/");
00044   subdir_                = ps.getUntrackedParameter<std::string>("TaskFolder","BeamMonitor_Hcal");
00045   if (subdir_.size()>0 && subdir_.substr(subdir_.size()-1,subdir_.size())!="/")
00046     subdir_.append("/");
00047   subdir_=prefixME_+subdir_;
00048   AllowedCalibTypes_     = ps.getUntrackedParameter<std::vector<int> > ("AllowedCalibTypes");
00049   skipOutOfOrderLS_      = ps.getUntrackedParameter<bool>("skipOutOfOrderLS",true);
00050   NLumiBlocks_           = ps.getUntrackedParameter<int>("NLumiBlocks",4000);
00051   makeDiagnostics_       = ps.getUntrackedParameter<bool>("makeDiagnostics",false);
00052 
00053   // Beam Monitor-specific stuff
00054 
00055   // Collection type info
00056   digiLabel_             =ps.getUntrackedParameter<edm::InputTag>("digiLabel");
00057   hbheRechitLabel_       = ps.getUntrackedParameter<edm::InputTag>("hbheRechitLabel");
00058   hoRechitLabel_         = ps.getUntrackedParameter<edm::InputTag>("hoRechitLabel");
00059   hfRechitLabel_         = ps.getUntrackedParameter<edm::InputTag>("hfRechitLabel");
00060 
00061   // minimum events required in lumi block for tests to be processed
00062   minEvents_       = ps.getUntrackedParameter<int>("minEvents",500); 
00063   lumiqualitydir_ = ps.getUntrackedParameter<std::string>("lumiqualitydir","");
00064   if (lumiqualitydir_.size()>0 && lumiqualitydir_.substr(lumiqualitydir_.size()-1,lumiqualitydir_.size())!="/")
00065     lumiqualitydir_.append("/");
00066   occThresh_ = ps.getUntrackedParameter<double>("occupancyThresh",0.0625);  // energy required to be counted by dead/hot checks
00067   hotrate_        = ps.getUntrackedParameter<double>("hotrate",0.25);
00068   minBadCells_    = ps.getUntrackedParameter<int>("minBadCells",10);
00069   Overwrite_      = ps.getUntrackedParameter<bool>("Overwrite",false);
00070   setupDone_      = false;
00071 }
00072 
00073 
00074 
00075 HcalBeamMonitor::~HcalBeamMonitor() {}
00076 
00077 void HcalBeamMonitor::reset() 
00078 {
00079   CenterOfEnergyRadius->Reset();
00080   CenterOfEnergy->Reset();
00081   COEradiusVSeta->Reset();
00082 
00083   HBCenterOfEnergyRadius->Reset();
00084   HBCenterOfEnergy->Reset();
00085   HECenterOfEnergyRadius->Reset();
00086   HECenterOfEnergy->Reset();
00087   HOCenterOfEnergyRadius->Reset();
00088   HOCenterOfEnergy->Reset();
00089   HFCenterOfEnergyRadius->Reset();
00090   HFCenterOfEnergy->Reset();
00091 
00092   Etsum_eta_L->Reset();
00093   Etsum_eta_S->Reset();
00094   Etsum_phi_L->Reset();
00095   Etsum_phi_S->Reset();
00096   Etsum_ratio_p->Reset();
00097   Etsum_ratio_m->Reset();
00098   Etsum_map_L->Reset();
00099   Etsum_map_S->Reset();
00100   Etsum_ratio_map->Reset();
00101   Etsum_rphi_L->Reset();
00102   Etsum_rphi_S->Reset();
00103   Energy_Occ->Reset();
00104 
00105   Occ_rphi_L->Reset();
00106   Occ_rphi_S->Reset();
00107   Occ_eta_L->Reset();
00108   Occ_eta_S->Reset();
00109   Occ_phi_L->Reset();
00110   Occ_phi_S->Reset();
00111   Occ_map_L->Reset();
00112   Occ_map_S->Reset();
00113   
00114   HFlumi_ETsum_perwedge->Reset();
00115   HFlumi_Occupancy_above_thr_r1->Reset();
00116   HFlumi_Occupancy_between_thrs_r1->Reset();
00117   HFlumi_Occupancy_below_thr_r1->Reset();
00118   HFlumi_Occupancy_above_thr_r2->Reset();
00119   HFlumi_Occupancy_between_thrs_r2->Reset();
00120   HFlumi_Occupancy_below_thr_r2->Reset();
00121 
00122   HFlumi_Occupancy_per_channel_vs_lumiblock_RING1->Reset();
00123   HFlumi_Occupancy_per_channel_vs_lumiblock_RING2->Reset();
00124   HFlumi_Occupancy_per_channel_vs_BX_RING1->Reset();
00125   HFlumi_Occupancy_per_channel_vs_BX_RING2->Reset();
00126   HFlumi_ETsum_vs_BX->Reset();
00127   HFlumi_Et_per_channel_vs_lumiblock->Reset();
00128 
00129   HFlumi_occ_LS->Reset();
00130   HFlumi_total_hotcells->Reset();
00131   HFlumi_total_deadcells->Reset();
00132   HFlumi_diag_hotcells->Reset();
00133   HFlumi_diag_deadcells->Reset();
00134 
00135 
00136   HFlumi_Ring1Status_vs_LS->Reset();
00137   HFlumi_Ring2Status_vs_LS->Reset();
00138 }
00139 
00140 void HcalBeamMonitor::cleanup()
00141 {
00142   if (dbe_) 
00143     {
00144       dbe_->setCurrentFolder(subdir_);
00145       dbe_->removeContents();
00146       dbe_->setCurrentFolder(subdir_+"LSvalues");
00147       dbe_->removeContents();
00148     } // if (dbe_)
00149 } // void HcalBeamMonitor::cleanup()
00150 
00151 
00152 void HcalBeamMonitor::setup()
00153 {
00154   if (setupDone_)
00155     return;
00156   setupDone_ = true;
00157    if (debug_>0) std::cout <<"<HcalBeamMonitor::setup> Setup in progress..."<<std::endl;
00158   HcalBaseDQMonitor::setup();
00159   if (!dbe_) return;
00160 
00161   //jason's
00162   dbe_->setCurrentFolder(subdir_);
00163   CenterOfEnergyRadius = dbe_->book1D("CenterOfEnergyRadius",
00164                                        "Center Of Energy radius",
00165                                        200,0,1);
00166       
00167   CenterOfEnergyRadius->setAxisTitle("(normalized) radius",1);
00168       
00169   CenterOfEnergy = dbe_->book2D("CenterOfEnergy",
00170                                  "Center of Energy;normalized x coordinate;normalize y coordinate",
00171                                  40,-1,1,
00172                                  40,-1,1);
00173 
00174   COEradiusVSeta = dbe_->bookProfile("COEradiusVSeta",
00175                                       "Center of Energy radius vs i#eta",
00176                                       172,-43,43,
00177                                       20,0,1);
00178   COEradiusVSeta->setAxisTitle("i#eta",1);
00179   COEradiusVSeta->setAxisTitle("(normalized) radius",2);
00180       
00181   std::stringstream histname;
00182   std::stringstream histtitle;
00183   dbe_->setCurrentFolder(subdir_+"HB");
00184   HBCenterOfEnergyRadius = dbe_->book1D("HBCenterOfEnergyRadius",
00185                                          "HB Center Of Energy radius",
00186                                          200,0,1);
00187   HBCenterOfEnergy = dbe_->book2D("HBCenterOfEnergy",
00188                                    "HB Center of Energy",
00189                                    40,-1,1,
00190                                    40,-1,1);
00191   if (makeDiagnostics_)
00192     {
00193       for (int i=-16;i<=16;++i)
00194         {
00195           if (i==0) continue;
00196           histname.str("");
00197           histtitle.str("");
00198           histname<<"HB_CenterOfEnergyRadius_ieta"<<i;
00199           histtitle<<"HB Center Of Energy ieta = "<<i;
00200           HB_CenterOfEnergyRadius[i+ETA_OFFSET_HB]=dbe_->book1D(histname.str().c_str(),
00201                                                                  histtitle.str().c_str(),
00202                                                                  200,0,1);
00203         } // end of HB loop
00204     }
00205   dbe_->setCurrentFolder(subdir_+"HE");
00206   HECenterOfEnergyRadius = dbe_->book1D("HECenterOfEnergyRadius",
00207                                          "HE Center Of Energy radius",
00208                                          200,0,1);
00209   HECenterOfEnergy = dbe_->book2D("HECenterOfEnergy",
00210                                    "HE Center of Energy",
00211                                    40,-1,1,
00212                                    40,-1,1);
00213 
00214   if (makeDiagnostics_)
00215     {
00216       for (int i=-29;i<=29;++i)
00217         {
00218           if (abs(i)<ETA_BOUND_HE) continue;
00219           histname.str("");
00220           histtitle.str("");
00221           histname<<"HE_CenterOfEnergyRadius_ieta"<<i;
00222           histtitle<<"HE Center Of Energy ieta = "<<i;
00223           HE_CenterOfEnergyRadius[i+ETA_OFFSET_HE]=dbe_->book1D(histname.str().c_str(),
00224                                                                  histtitle.str().c_str(),
00225                                                                  200,0,1);
00226         } // end of HE loop
00227     }
00228   dbe_->setCurrentFolder(subdir_+"HO");
00229   HOCenterOfEnergyRadius = dbe_->book1D("HOCenterOfEnergyRadius",
00230                                          "HO Center Of Energy radius",
00231                                          200,0,1);
00232   HOCenterOfEnergy = dbe_->book2D("HOCenterOfEnergy",
00233                                    "HO Center of Energy",
00234                                    40,-1,1,
00235                                    40,-1,1);
00236   if (makeDiagnostics_)
00237     {
00238       for (int i=-15;i<=15;++i)
00239         {
00240           if (i==0) continue;
00241           histname.str("");
00242           histtitle.str("");
00243           histname<<"HO_CenterOfEnergyRadius_ieta"<<i;
00244           histtitle<<"HO Center Of Energy radius ieta = "<<i;
00245           HO_CenterOfEnergyRadius[i+ETA_OFFSET_HO]=dbe_->book1D(histname.str().c_str(),
00246                                                                  histtitle.str().c_str(),
00247                                                                  200,0,1);
00248         } // end of HO loop
00249     }
00250   dbe_->setCurrentFolder(subdir_+"HF");
00251   HFCenterOfEnergyRadius = dbe_->book1D("HFCenterOfEnergyRadius",
00252                                          "HF Center Of Energy radius",
00253                                          200,0,1);
00254   HFCenterOfEnergy = dbe_->book2D("HFCenterOfEnergy",
00255                                    "HF Center of Energy",
00256                                    40,-1,1,
00257                                    40,-1,1);
00258   if (makeDiagnostics_)
00259     {
00260       for (int i=-41;i<=41;++i)
00261         {
00262           if (abs(i)<ETA_BOUND_HF) continue;
00263           histname.str("");
00264           histtitle.str("");
00265           histname<<"HF_CenterOfEnergyRadius_ieta"<<i;
00266           histtitle<<"HF Center Of Energy radius ieta = "<<i;
00267           HF_CenterOfEnergyRadius[i+ETA_OFFSET_HF]=dbe_->book1D(histname.str().c_str(),
00268                                                                  histtitle.str().c_str(),
00269                                                                  200,0,1);
00270         } // end of HF loop
00271     }
00272       
00273   dbe_->setCurrentFolder(subdir_+"Lumi");
00274   // Wenhan's 
00275   // reducing bins from ",200,0,2000" to ",40,0,800"
00276       
00277   float radiusbins[13]={169,201,240,286,340,406,483,576,686,818,975,1162,1300};
00278   float phibins[71]={-3.5,-3.4,-3.3,-3.2,-3.1,
00279                      -3.0,-2.9,-2.8,-2.7,-2.6,-2.5,-2.4,-2.3,-2.2,-2.1,
00280                      -2.0,-1.9,-1.8,-1.7,-1.6,-1.5,-1.4,-1.3,-1.2,-1.1,
00281                      -1.0,-0.9,-0.8,-0.7,-0.6,-0.5,-0.4,-0.3,-0.2,-0.1,
00282                      0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9,
00283                      1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9,
00284                      2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9,
00285                      3.0, 3.1, 3.2, 3.3, 3.4, 3.5};
00286   Etsum_eta_L=dbe_->bookProfile("Et Sum vs Eta Long Fiber","Et Sum per Area vs Eta Long Fiber",27,0,27,100,0,100);
00287   Etsum_eta_S=dbe_->bookProfile("Et Sum vs Eta Short Fiber","Et Sum per Area vs Eta Short Fiber",27,0,27,100,0,100);
00288   Etsum_phi_L=dbe_->bookProfile("Et Sum vs Phi Long Fiber","Et Sum per Area vs Phi Long Fiber",36,0.5,72.5,100,0,100);
00289   Etsum_phi_S=dbe_->bookProfile("Et Sum vs Phi Short Fiber","Et Sum per Area crossing vs Phi Short Fiber",36,0.5,72.5,100,0,100);
00290 
00291   Etsum_ratio_p=dbe_->book1D("Occ vs PMT events HF+","Energy difference of Long and Short Fiber HF+ in PMT events",105,0.,1.05);
00292   Energy_Occ=dbe_->book1D("Occ vs Energy","Occupancy vs Energy",200,0,2000);
00293   Etsum_ratio_m=dbe_->book1D("Occ vs PMT events HF-","Energy difference of Long and Short Fiber HF- in PMT events",105,0.,1.05);
00294   Etsum_map_L=dbe_->book2D("EtSum 2D phi and eta Long Fiber","Et Sum 2D phi and eta Long Fiber",27,0,27,36,0.5,72.5);
00295   Etsum_map_S=dbe_->book2D("EtSum 2D phi and eta Short Fiber","Et Sum 2D phi and eta Short Fiber",27,0,27,36,0.5,72.5);
00296 
00297   Etsum_rphi_S=dbe_->book2D("EtSum 2D phi and radius Short Fiber","Et Sum 2D phi and radius Short Fiber",12, radiusbins, 70, phibins);
00298   Etsum_rphi_L=dbe_->book2D("EtSum 2D phi and radius Long Fiber","Et Sum 2D phi and radius Long Fiber",12, radiusbins, 70, phibins);
00299 
00300   Etsum_ratio_map=dbe_->book2D("Abnormal PMT events","Abnormal PMT events",
00301                                 8,0,8,36, 0.5,72.5);
00302   SetEtaLabels(Etsum_ratio_map);
00303 
00304   HFlumi_occ_LS = dbe_->book2D("HFlumi_occ_LS","HFlumi occupancy for current LS",
00305                                 8,0,8,36, 0.5,72.5);
00306   SetEtaLabels(HFlumi_occ_LS);
00307       
00308   HFlumi_total_deadcells = dbe_->book2D("HFlumi_total_deadcells","Number of dead lumi channels for LS with at least 10 bad channels",
00309                                          8,0,8,36,0.5,72.5);
00310   SetEtaLabels(HFlumi_total_deadcells);
00311   HFlumi_total_hotcells = dbe_->book2D("HFlumi_total_hotcells","Number of hot lumi channels for LS with at least 10 bad channels",
00312                                         8,0,8,36,0.5,72.5);
00313   SetEtaLabels(HFlumi_total_hotcells);
00314 
00315   HFlumi_diag_deadcells = dbe_->book2D("HFlumi_diag_deadcells","Channels that had no hit for at least one LS",
00316                                        8,0,8,36,0.5,72.5);
00317   SetEtaLabels(HFlumi_diag_deadcells);
00318   HFlumi_diag_hotcells = dbe_->book2D("HFlumi_diag_hotcells","Channels that appeared hot for at least one LS",
00319                                       8,0,8,36,0.5,72.5);
00320   SetEtaLabels(HFlumi_diag_hotcells);
00321 
00322 
00323 
00324   Occ_rphi_S=dbe_->book2D("Occ 2D phi and radius Short Fiber","Occupancy 2D phi and radius Short Fiber",12, radiusbins, 70, phibins);
00325   Occ_rphi_L=dbe_->book2D("Occ 2D phi and radius Long Fiber","Occupancy 2D phi and radius Long Fiber",12, radiusbins, 70, phibins);
00326   Occ_eta_S=dbe_->bookProfile("Occ vs iEta Short Fiber","Occ per Bunch crossing vs iEta Short Fiber",27,0,27,40,0,800);
00327   Occ_eta_L=dbe_->bookProfile("Occ vs iEta Long Fiber","Occ per Bunch crossing vs iEta Long Fiber",27,0,27,40,0,800);
00328       
00329   Occ_phi_L=dbe_->bookProfile("Occ vs iPhi Long Fiber","Occ per Bunch crossing vs iPhi Long Fiber",36,0.5,72.5,40,0,800);
00330       
00331   Occ_phi_S=dbe_->bookProfile("Occ vs iPhi Short Fiber","Occ per Bunch crossing vs iPhi Short Fiber",36,0.5,72.5,40,0,800);
00332       
00333   Occ_map_L=dbe_->book2D("Occ_map Long Fiber","Occ Map long Fiber (above threshold)",27,0,27,36,0.5,72.5);
00334   Occ_map_S=dbe_->book2D("Occ_map Short Fiber","Occ Map Short Fiber (above threshold)",27,0,27,36,0.5,72.5);
00335 
00336   std::stringstream binlabel;
00337   for (int zz=0;zz<27;++zz)
00338     {
00339       if (zz<13)
00340         binlabel<<zz-41;
00341       else if (zz==13)
00342         binlabel<<"NULL";
00343       else
00344         binlabel<<zz+15;
00345       Occ_eta_S->setBinLabel(zz+1,binlabel.str().c_str());
00346       Occ_eta_L->setBinLabel(zz+1,binlabel.str().c_str());
00347       Occ_map_S->setBinLabel(zz+1,binlabel.str().c_str());
00348       Occ_map_L->setBinLabel(zz+1,binlabel.str().c_str());
00349       Etsum_eta_S->setBinLabel(zz+1,binlabel.str().c_str());
00350       Etsum_eta_L->setBinLabel(zz+1,binlabel.str().c_str());
00351       Etsum_map_S->setBinLabel(zz+1,binlabel.str().c_str());
00352       Etsum_map_L->setBinLabel(zz+1,binlabel.str().c_str());
00353       binlabel.str("");
00354     }
00355 
00356   //HFlumi plots
00357   HFlumi_ETsum_perwedge =  dbe_->book1D("HF lumi ET-sum per wedge","HF lumi ET-sum per wedge;wedge",36,1,37);
00358   HFlumi_ETsum_perwedge->getTH1F()->SetMinimum(0); 
00359       
00360   HFlumi_Occupancy_above_thr_r1 =  dbe_->book1D("HF lumi Occupancy above threshold ring1","HF lumi Occupancy above threshold ring1;wedge",36,1,37);
00361   HFlumi_Occupancy_between_thrs_r1 = dbe_->book1D("HF lumi Occupancy between thresholds ring1","HF lumi Occupancy between thresholds ring1;wedge",36,1,37);
00362   HFlumi_Occupancy_below_thr_r1 = dbe_->book1D("HF lumi Occupancy below threshold ring1","HF lumi Occupancy below threshold ring1;wedge",36,1,37);
00363   HFlumi_Occupancy_above_thr_r2 = dbe_->book1D("HF lumi Occupancy above threshold ring2","HF lumi Occupancy above threshold ring2;wedge",36,1,37);
00364   HFlumi_Occupancy_between_thrs_r2 = dbe_->book1D("HF lumi Occupancy between thresholds ring2","HF lumi Occupancy between thresholds ring2;wedge",36,1,37);
00365   HFlumi_Occupancy_below_thr_r2 = dbe_->book1D("HF lumi Occupancy below threshold ring2","HF lumi Occupancy below threshold ring2;wedge",36,1,37);
00366 
00367   HFlumi_Occupancy_above_thr_r1->getTH1F()->SetMinimum(0);
00368   HFlumi_Occupancy_between_thrs_r1->getTH1F()->SetMinimum(0);
00369   HFlumi_Occupancy_below_thr_r1->getTH1F()->SetMinimum(0);
00370   HFlumi_Occupancy_above_thr_r2->getTH1F()->SetMinimum(0);
00371   HFlumi_Occupancy_between_thrs_r2->getTH1F()->SetMinimum(0);
00372   HFlumi_Occupancy_below_thr_r2->getTH1F()->SetMinimum(0);
00373  
00374   HFlumi_Occupancy_per_channel_vs_lumiblock_RING1 = dbe_->bookProfile("HFlumiRing1OccupancyPerChannelVsLB",
00375                                                                       "HFlumi Occupancy per channel vs lumi-block (RING 1);LS; -ln(empty fraction)",
00376                                                                       NLumiBlocks_,0.5,NLumiBlocks_+0.5,100,0,10000);
00377   HFlumi_Occupancy_per_channel_vs_lumiblock_RING2 = dbe_->bookProfile("HFlumiRing2OccupancyPerChannelVsLB","HFlumi Occupancy per channel vs lumi-block (RING 2);LS; -ln(empty fraction)",NLumiBlocks_,0.5,NLumiBlocks_+0.5,100,0,10000);
00378 
00379   HFlumi_Occupancy_per_channel_vs_BX_RING1 = dbe_->bookProfile("HFlumi Occupancy per channel vs BX (RING 1)","HFlumi Occupancy per channel vs BX (RING 1);BX; -ln(empty fraction)",4000,0,4000,100,0,10000);
00380   HFlumi_Occupancy_per_channel_vs_BX_RING2 = dbe_->bookProfile("HFlumi Occupancy per channel vs BX (RING 2)","HFlumi Occupancy per channel vs BX (RING 2);BX; -ln(empty fraction)",4000,0,4000,100,0,10000);
00381   HFlumi_ETsum_vs_BX = dbe_->bookProfile("HFlumi_ETsum_vs_BX","HFlumi ETsum vs BX; BX; ETsum",4000,0,4000,100,0,10000);
00382 
00383   HFlumi_Et_per_channel_vs_lumiblock = dbe_->bookProfile("HFlumi Et per channel vs lumi-block","HFlumi Et per channel vs lumi-block;LS;ET",NLumiBlocks_,0.5,NLumiBlocks_+0.5,100,0,10000);
00384 
00385   HFlumi_Occupancy_per_channel_vs_lumiblock_RING1->getTProfile()->SetMarkerStyle(20);
00386   HFlumi_Occupancy_per_channel_vs_lumiblock_RING2->getTProfile()->SetMarkerStyle(20);
00387   HFlumi_Et_per_channel_vs_lumiblock->getTProfile()->SetMarkerStyle(20);
00388 
00389   HFlumi_Ring1Status_vs_LS = dbe_->bookProfile("HFlumi_Ring1Status_vs_LS","Fraction of good Ring 1 channels vs LS;LS; Fraction of Good Channels",NLumiBlocks_,0.5,NLumiBlocks_+0.5,100,0,10000);
00390   HFlumi_Ring2Status_vs_LS = dbe_->bookProfile("HFlumi_Ring2Status_vs_LS","Fraction of good Ring 2 channels vs LS;LS; Fraction of Good Channels",NLumiBlocks_,0.5,NLumiBlocks_+0.5,100,0,10000);
00391   HFlumi_Ring1Status_vs_LS->getTProfile()->SetMarkerStyle(20);
00392   HFlumi_Ring2Status_vs_LS->getTProfile()->SetMarkerStyle(20);
00393 
00394   return;
00395 }
00396 
00397 void HcalBeamMonitor::beginRun(const edm::Run& run, const edm::EventSetup& c)
00398 {
00399   HcalBaseDQMonitor::beginRun(run,c);  
00400 
00401   if (debug_>1) std::cout <<"HcalBeamMonitor::beginRun"<<std::endl;
00402   HcalBaseDQMonitor::beginRun(run,c);
00403 
00404   lastProcessedLS_=0;
00405   runNumber_=run.id().run();
00406   if (lumiqualitydir_.size()>0 && Online_==true)
00407     {
00408       if (Overwrite_==false)
00409         outfile_ <<lumiqualitydir_<<"HcalHFLumistatus_"<<runNumber_<<".txt";
00410       else
00411         outfile_ <<lumiqualitydir_<<"HcalHFLumistatus.txt";
00412       std::ofstream outStream(outfile_.str().c_str()); // recreate the file, rather than appending to it
00413       outStream<<"## Run "<<runNumber_<<std::endl;
00414       outStream<<"## LumiBlock\tRing1Status\t\tRing2Status\t\tGlobalStatus\tNentries"<<std::endl;
00415       outStream.close();
00416     }
00417 
00418   // Get expected good channels in run according to channel quality database
00419   // Get channel quality status info for each run
00420 
00421   // Default number of expected good channels in the run
00422   ring1totalchannels_=144;
00423   ring2totalchannels_=144;
00424   BadCells_.clear(); // remove any old maps
00425   // Get Channel quality info for the run
00426   // Exclude bad channels from overall calculation
00427   edm::ESHandle<HcalChannelQuality> p;
00428   c.get<HcalChannelQualityRcd>().get(p);
00429   HcalChannelQuality* chanquality = new HcalChannelQuality(*p.product());
00430   std::vector<DetId> mydetids = chanquality->getAllChannels();
00431   
00432   for (unsigned int i=0;i<mydetids.size();++i)
00433     {
00434       if (mydetids[i].det()!=DetId::Hcal) continue;
00435       HcalDetId id=mydetids[i];
00436       
00437       if (id.subdet()!=HcalForward) continue;
00438       if ((id.depth()==1 && (abs(id.ieta())==33 || abs(id.ieta())==34)) ||
00439           (id.depth()==2 && (abs(id.ieta())==35 || abs(id.ieta())==36)))
00440         {
00441           const HcalChannelStatus* origstatus=chanquality->getValues(id);
00442           HcalChannelStatus* mystatus=new HcalChannelStatus(origstatus->rawId(),origstatus->getValue());
00443           if (mystatus->isBitSet(HcalChannelStatus::HcalCellHot)) 
00444             BadCells_[id]=HcalChannelStatus::HcalCellHot;
00445           
00446           else if (mystatus->isBitSet(HcalChannelStatus::HcalCellDead))
00447             BadCells_[id]=HcalChannelStatus::HcalCellDead;
00448           
00449           if (mystatus->isBitSet(HcalChannelStatus::HcalCellHot) || 
00450               mystatus->isBitSet(HcalChannelStatus::HcalCellDead))
00451             {
00452               if (id.depth()==1) --ring1totalchannels_;
00453               else if (id.depth()==2) --ring2totalchannels_;
00454             }
00455           delete mystatus;
00456         } // if ((id.depth()==1) ...
00457     } // for (unsigned int i=0;...)
00458     
00459   if (tevt_==0) this->setup(); // create all histograms; not necessary if merging runs together
00460   if (mergeRuns_==false) this->reset(); // call reset at start of all runs
00461 
00462   return;
00463 
00464 } // void HcalBeamMonitor::beginRun(const edm::Run& run, const edm::EventSetup& c)
00465 
00466 
00467 void HcalBeamMonitor::analyze(const edm::Event& e, const edm::EventSetup& c)
00468 {
00469   if (!IsAllowedCalibType()) return;
00470   if (LumiInOrder(e.luminosityBlock())==false) return;
00471 
00472   // try to get rechits and digis
00473   edm::Handle<HFDigiCollection> hf_digi;
00474 
00475   edm::Handle<HBHERecHitCollection> hbhe_rechit;
00476   edm::Handle<HORecHitCollection> ho_rechit;
00477   edm::Handle<HFRecHitCollection> hf_rechit;
00478   
00479   if (!(e.getByLabel(digiLabel_,hf_digi)))
00480     {
00481       edm::LogWarning("HcalBeamMonitor")<< digiLabel_<<" hf_digi not available";
00482       return;
00483     }
00484 
00485   if (!(e.getByLabel(hbheRechitLabel_,hbhe_rechit)))
00486     {
00487       edm::LogWarning("HcalBeamMonitor")<< hbheRechitLabel_<<" hbhe_rechit not available";
00488       return;
00489     }
00490 
00491   if (!(e.getByLabel(hfRechitLabel_,hf_rechit)))
00492     {
00493       edm::LogWarning("HcalBeamMonitor")<< hfRechitLabel_<<" hf_rechit not available";
00494       return;
00495     }
00496   if (!(e.getByLabel(hoRechitLabel_,ho_rechit)))
00497     {
00498       edm::LogWarning("HcalBeamMonitor")<< hoRechitLabel_<<" ho_rechit not available";
00499       return;
00500     }
00501 
00502   //good event; increment counters and process
00503   HcalBaseDQMonitor::analyze(e,c);
00504   processEvent(*hbhe_rechit, *ho_rechit, *hf_rechit, *hf_digi, e.bunchCrossing());
00505 
00506 } //void HcalBeamMonitor::analyze(const edm::Event& e, const edm::EventSetup& c)
00507 
00508 
00509 void HcalBeamMonitor::processEvent(const HBHERecHitCollection& hbheHits,
00510                                    const HORecHitCollection& hoHits,
00511                                    const HFRecHitCollection& hfHits,
00512                                    const HFDigiCollection& hf,
00513                                    int   bunchCrossing
00514                                    )
00515   
00516 { 
00517   //processEvent loop
00518   if (!dbe_)
00519     {
00520       if (debug_>0) std::cout <<"HcalBeamMonitor::processEvent   DQMStore not instantiated!!!"<<std::endl;
00521       return;
00522     }
00523 
00524   HBHERecHitCollection::const_iterator HBHEiter;
00525   HORecHitCollection::const_iterator HOiter;
00526   HFRecHitCollection::const_iterator HFiter;
00527 
00528   double totalX=0;
00529   double totalY=0;
00530   double totalE=0;
00531 
00532   double HBtotalX=0;
00533   double HBtotalY=0;
00534   double HBtotalE=0;
00535   double HEtotalX=0;
00536   double HEtotalY=0;
00537   double HEtotalE=0;
00538   double HOtotalX=0;
00539   double HOtotalY=0;
00540   double HOtotalE=0;
00541   double HFtotalX=0;
00542   double HFtotalY=0;
00543   double HFtotalE=0;
00544      
00545   float hitsp[13][36][2];
00546   float hitsm[13][36][2];
00547   float hitsp_Et[13][36][2];
00548   float hitsm_Et[13][36][2];
00549   
00550   for(int m=0;m<13;m++){
00551     for(int n=0;n<36;n++){
00552       hitsp[m][n][0]=0;
00553       hitsp[m][n][1]=0; 
00554       hitsm[m][n][0]=0;
00555       hitsm[m][n][1]=0;
00556 
00557       hitsp_Et[m][n][0]=0;
00558       hitsp_Et[m][n][1]=0; 
00559       hitsm_Et[m][n][0]=0;
00560       hitsm_Et[m][n][1]=0;
00561     }
00562   }
00563 
00564   if(hbheHits.size()>0)
00565     {
00566       double HB_weightedX[HBETASIZE]={0.};
00567       double HB_weightedY[HBETASIZE]={0.};
00568       double HB_energy[HBETASIZE]={0.};
00569       
00570       double HE_weightedX[HEETASIZE]={0.};
00571       double HE_weightedY[HEETASIZE]={0.};
00572       double HE_energy[HEETASIZE]={0.};
00573       
00574       int ieta, iphi;
00575       
00576       for (HBHEiter=hbheHits.begin(); 
00577            HBHEiter!=hbheHits.end(); 
00578            ++HBHEiter) 
00579         { 
00580           
00581           // loop over all hits
00582           if (HBHEiter->energy()<0) continue; // don't consider negative-energy cells
00583           HcalDetId id(HBHEiter->detid().rawId());
00584           ieta=id.ieta();
00585           iphi=id.iphi();
00586           
00587           int index=-1;
00588           if ((HcalSubdetector)(id.subdet())==HcalBarrel)
00589             {
00590               HBtotalX+=HBHEiter->energy()*cos(PI*iphi/36.);
00591               HBtotalY+=HBHEiter->energy()*sin(PI*iphi/36.);
00592               HBtotalE+=HBHEiter->energy();
00593               
00594               index=ieta+ETA_OFFSET_HB;
00595               if (index<0 || index>= HBETASIZE) continue;
00596               HB_weightedX[index]+=HBHEiter->energy()*cos(PI*iphi/36.);
00597               HB_weightedY[index]+=HBHEiter->energy()*sin(PI*iphi/36.);
00598               HB_energy[index]+=HBHEiter->energy();
00599             } // if id.subdet()==HcalBarrel
00600           
00601           else
00602             {
00603               HEtotalX+=HBHEiter->energy()*cos(PI*iphi/36.);
00604               HEtotalY+=HBHEiter->energy()*sin(PI*iphi/36.);
00605               HEtotalE+=HBHEiter->energy();
00606               
00607               index=ieta+ETA_OFFSET_HE;
00608               if (index<0 || index>= HEETASIZE) continue;
00609               HE_weightedX[index]+=HBHEiter->energy()*cos(PI*iphi/36.);
00610               HE_weightedY[index]+=HBHEiter->energy()*sin(PI*iphi/36.);
00611               HE_energy[index]+=HBHEiter->energy();
00612             }
00613         } // for (HBHEiter=hbheHits.begin()...
00614           // Fill each histogram
00615       
00616       int hbeta=ETA_OFFSET_HB;
00617       for (int i=-1*hbeta;i<=hbeta;++i)
00618         {
00619           if (i==0) continue;
00620           int index = i+ETA_OFFSET_HB;
00621           if (index<0 || index>= HBETASIZE) continue;
00622           if (HB_energy[index]==0) continue;
00623           double moment=pow(HB_weightedX[index],2)+pow(HB_weightedY[index],2);
00624           moment=pow(moment,0.5);
00625           moment/=HB_energy[index];
00626           if (moment!=0)
00627             {
00628               if (makeDiagnostics_) HB_CenterOfEnergyRadius[index]->Fill(moment);
00629               COEradiusVSeta->Fill(i,moment);
00630             }
00631         } // for (int i=-1*hbeta;i<=hbeta;++i)
00632 
00633       int heeta=ETA_OFFSET_HE;
00634       for (int i=-1*heeta;i<=heeta;++i)
00635         {
00636           if (i==0) continue;
00637           if (i>-1*ETA_BOUND_HE && i <ETA_BOUND_HE) continue;
00638           int index = i + ETA_OFFSET_HE;
00639           if (index<0 || index>= HEETASIZE) continue;
00640           if (HE_energy[index]==0) continue;
00641           double moment=pow(HE_weightedX[index],2)+pow(HE_weightedY[index],2);
00642           moment=pow(moment,0.5);
00643           moment/=HE_energy[index];
00644           if (moment!=0)
00645             {
00646               if (makeDiagnostics_) HE_CenterOfEnergyRadius[index]->Fill(moment);
00647               COEradiusVSeta->Fill(i,moment);
00648             }
00649         } // for (int i=-1*heeta;i<=heeta;++i)
00650 
00651     } // if (hbheHits.size()>0)
00652 
00653   
00654   // HO loop
00655   if(hoHits.size()>0)
00656     {
00657       double HO_weightedX[HOETASIZE]={0.};
00658       double HO_weightedY[HOETASIZE]={0.};
00659       double HO_energy[HOETASIZE]={0.};
00660       double offset;
00661 
00662       int ieta, iphi;
00663       for (HOiter=hoHits.begin(); 
00664            HOiter!=hoHits.end(); 
00665            ++HOiter) 
00666         { 
00667           // loop over all cells
00668           if (HOiter->energy()<0) continue;  // don't include negative-energy cells?
00669           HcalDetId id(HOiter->detid().rawId());
00670           ieta=id.ieta();
00671           iphi=id.iphi();
00672 
00673           HOtotalX+=HOiter->energy()*cos(PI*iphi/36.);
00674           HOtotalY+=HOiter->energy()*sin(PI*iphi/36.);
00675           HOtotalE+=HOiter->energy();
00676 
00677           int index=ieta+ETA_OFFSET_HO;
00678           if (index<0 || index>= HOETASIZE) continue;
00679           HO_weightedX[index]+=HOiter->energy()*cos(PI*iphi/36.);
00680           HO_weightedY[index]+=HOiter->energy()*sin(PI*iphi/36.);
00681           HO_energy[index]+=HOiter->energy();
00682         } // for (HOiter=hoHits.begin();...)
00683           
00684       for (int i=-1*ETA_OFFSET_HO;i<=ETA_OFFSET_HO;++i)
00685         {
00686           if (i==0) continue;
00687           int index = i + ETA_OFFSET_HO;
00688           if (index < 0 || index>= HOETASIZE) continue;
00689           if (HO_energy[index]==0) continue;
00690           double moment=pow(HO_weightedX[index],2)+pow(HO_weightedY[index],2);
00691           moment=pow(moment,0.5);
00692           moment/=HO_energy[index];
00693           // Shift HO values by 0.5 units in eta relative to HB
00694           offset = (i>0 ? 0.5: -0.5);
00695           if (moment!=0)
00696             {
00697               if (makeDiagnostics_) HO_CenterOfEnergyRadius[index]->Fill(moment);
00698               COEradiusVSeta->Fill(i+offset,moment);
00699             }
00700         } // for (int i=-1*hoeta;i<=hoeta;++i)
00701     } // if (hoHits.size()>0)
00702     
00704   // HF loop
00705 
00706   Etsum_ratio_map->Fill(-1,-1,1); // fill underflow bin with number of events
00707   {
00708     if(hfHits.size()>0)
00709       {
00710         double HF_weightedX[HFETASIZE]={0.};
00711         double HF_weightedY[HFETASIZE]={0.};
00712         double HF_energy[HFETASIZE]={0.};
00713         double offset;
00714         
00715         // Assume ZS until shown otherwise
00716         double emptytowersRing1 = ring1totalchannels_;
00717         double emptytowersRing2 = ring2totalchannels_;
00718         double ZStowersRing1 = ring1totalchannels_;
00719         double ZStowersRing2 = ring2totalchannels_;
00720         
00721         int ieta, iphi;
00722         float et,eta,phi,r;
00723 
00724         HFlumi_occ_LS->Fill(-1,-1,1 ); // event counter in occupancy histogram underflow bin
00725         // set maximum to HFlumi_occ_LS->getBinContent(0,0)?  
00726         // that won't work -- offline will add multiple histograms, and maximum will get screwed up?
00727         // No, we can add it here, but we also need a call to setMaximum in the client as well.
00728         HFlumi_occ_LS->getTH2F()->SetMaximum(HFlumi_occ_LS->getBinContent(0,0));
00729 
00730         double etx=0, ety=0;
00731 
00732         for (HFiter=hfHits.begin(); 
00733              HFiter!=hfHits.end(); 
00734              ++HFiter) 
00735           {  // loop on hfHits
00736             // If hit present, don't count it as ZS any more
00737             ieta = HFiter->id().ieta();
00738             iphi = HFiter->id().iphi();
00739 
00740             int binieta=ieta;
00741             if (ieta<0) binieta+=41;
00742             else if (ieta>0) binieta-=15;
00743 
00744             // Count that hit was found in one of the rings used for luminosity calculation.
00745             // If so, decrease the number of empty channels per ring by 1
00746             if (abs(ieta)>=33 && abs(ieta)<=36) // luminosity ring check
00747               {
00748                 // don't subtract away cells that have already been removed as bad
00749                 if (BadCells_.find(HFiter->id())==BadCells_.end()) // bad cell not found
00750                   {
00751                     if ((abs(ieta)<35) && HFiter->id().depth()==1) --ZStowersRing1;
00752                     else if ((abs(ieta)>34) && HFiter->id().depth()==2) -- ZStowersRing2;
00753                   }
00754               }
00755 
00756             if (HFiter->energy()<0) continue;  // don't include negative-energy cells?
00757 
00758             eta=theHFEtaBounds[abs(ieta)-29];
00759             et=HFiter->energy()/cosh(eta)/area[abs(ieta)-29];
00760             if (abs(ieta)>=33 && abs(ieta)<=36) // Luminosity ring check
00761               {
00762                 // don't count cells that are below threshold, or that have been marked bad in Chan Stat DB
00763                 if (et>=occThresh_ && BadCells_.find(HFiter->id())==BadCells_.end() ) // minimum ET threshold
00764                   {
00765                     if ((abs(ieta)<35) && HFiter->id().depth()==1) --emptytowersRing1;
00766                     else if ((abs(ieta)>34) && HFiter->id().depth()==2) -- emptytowersRing2;
00767                   }
00768               }
00769             r=radius[abs(ieta)-29];
00770             if(HFiter->id().iphi()<37)
00771               phi=HFiter->id().iphi()*0.087266;
00772             else phi=(HFiter->id().iphi()-72)*0.087266;
00773            
00774             
00775             if (HFiter->id().depth()==1)
00776               {
00777                 Etsum_eta_L->Fill(binieta,et);
00778                 Etsum_phi_L->Fill(iphi,et);
00779                 Etsum_map_L->Fill(binieta,iphi,et);
00780                 Etsum_rphi_L->Fill(r,phi,et);
00781               
00782                 if(ieta>0) {
00783                   hitsp[ieta-29][(HFiter->id().iphi()-1)/2][0]=HFiter->energy();
00784                   hitsp_Et[ieta-29][(HFiter->id().iphi()-1)/2][0]=et;
00785                 }
00786                 else if(ieta<0) {
00787                   hitsm[-ieta-29][(HFiter->id().iphi()-1)/2][0]=HFiter->energy(); 
00788                   hitsm_Et[-ieta-29][(HFiter->id().iphi()-1)/2][0]=et; 
00789                 }
00790               } // if (HFiter->id().depth()==1)
00791          
00792             //Fill 3 histos for Short Fibers :
00793             if (HFiter->id().depth()==2)
00794               {
00795                 Etsum_eta_S->Fill(binieta,et);
00796                 Etsum_phi_S->Fill(iphi,et);
00797                 Etsum_rphi_S->Fill(r,phi,et); 
00798                 Etsum_map_S->Fill(binieta,iphi,et);
00799                 if(ieta>0)  
00800                   {
00801                     hitsp[ieta-29][(HFiter->id().iphi()-1)/2][1]=HFiter->energy();
00802                     hitsp_Et[ieta-29][(HFiter->id().iphi()-1)/2][1]=et;
00803                   }
00804                 else if(ieta<0)  { 
00805                   hitsm[-ieta-29][(HFiter->id().iphi()-1)/2][1]=HFiter->energy();
00806                   hitsm_Et[-ieta-29][(HFiter->id().iphi()-1)/2][1]=et;
00807                 }
00808           
00809               } // depth()==2
00810             Energy_Occ->Fill(HFiter->energy()); 
00811             
00812             //HF: no non-threshold occupancy map is filled?
00813 
00814             if ((abs(ieta) == 33 || abs(ieta) == 34) && HFiter->id().depth() == 1)
00815               { 
00816                 etx+=et*cos(PI*iphi/36.);
00817                 ety+=et*sin(PI*iphi/36.);
00818 
00819                 HFlumi_Et_per_channel_vs_lumiblock->Fill(currentLS,et);
00820                 if (et>occThresh_)
00821                   {
00822                     int etabin=0;
00823                     if (ieta<0)
00824                       etabin=36+ieta; // bins 0-3 correspond to ieta = -36, -35, -34, -33
00825                     else
00826                       etabin=ieta-29; // bins 4-7 correspond to ieta = 33, 34, 35, 36
00827                     HFlumi_occ_LS->Fill(etabin,HFiter->id().iphi());
00828                   }
00829               }
00830 
00831             else if ((abs(ieta) == 35 || abs(ieta) == 36) && HFiter->id().depth() == 2)
00832               { 
00833                 etx+=et*cos(PI*iphi/36.);
00834                 ety+=et*sin(PI*iphi/36.);
00835 
00836                 HFlumi_Et_per_channel_vs_lumiblock->Fill(currentLS,et);
00837                 if (et>occThresh_)
00838                   {
00839                     int etabin=0;
00840                     if (ieta<0)
00841                       etabin=36+ieta; // bins 0-3 correspond to ieta = -36, -35, -34, -33
00842                     else
00843                       etabin=ieta-29; // bins 4-7 correspond to ieta = 33, 34, 35, 36
00844                     HFlumi_occ_LS->Fill(etabin,HFiter->id().iphi());
00845                   }
00846               }
00847 
00848             // Fill occupancy plots.
00849             
00850             int value=0;
00851             if(et>occThresh_) value=1;
00852 
00853             if (HFiter->id().depth()==1)
00854               {
00855                 Occ_eta_L->Fill(binieta,value);
00856                 Occ_phi_L->Fill(iphi,value);
00857                 Occ_map_L->Fill(binieta,iphi,value);
00858                 Occ_rphi_L->Fill(r,phi,value);
00859               }
00860               
00861             else if (HFiter->id().depth()==2)
00862               {
00863                 Occ_eta_S->Fill(binieta,value);
00864                 Occ_phi_S->Fill(iphi,value);
00865                 Occ_map_S->Fill(binieta,iphi,value);
00866                 Occ_rphi_S->Fill(r,phi,value);
00867               }  
00868             HcalDetId id(HFiter->detid().rawId());
00869 
00870             HFtotalX+=HFiter->energy()*cos(PI*iphi/36.);
00871             HFtotalY+=HFiter->energy()*sin(PI*iphi/36.);
00872             HFtotalE+=HFiter->energy();
00873 
00874             int index=ieta+ETA_OFFSET_HF;
00875             if (index<0 || index>= HFETASIZE) continue;
00876             HF_weightedX[index]+=HFiter->energy()*cos(PI*iphi/36.);
00877             HF_weightedY[index]+=HFiter->energy()*sin(PI*iphi/36.);
00878             HF_energy[index]+=HFiter->energy();
00879             
00880           } // for (HFiter=hfHits.begin();...)
00881         
00882         // looped on all HF hits; calculate empty fraction
00883         //  empty towers  = # of cells with ET < 0.0625 GeV, or cells missing because of ZS
00884         //  Calculated as :  144 - (# of cells with ET >= 0.0625 GeV)
00885         //  At some point, allow for calculations when channels are masked (and less than 144 channels expected)
00886 
00887         // Check Ring 1
00888         double logvalue=-1;
00889         if (ring1totalchannels_>0)
00890           {
00891             if (emptytowersRing1>0)
00892               logvalue=-1.*log(emptytowersRing1/ring1totalchannels_);
00893             HFlumi_Occupancy_per_channel_vs_lumiblock_RING1->Fill(currentLS,logvalue);
00894             HFlumi_Occupancy_per_channel_vs_BX_RING1->Fill(bunchCrossing,logvalue);
00895           }
00896         // Check Ring 2
00897         logvalue=-1;
00898         if (ring2totalchannels_>0)
00899           {
00900             if (emptytowersRing2>0)
00901               logvalue=-1.*log(emptytowersRing2/ring2totalchannels_);
00902             HFlumi_Occupancy_per_channel_vs_lumiblock_RING2->Fill(currentLS,logvalue);
00903             HFlumi_Occupancy_per_channel_vs_BX_RING2->Fill(bunchCrossing,logvalue);
00904           }
00905 
00906         HFlumi_ETsum_vs_BX->Fill(bunchCrossing,pow(etx*etx+ety*ety,0.5));
00907         int hfeta=ETA_OFFSET_HF;
00908         for (int i=-1*hfeta;i<=hfeta;++i)
00909           {
00910             if (i==0) continue;
00911             if (i>-1*ETA_BOUND_HF && i <ETA_BOUND_HF) continue;
00912             int index = i + ETA_OFFSET_HF;
00913             if (index<0 || index>= HFETASIZE) continue;
00914             if (HF_energy[index]==0) continue;
00915             double moment=pow(HF_weightedX[index],2)+pow(HF_weightedY[index],2);
00916             moment=pow(moment,0.5);
00917             moment/=HF_energy[index];
00918             offset = (i>0 ? 0.5: -0.5);
00919             if (moment!=0)
00920               {
00921                 if (makeDiagnostics_) HF_CenterOfEnergyRadius[index]->Fill(moment);
00922                 COEradiusVSeta->Fill(i+offset,moment);
00923               }
00924           } // for (int i=-1*hfeta;i<=hfeta;++i)
00925         float ratiom,ratiop;
00926           
00927         for(int i=0;i<13;i++){
00928           for(int j=0;j<36;j++){
00929               
00930             if(hitsp[i][j][0]==hitsp[i][j][1]) continue;
00931               
00932             if (hitsp[i][j][0] < 1.2 && hitsp[i][j][1] < 1.8) continue;
00933             //use only lumi rings
00934             if (((i+29) < 33) || ((i+29) > 36)) continue;
00935             ratiop=fabs((fabs(hitsp[i][j][0])-fabs(hitsp[i][j][1]))/(fabs(hitsp[i][j][0])+fabs(hitsp[i][j][1])));
00936             //cout<<ratiop<<std::endl;
00937             if ((hitsp_Et[i][j][0] > 5. && hitsp[i][j][1] < 1.8) || (hitsp_Et[i][j][1] > 5. &&  hitsp[i][j][0] < 1.2)){
00938               Etsum_ratio_p->Fill(ratiop);
00939               if(abs(ratiop>0.95)) Etsum_ratio_map->Fill(i,2*j+1); // i=4,5,6,7 for HFlumi rings 
00940             }
00941           }
00942         }
00943           
00944         for(int p=0;p<13;p++){
00945           for(int q=0;q<36;q++){
00946               
00947             if(hitsm[p][q][0]==hitsm[p][q][1]) continue;
00948 
00949             if (hitsm[p][q][0] < 1.2 && hitsm[p][q][1] < 1.8) continue;
00950             //use only lumi rings
00951             if (((p+29) < 33) || ((p+29) > 36)) continue;
00952             ratiom=fabs((fabs(hitsm[p][q][0])-fabs(hitsm[p][q][1]))/(fabs(hitsm[p][q][0])+fabs(hitsm[p][q][1])));         
00953             if ((hitsm_Et[p][q][0] > 5. && hitsm[p][q][1] < 1.8) || (hitsm_Et[p][q][1] > 5. && hitsm[p][q][0] < 1.2)){
00954               Etsum_ratio_m->Fill(ratiom);
00955               if(abs(ratiom>0.95)) Etsum_ratio_map->Fill(7-p,2*q+1); // p=4,5,6,7 for HFlumi rings
00956               //p=7:  ieta=-36; p=4:  ieta=-33
00957             }
00958           }
00959         } 
00960       } // if (hfHits.size()>0)
00961   
00962     totalX=HBtotalX+HEtotalX+HOtotalX+HFtotalX;
00963     totalY=HBtotalY+HEtotalY+HOtotalY+HFtotalY;
00964     totalE=HBtotalE+HEtotalE+HOtotalE+HFtotalE;
00965 
00966     double moment;
00967     if (HBtotalE>0)
00968       {
00969         moment=pow(HBtotalX*HBtotalX+HBtotalY*HBtotalY,0.5)/HBtotalE;
00970         HBCenterOfEnergyRadius->Fill(moment);
00971         HBCenterOfEnergy->Fill(HBtotalX/HBtotalE, HBtotalY/HBtotalE);
00972       }
00973     if (HEtotalE>0)
00974       {
00975         moment=pow(HEtotalX*HEtotalX+HEtotalY*HEtotalY,0.5)/HEtotalE;
00976         HECenterOfEnergyRadius->Fill(moment);
00977         HECenterOfEnergy->Fill(HEtotalX/HEtotalE, HEtotalY/HEtotalE);
00978       }
00979     if (HOtotalE>0)
00980       {
00981         moment=pow(HOtotalX*HOtotalX+HOtotalY*HOtotalY,0.5)/HOtotalE;
00982         HOCenterOfEnergyRadius->Fill(moment);
00983         HOCenterOfEnergy->Fill(HOtotalX/HOtotalE, HOtotalY/HOtotalE);
00984       }
00985     if (HFtotalE>0)
00986       {
00987         moment=pow(HFtotalX*HFtotalX+HFtotalY*HFtotalY,0.5)/HFtotalE;
00988         HFCenterOfEnergyRadius->Fill(moment);
00989         HFCenterOfEnergy->Fill(HFtotalX/HFtotalE, HFtotalY/HFtotalE);
00990       }
00991     if (totalE>0)
00992       {
00993         moment = pow(totalX*totalX+totalY*totalY,0.5)/totalE;
00994         CenterOfEnergyRadius->Fill(moment);
00995         CenterOfEnergy->Fill(totalX/totalE, totalY/totalE);
00996       }
00997 
00998 
00999     
01000     for (HFDigiCollection::const_iterator j=hf.begin(); j!=hf.end(); j++){
01001       const HFDataFrame digi = (const HFDataFrame)(*j);
01002       //  calibs_= cond.getHcalCalibrations(digi.id());  // Old method was made private. 
01003       //       float en=0;
01004       //       float ts =0; float bs=0;
01005       //       int maxi=0; float maxa=0;
01006       //       for(int i=sigS0_; i<=sigS1_; i++){
01007       //        if(digi.sample(i).adc()>maxa){maxa=digi.sample(i).adc(); maxi=i;}
01008       //       }
01009       //       for(int i=sigS0_; i<=sigS1_; i++){         
01010       //        float tmp1 =0;   
01011       //         int j1=digi.sample(i).adc();
01012       //         tmp1 = (LedMonAdc2fc[j1]+0.5);           
01013       //        en += tmp1-calibs_.pedestal(digi.sample(i).capid());
01014       //        if(i>=(maxi-1) && i<=maxi+1){
01015       //          ts += i*(tmp1-calibs_.pedestal(digi.sample(i).capid()));
01016       //          bs += tmp1-calibs_.pedestal(digi.sample(i).capid());
01017       //        }
01018       //       }
01019 
01020       //---HFlumiplots
01021       int theTStobeused = 6;
01022       // will have masking later:
01023       int mask=1; 
01024       if(mask!=1) continue;
01025       //if we want to sum the 10 TS instead of just taking one:
01026       for (int i=0; i<digi.size(); i++) {
01027         if (i==theTStobeused) {
01028           float tmpET =0;
01029           int jadc=digi.sample(i).adc();
01030           //NOW LUT used in HLX are only identy LUTs, so Et filled
01031           //with unlinearised adc, ie tmpET = jadc
01032           //      tmpET = (adc2fc[jadc]+0.5);
01033           tmpET = jadc;
01034 
01035           //-find which wedge we are in
01036           //  ETsum and Occupancy will be summed for both L and S
01037           if(digi.id().ieta()>28){
01038             if((digi.id().iphi()==1)||(digi.id().iphi()==71)){
01039               HFlumi_ETsum_perwedge->Fill(1,tmpET);
01040               if((digi.id().ieta()==33)||(digi.id().ieta()==34)) {
01041                 if(jadc>100) HFlumi_Occupancy_above_thr_r1->Fill(1,1);
01042                 if((jadc>=10)&&(jadc<=100)) HFlumi_Occupancy_between_thrs_r1->Fill(1,1);
01043                 if(jadc<10) HFlumi_Occupancy_below_thr_r1->Fill(1,1);
01044               }
01045               else if((digi.id().ieta()==35)||(digi.id().ieta()==36)) {
01046                 if(jadc>100) HFlumi_Occupancy_above_thr_r2->Fill(1,1);
01047                 if((jadc>=10)&&(jadc<=100)) HFlumi_Occupancy_between_thrs_r2->Fill(1,1);
01048                 if(jadc<10) HFlumi_Occupancy_below_thr_r2->Fill(1,1);
01049               }
01050             }
01051             else {
01052               for (int iwedge=2; iwedge<19; iwedge++) {
01053                 int itmp=4*(iwedge-1);
01054                 if( (digi.id().iphi()==(itmp+1)) || (digi.id().iphi()==(itmp-1))) {
01055                   HFlumi_ETsum_perwedge->Fill(iwedge,tmpET);
01056                   if((digi.id().ieta()==33)||(digi.id().ieta()==34)) {
01057                     if(jadc>100) HFlumi_Occupancy_above_thr_r1->Fill(iwedge,1);
01058                     if((jadc>=10)&&(jadc<=100)) HFlumi_Occupancy_between_thrs_r1->Fill(iwedge,1);
01059                     if(jadc<10) HFlumi_Occupancy_below_thr_r1->Fill(iwedge,1);
01060                   }
01061                   else if((digi.id().ieta()==35)||(digi.id().ieta()==36)) {
01062                     if(jadc>100) HFlumi_Occupancy_above_thr_r2->Fill(iwedge,1);
01063                     if((jadc>=10)&&(jadc<=100)) HFlumi_Occupancy_between_thrs_r2->Fill(iwedge,1);
01064                     if(jadc<10) HFlumi_Occupancy_below_thr_r2->Fill(iwedge,1);
01065                   }
01066                   iwedge=99;
01067                 }
01068               }
01069             }
01070           }  //--endif ieta in HF+
01071           else if(digi.id().ieta()<-28){
01072             if((digi.id().iphi()==1)||(digi.id().iphi()==71)){
01073               HFlumi_ETsum_perwedge->Fill(19,tmpET);
01074               if((digi.id().ieta()==-33)||(digi.id().ieta()==-34)) {
01075                 if(jadc>100) HFlumi_Occupancy_above_thr_r1->Fill(19,1);
01076                 if((jadc>=10)&&(jadc<=100)) HFlumi_Occupancy_between_thrs_r1->Fill(19,1);
01077                 if(jadc<10) HFlumi_Occupancy_below_thr_r1->Fill(19,1);
01078               }
01079               else if((digi.id().ieta()==-35)||(digi.id().ieta()==-36)) {
01080                 if(jadc>100) HFlumi_Occupancy_above_thr_r2->Fill(19,1);
01081                 if((jadc>=10)&&(jadc<=100)) HFlumi_Occupancy_between_thrs_r2->Fill(19,1);
01082                 if(jadc<10) HFlumi_Occupancy_below_thr_r2->Fill(19,1);
01083               }
01084             }
01085             else {
01086               for (int iw=2; iw<19; iw++) {
01087                 int itemp=4*(iw-1);
01088                 if( (digi.id().iphi()==(itemp+1)) || (digi.id().iphi()==(itemp-1))) {
01089                   HFlumi_ETsum_perwedge->Fill(iw+18,tmpET);
01090                   if((digi.id().ieta()==-33)||(digi.id().ieta()==-34)) {
01091                     if(jadc>100) HFlumi_Occupancy_above_thr_r1->Fill(iw+18,1);
01092                     if((jadc>=10)&&(jadc<=100)) HFlumi_Occupancy_between_thrs_r1->Fill(iw+18,1);
01093                     if(jadc<10) HFlumi_Occupancy_below_thr_r1->Fill(iw+18,1);
01094                   }
01095                   else if((digi.id().ieta()==-35)||(digi.id().ieta()==-36)) {
01096                     if(jadc>100) HFlumi_Occupancy_above_thr_r2->Fill(iw+18,1);
01097                     if((jadc>=10)&&(jadc<=100)) HFlumi_Occupancy_between_thrs_r2->Fill(iw+18,1);
01098                     if(jadc<10) HFlumi_Occupancy_below_thr_r2->Fill(iw+18,1);
01099                   }
01100                   iw=99;
01101                 }
01102               }
01103             }
01104           }//---endif ieta inHF-
01105         }//---endif TS=nr6
01106       } 
01107     }//------end loop over TS for lumi
01108     return;
01109   }
01110 }
01111  // void HcalBeamMonitor::processEvent(const HBHERecHit Collection&hbheHits; ...)
01112 
01113 
01114 void HcalBeamMonitor::beginLuminosityBlock(const edm::LuminosityBlock& lumiSeg,
01115                                            const edm::EventSetup& c)
01116   
01117 {
01118   // reset histograms that get updated each luminosity section
01119 
01120   if (LumiInOrder(lumiSeg.luminosityBlock())==false) return;
01121   HcalBaseDQMonitor::beginLuminosityBlock(lumiSeg,c);
01122 
01123   if (lumiSeg.luminosityBlock()==lastProcessedLS_) return; // we're seeing more events from current lumi section (after some break) -- should not reset histogram
01124   ProblemsCurrentLB->Reset();
01125   HFlumi_occ_LS->Reset();
01126   std::stringstream title;
01127   title <<"HFlumi occupancy for LS # " <<currentLS;
01128   HFlumi_occ_LS->getTH2F()->SetTitle(title.str().c_str());
01129   return;
01130 } // void HcalBeamMonitor::beginLuminosityBlock()
01131 
01132 void HcalBeamMonitor::endLuminosityBlock(const edm::LuminosityBlock& lumiSeg,
01133                                          const edm::EventSetup& c)
01134 {
01135   if (debug_>1) std::cout <<"<HcalBeamMonitor::endLuminosityBlock>"<<std::endl;
01136   if (LumiInOrder(lumiSeg.luminosityBlock())==false)
01137     {
01138       if (debug_>1)  
01139         std::cout <<"<HcalBeamMonitor::endLuminosityBlock>  Failed LumiInOrder test!"<<std::endl;
01140       return;
01141     }
01142   lastProcessedLS_=lumiSeg.luminosityBlock();
01143   float Nentries=HFlumi_occ_LS->getBinContent(-1,-1);
01144   if (debug_>3) 
01145     std::cout <<"Number of entries in this LB = "<<Nentries<<std::endl;
01146 
01147   if (Nentries<minEvents_) 
01148     {
01149       // not enough entries to determine status; fill everything with -1 and return
01150       HFlumi_Ring1Status_vs_LS->Fill(currentLS,-1);
01151       HFlumi_Ring2Status_vs_LS->Fill(currentLS,-1);
01152       if (Online_==false)
01153         return;
01154       // write to output file if required (Online running)
01155       if (lumiqualitydir_.size()==0)
01156         return;
01157       // dump out lumi quality file
01158       std::ofstream outStream(outfile_.str().c_str(),std::ios::app);
01159       outStream<<currentLS<<"\t\t-1\t\t\t-1\t\t\t-1\t\t"<<Nentries<<std::endl;
01160       outStream.close();
01161       return;
01162     }
01163   if (Nentries==0) return;
01164 
01165 
01166   HFlumi_total_deadcells->Fill(-1,-1,1); // counts good lumi sections in underflow bin
01167   HFlumi_total_hotcells->Fill(-1,-1,1);
01168   HFlumi_diag_deadcells->Fill(-1,-1,1); // counts good lumi sections in underflow bin
01169   HFlumi_diag_hotcells->Fill(-1,-1,1);
01170 
01171   // ADD IETA MAP
01172   int ietamap[8]={-36,-35,-34,-33,33,34,35,36};
01173   int ieta=-1, iphi = -1, depth=-1;
01174   int badring1=0;
01175   int badring2=0;
01176   int ndeadcells=0;
01177   int nhotcells=0;
01178   
01179   // Loop over cells once to count hot & dead chanels
01180   for (int x=1;x<=HFlumi_occ_LS->getTH2F()->GetNbinsX();++x)
01181     {
01182       for (int y=1;y<=HFlumi_occ_LS->getTH2F()->GetNbinsY();++y)
01183         {
01184 
01185           // Skip over channels that are flagged as bad
01186           if (x<=8)
01187             ieta=ietamap[x-1];
01188           else
01189             ieta=-1;
01190           iphi=2*y-1;
01191           if (abs(ieta)==33 || abs(ieta)==34)  depth=1;
01192           else if (abs(ieta)==35 || abs(ieta)==36) depth =2;
01193           else depth = -1;
01194           if (depth !=-1 && ieta!=1)
01195             {
01196               HcalDetId thisID(HcalForward, ieta, iphi, depth);
01197               if (BadCells_.find(thisID)!=BadCells_.end())
01198                 continue;
01199             }
01200           double Ncellhits=HFlumi_occ_LS->getBinContent(x,y);
01201           if (Ncellhits==0)
01202             {
01203               ++ndeadcells;
01204               HFlumi_diag_deadcells->Fill(x-1,2*y-1,1);
01205             }
01206           // hot if present in more than 25% of events in the LS
01207           if (Ncellhits>hotrate_*Nentries) 
01208             {
01209               ++nhotcells;
01210               HFlumi_diag_hotcells->Fill(x-1,2*y-1,1);
01211             }
01212           if (Ncellhits==0 || Ncellhits>hotrate_*Nentries) // cell was either hot or dead
01213             {
01214               if (depth==1)  badring1++;
01215               else if (depth==2)  badring2++;
01216             }
01217         } // loop over y
01218     } // loop over x
01219 
01220   // Fill problem histogram underflow bind with number of events
01221   ProblemsCurrentLB->Fill(-1,-1,levt_);
01222   if (ndeadcells+nhotcells>=minBadCells_)
01223     {
01224       // Fill with number of error channels * events (assume bad for all events in LS)
01225       ProblemsCurrentLB->Fill(6,0,(ndeadcells+nhotcells)*levt_);
01226       for (int x=1;x<=HFlumi_occ_LS->getTH2F()->GetNbinsX();++x)
01227         {
01228           for (int y=1;y<=HFlumi_occ_LS->getTH2F()->GetNbinsY();++y)
01229             {
01230               if (x<=8)
01231                 ieta=ietamap[x-1];
01232               else
01233                 ieta=-1;
01234               iphi=2*y-1;
01235               if (abs(ieta)==33 || abs(ieta)==34)  depth=1;
01236               else if (abs(ieta)==35 || abs(ieta)==36) depth =2;
01237               else depth = -1;
01238               if (depth !=-1 && ieta!=1)
01239                 {
01240                   // skip over channels that are flagged as bad
01241                   HcalDetId thisID(HcalForward, ieta, iphi, depth);
01242                   if (BadCells_.find(thisID)!=BadCells_.end())
01243                     continue;
01244                 }
01245               double Ncellhits=HFlumi_occ_LS->getBinContent(x,y);
01246               if (Ncellhits==0)
01247                 {
01248                   // One new luminosity section found with no entries for the cell in question
01249                   HFlumi_total_deadcells->Fill(x-1,2*y-1,1);
01250                 } // dead cell check
01251               
01252               // hot if present in more than 25% of events in the LS
01253               if (Ncellhits>hotrate_*Nentries)
01254                 {
01255                   HFlumi_total_hotcells->Fill(x-1,2*y-1,1);
01256                 } // hot cell check
01257             } // loop over y
01258         } // loop over x
01259     } // if (ndeadcells+nhotcells>=minBadCells_)
01260 
01261   // Fill fraction of bad channels found in this LS
01262   double ring1status=0;
01263   double ring2status=0;
01264   if (ring1totalchannels_==0)
01265     ring1status=0;
01266   else
01267     ring1status=1-1.*badring1/ring1totalchannels_;
01268   HFlumi_Ring1Status_vs_LS->Fill(currentLS,ring1status);
01269   if (ring2totalchannels_==0)
01270     ring2status=0;
01271   else
01272     ring2status=1-1.*badring2/ring2totalchannels_;
01273   HFlumi_Ring2Status_vs_LS->Fill(currentLS,ring2status);  
01274   
01275   // Good status:  ring1 and ring2 status both > 90%
01276   int totalstatus=0;
01277   if (ring1status>0.9 && ring2status>0.9)
01278     totalstatus=1;
01279   else 
01280     {
01281       if (ring1status<=0.9)
01282         totalstatus-=2;
01283       if (ring2status<=0.9)
01284         totalstatus-=4;
01285     }
01286 
01287   if (lumiqualitydir_.size()==0)
01288     return;
01289   // dump out lumi quality file
01290   std::ofstream outStream(outfile_.str().c_str(),std::ios::app);
01291   outStream.precision(6);
01292   outStream<<currentLS<<"\t\t"<<ring1status<<"\t\t"<<ring2status<<"\t\t"<<totalstatus<<"\t\t"<<Nentries<<std::endl;
01293   outStream.close();
01294   return;
01295 }
01296 
01297 const float HcalBeamMonitor::area[]={0.111,0.175,0.175,0.175,0.175,0.175,0.174,0.178,0.172,0.175,0.178,0.346,0.604};
01298 const float HcalBeamMonitor::radius[]={1300,1162,975,818,686,576,483,406,340,286,240,201,169};
01299 
01300 void HcalBeamMonitor::SetEtaLabels(MonitorElement * h)
01301 {
01302   h->getTH2F()->GetXaxis()->SetBinLabel(1,"-36S");
01303   h->getTH2F()->GetXaxis()->SetBinLabel(2,"-35S");
01304   h->getTH2F()->GetXaxis()->SetBinLabel(3,"-34L");
01305   h->getTH2F()->GetXaxis()->SetBinLabel(4,"-33L");
01306   h->getTH2F()->GetXaxis()->SetBinLabel(5,"33L");
01307   h->getTH2F()->GetXaxis()->SetBinLabel(6,"34L");
01308   h->getTH2F()->GetXaxis()->SetBinLabel(7,"35S");
01309   h->getTH2F()->GetXaxis()->SetBinLabel(8,"36S");
01310   return;
01311 }
01312 
01313 DEFINE_FWK_MODULE(HcalBeamMonitor);
01314