CMS 3D CMS Logo

CastorFastTowerProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: CastorFastTowerProducer
4 // Class: CastorFastTowerProducer
5 //
13 //
14 // Original Author: Hans Van Haevermaet
15 // Created: Thu Mar 13 12:00:56 CET 2008
16 // $Id: CastorFastTowerProducer.cc,v 1.3 2011/03/04 10:52:06 hvanhaev Exp $
17 //
18 //
19 
20 // system include files
21 #include <memory>
22 #include <vector>
23 #include <iostream>
24 #include <sstream>
25 #include <TMath.h>
26 #include <TRandom3.h>
27 #include <TF1.h>
28 
29 // user include files
32 
35 
37 
39 
40 // Castorobject includes
44 
45 // genCandidate particle includes
48 
50 
51 //
52 // constructors and destructor
53 //
55  //register your products
56  produces<CastorTowerCollection>();
57 
58  //now do what ever other initialization is needed
59 }
60 
62  // do anything here that needs to be done at desctruction time
63  // (e.g. close files, deallocate resources etc.)
64 }
65 
66 //
67 // member functions
68 //
69 
70 // ------------ method called to produce the data ------------
72  using namespace edm;
73  using namespace reco;
74  using namespace std;
75  using namespace TMath;
76 
77  //
78  // Make CastorTower objects
79  //
80 
81  //cout << "entering event" << endl;
82 
84  iEvent.getByLabel("genParticles", genParticles);
85 
86  // make pointer to towers that will be made
87  unique_ptr<CastorTowerCollection> CastorTowers(new CastorTowerCollection);
88 
89  // declare castor array
90  double castorplus[4][16]; // (0,x): Energies - (1,x): emEnergies - (2,x): hadEnergies - (3,x): phi position - eta = 5.9
91  double castormin[4][16]; // (0,x): Energies - (1,x): emEnergies - (2,x): hadEnergies - (3,x): phi position - eta = -5.9
92  // set phi values of array sectors and everything else to zero
93  for (int j = 0; j < 16; j++) {
94  castorplus[3][j] = -2.94524 + j * 0.3927;
95  castormin[3][j] = -2.94524 + j * 0.3927;
96  castorplus[0][j] = 0.;
97  castormin[0][j] = 0.;
98  castorplus[1][j] = 0.;
99  castormin[1][j] = 0.;
100  castorplus[2][j] = 0.;
101  castormin[2][j] = 0.;
102  //castorplus[4][j] = 0.;
103  //castormin[4][j] = 0.;
104  }
105 
106  // declare properties vectors
107  vector<double> depthplus[16];
108  vector<double> depthmin[16];
109  vector<double> fhotplus[16];
110  vector<double> fhotmin[16];
111  vector<double> energyplus[16];
112  vector<double> energymin[16];
113  //vector<double> femplus [16];
114  //vector<double> femmin [16];
115 
116  for (int i = 0; i < 16; i++) {
117  depthplus[i].clear();
118  depthmin[i].clear();
119  fhotplus[i].clear();
120  fhotmin[i].clear();
121  energyplus[i].clear();
122  energymin[i].clear();
123  //femplus[i].clear();
124  //femmin[i].clear();
125  }
126 
127  //cout << "declared everything" << endl;
128 
129  // start particle loop
130  for (size_t i = 0; i < genParticles->size(); ++i) {
131  const Candidate& p = (*genParticles)[i];
132 
133  // select particles in castor
134  if (fabs(p.eta()) > 5.2 && fabs(p.eta()) < 6.6) {
135  //cout << "found particle in castor, start calculating" << endl;
136 
137  // declare energies
138  //double gaus_E = -1.;
139  double energy = -1.;
140  double emEnergy = 0.;
141  double hadEnergy = 0.;
142  double fhot = 0.;
143  double depth = 0.;
144  //double fem = 0.;
145 
146  // add energies - em: if particle is e- or gamma
147  if (p.pdgId() == 11 || p.pdgId() == 22) {
148  // calculate primary tower energy for electrons
149  while (energy < 0.) {
150  // apply energy smearing with gaussian random generator
151  TRandom3 r(0);
152  // use sigma/E parametrization from the full simulation
153  double mean = 1.0024 * p.energy() - 0.3859;
154  double sigma = 0.0228 * p.energy() + 2.1061;
155  energy = r.Gaus(mean, sigma);
156  }
157 
158  // calculate electromagnetic electron/photon energy leakage
159  double tmax;
160  double a;
161  double cte;
162  if (p.pdgId() == 11) {
163  cte = -0.5;
164  } else {
165  cte = 0.5;
166  }
167  tmax = 1.0 * (log(energy / 0.0015) + cte);
168  a = tmax * 0.5 + 1;
169  double leakage;
170  double x = 0.5 * 19.38;
171  leakage = energy - energy * Gamma(a, x);
172 
173  // add emEnergy
174  emEnergy = energy - leakage;
175  // add hadEnergy leakage
176  hadEnergy = leakage;
177 
178  // calculate EM depth from parametrization
179  double d0 = 0.2338 * pow(p.energy(), -0.1634);
180  double d1 = 5.4336 * pow(p.energy(), 0.2410) + 14408.1025;
181  double d2 = 1.4692 * pow(p.energy(), 0.1307) - 0.5216;
182  if (d0 < 0.)
183  d0 = abs(d0);
184 
185  TF1* fdepth =
186  new TF1("fdepth", "[0] * TMath::Exp(-0.5*( (x-[1])/[2] + TMath::Exp(-(x-[1])/[2])))", 14400., 14460.);
187  fdepth->SetParameters(d0, d1, d2);
188  depth = fdepth->GetRandom();
189  fdepth->Delete();
190  if (p.eta() < 0.)
191  depth = -1 * depth;
192 
193  } else {
194  // calculate primary tower energy for hadrons
195  while (energy < 0.) {
196  // apply energy smearing with gaussian random generator
197  TRandom3 r(0);
198  // use sigma/E parametrization from the full simulation
199  double mean = 0.8340 * p.energy() - 8.5054;
200  double sigma = 0.1595 * p.energy() + 3.1183;
201  energy = r.Gaus(mean, sigma);
202  }
203 
204  // add hadEnergy
205  hadEnergy = energy;
206 
207  // in the near future add fem parametrization
208 
209  // calculate depth for HAD particle from parametrization
210  double d0 = -0.000012 * p.energy() + 0.0661;
211  double d1 = 785.7524 * pow(p.energy(), 0.0262) + 13663.4262;
212  double d2 = 9.8748 * pow(p.energy(), 0.1720) + 37.0187;
213  if (d0 < 0.)
214  d0 = abs(d0);
215 
216  TF1* fdepth =
217  new TF1("fdepth", "[0] * TMath::Exp(-0.5*( (x-[1])/[2] + TMath::Exp(-(x-[1])/[2]) ))", 14400., 15500.);
218  fdepth->SetParameters(d0, d1, d2);
219  depth = fdepth->GetRandom();
220  fdepth->Delete();
221  if (p.eta() < 0.)
222  depth = -1 * depth;
223  }
224 
225  // make tower
226 
227  // set sector
228  int sector = -1;
229  for (int j = 0; j < 16; j++) {
230  double a = -M_PI + j * 0.3927;
231  double b = -M_PI + (j + 1) * 0.3927;
232  if ((p.phi() > a) && (p.phi() < b)) {
233  sector = j;
234  }
235  }
236 
237  // set eta
238  if (p.eta() > 0) {
239  castorplus[0][sector] = castorplus[0][sector] + energy;
240  castorplus[1][sector] = castorplus[1][sector] + emEnergy;
241  castorplus[2][sector] = castorplus[2][sector] + hadEnergy;
242 
243  depthplus[sector].push_back(depth);
244  fhotplus[sector].push_back(fhot);
245  energyplus[sector].push_back(energy);
246  //cout << "filled vectors" << endl;
247  //cout << "energyplus size = " << energyplus[sector].size() << endl;
248  //cout << "depthplus size = " << depthplus[sector].size() << endl;
249  //cout << "fhotplus size = " << fhotplus[sector].size() << endl;
250 
251  } else {
252  castormin[0][sector] = castormin[0][sector] + energy;
253  castormin[1][sector] = castormin[1][sector] + emEnergy;
254  castormin[2][sector] = castormin[2][sector] + hadEnergy;
255 
256  depthmin[sector].push_back(depth);
257  fhotmin[sector].push_back(fhot);
258  energymin[sector].push_back(energy);
259  //cout << "filled vectors" << endl;
260  }
261  }
262  }
263 
264  // add and substract pedestals/noise
265  for (int j = 0; j < 16; j++) {
266  double hadnoise = 0.;
267  double emnoise = 0.;
268  for (int i = 0; i < 12; i++) {
269  hadnoise = hadnoise + make_noise();
270  if (i < 2)
271  emnoise = emnoise + make_noise();
272  }
273 
274  hadnoise = hadnoise - 12 * 0.053;
275  emnoise = emnoise - 2 * 0.053;
276  if (hadnoise < 0.)
277  hadnoise = 0.;
278  if (emnoise < 0.)
279  emnoise = 0.;
280  double totnoise = hadnoise + emnoise;
281 
282  // add random noise
283  castorplus[0][j] = castorplus[0][j] + totnoise;
284  castormin[0][j] = castormin[0][j] + totnoise;
285  castorplus[1][j] = castorplus[1][j] + emnoise;
286  castormin[1][j] = castormin[1][j] + emnoise;
287  castorplus[2][j] = castorplus[2][j] + hadnoise;
288  castormin[2][j] = castormin[2][j] + hadnoise;
289 
290  //cout << "after constant substraction" << endl;
291  //cout << "total noise = " << castorplus[0][j] << " em noise = " << castorplus[1][j] << " had noise = " << castorplus[2][j] << endl;
292  //cout << "fem should be = " << castorplus[1][j]/castorplus[0][j] << endl;
293  }
294 
295  // store towers from castor arrays
296  // eta = 5.9
297  for (int j = 0; j < 16; j++) {
298  if (castorplus[0][j] != 0.) {
299  double fem = 0.;
300  fem = castorplus[1][j] / castorplus[0][j];
301  TowerPoint pt1(88.5, 5.9, castorplus[3][j]);
302  Point pt2(pt1);
303 
304  //cout << "fem became = " << castorplus[1][j]/castorplus[0][j] << endl;
305 
306  double depth_mean = 0.;
307  double fhot_mean = 0.;
308  double sum_energy = 0.;
309 
310  //cout << "energyplus size = " << energyplus[j].size()<< endl;
311  for (size_t p = 0; p < energyplus[j].size(); p++) {
312  depth_mean = depth_mean + depthplus[j][p] * energyplus[j][p];
313  fhot_mean = fhot_mean + fhotplus[j][p] * energyplus[j][p];
314  sum_energy = sum_energy + energyplus[j][p];
315  }
316  depth_mean = depth_mean / sum_energy;
317  fhot_mean = fhot_mean / sum_energy;
318  //cout << "computed depth/fhot" << endl;
319 
320  //std::vector<CastorCell> usedCells;
322  CastorTowers->push_back(reco::CastorTower(
323  castorplus[0][j], pt2, castorplus[1][j], castorplus[2][j], fem, depth_mean, fhot_mean, refvector));
324  }
325  }
326  // eta = -5.9
327  for (int j = 0; j < 16; j++) {
328  if (castormin[0][j] != 0.) {
329  double fem = 0.;
330  fem = castormin[1][j] / castormin[0][j];
331  TowerPoint pt1(88.5, -5.9, castormin[3][j]);
332  Point pt2(pt1);
333 
334  double depth_mean = 0.;
335  double fhot_mean = 0.;
336  double sum_energy = 0.;
337 
338  for (size_t p = 0; p < energymin[j].size(); p++) {
339  depth_mean = depth_mean + depthmin[j][p] * energymin[j][p];
340  fhot_mean = fhot_mean + fhotmin[j][p] * energymin[j][p];
341  sum_energy = sum_energy + energymin[j][p];
342  }
343  depth_mean = depth_mean / sum_energy;
344  fhot_mean = fhot_mean / sum_energy;
345 
346  //std::vector<CastorCell> usedCells;
348  CastorTowers->push_back(reco::CastorTower(
349  castormin[0][j], pt2, castormin[1][j], castormin[2][j], fem, depth_mean, fhot_mean, refvector));
350  }
351  }
352 
353  iEvent.put(std::move(CastorTowers));
354 }
355 
357  double result = -1.;
358  TRandom3 r2(0);
359  double mu_noise = 0.053; // GeV (from 1.214 ADC) per channel
360  double sigma_noise = 0.027; // GeV (from 0.6168 ADC) per channel
361 
362  while (result < 0.) {
363  result = r2.Gaus(mu_noise, sigma_noise);
364  }
365 
366  return result;
367 }
368 
369 //define this as a plug-in
mps_fire.i
i
Definition: mps_fire.py:428
genParticles2HepMC_cfi.genParticles
genParticles
Definition: genParticles2HepMC_cfi.py:4
SiStripPI::mean
Definition: SiStripPayloadInspectorHelper.h:169
CastorTower.h
EDProducer.h
CastorFastTowerProducer::TowerPoint
ROOT::Math::RhoEtaPhiPoint TowerPoint
Definition: CastorFastTowerProducer.h:28
edm
HLT enums.
Definition: AlignableModifier.h:19
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
hcaldqm::quantity::fdepth
Definition: DetectorQuantity.h:16
CastorFastTowerProducer::make_noise
double make_noise()
Definition: CastorFastTowerProducer.cc:356
CastorFastTowerProducer::CastorFastTowerProducer
CastorFastTowerProducer(const edm::ParameterSet &)
Definition: CastorFastTowerProducer.cc:54
CastorFastTowerProducer::CastorTowerCollection
std::vector< reco::CastorTower > CastorTowerCollection
Definition: CastorFastTowerProducer.h:29
DDAxes::x
edm::RefVector
Definition: EDProductfwd.h:27
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
tools.TF1
TF1
Definition: tools.py:23
edm::Handle
Definition: AssociativeIterator.h:50
tmax
static const double tmax[3]
Definition: CastorTimeSlew.cc:7
GenParticle.h
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
HLT_FULL_cff.pt1
pt1
Definition: HLT_FULL_cff.py:9870
HCALHighEnergyHPDFilter_cfi.energy
energy
Definition: HCALHighEnergyHPDFilter_cfi.py:5
b
double b
Definition: hdecay.h:118
LEDCalibrationChannels.depth
depth
Definition: LEDCalibrationChannels.py:65
Point
Structure Point Contains parameters of Gaussian fits to DMRs.
Definition: DMRtrends.cc:57
edm::ParameterSet
Definition: ParameterSet.h:47
a
double a
Definition: hdecay.h:119
Event.h
diffTwoXMLs.r2
r2
Definition: diffTwoXMLs.py:73
iEvent
int iEvent
Definition: GenABIO.cc:224
M_PI
#define M_PI
Definition: BXVectorInputProducer.cc:49
CastorFastTowerProducer.h
CastorFastTowerProducer
Definition: CastorFastTowerProducer.h:17
edm::EventSetup
Definition: EventSetup.h:57
HLT_FULL_cff.pt2
pt2
Definition: HLT_FULL_cff.py:9872
edm::RefVector::push_back
void push_back(value_type const &ref)
Add a Ref<C, T> to the RefVector.
Definition: RefVector.h:67
reco::Candidate
Definition: Candidate.h:27
alignCSCRings.r
r
Definition: alignCSCRings.py:93
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
CastorFastTowerProducer::~CastorFastTowerProducer
~CastorFastTowerProducer() override
Definition: CastorFastTowerProducer.cc:61
Frameworkfwd.h
Point3D.h
reco::CastorTower
Definition: CastorTower.h:26
dqm-mbProfile.log
log
Definition: dqm-mbProfile.py:17
CastorFastTowerProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: CastorFastTowerProducer.cc:71
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
mps_fire.result
result
Definition: mps_fire.py:311
CastorRecHit.h
Candidate.h
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ParameterSet.h
HcalCastorDetId.h
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
edm::Event
Definition: Event.h:73
d0
static constexpr float d0
Definition: L1EGammaCrystalsEmulatorProducer.cc:84
d1
static constexpr float d1
Definition: L1EGammaCrystalsEmulatorProducer.cc:84