CMS 3D CMS Logo

HGCalHitCalibration.cc
Go to the documentation of this file.
1 // user include files
4 
8 
10 
15 
24 
30 
33 
36 
37 #include "TH1F.h"
38 #include <string>
39 #include <map>
40 
41 //#define EDM_ML_DEBUG
42 
43 class HGCalHitCalibration : public edm::one::EDAnalyzer<edm::one::SharedResources> {
44 public:
45  explicit HGCalHitCalibration(const edm::ParameterSet&);
47 
48  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
49 
50 private:
51  virtual void beginJob() override {}
52  virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
53  virtual void endJob() override {}
54 
59 
60  bool rawRecHits;
61  int algo;
64 
69 
70  std::vector<float> Energy_layer_calib;
71  std::vector<float> Energy_layer_calib_fraction;
72 };
73 
74 
75 
77  rawRecHits(iConfig.getParameter<bool>("rawRecHits")) {
78 
79  usesResource(TFileService::kSharedResource);
80  std::string detector = iConfig.getParameter<std::string >("detector");
81  if(detector=="all") {
82  _recHitsEE = consumes<HGCRecHitCollection>(edm::InputTag("HGCalRecHit","HGCEERecHits"));
83  _recHitsFH = consumes<HGCRecHitCollection>(edm::InputTag("HGCalRecHit","HGCHEFRecHits"));
84  _recHitsBH = consumes<HGCRecHitCollection>(edm::InputTag("HGCalRecHit","HGCHEBRecHits"));
85  algo = 1;
86  }else if(detector=="EM") {
87  _recHitsEE = consumes<HGCRecHitCollection>(edm::InputTag("HGCalRecHit","HGCEERecHits"));
88  algo = 2;
89  }else if(detector=="HAD") {
90  _recHitsFH = consumes<HGCRecHitCollection>(edm::InputTag("HGCalRecHit","HGCHEFRecHits"));
91  _recHitsBH = consumes<HGCRecHitCollection>(edm::InputTag("HGCalRecHit","HGCHEBRecHits"));
92  algo = 3;
93  }
94  _caloParticles = consumes<std::vector<CaloParticle> >(edm::InputTag("mix","MergedCaloTruth"));
95 
97  h_EoP_CPene_100_calib_fraction = fs->make<TH1F>("h_EoP_CPene_100_calib_fraction", "", 1000, -0.5, 2.5);
98  h_EoP_CPene_200_calib_fraction = fs->make<TH1F>("h_EoP_CPene_200_calib_fraction", "", 1000, -0.5, 2.5);
99  h_EoP_CPene_300_calib_fraction = fs->make<TH1F>("h_EoP_CPene_300_calib_fraction", "", 1000, -0.5, 2.5);
100  LayerOccupancy = fs->make<TH1F>("LayerOccupancy", "", 60, 0., 60.);
101 }
102 
104 
105  // do anything here that needs to be done at desctruction time
106  // (e.g. close files, deallocate resources etc.)
107 }
108 
109 
110 void
112 {
113 
114 
115  recHitTools.getEventSetup(iSetup);
116 
117  edm::Handle<HGCRecHitCollection> recHitHandleEE;
118  edm::Handle<HGCRecHitCollection> recHitHandleFH;
119  edm::Handle<HGCRecHitCollection> recHitHandleBH;
120  iEvent.getByToken(_recHitsEE,recHitHandleEE);
121  iEvent.getByToken(_recHitsFH,recHitHandleFH);
122  iEvent.getByToken(_recHitsBH,recHitHandleBH);
123 
124  edm::Handle<std::vector<CaloParticle> > caloParticleHandle;
125  iEvent.getByToken(_caloParticles, caloParticleHandle);
126  const std::vector<CaloParticle>& caloParticles = *caloParticleHandle;
127 
128  // loop over caloParticles
129  for (std::vector<CaloParticle>::const_iterator it_caloPart = caloParticles.begin(); it_caloPart != caloParticles.end(); ++it_caloPart) {
130  const SimClusterRefVector simClusterRefVector = it_caloPart->simClusters();
131 
132  //size should be HGC layers 52 is enough
133  Energy_layer_calib.assign(60,0.);
134  Energy_layer_calib_fraction.assign(60,0.);
135 
136  int seedDet = 0;
137  float seedEnergy = 0.;
138  int simClusterCount = 0;
139 
140  for ( const auto & simCluster : simClusterRefVector) {
141  ++simClusterCount;
142 #ifdef EDM_ML_DEBUG
143  std::cout << ">>> simCluster.energy() = " << simCluster->energy() << std::endl;
144 #endif
145  const std::vector<std::pair<uint32_t,float> > hits_and_fractions = simCluster->hits_and_fractions();
146 
147  //loop over hits
148  for (std::vector<std::pair<uint32_t,float> >::const_iterator it_haf = hits_and_fractions.begin(); it_haf != hits_and_fractions.end(); ++it_haf) {
149  unsigned int hitlayer = recHitTools.getLayerWithOffset(it_haf->first);
150  DetId hitid = (it_haf->first);
151 
152  // dump raw RecHits and match
153  if (rawRecHits) {
154  if (hitid.det() == DetId::Forward && hitid.subdetId() == HGCEE &&
155  (algo == 1 || algo == 2)) {
156  const HGCRecHitCollection& rechitsEE = *recHitHandleEE;
157  // loop over EE RecHits
158  for (HGCRecHitCollection::const_iterator it_hit = rechitsEE.begin(); it_hit < rechitsEE.end(); ++it_hit) {
159  const HGCalDetId detid = it_hit->detid();
160  unsigned int layer = recHitTools.getLayerWithOffset(detid);
161  if(detid == hitid){
162  if(hitlayer != layer) {
163 #ifdef EDM_ML_DEBUG
164  std::cout << " recHit ID problem EE " << std::endl;
165 #endif
166  return;
167  }
168  Energy_layer_calib_fraction[layer] += it_hit->energy()*it_haf->second;
169  LayerOccupancy->Fill(layer);
170  if(seedEnergy < it_hit->energy()){
171  seedEnergy = it_hit->energy();
172  seedDet = recHitTools.getSiThickness(detid);
173  }
174  break;
175  }
176  }
177  }
178  if (hitid.det() == DetId::Forward && hitid.subdetId() == HGCHEF &&
179  (algo == 1 || algo == 3)) {
180  const HGCRecHitCollection& rechitsFH = *recHitHandleFH;
181  // loop over HEF RecHits
182  for (HGCRecHitCollection::const_iterator it_hit = rechitsFH.begin(); it_hit < rechitsFH.end(); ++it_hit) {
183  const HGCalDetId detid = it_hit->detid();
184  unsigned int layer = recHitTools.getLayerWithOffset(detid);
185  if(detid == hitid){
186  if (hitlayer != layer) {
187 #ifdef EDM_ML_DEBUG
188  std::cout << " recHit ID problem FH " << std::endl;
189 #endif
190  return;
191  }
192  Energy_layer_calib_fraction[layer] += it_hit->energy()*it_haf->second;
193  LayerOccupancy->Fill(layer);
194  if(seedEnergy < it_hit->energy()){
195  seedEnergy = it_hit->energy();
196  seedDet = recHitTools.getSiThickness(detid);
197  }
198  break;
199  }
200  }
201  }
202  if (hitid.det() == DetId::Forward && hitid.subdetId() == HGCHEB &&
203  (algo == 1 || algo == 3)) {
204  const HGCRecHitCollection& rechitsBH = *recHitHandleBH;
205  // loop over BH RecHits
206  for (HGCRecHitCollection::const_iterator it_hit = rechitsBH.begin(); it_hit < rechitsBH.end(); ++it_hit) {
207  const HcalDetId detid = it_hit->detid();
208  unsigned int layer = recHitTools.getLayerWithOffset(detid);
209  if(detid == hitid){
210  if (hitlayer != layer) {
211 #ifdef EDM_ML_DEBUG
212  std::cout << " recHit ID problem BH " << std::endl;
213 #endif
214  return;
215  }
216  Energy_layer_calib_fraction[layer] += it_hit->energy()*it_haf->second;
217  LayerOccupancy->Fill(layer);
218  if(seedEnergy < it_hit->energy()){
219  seedEnergy = it_hit->energy();
220  seedDet = recHitTools.getSiThickness(detid);
221  }
222  break;
223  }
224  }
225  }
226 
227  }//end recHits
228  }// end simHit
229  }//end simCluster
230 
231 
232  float sumCalibRecHitCalib_fraction = 0;
233  for(unsigned int iL=0; iL<Energy_layer_calib_fraction.size(); ++iL){
234  sumCalibRecHitCalib_fraction += Energy_layer_calib_fraction[iL];
235  }
236 
237  if(seedDet == 100){
238  h_EoP_CPene_100_calib_fraction->Fill(sumCalibRecHitCalib_fraction / it_caloPart->energy());
239  }
240  if(seedDet == 200){
241  h_EoP_CPene_200_calib_fraction->Fill(sumCalibRecHitCalib_fraction / it_caloPart->energy());
242  }
243  if(seedDet == 300){
244  h_EoP_CPene_300_calib_fraction->Fill(sumCalibRecHitCalib_fraction / it_caloPart->energy());
245  }
246 
247  }//end caloparticle
248 
249 
250 }
251 
252 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
253 void
255  //The following says we do not know what parameters are allowed so do no validation
256  // Please change this to state exactly what you do use, even if it is no parameters
258  desc.add<std::string>("detector","all");
259  desc.add<bool>("rawRecHits",true);
260  descriptions.add("hgcalHitCalibration",desc);
261 }
262 
263 //define this as a plug-in
static const std::string kSharedResource
Definition: TFileService.h:76
T getParameter(std::string const &) const
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< HGCRecHit >::const_iterator const_iterator
HGCalDepthPreClusterer pre
edm::EDGetTokenT< HGCRecHitCollection > _recHitsBH
HGCalHitCalibration(const edm::ParameterSet &)
void getEventSetup(const edm::EventSetup &)
Definition: RecHitTools.cc:66
edm::EDGetTokenT< std::vector< CaloParticle > > _caloParticles
edm::EDGetTokenT< HGCRecHitCollection > _recHitsFH
int iEvent
Definition: GenABIO.cc:230
ParameterDescriptionBase * add(U const &iLabel, T const &value)
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
virtual void beginJob() override
const_iterator end() const
std::float_t getSiThickness(const DetId &) const
Definition: RecHitTools.cc:99
Definition: DetId.h:18
virtual void endJob() override
edm::EDGetTokenT< HGCRecHitCollection > _recHitsEE
std::vector< float > Energy_layer_calib_fraction
unsigned int getLayerWithOffset(const DetId &) const
Definition: RecHitTools.cc:139
void add(std::string const &label, ParameterSetDescription const &psetDescription)
virtual void analyze(const edm::Event &, const edm::EventSetup &) override
hgcal::RecHitTools recHitTools
std::vector< float > Energy_layer_calib
Detector det() const
get the detector field from this detid
Definition: DetId.h:35
const_iterator begin() const