CMS 3D CMS Logo

List of all members | Public Member Functions | Private Types | Private Member Functions
CastorFastTowerProducer Class Reference

#include <FastSimulation/ForwardDetectors/plugins/CastorFastTowerProducer.cc>

Inheritance diagram for CastorFastTowerProducer:
edm::stream::EDProducer<>

Public Member Functions

 CastorFastTowerProducer (const edm::ParameterSet &)
 
 ~CastorFastTowerProducer () override
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndRuns () const final
 

Private Types

typedef std::vector< reco::CastorTowerCastorTowerCollection
 
typedef math::XYZPointD Point
 
typedef ROOT::Math::RhoEtaPhiPoint TowerPoint
 

Private Member Functions

double make_noise ()
 
void produce (edm::Event &, const edm::EventSetup &) override
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
typedef CacheContexts< T... > CacheTypes
 
typedef CacheTypes::GlobalCache GlobalCache
 
typedef AbilityChecker< T... > HasAbility
 
typedef CacheTypes::LuminosityBlockCache LuminosityBlockCache
 
typedef LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCacheLuminosityBlockContext
 
typedef CacheTypes::LuminosityBlockSummaryCache LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache, GlobalCacheRunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 

Detailed Description

Description: <one line="" class="" summary>="">

Implementation: <Notes on="" implementation>="">

Definition at line 17 of file CastorFastTowerProducer.h.

Member Typedef Documentation

Definition at line 29 of file CastorFastTowerProducer.h.

Definition at line 27 of file CastorFastTowerProducer.h.

typedef ROOT::Math::RhoEtaPhiPoint CastorFastTowerProducer::TowerPoint
private

Definition at line 28 of file CastorFastTowerProducer.h.

Constructor & Destructor Documentation

CastorFastTowerProducer::CastorFastTowerProducer ( const edm::ParameterSet iConfig)
explicit

Definition at line 54 of file CastorFastTowerProducer.cc.

54  {
55  //register your products
56  produces<CastorTowerCollection>();
57 
58  //now do what ever other initialization is needed
59 }
CastorFastTowerProducer::~CastorFastTowerProducer ( )
override

Definition at line 61 of file CastorFastTowerProducer.cc.

61  {
62  // do anything here that needs to be done at desctruction time
63  // (e.g. close files, deallocate resources etc.)
64 }

Member Function Documentation

double CastorFastTowerProducer::make_noise ( )
private

Definition at line 356 of file CastorFastTowerProducer.cc.

References DEFINE_FWK_MODULE, diffTwoXMLs::r2, and mps_fire::result.

Referenced by produce().

356  {
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 }
void CastorFastTowerProducer::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivate

Definition at line 71 of file CastorFastTowerProducer.cc.

References a, funct::abs(), b, HLTMuonOfflineAnalyzer_cfi::d0, LEDCalibrationChannels::depth, HCALHighEnergyHPDFilter_cfi::energy, reco::Candidate::energy(), reco::Candidate::eta(), hcaldqm::quantity::fdepth, genParticles2HepMC_cfi::genParticles, edm::Event::getByLabel(), mps_fire::i, dqmiolumiharvest::j, dqm-mbProfile::log, M_PI, make_noise(), SiStripPI::mean, eostools::move(), AlCaHLTBitMon_ParallelJobs::p, reco::Candidate::pdgId(), reco::Candidate::phi(), funct::pow(), HLT_2018_cff::pt1, HLT_2018_cff::pt2, edm::RefVector< C, T, F >::push_back(), edm::Event::put(), alignCSCRings::r, tmax, and x.

Referenced by JSONExport.JsonExport::export(), HTMLExport.HTMLExport::export(), and HTMLExport.HTMLExportStatic::export().

71  {
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 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
ROOT::Math::RhoEtaPhiPoint TowerPoint
virtual double energy() const =0
energy
virtual int pdgId() const =0
PDG identifier.
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:488
#define M_PI
static const double tmax[3]
virtual double eta() const =0
momentum pseudorapidity
double b
Definition: hdecay.h:118
fixed size matrix
HLT enums.
Structure Point Contains parameters of Gaussian fits to DMRs.
Definition: DMRtrends.cc:57
double a
Definition: hdecay.h:119
void push_back(value_type const &ref)
Add a Ref<C, T> to the RefVector.
Definition: RefVector.h:67
std::vector< CastorTower > CastorTowerCollection
collection of CastorTower objects
Definition: CastorTower.h:137
virtual double phi() const =0
momentum azimuthal angle
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:30
def move(src, dest)
Definition: eostools.py:511