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
18 
19 // to retreive hits
23 
26 
30 
32 
33 #include "CLHEP/Units/GlobalSystemOfUnits.h"
34 #include "CLHEP/Units/GlobalPhysicalConstants.h"
35 #include "globals.hh"
36 #include "Randomize.hh"
37 
38 // system include files
39 #include <iostream>
40 #include <iomanip>
41 
42 //#define EDM_ML_DEBUG
43 //
44 // constructors and destructor
45 //
46 
48 
49  usesResource("TFileService");
50 
51  m_ECAL = p.getParameter<bool>("ECAL");
52  if(m_ECAL) {
53  m_EcalToken = consumes<edm::PCaloHitContainer>(edm::InputTag("g4SimHits","EcalHitsEB"));
54  }
55  m_HcalToken = consumes<edm::PCaloHitContainer>(edm::InputTag("g4SimHits","HcalHits"));
56  m_BeamToken = consumes<edm::PCaloHitContainer>(edm::InputTag("g4SimHits","HcalTB06BeamHits"));
57  m_eta = p.getParameter<double>("MinEta");
58  m_phi = p.getParameter<double>("MinPhi");
59  m_ener= p.getParameter<double>("MinE");
60  m_PDG = p.getParameter<std::vector<int> >("PartID");
61 
62  double minEta = p.getParameter<double>("MinEta");
63  double maxEta = p.getParameter<double>("MaxEta");
64  double minPhi = p.getParameter<double>("MinPhi");
65  double maxPhi = p.getParameter<double>("MaxPhi");
66  double beamEta = (maxEta+minEta)*0.5;
67  double beamPhi = (maxPhi+minPhi)*0.5;
68  if (beamPhi < 0) { beamPhi += twopi; }
69 
70  m_idxetaEcal = 13;
71  m_idxphiEcal = 13;
72 
73  m_idxetaHcal = (int)(beamEta/0.087) + 1;
74  m_idxphiHcal = (int)(beamPhi/0.087) + 6;
75  if(m_idxphiHcal > 72) { m_idxphiHcal -= 73; }
76 
77  edm::ParameterSet ptb = p.getParameter<edm::ParameterSet>("TestBeamAnalysis");
78  m_timeLimit = ptb.getParameter<double>("TimeLimit");
79  m_widthEcal = ptb.getParameter<double>("EcalWidth");
80  m_widthHcal = ptb.getParameter<double>("HcalWidth");
81  m_factEcal = ptb.getParameter<double>("EcalFactor");
82  m_factHcal = ptb.getParameter<double>("HcalFactor");
83  double eMIP = ptb.getParameter<double>("MIP");
84 
85  edm::LogInfo("HcalTB06Analysis")
86  << "Beam parameters: E(GeV)= " << m_ener
87  << " pdgID= " << m_PDG[0]
88  << "\n eta= " << m_eta
89  << " idx_etaEcal= " << m_idxetaEcal
90  << " idx_etaHcal= " << m_idxetaHcal
91  << " phi= " << m_phi
92  << " idx_phiEcal= " << m_idxphiEcal
93  << " idx_phiHcal= " << m_idxphiHcal
94  << "\n EcalFactor= " << m_factEcal
95  << " EcalWidth= " << m_widthEcal << " GeV"
96  << "\n HcalFactor= " << m_factHcal
97  << " HcalWidth= " << m_widthHcal << " GeV"
98  << " MIP= " << eMIP << " GeV"
99  << "\n TimeLimit= " << m_timeLimit << " ns" << "\n";
100  m_histo = new HcalTB06Histo(ptb);
101 }
102 
104  delete m_histo;
105 }
106 
108  edm::LogInfo("HcalTB06Analysis") <<" =====> Begin of Run";
109 }
110 
112  edm::LogInfo("HcalTB06Analysis")
113  << " =====> End of Run; Total number of events: " << count;
114 }
115 
117 {
118  ++count;
119 
120  //Beam Information
122 
126  std::vector<double> eCalo(6,0), eTrig(7,0);
127 
128  const std::vector<PCaloHit>* EcalHits = nullptr;
129  if(m_ECAL) {
130  evt.getByToken(m_EcalToken, Ecal);
131  EcalHits = Ecal.product();
132  }
133  evt.getByToken(m_HcalToken, Hcal);
134  const std::vector<PCaloHit>* HcalHits = Hcal.product();
135  evt.getByToken(m_BeamToken, Beam);
136  const std::vector<PCaloHit>* BeamHits = Beam.product();
137 
138  // Total Energy
139  double eecals = 0.;
140  double ehcals = 0.;
141 
142  unsigned int ne = 0;
143  unsigned int nh = 0;
144  if(m_ECAL) {
145  ne = EcalHits->size();
146  for (unsigned int i=0; i<ne; ++i) {
147  EBDetId ecalid((*EcalHits)[i].id());
148 #ifdef EDM_ML_DEBUG
149  std::cout << "EB " << i << " " << ecalid.ieta() << ":" << m_idxetaEcal
150  << " " << ecalid.iphi() << ":" << m_idxphiEcal << " "
151  << (*EcalHits)[i].time() << ":" << m_timeLimit << " "
152  << (*EcalHits)[i].energy() << std::endl;
153 #endif
154  // 7x7 crystal selection
155  if(std::abs(m_idxetaEcal - ecalid.ieta()) <= 3 &&
156  std::abs(m_idxphiEcal - ecalid.iphi()) <= 3 &&
157  (*EcalHits)[i].time() < m_timeLimit) {
158  eCalo[0] += (*EcalHits)[i].energy();
159  }
160  }
161  if(m_widthEcal > 0.0) {
162  eCalo[1] = G4RandGauss::shoot(0.0,m_widthEcal);
163  }
164  eecals = m_factEcal*(eCalo[0]+eCalo[1]);
165  }
166  if(HcalHits) {
167  nh = HcalHits->size();
168  for (unsigned int i=0; i<nh; ++i) {
169  HcalDetId hcalid((*HcalHits)[i].id());
170 #ifdef EDM_ML_DEBUG
171  std::cout << "HC " << i << " " << hcalid.subdet() << " "
172  << hcalid.ieta() << ":" << m_idxetaHcal << " "
173  << hcalid.iphi() << ":" << m_idxphiHcal << " "
174  << (*HcalHits)[i].time() << ":" << m_timeLimit << " "
175  << (*HcalHits)[i].energy() << std::endl;
176 #endif
177  // 3x3 towers selection
178  if(std::abs(m_idxetaHcal - hcalid.ieta()) <= 1 &&
179  std::abs(m_idxphiHcal - hcalid.iphi()) <= 1 &&
180  (*HcalHits)[i].time() < m_timeLimit) {
181  if (hcalid.subdet() != HcalOuter) {
182  eCalo[2] += (*HcalHits)[i].energy();
183  } else {
184  eCalo[4] += (*HcalHits)[i].energy();
185  }
186  }
187  }
188  if(m_widthHcal > 0.0) {
189  eCalo[3] = G4RandGauss::shoot(0.0,m_widthHcal);
190  eCalo[5] = G4RandGauss::shoot(0.0,m_widthHcal);
191  }
192  ehcals = m_factHcal*eCalo[2] + eCalo[3];
193  }
194  double etots = eecals + ehcals;
195 
196  edm::LogInfo("HcalTBSim") << "HcalTB06Analysis:: Etot(MeV)= " << etots
197  << " E(Ecal)= " << eecals
198  << " E(Hcal)= " << ehcals
199  << " Nhits(ECAL)= " << ne
200  << " Nhits(HCAL)= " << nh;
201  m_histo->fillEdep(etots, eecals, ehcals);
202 
203  if(BeamHits) {
204  for (unsigned int i=0; i<BeamHits->size(); ++i) {
205  unsigned int id = ((*BeamHits)[i].id());
206  int det, lay, ix, iy;
207  HcalTestBeamNumbering::unpackIndex(id,det,lay,ix,iy);
208  if ((det == 1) && ((*BeamHits)[i].time() < m_timeLimit)) {
209  if (lay > 0 && lay <= 4) {
210  eTrig[lay-1] += (*BeamHits)[i].energy();
211  } else if (lay == 7 || lay == 8) {
212  eTrig[lay-2] += (*BeamHits)[i].energy();
213  } else if (lay >= 11 && lay <= 14) {
214  eTrig[4] += (*BeamHits)[i].energy();
215  }
216  }
217  }
218  }
219 
220  edm::LogInfo("HcalTBSim") << "HcalTB06Analysis:: Trigger Info: "
221  << eTrig[0] << ":" << eTrig[1] << ":" << eTrig[2]
222  << ":" << eTrig[3] << ":" << eTrig[4] << ":"
223  << eTrig[5] << ":" << eTrig[6];
224 
225  m_histo->fillTree(eCalo,eTrig);
226 }
T getParameter(std::string const &) const
HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:49
void beginJob() override
edm::EDGetTokenT< edm::PCaloHitContainer > m_BeamToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
void analyze(const edm::Event &e, const edm::EventSetup &c) override
void fillEdep(double etots, double eecals, double ehcals)
double maxEta
int iphi() const
get the crystal iphi
Definition: EBDetId.h:53
void fillTree(std::vector< double > &ecalo, std::vector< double > &etrig)
HcalTB06Histo * m_histo
int ieta() const
get the cell ieta
Definition: HcalDetId.h:56
edm::EDGetTokenT< edm::PCaloHitContainer > m_HcalToken
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int ieta() const
get the crystal ieta
Definition: EBDetId.h:51
int iphi() const
get the cell iphi
Definition: HcalDetId.cc:103
T const * product() const
Definition: Handle.h:81
~HcalTB06Analysis() override
HcalTB06Analysis(const edm::ParameterSet &p)
std::vector< int > m_PDG
static void unpackIndex(const uint32_t &idx, int &det, int &lay, int &x, int &y)
void fillPrimary(double energy, double eta, double phi)
edm::EDGetTokenT< edm::PCaloHitContainer > m_EcalToken
void endJob() override