test
CMS 3D CMS Logo

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