00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "FWCore/Framework/interface/Event.h"
00016 #include "FWCore/Framework/interface/EventSetup.h"
00017 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00018 #include "FWCore/ServiceRegistry/interface/Service.h"
00019
00020
00021
00022 #include "DQMServices/Core/interface/MonitorElement.h"
00023
00024
00025 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00026 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00027 #include "DataFormats/EcalDetId/interface/EEDetId.h"
00028 #include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
00029
00030 #include "DataFormats/EcalRecHit/interface/EcalRecHit.h"
00031
00032 #include "DQMServices/Core/interface/DQMStore.h"
00033 #include "DQMOffline/CalibCalo/interface/DQMSourceEleCalib.h"
00034
00035
00036 using namespace std;
00037 using namespace edm;
00038
00039
00040
00041
00042
00043
00044 DQMSourceEleCalib::DQMSourceEleCalib( const edm::ParameterSet& ps ) :
00045 eventCounter_(0)
00046 {
00047 dbe_ = Service<DQMStore>().operator->();
00048 folderName_ = ps.getUntrackedParameter<string>("FolderName","ALCAStreamEcalSingleEle");
00049 productMonitoredEB_= ps.getParameter<edm::InputTag>("AlCaStreamEBTag");
00050 productMonitoredEE_= ps.getParameter<edm::InputTag>("AlCaStreamEETag");
00051
00052 saveToFile_=ps.getUntrackedParameter<bool>("SaveToFile",false);
00053 fileName_= ps.getUntrackedParameter<string>("FileName","MonitorAlCaEcalSingleEle.root");
00054 productMonitoredElectrons_ = ps.getParameter<InputTag>("electronCollection");
00055 prescaleFactor_ = ps.getUntrackedParameter<unsigned int>("prescaleFactor",1);
00056
00057 }
00058
00059
00060 DQMSourceEleCalib::~DQMSourceEleCalib()
00061 {}
00062
00063
00064
00065 void DQMSourceEleCalib::beginJob(){
00066
00067
00068 dbe_->setCurrentFolder(folderName_);
00069
00070 recHitsPerElectron_ = dbe_->book1D("recHitsPerElectron_","recHitPerElectron",
00071 200,0,200);
00072 ElectronsNumber_ = dbe_->book1D("ElectronsNumber_","electrons in the event",
00073 40,0,40);
00074 ESCoP_ = dbe_->book1D ("ESCoP","ESCoP",50,0,5);
00075
00076 OccupancyEB_= dbe_->book2D("OccupancyEB_","OccupancyEB",360,1,361,171,-85,86);
00077 OccupancyEEP_= dbe_->book2D("OccupancyEEP_","Occupancy EE Plus",100,1,101,100,1,101);
00078 OccupancyEEM_= dbe_->book2D("OccupancyEEM_","Occupancy EE Minus",100,1,101,100,1,101);
00079 HitsVsAssociatedHits_ = dbe_->book1D ("HitsVsAssociatedHits_","HitsVsAssociatedHits",100,0,5);
00080 LocalOccupancyEB_ = dbe_->book2D ("LocalOccupancyEB_","Local occupancy Barrel",9,-4,5,9,-4,5);
00081 LocalOccupancyEE_ = dbe_->book2D ("LocalOccupancyEE_","Local occupancy Endcap",9,-4,5,9,-4,5);
00082
00083 }
00084
00085
00086 void DQMSourceEleCalib::beginRun(const edm::Run& r, const EventSetup& context) {
00087
00088 }
00089
00090
00091 void DQMSourceEleCalib::beginLuminosityBlock(const LuminosityBlock& lumiSeg,
00092 const EventSetup& context) {
00093
00094 }
00095
00096
00097
00098 void DQMSourceEleCalib::analyze(const Event& iEvent,
00099 const EventSetup& iSetup ){
00100
00101
00102 eventCounter_++;
00103 int numberOfHits=0;
00104 int numberOfElectrons=0;
00105 int numberOfAssociatedHits = 0;
00106
00107 edm::Handle<EcalRecHitCollection> rhEB;
00108 edm::Handle<EcalRecHitCollection> rhEE;
00109
00110 iEvent.getByLabel(productMonitoredEB_, rhEB);
00111 iEvent.getByLabel(productMonitoredEE_, rhEE);
00112
00113 EcalRecHitCollection::const_iterator itb;
00114
00115
00116 edm::Handle<reco::GsfElectronCollection> pElectrons ;
00117 iEvent.getByLabel (productMonitoredElectrons_, pElectrons) ;
00118
00119 if (pElectrons.isValid()){
00120 ElectronsNumber_->Fill(pElectrons->size()+0.1);
00121 numberOfElectrons = pElectrons->size();
00122 for (reco::GsfElectronCollection::const_iterator eleIt = pElectrons->begin();
00123 eleIt!= pElectrons->end(); ++eleIt){
00124 ESCoP_->Fill(eleIt->eSuperClusterOverP());
00125 numberOfAssociatedHits+= eleIt->superCluster()->size();
00126 DetId Max = findMaxHit (eleIt->superCluster ()->hitsAndFractions (),
00127 rhEB.product(), rhEE.product()) ;
00128 if (!Max.det()) continue;
00129 if (Max.subdetId()==EcalBarrel) {
00130 EBDetId EBMax (Max);
00131 fillAroundBarrel (rhEB.product(),EBMax.ieta(),EBMax.iphi());
00132 }
00133 if (Max.subdetId()==EcalEndcap) {
00134 EEDetId EEMax (Max);
00135 fillAroundEndcap (rhEE.product(),EEMax.ix(),EEMax.iy());
00136 }
00137 }
00138 }
00139
00140
00141 if (rhEB.isValid())
00142 {
00143 numberOfHits+= rhEB->size();
00144 for(itb=rhEB->begin(); itb!=rhEB->end(); ++itb){
00145 EBDetId id(itb->id());
00146 OccupancyEB_->Fill(id.iphi(),id.ieta());
00147 }
00148 }
00149 if (rhEE.isValid())
00150 {
00151 numberOfHits+= rhEE->size();
00152 for (itb = rhEE->begin(); itb!=rhEE->end(); ++itb){
00153 EEDetId id (itb->id());
00154 if (id.zside()>0){
00155 OccupancyEEP_->Fill(id.ix(),id.iy());
00156 }
00157 else if (id.zside()<0){
00158 OccupancyEEM_->Fill(id.ix(),id.iy());
00159 }
00160
00161 }
00162 }
00163 if (numberOfElectrons) recHitsPerElectron_->Fill((double)numberOfHits/((double)numberOfElectrons));
00164 if (numberOfHits) HitsVsAssociatedHits_->Fill((double)numberOfAssociatedHits/((double)numberOfHits));
00165 }
00166
00167
00168
00169
00170
00171 void DQMSourceEleCalib::endLuminosityBlock(const LuminosityBlock& lumiSeg,
00172 const EventSetup& context) {
00173 }
00174
00175 void DQMSourceEleCalib::endRun(const Run& r, const EventSetup& context){
00176
00177 }
00178
00179 void DQMSourceEleCalib::endJob(){
00180
00181 if (saveToFile_) {
00182 dbe_->save(fileName_);
00183 }
00184
00185 }
00186
00187
00188 DetId
00189 DQMSourceEleCalib::findMaxHit (const std::vector<std::pair<DetId,float> > & v1,
00190 const EcalRecHitCollection* EBhits,
00191 const EcalRecHitCollection* EEhits)
00192 {
00193
00194 double currEnergy = 0. ;
00195 DetId maxHit ;
00196 for (std::vector<std::pair<DetId,float> >::const_iterator idsIt = v1.begin () ;
00197 idsIt != v1.end () ; ++idsIt)
00198 {
00199
00200 if (idsIt->first.subdetId () == EcalBarrel)
00201 {
00202 EcalRecHitCollection::const_iterator itrechit ;
00203 itrechit = EBhits->find ((*idsIt).first) ;
00204 if (itrechit == EBhits->end () )
00205 {
00206 edm::LogInfo ("reading")
00207 << "[findMaxHit] rechit not found! " ;
00208 continue ;
00209 }
00210
00211 if (itrechit->energy () > currEnergy)
00212 {
00213 currEnergy = itrechit->energy () ;
00214 maxHit= (*idsIt).first ;
00215 }
00216 }
00217 else
00218 {
00219 EcalRecHitCollection::const_iterator itrechit ;
00220 itrechit = EEhits->find ((*idsIt).first) ;
00221 if (itrechit == EEhits->end () )
00222 {
00223 edm::LogInfo ("reading")
00224 << "[findMaxHit] rechit not found! " ;
00225 continue ;
00226 }
00227
00228
00229 if (itrechit->energy () > currEnergy)
00230 {
00231 currEnergy=itrechit->energy () ;
00232 maxHit= (*idsIt).first ;
00233 }
00234 }
00235 }
00236 return maxHit ;
00237 }
00238
00239
00240 void
00241 DQMSourceEleCalib::fillAroundBarrel (const EcalRecHitCollection * recHits, int eta, int phi)
00242 {
00243
00244 for (EcalRecHitCollection::const_iterator elem = recHits->begin () ;
00245 elem != recHits->end () ;
00246 ++elem)
00247 {
00248 EBDetId elementId = elem->id () ;
00249 LocalOccupancyEB_->Fill (
00250 elementId.ieta () - eta ,
00251 elementId.iphi () - phi ,
00252 elem->energy ()
00253 ) ;
00254 }
00255 return ;
00256 }
00257
00258
00259
00260
00261
00262 void
00263 DQMSourceEleCalib::fillAroundEndcap (const EcalRecHitCollection * recHits, int ics, int ips)
00264 {
00265 for (EcalRecHitCollection::const_iterator elem = recHits->begin () ;
00266 elem != recHits->end () ;
00267 ++elem)
00268 {
00269 EEDetId elementId = elem->id () ;
00270 LocalOccupancyEE_->Fill (
00271 elementId.ix () - ics ,
00272 elementId.iy () - ips ,
00273 elem->energy ()
00274 ) ;
00275 }
00276 return ;
00277 }