CMS 3D CMS Logo

HcalTB06Analysis.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: HcalTestBeam
4 // Class : HcalTB06Analysis
5 //
6 // Implementation:
7 // Main analysis class for Hcal Test Beam 2006 Analysis
8 //
9 // Original Author:
10 // Created: 19 November 2015
11 //
12 
13 // user include files
16 
17 // to retreive hits
22 
25 
36 
38 
41 
42 #include "Randomize.hh"
43 #include "globals.hh"
44 
45 #include <CLHEP/Units/GlobalSystemOfUnits.h>
46 #include <CLHEP/Units/GlobalPhysicalConstants.h>
47 
48 // system include files
49 #include <memory>
50 #include <string>
51 #include <vector>
52 
53 //#define EDM_ML_DEBUG
54 
55 class HcalTB06Analysis : public edm::one::EDAnalyzer<edm::one::SharedResources> {
56 public:
57  explicit HcalTB06Analysis(const edm::ParameterSet& p);
58  ~HcalTB06Analysis() override = default;
59 
60  void beginJob() override;
61  void endJob() override;
62  void analyze(const edm::Event& e, const edm::EventSetup& c) override;
63 
64  HcalTB06Analysis(const HcalTB06Analysis&) = delete;
65  const HcalTB06Analysis& operator=(const HcalTB06Analysis&) = delete;
66 
67 private:
68  const bool m_ECAL;
69  const double m_eta;
70  const double m_phi;
71  const double m_ener;
72  const std::vector<int> m_PDG;
73 
77 
79  const double m_timeLimit;
80  const double m_widthEcal;
81  const double m_widthHcal;
82  const double m_factEcal;
83  const double m_factHcal;
84  const double m_eMIP;
85 
86  int count;
91 
92  std::unique_ptr<HcalTB06Histo> m_histo;
93 };
94 
96  : m_ECAL(p.getParameter<bool>("ECAL")),
97  m_eta(p.getParameter<double>("MinEta")),
98  m_phi(p.getParameter<double>("MinPhi")),
99  m_ener(p.getParameter<double>("MinE")),
100  m_PDG(p.getParameter<std::vector<int> >("PartID")),
101  m_HcalToken(consumes<edm::PCaloHitContainer>(edm::InputTag("g4SimHits", "HcalHits"))),
102  m_BeamToken(consumes<edm::PCaloHitContainer>(edm::InputTag("g4SimHits", "HcalTB06BeamHits"))),
103  m_ptb(p.getParameter<edm::ParameterSet>("TestBeamAnalysis")),
104  m_timeLimit(m_ptb.getParameter<double>("TimeLimit")),
105  m_widthEcal(m_ptb.getParameter<double>("EcalWidth")),
106  m_widthHcal(m_ptb.getParameter<double>("HcalWidth")),
107  m_factEcal(m_ptb.getParameter<double>("EcalFactor")),
108  m_factHcal(m_ptb.getParameter<double>("HcalFactor")),
109  m_eMIP(m_ptb.getParameter<double>("MIP")),
110  count(0) {
111  usesResource("TFileService");
112  if (m_ECAL)
113  m_EcalToken = consumes<edm::PCaloHitContainer>(edm::InputTag("g4SimHits", "EcalHitsEB"));
114  double minEta = p.getParameter<double>("MinEta");
115  double maxEta = p.getParameter<double>("MaxEta");
116  double minPhi = p.getParameter<double>("MinPhi");
117  double maxPhi = p.getParameter<double>("MaxPhi");
118  double beamEta = (maxEta + minEta) * 0.5;
119  double beamPhi = (maxPhi + minPhi) * 0.5;
120  if (beamPhi < 0) {
121  beamPhi += twopi;
122  }
123 
124  m_idxetaEcal = 13;
125  m_idxphiEcal = 13;
126 
127  m_idxetaHcal = static_cast<int>(beamEta / 0.087) + 1;
128  m_idxphiHcal = static_cast<int>(beamPhi / 0.087) + 6;
129  if (m_idxphiHcal > 72) {
130  m_idxphiHcal -= 73;
131  }
132 
133  edm::LogInfo("HcalTB06Analysis") << "Beam parameters: E(GeV)= " << m_ener << " pdgID= " << m_PDG[0]
134  << "\n eta= " << m_eta << " idx_etaEcal= " << m_idxetaEcal
135  << " idx_etaHcal= " << m_idxetaHcal << " phi= " << m_phi
136  << " idx_phiEcal= " << m_idxphiEcal << " idx_phiHcal= " << m_idxphiHcal
137  << "\n EcalFactor= " << m_factEcal << " EcalWidth= " << m_widthEcal << " GeV"
138  << "\n HcalFactor= " << m_factHcal << " HcalWidth= " << m_widthHcal << " GeV"
139  << " MIP= " << m_eMIP << " GeV"
140  << "\n TimeLimit= " << m_timeLimit << " ns"
141  << "\n";
142  m_histo = std::make_unique<HcalTB06Histo>(m_ptb);
143 }
144 
145 void HcalTB06Analysis::beginJob() { edm::LogInfo("HcalTB06Analysis") << " =====> Begin of Run"; }
146 
148  edm::LogInfo("HcalTB06Analysis") << " =====> End of Run; Total number of events: " << count;
149 }
150 
152  ++count;
153 
154  //Beam Information
155  m_histo->fillPrimary(m_ener, m_eta, m_phi);
156 
157  std::vector<double> eCalo(6, 0), eTrig(7, 0);
158 
159  const std::vector<PCaloHit>* EcalHits = nullptr;
160  if (m_ECAL) {
162  EcalHits = Ecal.product();
163  }
165  const std::vector<PCaloHit>* HcalHits = Hcal.product();
167  const std::vector<PCaloHit>* BeamHits = Beam.product();
168 
169  // Total Energy
170  double eecals = 0.;
171  double ehcals = 0.;
172 
173  unsigned int ne = 0;
174  unsigned int nh = 0;
175  if (m_ECAL) {
176  ne = EcalHits->size();
177  for (unsigned int i = 0; i < ne; ++i) {
178  EBDetId ecalid((*EcalHits)[i].id());
179 #ifdef EDM_ML_DEBUG
180  edm::LogVerbatim("HcalTBSim") << "EB " << i << " " << ecalid.ieta() << ":" << m_idxetaEcal << " "
181  << ecalid.iphi() << ":" << m_idxphiEcal << " " << (*EcalHits)[i].time() << ":"
182  << m_timeLimit << " " << (*EcalHits)[i].energy();
183 #endif
184  // 7x7 crystal selection
185  if (std::abs(m_idxetaEcal - ecalid.ieta()) <= 3 && std::abs(m_idxphiEcal - ecalid.iphi()) <= 3 &&
186  (*EcalHits)[i].time() < m_timeLimit) {
187  eCalo[0] += (*EcalHits)[i].energy();
188  }
189  }
190  if (m_widthEcal > 0.0) {
191  eCalo[1] = G4RandGauss::shoot(0.0, m_widthEcal);
192  }
193  eecals = m_factEcal * (eCalo[0] + eCalo[1]);
194  }
195  if (HcalHits) {
196  nh = HcalHits->size();
197  for (unsigned int i = 0; i < nh; ++i) {
198  HcalDetId hcalid((*HcalHits)[i].id());
199 #ifdef EDM_ML_DEBUG
200  edm::LogVerbatim("HcalTBSim") << "HC " << i << " " << hcalid.subdet() << " " << hcalid.ieta() << ":"
201  << m_idxetaHcal << " " << hcalid.iphi() << ":" << m_idxphiHcal << " "
202  << (*HcalHits)[i].time() << ":" << m_timeLimit << " " << (*HcalHits)[i].energy();
203 #endif
204  // 3x3 towers selection
205  if (std::abs(m_idxetaHcal - hcalid.ieta()) <= 1 && std::abs(m_idxphiHcal - hcalid.iphi()) <= 1 &&
206  (*HcalHits)[i].time() < m_timeLimit) {
207  if (hcalid.subdet() != HcalOuter) {
208  eCalo[2] += (*HcalHits)[i].energy();
209  } else {
210  eCalo[4] += (*HcalHits)[i].energy();
211  }
212  }
213  }
214  if (m_widthHcal > 0.0) {
215  eCalo[3] = G4RandGauss::shoot(0.0, m_widthHcal);
216  eCalo[5] = G4RandGauss::shoot(0.0, m_widthHcal);
217  }
218  ehcals = m_factHcal * eCalo[2] + eCalo[3];
219  }
220  double etots = eecals + ehcals;
221 
222  edm::LogInfo("HcalTBSim") << "HcalTB06Analysis:: Etot(MeV)= " << etots << " E(Ecal)= " << eecals
223  << " E(Hcal)= " << ehcals << " Nhits(ECAL)= " << ne << " Nhits(HCAL)= " << nh;
224  m_histo->fillEdep(etots, eecals, ehcals);
225 
226  if (BeamHits) {
227  for (unsigned int i = 0; i < BeamHits->size(); ++i) {
228  unsigned int id = ((*BeamHits)[i].id());
229  int det, lay, ix, iy;
230  HcalTestBeamNumbering::unpackIndex(id, det, lay, ix, iy);
231  if ((det == 1) && ((*BeamHits)[i].time() < m_timeLimit)) {
232  if (lay > 0 && lay <= 4) {
233  eTrig[lay - 1] += (*BeamHits)[i].energy();
234  } else if (lay == 7 || lay == 8) {
235  eTrig[lay - 2] += (*BeamHits)[i].energy();
236  } else if (lay >= 11 && lay <= 14) {
237  eTrig[4] += (*BeamHits)[i].energy();
238  }
239  }
240  }
241  }
242 
243  edm::LogInfo("HcalTBSim") << "HcalTB06Analysis:: Trigger Info: " << eTrig[0] << ":" << eTrig[1] << ":" << eTrig[2]
244  << ":" << eTrig[3] << ":" << eTrig[4] << ":" << eTrig[5] << ":" << eTrig[6];
245 
246  m_histo->fillTree(eCalo, eTrig);
247 }
248 
250 
const HcalTB06Analysis & operator=(const HcalTB06Analysis &)=delete
Log< level::Info, true > LogVerbatim
const std::vector< int > m_PDG
std::vector< PCaloHit > PCaloHitContainer
void beginJob() override
int iphi() const
get the crystal iphi
Definition: EBDetId.h:51
const double m_timeLimit
T const * product() const
Definition: Handle.h:70
void analyze(const edm::Event &e, const edm::EventSetup &c) override
~HcalTB06Analysis() override=default
const double m_eta
const double m_eMIP
const edm::ParameterSet m_ptb
int ieta() const
get the crystal ieta
Definition: EBDetId.h:49
const edm::EDGetTokenT< edm::PCaloHitContainer > m_HcalToken
std::unique_ptr< HcalTB06Histo > m_histo
constexpr HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:138
const edm::EDGetTokenT< edm::PCaloHitContainer > m_BeamToken
const double m_widthEcal
constexpr int ieta() const
get the cell ieta
Definition: HcalDetId.h:155
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const double m_factHcal
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
uint32_t nh
Log< level::Info, false > LogInfo
HcalTB06Analysis(const edm::ParameterSet &p)
const double m_widthHcal
Handle< PROD > getHandle(EDGetTokenT< PROD > token) const
Definition: Event.h:552
HLT enums.
const double m_ener
static void unpackIndex(const uint32_t &idx, int &det, int &lay, int &x, int &y)
const double m_phi
const double m_factEcal
edm::EDGetTokenT< edm::PCaloHitContainer > m_EcalToken
constexpr int iphi() const
get the cell iphi
Definition: HcalDetId.h:157
void endJob() override