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