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 
84  edm::LogInfo("HcalTB06Analysis")
85  << "Beam parameters: E(GeV)= " << m_ener
86  << " pdgID= " << m_PDG[0]
87  << "\n eta= " << m_eta
88  << " idx_etaEcal= " << m_idxetaEcal
89  << " idx_etaHcal= " << m_idxetaHcal
90  << " phi= " << m_phi
91  << " idx_phiEcal= " << m_idxphiEcal
92  << " idx_phiHcal= " << m_idxphiHcal
93  << "\n EcalFactor= " << m_factEcal
94  << " EcalWidth= " << m_widthEcal << " GeV"
95  << "\n HcalFactor= " << m_factHcal
96  << " HcalWidth= " << m_widthHcal << " GeV"
97  << "\n TimeLimit= " << m_timeLimit << " ns" << "\n";
98  m_histo = new HcalTB06Histo(ptb);
99 }
100 
102  delete m_histo;
103 }
104 
106  edm::LogInfo("HcalTB06Analysis") <<" =====> Begin of Run";
107 }
108 
110  edm::LogInfo("HcalTB06Analysis")
111  << " =====> End of Run; Total number of events: " << count;
112 }
113 
115 {
116  ++count;
117 
118  //Beam Information
120 
124  std::vector<double> eCalo(6,0), eTrig(7,0);
125 
126  const std::vector<PCaloHit>* EcalHits = nullptr;
127  if(m_ECAL) {
128  evt.getByToken(m_EcalToken, Ecal);
129  EcalHits = Ecal.product();
130  }
131  evt.getByToken(m_HcalToken, Hcal);
132  const std::vector<PCaloHit>* HcalHits = Hcal.product();
133  evt.getByToken(m_BeamToken, Beam);
134  const std::vector<PCaloHit>* BeamHits = Beam.product();
135 
136  // Total Energy
137  double eecals = 0.;
138  double ehcals = 0.;
139 
140  unsigned int ne = 0;
141  unsigned int nh = 0;
142  if(m_ECAL) {
143  ne = EcalHits->size();
144  for (unsigned int i=0; i<ne; ++i) {
145  EBDetId ecalid((*EcalHits)[i].id());
146 #ifdef EDM_ML_DEBUG
147  std::cout << "EB " << i << " " << ecalid.ieta() << ":" << m_idxetaEcal
148  << " " << ecalid.iphi() << ":" << m_idxphiEcal << " "
149  << (*EcalHits)[i].time() << ":" << m_timeLimit << " "
150  << (*EcalHits)[i].energy() << std::endl;
151 #endif
152  // 7x7 crystal selection
153  if(std::abs(m_idxetaEcal - ecalid.ieta()) <= 3 &&
154  std::abs(m_idxphiEcal - ecalid.iphi()) <= 3 &&
155  (*EcalHits)[i].time() < m_timeLimit) {
156  eCalo[0] += (*EcalHits)[i].energy();
157  }
158  }
159  if(m_widthEcal > 0.0) {
160  eCalo[1] = G4RandGauss::shoot(0.0,m_widthEcal);
161  }
162  eecals = m_factEcal*(eCalo[0]+eCalo[1]);
163  }
164  if(HcalHits) {
165  nh = HcalHits->size();
166  for (unsigned int i=0; i<nh; ++i) {
167  HcalDetId hcalid((*HcalHits)[i].id());
168 #ifdef EDM_ML_DEBUG
169  std::cout << "HC " << i << " " << hcalid.subdet() << " "
170  << hcalid.ieta() << ":" << m_idxetaHcal << " "
171  << hcalid.iphi() << ":" << m_idxphiHcal << " "
172  << (*HcalHits)[i].time() << ":" << m_timeLimit << " "
173  << (*HcalHits)[i].energy() << std::endl;
174 #endif
175  // 3x3 towers selection
176  if(std::abs(m_idxetaHcal - hcalid.ieta()) <= 1 &&
177  std::abs(m_idxphiHcal - hcalid.iphi()) <= 1 &&
178  (*HcalHits)[i].time() < m_timeLimit) {
179  if (hcalid.subdet() != HcalOuter) {
180  eCalo[2] += (*HcalHits)[i].energy();
181  } else {
182  eCalo[4] += (*HcalHits)[i].energy();
183  }
184  }
185  }
186  if(m_widthHcal > 0.0) {
187  eCalo[3] = G4RandGauss::shoot(0.0,m_widthHcal);
188  eCalo[5] = G4RandGauss::shoot(0.0,m_widthHcal);
189  }
190  ehcals = m_factHcal*eCalo[2] + eCalo[3];
191  }
192  double etots = eecals + ehcals;
193 
194  edm::LogInfo("HcalTBSim") << "HcalTB06Analysis:: Etot(MeV)= " << etots
195  << " E(Ecal)= " << eecals
196  << " E(Hcal)= " << ehcals
197  << " Nhits(ECAL)= " << ne
198  << " Nhits(HCAL)= " << nh;
199  m_histo->fillEdep(etots, eecals, ehcals);
200 
201  if(BeamHits) {
202  for (unsigned int i=0; i<BeamHits->size(); ++i) {
203  unsigned int id = ((*BeamHits)[i].id());
204  int det, lay, ix, iy;
205  HcalTestBeamNumbering::unpackIndex(id,det,lay,ix,iy);
206  if ((det == 1) && ((*BeamHits)[i].time() < m_timeLimit)) {
207  if (lay > 0 && lay <= 4) {
208  eTrig[lay-1] += (*BeamHits)[i].energy();
209  } else if (lay == 7 || lay == 8) {
210  eTrig[lay-2] += (*BeamHits)[i].energy();
211  } else if (lay >= 11 && lay <= 14) {
212  eTrig[4] += (*BeamHits)[i].energy();
213  }
214  }
215  }
216  }
217 
218  edm::LogInfo("HcalTBSim") << "HcalTB06Analysis:: Trigger Info: "
219  << eTrig[0] << ":" << eTrig[1] << ":" << eTrig[2]
220  << ":" << eTrig[3] << ":" << eTrig[4] << ":"
221  << eTrig[5] << ":" << eTrig[6];
222 
223  m_histo->fillTree(eCalo,eTrig);
224 }
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:508
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:124
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