CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CastorFastClusterProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: CastorFastClusterProducer
4 // Class: CastorFastClusterProducer
5 //
13 //
14 // Original Author: Hans Van Haevermaet
15 // Created: Thu Mar 13 12:00:56 CET 2008
16 // $Id: CastorFastClusterProducer.cc,v 1.2 2011/03/04 11:00:55 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<CastorClusterCollection>();
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 CastorCluster 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<CastorClusterCollection> CastorClusters (new CastorClusterCollection);
99 
100  /*
101  // declare castor array
102  double castorplus [4][16]; // (0,x): Energies - (1,x): emEnergies - (2,x): hadEnergies - (3,x): phi position - eta = 5.9
103  double castormin [4][16]; // (0,x): Energies - (1,x): emEnergies - (2,x): hadEnergies - (3,x): phi position - eta = -5.9
104  // set phi values of array sectors and everything else to zero
105  for (int j = 0; j < 16; j++) {
106  castorplus[3][j] = -2.94524 + j*0.3927;
107  castormin[3][j] = -2.94524 + j*0.3927;
108  castorplus[0][j] = 0.;
109  castormin[0][j] = 0.;
110  castorplus[1][j] = 0.;
111  castormin[1][j] = 0.;
112  castorplus[2][j] = 0.;
113  castormin[2][j] = 0.;
114  //castorplus[4][j] = 0.;
115  //castormin[4][j] = 0.;
116  }
117 
118  // declare properties vectors
119  vector<double> depthplus[16];
120  vector<double> depthmin[16];
121  vector<double> fhotplus [16];
122  vector<double> fhotmin [16];
123  vector<double> energyplus [16];
124  vector<double> energymin [16];
125 
126  for (int i=0;i<16;i++) {
127  depthplus[i].clear();
128  depthmin[i].clear();
129  fhotplus[i].clear();
130  fhotmin[i].clear();
131  energyplus[i].clear();
132  energymin[i].clear();
133  }
134  */
135 
136  //cout << "declared everything" << endl;
137 
138  // start particle loop
139  for (size_t i = 0; i < genParticles->size(); ++i) {
140  const Candidate & p = (*genParticles)[i];
141 
142  // select particles in castor
143  if ( fabs(p.eta()) > 5.2 && fabs(p.eta()) < 6.6) {
144 
145  //cout << "found particle in castor, start calculating" << endl;
146 
147  // declare energies
148  double gaus_E = -1.;
149  double emEnergy = 0.;
150  double hadEnergy = 0.;
151  //double fhot = 0.;
152  //double depth = 0.;
153 
154  // add energies - em: if particle is e- or gamma
155  if (p.pdgId() == 11 || p.pdgId() == 22) {
156 
157  while ( gaus_E < 0.) {
158  // apply energy smearing with gaussian random generator
159  TRandom3 r(0);
160  // use sigma/E parametrization for the EM sections of CASTOR TB 2007 results
161  double sigma = p.energy()*(sqrt(pow(0.044,2) + pow(0.513/sqrt(p.energy()),2)));
162  gaus_E = r.Gaus(p.energy(),sigma);
163  }
164 
165  // calculate electromagnetic electron/photon energy leakage
166  double tmax;
167  double a;
168  double cte;
169  if ( p.pdgId() == 11) { cte = -0.5; } else { cte = 0.5; }
170  tmax = 1.0*(log(gaus_E/0.0015)+cte);
171  a = tmax*0.5 + 1;
172  double leakage;
173  double x = 0.5*19.38;
174  leakage = gaus_E - gaus_E*Gamma(a,x);
175 
176  // add emEnergy
177  emEnergy = gaus_E - leakage;
178  // add hadEnergy leakage
179  hadEnergy = leakage;
180 
181  // make cluster
182  ClusterPoint pt1;
183  if (p.eta() > 0.) {ClusterPoint temp(88.5,5.9,p.phi()); pt1 = temp;}
184  if (p.eta() < 0.) {ClusterPoint temp(88.5,-5.9,p.phi()); pt1 = temp;}
185  Point pt2(pt1);
186  CastorTowerRefVector refvector;
187  CastorClusters->push_back(reco::CastorCluster(gaus_E,pt2,emEnergy,hadEnergy,emEnergy/gaus_E,0.,0.,0.,0.,refvector));
188 
189  } else {
190 
191  while (gaus_E < 0.) {
192  // apply energy smearing with gaussian random generator
193  TRandom3 r(0);
194  // use sigma/E parametrization for the HAD sections of CASTOR TB 2007 results
195  double sigma = p.energy()*(sqrt(pow(0.121,2) + pow(1.684/sqrt(p.energy()),2)));
196  gaus_E = r.Gaus(p.energy(),sigma);
197  }
198 
199  // add hadEnergy
200  hadEnergy = gaus_E;
201 
202  // make cluster
203  ClusterPoint pt1;
204  if (p.eta() > 0.) {ClusterPoint temp(88.5,5.9,p.phi()); pt1 = temp;}
205  if (p.eta() < 0.) {ClusterPoint temp(88.5,-5.9,p.phi()); pt1 = temp;}
206  Point pt2(pt1);
207  CastorTowerRefVector refvector;
208  CastorClusters->push_back(reco::CastorCluster(gaus_E,pt2,0.,hadEnergy,0.,0.,0.,0.,0.,refvector));
209  }
210 
211  /*
212  // make tower
213 
214  // set sector
215  int sector = -1;
216  for (int j = 0; j < 16; j++) {
217  double a = -M_PI + j*0.3927;
218  double b = -M_PI + (j+1)*0.3927;
219  if ( (p.phi() > a) && (p.phi() < b)) {
220  sector = j;
221  }
222  }
223 
224  // set eta
225  if (p.eta() > 0) {
226  castorplus[0][sector] = castorplus[0][sector] + gaus_E;
227  castorplus[1][sector] = castorplus[1][sector] + emEnergy;
228  castorplus[2][sector] = castorplus[2][sector] + hadEnergy;
229 
230  depthplus[sector].push_back(depth);
231  fhotplus[sector].push_back(fhot);
232  energyplus[sector].push_back(gaus_E);
233  //cout << "filled vectors" << endl;
234  //cout << "energyplus size = " << energyplus[sector].size() << endl;
235  //cout << "depthplus size = " << depthplus[sector].size() << endl;
236  //cout << "fhotplus size = " << fhotplus[sector].size() << endl;
237 
238  } else {
239  castormin[0][sector] = castormin[0][sector] + gaus_E;
240  castormin[1][sector] = castormin[1][sector] + emEnergy;
241  castormin[2][sector] = castormin[2][sector] + hadEnergy;
242 
243 
244  depthmin[sector].push_back(depth);
245  fhotmin[sector].push_back(fhot);
246  energymin[sector].push_back(gaus_E);
247  //cout << "filled vectors" << endl;
248 
249  }
250  */
251 
252  }
253 
254  }
255 
256  /*
257  // substract pedestals/noise
258  for (int j = 0; j < 16; j++) {
259  double hadnoise = 0.;
260  for (int i=0;i<12;i++) {
261  hadnoise = hadnoise + make_noise();
262  }
263  castorplus[0][j] = castorplus[0][j] - hadnoise - make_noise() - make_noise();
264  castormin[0][j] = castormin[0][j] - hadnoise - make_noise() - make_noise();
265  castorplus[1][j] = castorplus[1][j] - make_noise() - make_noise();
266  castormin[1][j] = castormin[1][j] - make_noise() - make_noise();
267  castorplus[2][j] = castorplus[2][j] - hadnoise;
268  castormin[2][j] = castormin[2][j] - hadnoise;
269 
270  // set possible negative values to zero
271  if (castorplus[0][j] < 0.) castorplus[0][j] = 0.;
272  if (castormin[0][j] < 0.) castormin[0][j] = 0.;
273  if (castorplus[1][j] < 0.) castorplus[1][j] = 0.;
274  if (castormin[1][j] < 0.) castormin[1][j] = 0.;
275  if (castorplus[2][j] < 0.) castorplus[2][j] = 0.;
276  if (castormin[2][j] < 0.) castormin[2][j] = 0.;
277  }
278  */
279 
280  /*
281  // store towers from castor arrays
282  // eta = 5.9
283  for (int j=0;j<16;j++) {
284  if (castorplus[0][j] > 0.) {
285 
286  double fem = 0.;
287  fem = castorplus[1][j]/castorplus[0][j];
288  ClusterPoint pt1(88.5,5.9,castorplus[3][j]);
289  Point pt2(pt1);
290 
291  // parametrize depth and fhot from full sim
292  // get fit parameters from energy
293  // get random number according to distribution with fit parameters
294  double depth_mean = 0.;
295  double fhot_mean = 0.;
296  double sum_energy = 0.;
297 
298  //cout << "energyplus size = " << energyplus[j].size()<< endl;
299  for (size_t p = 0; p<energyplus[j].size();p++) {
300  depth_mean = depth_mean + depthplus[j][p]*energyplus[j][p];
301  fhot_mean = fhot_mean + fhotplus[j][p]*energyplus[j][p];
302  sum_energy = sum_energy + energyplus[j][p];
303  }
304  depth_mean = depth_mean/sum_energy;
305  fhot_mean = fhot_mean/sum_energy;
306  cout << "computed depth/fhot" << endl;
307 
308 
309  edm::RefVector<edm::SortedCollection<CastorRecHit> > refvector;
310  CastorClusters->push_back(reco::CastorCluster(castorplus[0][j],pt2,castorplus[1][j],castorplus[2][j],fem,depth_mean,fhot_mean,refvector));
311  }
312  }
313  // eta = -5.9
314  for (int j=0;j<16;j++) {
315  if (castormin[0][j] > 0.) {
316  double fem = 0.;
317  fem = castormin[1][j]/castormin[0][j];
318  ClusterPoint pt1(88.5,-5.9,castormin[3][j]);
319  Point pt2(pt1);
320 
321  // parametrize depth and fhot from full sim
322  // get fit parameters from energy
323  // get random number according to distribution with fit parameters
324  double depth_mean = 0.;
325  double fhot_mean = 0.;
326  double sum_energy = 0.;
327 
328 
329  for (size_t p = 0; p<energymin[j].size();p++) {
330  depth_mean = depth_mean + depthmin[j][p]*energymin[j][p];
331  fhot_mean = fhot_mean + fhotmin[j][p]*energymin[j][p];
332  sum_energy = sum_energy + energymin[j][p];
333  }
334  depth_mean = depth_mean/sum_energy;
335  fhot_mean = fhot_mean/sum_energy;
336 
337 
338  edm::RefVector<edm::SortedCollection<CastorRecHit> > refvector;
339  CastorClusters->push_back(reco::CastorCluster(castormin[0][j],pt2,castormin[1][j],castormin[2][j],fem,depth_mean,fhot_mean,refvector));
340  }
341  }
342  */
343 
344  iEvent.put(CastorClusters);
345 
346 }
347 
349  double result = -1.;
350  TRandom3 r2(0);
351  double mu_noise = 0.053; // GeV (from 1.214 ADC) per channel
352  double sigma_noise = 0.027; // GeV (from 0.6168 ADC) per channel
353 
354  while (result < 0.) {
355  result = r2.Gaus(mu_noise,sigma_noise);
356  }
357 
358  return result;
359 }
360 
361 //define this as a plug-in
int i
Definition: DBlmapReader.cc:9
virtual double energy() const =0
energy
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual void produce(edm::Event &, const edm::EventSetup &) override
tuple result
Definition: mps_fire.py:84
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
T sqrt(T t)
Definition: SSEVec.h:18
CastorFastClusterProducer(const edm::ParameterSet &)
std::vector< reco::CastorCluster > CastorClusterCollection
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:418
virtual int pdgId() const =0
PDG identifier.
static const double tmax[3]
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:69
ROOT::Math::RhoEtaPhiPoint ClusterPoint
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
virtual double phi() const =0
momentum azimuthal angle
virtual double eta() const =0
momentum pseudorapidity