CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
AlCaElectronsTest.h
Go to the documentation of this file.
1 // system include files
2 #include <memory>
3 #include <string>
4 #include <iostream>
5 #include <algorithm>
6 
7 // user include files
18 //#include "Calibration/EcalAlCaRecoProducers/interface/AlCaElectronsProducer.h"
28 
29 #include "TFile.h"
30 #include "TH1.h"
31 #include "TH2.h"
32 
33 #include <Math/VectorUtil.h>
34 
35 class AlCaElectronsTest : public edm::one::EDAnalyzer<edm::one::SharedResources> {
36 public:
37  explicit AlCaElectronsTest(const edm::ParameterSet&);
38  ~AlCaElectronsTest() = default;
39  void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) override;
40  void beginJob() override;
41 
42 private:
44  void fillAroundBarrel(const EcalRecHitCollection* recHits, int eta, int phi);
45  void fillAroundEndcap(const EcalRecHitCollection* recHits, int ics, int ips);
46 
50 
71 };
72 
73 // ----------------------------------------------------------------
74 
76  : m_barrelAlCa(consumes<EBRecHitCollection>(iConfig.getParameter<edm::InputTag>("alcaBarrelHitCollection"))),
77  m_endcapAlCa(consumes<EERecHitCollection>(iConfig.getParameter<edm::InputTag>("alcaEndcapHitCollection"))),
78  m_outputFileName(
79  iConfig.getUntrackedParameter<std::string>("HistOutFile", std::string("AlCaElectronsTest.root"))) {
80  usesResource(TFileService::kSharedResource);
81 }
82 
83 // ----------------------------------------------------------------
84 
88  fs->make<TH2F>("m_barrelGlobalCrystalsMap", "m_barrelGlobalCrystalsMap", 171, -85, 86, 360, 0, 360);
90  fs->make<TH2F>("m_barrelLocalCrystalsMap", "m_barrelLocalCrystalsMap", 20, -10, 10, 20, -10, 10);
92  fs->make<TH2F>("m_endcapGlobalCrystalsMap", "m_endcapGlobalCrystalsMap", 100, 0, 100, 100, 0, 100);
94  fs->make<TH2F>("m_endcapLocalCrystalsMap", "m_endcapLocalCrystalsMap", 20, -10, 10, 20, -10, 10);
96  fs->make<TH2F>("m_barrelGlobalCrystalsEnergy", "m_barrelGlobalCrystalsEnergy", 171, -85, 86, 360, 0, 360);
98  fs->make<TH2F>("m_barrelLocalCrystalsEnergy", "m_barrelLocalCrystalsEnergy", 20, -10, 10, 20, -10, 10);
100  fs->make<TH2F>("m_endcapGlobalCrystalsEnergy", "m_endcapGlobalCrystalsEnergy", 100, 0, 100, 100, 0, 100);
102  fs->make<TH2F>("m_endcapLocalCrystalsEnergy", "m_endcapLocalCrystalsEnergy", 20, -10, 10, 20, -10, 10);
104  fs->make<TH2F>("m_barrelGlobalCrystalsEnergyMap", "m_barrelGlobalCrystalsEnergyMap", 171, -85, 86, 360, 0, 360);
106  fs->make<TH2F>("m_endcapGlobalCrystalsEnergyMap", "m_endcapGlobalCrystalsEnergyMap", 100, 0, 100, 100, 0, 100);
107 }
108 
109 // ----------------------------------------------------------------
110 
112  //FIXME replace with msg logger
113  edm::LogVerbatim("ElectronsTest") << "[AlCaElectronsTest] analysing event " << iEvent.id();
114 
115  //PG get the collections
116  // get Barrel RecHits
117  edm::Handle<EBRecHitCollection> barrelRecHitsHandle;
118  iEvent.getByToken(m_barrelAlCa, barrelRecHitsHandle);
119  if (!barrelRecHitsHandle.isValid()) {
121  labelsForToken(m_barrelAlCa, labels);
122  edm::LogError("ElectronsTest") << "[AlCaElectronsTest] caught std::exception in rertieving " << labels.module;
123  return;
124  } else {
125  const EBRecHitCollection* barrelHitsCollection = barrelRecHitsHandle.product();
126  //PG fill the histo with the maximum
127  EcalRecHit barrelMax = getMaximum(barrelHitsCollection);
128  EBDetId barrelMaxId(barrelMax.id());
129  m_barrelGlobalCrystalsMap->Fill(barrelMaxId.ieta(), barrelMaxId.iphi());
130  m_barrelGlobalCrystalsEnergy->Fill(barrelMaxId.ieta(), barrelMaxId.iphi(), barrelMax.energy());
131  fillAroundBarrel(barrelHitsCollection, barrelMaxId.ieta(), barrelMaxId.iphi());
132  }
133 
134  // get Endcap RecHits
135  edm::Handle<EERecHitCollection> endcapRecHitsHandle;
136  iEvent.getByToken(m_endcapAlCa, endcapRecHitsHandle);
137  if (!endcapRecHitsHandle.isValid()) {
139  labelsForToken(m_endcapAlCa, labels);
140  edm::LogError("ElectronsTest") << "[AlCaElectronsTest] caught std::exception in rertieving " << labels.module;
141  return;
142  } else {
143  const EERecHitCollection* endcapHitsCollection = endcapRecHitsHandle.product();
144  //PG fill the histo with the maximum
145  EcalRecHit endcapMax = getMaximum(endcapHitsCollection);
146  EEDetId endcapMaxId(endcapMax.id());
147  m_endcapGlobalCrystalsMap->Fill(endcapMaxId.ix(), endcapMaxId.iy());
148  m_endcapGlobalCrystalsEnergy->Fill(endcapMaxId.ix(), endcapMaxId.iy(), endcapMax.energy());
149  fillAroundEndcap(endcapHitsCollection, endcapMaxId.ix(), endcapMaxId.iy());
150  }
151 }
152 
153 // ----------------------------------------------------------------
154 
156  double energy = 0.;
157  EcalRecHit max;
158  for (EcalRecHitCollection::const_iterator elem = recHits->begin(); elem != recHits->end(); ++elem) {
159  if (elem->energy() > energy) {
160  energy = elem->energy();
161  max = *elem;
162  }
163  }
164  return max;
165 }
166 
167 // ----------------------------------------------------------------
168 
170  for (EcalRecHitCollection::const_iterator elem = recHits->begin(); elem != recHits->end(); ++elem) {
171  EBDetId elementId = elem->id();
172  m_barrelLocalCrystalsMap->Fill(elementId.ieta() - eta, elementId.iphi() - phi);
173  m_barrelLocalCrystalsEnergy->Fill(elementId.ieta() - eta, elementId.iphi() - phi, elem->energy());
174  m_barrelGlobalCrystalsEnergyMap->Fill(elementId.ieta(), elementId.iphi(), elem->energy());
175  }
176  return;
177 }
178 
179 // ----------------------------------------------------------------
180 
182  for (EcalRecHitCollection::const_iterator elem = recHits->begin(); elem != recHits->end(); ++elem) {
183  EEDetId elementId = elem->id();
184  m_endcapLocalCrystalsMap->Fill(elementId.ix() - ics, elementId.iy() - ips);
185  m_endcapLocalCrystalsEnergy->Fill(elementId.ix() - ics, elementId.iy() - ips, elem->energy());
186  m_endcapGlobalCrystalsEnergyMap->Fill(elementId.ix(), elementId.iy(), elem->energy());
187  }
188  return;
189 }
static const std::string kSharedResource
Definition: TFileService.h:76
Log< level::Info, true > LogVerbatim
void fillAroundBarrel(const EcalRecHitCollection *recHits, int eta, int phi)
int ix() const
Definition: EEDetId.h:77
TH2F * m_endcapGlobalCrystalsEnergyMap
ECAL EnergyMap.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
std::vector< EcalRecHit >::const_iterator const_iterator
TH2F * m_endcapGlobalCrystalsEnergy
ECAL Energy.
~AlCaElectronsTest()=default
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
Log< level::Error, false > LogError
std::string m_outputFileName
int iphi() const
get the crystal iphi
Definition: EBDetId.h:51
void beginJob() override
int iEvent
Definition: GenABIO.cc:224
TH2F * m_endcapLocalCrystalsEnergy
local Energy
TH2F * m_barrelGlobalCrystalsMap
ECAL map.
float energy() const
Definition: EcalRecHit.h:68
edm::EDGetTokenT< EERecHitCollection > m_endcapAlCa
int iy() const
Definition: EEDetId.h:83
int ieta() const
get the crystal ieta
Definition: EBDetId.h:49
bool isValid() const
Definition: HandleBase.h:70
char const * module
Definition: ProductLabels.h:5
TH2F * m_barrelLocalCrystalsMap
local map
void fillAroundEndcap(const EcalRecHitCollection *recHits, int ics, int ips)
const_iterator end() const
DetId id() const
get the id
Definition: EcalRecHit.h:77
T const * product() const
Definition: Handle.h:70
TH2F * m_endcapGlobalCrystalsMap
ECAL map.
void labelsForToken(EDGetToken iToken, Labels &oLabels) const
void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) override
edm::EventID id() const
Definition: EventBase.h:59
TH2F * m_barrelGlobalCrystalsEnergyMap
ECAL EnergyMap.
AlCaElectronsTest(const edm::ParameterSet &)
TH2F * m_barrelGlobalCrystalsEnergy
ECAL Energy.
edm::EDGetTokenT< EBRecHitCollection > m_barrelAlCa
EcalRecHit getMaximum(const EcalRecHitCollection *recHits)
TH2F * m_barrelLocalCrystalsEnergy
local Energy
const_iterator begin() const
TH2F * m_endcapLocalCrystalsMap
local map