CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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
14 //#include "Calibration/EcalAlCaRecoProducers/interface/AlCaElectronsProducer.h"
24 
25 
26 #include "TFile.h"
27 #include "TH1.h"
28 #include "TH2.h"
29 
30 #include <Math/VectorUtil.h>
31 
33  public:
34  explicit AlCaElectronsTest (const edm::ParameterSet&) ;
36  virtual void analyze (const edm::Event& iEvent,
37  const edm::EventSetup& iSetup) ;
38  virtual void beginJob() ;
39  virtual void endJob () ;
40 
41  private:
42 
43  EcalRecHit getMaximum (const EcalRecHitCollection * recHits) ;
44  void fillAroundBarrel (const EcalRecHitCollection * recHits, int eta, int phi) ;
45  void fillAroundEndcap (const EcalRecHitCollection * recHits, int ics, int ips) ;
46 
47 
48  private:
49 
53 
74 } ;
75 
76 
77 // ----------------------------------------------------------------
78 
79 
81  m_barrelAlCa (iConfig.getParameter<edm::InputTag> ("alcaBarrelHitCollection")) ,
82  m_endcapAlCa (iConfig.getParameter<edm::InputTag> ("alcaEndcapHitCollection")) ,
83  m_outputFileName (iConfig.getUntrackedParameter<std::string>
84  ("HistOutFile",std::string ("AlCaElectronsTest.root")))
85 {}
86 
87 
88 // ----------------------------------------------------------------
89 
90 
91 void
93 {
94  m_barrelGlobalCrystalsMap = new TH2F ("m_barrelGlobalCrystalsMap","m_barrelGlobalCrystalsMap",171,-85,86,360,0,360) ;
95  m_barrelLocalCrystalsMap = new TH2F ("m_barrelLocalCrystalsMap","m_barrelLocalCrystalsMap",20,-10,10,20,-10,10) ;
96  m_endcapGlobalCrystalsMap = new TH2F ("m_endcapGlobalCrystalsMap","m_endcapGlobalCrystalsMap",100,0,100,100,0,100) ;
97  m_endcapLocalCrystalsMap = new TH2F ("m_endcapLocalCrystalsMap","m_endcapLocalCrystalsMap",20,-10,10,20,-10,10) ;
98  m_barrelGlobalCrystalsEnergy = new TH2F ("m_barrelGlobalCrystalsEnergy","m_barrelGlobalCrystalsEnergy",171,-85,86,360,0,360) ;
99  m_barrelLocalCrystalsEnergy = new TH2F ("m_barrelLocalCrystalsEnergy","m_barrelLocalCrystalsEnergy",20,-10,10,20,-10,10) ;
100  m_endcapGlobalCrystalsEnergy = new TH2F ("m_endcapGlobalCrystalsEnergy","m_endcapGlobalCrystalsEnergy",100,0,100,100,0,100) ;
101  m_endcapLocalCrystalsEnergy = new TH2F ("m_endcapLocalCrystalsEnergy","m_endcapLocalCrystalsEnergy",20,-10,10,20,-10,10) ;
102  m_barrelGlobalCrystalsEnergyMap = new TH2F ("m_barrelGlobalCrystalsEnergyMap","m_barrelGlobalCrystalsEnergyMap",171,-85,86,360,0,360) ;
103  m_endcapGlobalCrystalsEnergyMap = new TH2F ("m_endcapGlobalCrystalsEnergyMap","m_endcapGlobalCrystalsEnergyMap",100,0,100,100,0,100) ;
104  return ;
105 }
106 
107 
108 // ----------------------------------------------------------------
109 
110 
111 void
113 {
114  TFile output (m_outputFileName.c_str (),"recreate") ;
115  m_barrelGlobalCrystalsMap->Write () ;
116  m_barrelLocalCrystalsMap->Write () ;
117  m_endcapGlobalCrystalsMap->Write () ;
118  m_endcapLocalCrystalsMap->Write () ;
119  m_barrelGlobalCrystalsEnergy->Write () ;
120  m_barrelLocalCrystalsEnergy->Write () ;
121  m_endcapGlobalCrystalsEnergy->Write () ;
122  m_endcapLocalCrystalsEnergy->Write () ;
125  output.Close () ;
126  //PG save root things
127  return ;
128 }
129 
130 
131 // ----------------------------------------------------------------
132 
133 
134 void
136  const edm::EventSetup& iSetup)
137 {
138  //FIXME replace with msg logger
139  std::cout << "[AlCaElectronsTest] analysing event "
140  << iEvent.id () << std::endl ;
141 
142  //PG get the collections
143  // get Barrel RecHits
144  edm::Handle<EBRecHitCollection> barrelRecHitsHandle ;
145  iEvent.getByLabel (m_barrelAlCa, barrelRecHitsHandle) ;
146  if (!barrelRecHitsHandle.isValid()) {
147  std::cerr << "[AlCaElectronsTest] caught std::exception "
148  << " in rertieving " << m_barrelAlCa
149  << std::endl ;
150  return ;
151  } else {
152  const EBRecHitCollection* barrelHitsCollection = barrelRecHitsHandle.product () ;
153  //PG fill the histo with the maximum
154  EcalRecHit barrelMax = getMaximum (barrelHitsCollection) ;
155  EBDetId barrelMaxId (barrelMax.id ()) ;
157  barrelMaxId.ieta () ,
158  barrelMaxId.iphi ()
159  ) ;
161  barrelMaxId.ieta () ,
162  barrelMaxId.iphi () ,
163  barrelMax.energy ()
164  ) ;
166  barrelHitsCollection,
167  barrelMaxId.ieta (),
168  barrelMaxId.iphi ()
169  ) ;
170  }
171 
172  // get Endcap RecHits
173  edm::Handle<EERecHitCollection> endcapRecHitsHandle ;
174  iEvent.getByLabel (m_endcapAlCa,endcapRecHitsHandle) ;
175  if (!endcapRecHitsHandle.isValid()) {
176  std::cerr << "[AlCaElectronsTest] caught std::exception "
177  << " in rertieving " << m_endcapAlCa
178  << std::endl ;
179  return ;
180  } else {
181  const EERecHitCollection* endcapHitsCollection = endcapRecHitsHandle.product () ;
182  //PG fill the histo with the maximum
183  EcalRecHit endcapMax = getMaximum (endcapHitsCollection) ;
184  EEDetId endcapMaxId (endcapMax.id ()) ;
186  endcapMaxId.ix () ,
187  endcapMaxId.iy ()
188  ) ;
190  endcapMaxId.ix () ,
191  endcapMaxId.iy () ,
192  endcapMax.energy ()
193  ) ;
195  endcapHitsCollection,
196  endcapMaxId.ix (),
197  endcapMaxId.iy ()
198  ) ;
199  }
200 }
201 
202 
203 // ----------------------------------------------------------------
204 
205 
208 {
209  double energy = 0. ;
210  EcalRecHit max ;
211  for (EcalRecHitCollection::const_iterator elem = recHits->begin () ;
212  elem != recHits->end () ;
213  ++elem)
214  {
215  if (elem->energy () > energy)
216  {
217  energy = elem->energy () ;
218  max = *elem ;
219  }
220  }
221  return max ;
222 }
223 
224 
225 // ----------------------------------------------------------------
226 
227 
228 void
230 {
231  for (EcalRecHitCollection::const_iterator elem = recHits->begin () ;
232  elem != recHits->end () ;
233  ++elem)
234  {
235  EBDetId elementId = elem->id () ;
237  elementId.ieta () - eta ,
238  elementId.iphi () - phi
239  ) ;
241  elementId.ieta () - eta ,
242  elementId.iphi () - phi ,
243  elem->energy ()
244  ) ;
246  elementId.ieta () ,
247  elementId.iphi () ,
248  elem->energy ()
249  ) ;
250 
251  }
252  return ;
253 }
254 
255 
256 // ----------------------------------------------------------------
257 
258 
259 void
261 {
262  for (EcalRecHitCollection::const_iterator elem = recHits->begin () ;
263  elem != recHits->end () ;
264  ++elem)
265  {
266  EEDetId elementId = elem->id () ;
268  elementId.ix () - ics ,
269  elementId.iy () - ips
270  ) ;
272  elementId.ix () - ics ,
273  elementId.iy () - ips ,
274  elem->energy ()
275  ) ;
277  elementId.ix () ,
278  elementId.iy () ,
279  elem->energy ()
280  ) ;
281  }
282  return ;
283 }
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.
std::vector< EcalRecHit >::const_iterator const_iterator
TH2F * m_endcapGlobalCrystalsEnergy
ECAL Energy.
edm::InputTag m_barrelAlCa
T eta() const
std::string m_outputFileName
virtual void endJob()
int iphi() const
get the crystal iphi
Definition: EBDetId.h:53
int iEvent
Definition: GenABIO.cc:243
TH2F * m_endcapLocalCrystalsEnergy
local Energy
const T & max(const T &a, const T &b)
TH2F * m_barrelGlobalCrystalsMap
ECAL map.
float energy() const
Definition: CaloRecHit.h:17
int iy() const
Definition: EEDetId.h:82
int ieta() const
get the crystal ieta
Definition: EBDetId.h:51
bool isValid() const
Definition: HandleBase.h:76
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
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:80
T const * product() const
Definition: Handle.h:81
TH2F * m_endcapGlobalCrystalsMap
ECAL map.
return(e1-e2)*(e1-e2)+dp *dp
edm::EventID id() const
Definition: EventBase.h:56
TH2F * m_barrelGlobalCrystalsEnergyMap
ECAL EnergyMap.
AlCaElectronsTest(const edm::ParameterSet &)
tuple cout
Definition: gather_cfg.py:121
TH2F * m_barrelGlobalCrystalsEnergy
ECAL Energy.
edm::InputTag m_endcapAlCa
EcalRecHit getMaximum(const EcalRecHitCollection *recHits)
TH2F * m_barrelLocalCrystalsEnergy
local Energy
const_iterator begin() const
virtual void beginJob()
TH2F * m_endcapLocalCrystalsMap
local map
Definition: DDAxes.h:10