CMS 3D CMS Logo

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
15 //#include "Calibration/EcalAlCaRecoProducers/interface/AlCaElectronsProducer.h"
25 
26 
27 #include "TFile.h"
28 #include "TH1.h"
29 #include "TH2.h"
30 
31 #include <Math/VectorUtil.h>
32 
34  public:
35  explicit AlCaElectronsTest (const edm::ParameterSet&) ;
37  virtual void analyze (const edm::Event& iEvent,
38  const edm::EventSetup& iSetup) ;
39  virtual void beginJob() ;
40  virtual void endJob () ;
41 
42  private:
43 
44  EcalRecHit getMaximum (const EcalRecHitCollection * recHits) ;
45  void fillAroundBarrel (const EcalRecHitCollection * recHits, int eta, int phi) ;
46  void fillAroundEndcap (const EcalRecHitCollection * recHits, int ics, int ips) ;
47 
48 
49  private:
50 
54 
75 } ;
76 
77 
78 // ----------------------------------------------------------------
79 
80 
82  m_barrelAlCa (consumes<EBRecHitCollection>(iConfig.getParameter<edm::InputTag> ("alcaBarrelHitCollection"))) ,
83  m_endcapAlCa (consumes<EERecHitCollection>(iConfig.getParameter<edm::InputTag> ("alcaEndcapHitCollection"))) ,
84  m_outputFileName (iConfig.getUntrackedParameter<std::string>
85  ("HistOutFile",std::string ("AlCaElectronsTest.root")))
86 {}
87 
88 
89 // ----------------------------------------------------------------
90 
91 
92 void
94 {
95  m_barrelGlobalCrystalsMap = new TH2F ("m_barrelGlobalCrystalsMap","m_barrelGlobalCrystalsMap",171,-85,86,360,0,360) ;
96  m_barrelLocalCrystalsMap = new TH2F ("m_barrelLocalCrystalsMap","m_barrelLocalCrystalsMap",20,-10,10,20,-10,10) ;
97  m_endcapGlobalCrystalsMap = new TH2F ("m_endcapGlobalCrystalsMap","m_endcapGlobalCrystalsMap",100,0,100,100,0,100) ;
98  m_endcapLocalCrystalsMap = new TH2F ("m_endcapLocalCrystalsMap","m_endcapLocalCrystalsMap",20,-10,10,20,-10,10) ;
99  m_barrelGlobalCrystalsEnergy = new TH2F ("m_barrelGlobalCrystalsEnergy","m_barrelGlobalCrystalsEnergy",171,-85,86,360,0,360) ;
100  m_barrelLocalCrystalsEnergy = new TH2F ("m_barrelLocalCrystalsEnergy","m_barrelLocalCrystalsEnergy",20,-10,10,20,-10,10) ;
101  m_endcapGlobalCrystalsEnergy = new TH2F ("m_endcapGlobalCrystalsEnergy","m_endcapGlobalCrystalsEnergy",100,0,100,100,0,100) ;
102  m_endcapLocalCrystalsEnergy = new TH2F ("m_endcapLocalCrystalsEnergy","m_endcapLocalCrystalsEnergy",20,-10,10,20,-10,10) ;
103  m_barrelGlobalCrystalsEnergyMap = new TH2F ("m_barrelGlobalCrystalsEnergyMap","m_barrelGlobalCrystalsEnergyMap",171,-85,86,360,0,360) ;
104  m_endcapGlobalCrystalsEnergyMap = new TH2F ("m_endcapGlobalCrystalsEnergyMap","m_endcapGlobalCrystalsEnergyMap",100,0,100,100,0,100) ;
105  return ;
106 }
107 
108 
109 // ----------------------------------------------------------------
110 
111 
112 void
114 {
115  TFile output (m_outputFileName.c_str (),"recreate") ;
116  m_barrelGlobalCrystalsMap->Write () ;
117  m_barrelLocalCrystalsMap->Write () ;
118  m_endcapGlobalCrystalsMap->Write () ;
119  m_endcapLocalCrystalsMap->Write () ;
120  m_barrelGlobalCrystalsEnergy->Write () ;
121  m_barrelLocalCrystalsEnergy->Write () ;
122  m_endcapGlobalCrystalsEnergy->Write () ;
123  m_endcapLocalCrystalsEnergy->Write () ;
126  output.Close () ;
127  //PG save root things
128  return ;
129 }
130 
131 
132 // ----------------------------------------------------------------
133 
134 
135 void
137  const edm::EventSetup& iSetup)
138 {
139  //FIXME replace with msg logger
140  std::cout << "[AlCaElectronsTest] analysing event "
141  << iEvent.id () << std::endl ;
142 
143  //PG get the collections
144  // get Barrel RecHits
145  edm::Handle<EBRecHitCollection> barrelRecHitsHandle ;
146  iEvent.getByToken (m_barrelAlCa, barrelRecHitsHandle) ;
147  if (!barrelRecHitsHandle.isValid()) {
149  labelsForToken(m_barrelAlCa, labels);
150  std::cerr << "[AlCaElectronsTest] caught std::exception "
151  << " in rertieving " << labels.module
152  << std::endl ;
153  return ;
154  } else {
155  const EBRecHitCollection* barrelHitsCollection = barrelRecHitsHandle.product () ;
156  //PG fill the histo with the maximum
157  EcalRecHit barrelMax = getMaximum (barrelHitsCollection) ;
158  EBDetId barrelMaxId (barrelMax.id ()) ;
160  barrelMaxId.ieta () ,
161  barrelMaxId.iphi ()
162  ) ;
164  barrelMaxId.ieta () ,
165  barrelMaxId.iphi () ,
166  barrelMax.energy ()
167  ) ;
169  barrelHitsCollection,
170  barrelMaxId.ieta (),
171  barrelMaxId.iphi ()
172  ) ;
173  }
174 
175  // get Endcap RecHits
176  edm::Handle<EERecHitCollection> endcapRecHitsHandle ;
177  iEvent.getByToken (m_endcapAlCa,endcapRecHitsHandle) ;
178  if (!endcapRecHitsHandle.isValid()) {
180  labelsForToken(m_endcapAlCa, labels);
181  std::cerr << "[AlCaElectronsTest] caught std::exception "
182  << " in rertieving " << labels.module
183  << std::endl ;
184  return ;
185  } else {
186  const EERecHitCollection* endcapHitsCollection = endcapRecHitsHandle.product () ;
187  //PG fill the histo with the maximum
188  EcalRecHit endcapMax = getMaximum (endcapHitsCollection) ;
189  EEDetId endcapMaxId (endcapMax.id ()) ;
191  endcapMaxId.ix () ,
192  endcapMaxId.iy ()
193  ) ;
195  endcapMaxId.ix () ,
196  endcapMaxId.iy () ,
197  endcapMax.energy ()
198  ) ;
200  endcapHitsCollection,
201  endcapMaxId.ix (),
202  endcapMaxId.iy ()
203  ) ;
204  }
205 }
206 
207 
208 // ----------------------------------------------------------------
209 
210 
213 {
214  double energy = 0. ;
215  EcalRecHit max ;
216  for (EcalRecHitCollection::const_iterator elem = recHits->begin () ;
217  elem != recHits->end () ;
218  ++elem)
219  {
220  if (elem->energy () > energy)
221  {
222  energy = elem->energy () ;
223  max = *elem ;
224  }
225  }
226  return max ;
227 }
228 
229 
230 // ----------------------------------------------------------------
231 
232 
233 void
235 {
236  for (EcalRecHitCollection::const_iterator elem = recHits->begin () ;
237  elem != recHits->end () ;
238  ++elem)
239  {
240  EBDetId elementId = elem->id () ;
242  elementId.ieta () - eta ,
243  elementId.iphi () - phi
244  ) ;
246  elementId.ieta () - eta ,
247  elementId.iphi () - phi ,
248  elem->energy ()
249  ) ;
251  elementId.ieta () ,
252  elementId.iphi () ,
253  elem->energy ()
254  ) ;
255 
256  }
257  return ;
258 }
259 
260 
261 // ----------------------------------------------------------------
262 
263 
264 void
266 {
267  for (EcalRecHitCollection::const_iterator elem = recHits->begin () ;
268  elem != recHits->end () ;
269  ++elem)
270  {
271  EEDetId elementId = elem->id () ;
273  elementId.ix () - ics ,
274  elementId.iy () - ips
275  ) ;
277  elementId.ix () - ics ,
278  elementId.iy () - ips ,
279  elem->energy ()
280  ) ;
282  elementId.ix () ,
283  elementId.iy () ,
284  elem->energy ()
285  ) ;
286  }
287  return ;
288 }
virtual void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup)
void fillAroundBarrel(const EcalRecHitCollection *recHits, int eta, int phi)
int ix() const
Definition: EEDetId.h:76
TH2F * m_endcapGlobalCrystalsEnergyMap
ECAL EnergyMap.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
std::vector< EcalRecHit >::const_iterator const_iterator
TH2F * m_endcapGlobalCrystalsEnergy
ECAL Energy.
std::string m_outputFileName
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
virtual void endJob()
int iphi() const
get the crystal iphi
Definition: EBDetId.h:53
int iEvent
Definition: GenABIO.cc:230
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:82
int ieta() const
get the crystal ieta
Definition: EBDetId.h:51
bool isValid() const
Definition: HandleBase.h:74
char const * module
Definition: ProductLabels.h:5
TH2F * m_barrelLocalCrystalsMap
local map
def elem(elemtype, innerHTML='', html_class='', kwargs)
Definition: HTMLExport.py:18
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:81
TH2F * m_endcapGlobalCrystalsMap
ECAL map.
void labelsForToken(EDGetToken iToken, Labels &oLabels) const
return(e1-e2)*(e1-e2)+dp *dp
edm::EventID id() const
Definition: EventBase.h:58
HLT enums.
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
virtual void beginJob()
TH2F * m_endcapLocalCrystalsMap
local map