CMS 3D CMS Logo

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 // 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
31 
34 
36 
38 
39 // Castorobject includes
43 
44 // genCandidate particle includes
46 
48 
49 //
50 // constructors and destructor
51 //
53  : tokGenPart_(consumes<reco::GenParticleCollection>(edm::InputTag{"genParticles"})) {
54  //register your products
55  produces<CastorClusterCollection>();
56 
57  //now do what ever other initialization is needed
58 }
59 
61  // do anything here that needs to be done at desctruction time
62  // (e.g. close files, deallocate resources etc.)
63 }
64 
65 //
66 // member functions
67 //
68 
69 // ------------ method called to produce the data ------------
71  using namespace edm;
72  using namespace reco;
73  using namespace std;
74  using namespace TMath;
75 
76  //
77  // Make CastorCluster objects
78  //
79 
80  //cout << "entering event" << endl;
81 
83 
84  // make pointer to towers that will be made
85  unique_ptr<CastorClusterCollection> CastorClusters(new CastorClusterCollection);
86 
87  /*
88  // declare castor array
89  double castorplus [4][16]; // (0,x): Energies - (1,x): emEnergies - (2,x): hadEnergies - (3,x): phi position - eta = 5.9
90  double castormin [4][16]; // (0,x): Energies - (1,x): emEnergies - (2,x): hadEnergies - (3,x): phi position - eta = -5.9
91  // set phi values of array sectors and everything else to zero
92  for (int j = 0; j < 16; j++) {
93  castorplus[3][j] = -2.94524 + j*0.3927;
94  castormin[3][j] = -2.94524 + j*0.3927;
95  castorplus[0][j] = 0.;
96  castormin[0][j] = 0.;
97  castorplus[1][j] = 0.;
98  castormin[1][j] = 0.;
99  castorplus[2][j] = 0.;
100  castormin[2][j] = 0.;
101  //castorplus[4][j] = 0.;
102  //castormin[4][j] = 0.;
103  }
104 
105  // declare properties vectors
106  vector<double> depthplus[16];
107  vector<double> depthmin[16];
108  vector<double> fhotplus [16];
109  vector<double> fhotmin [16];
110  vector<double> energyplus [16];
111  vector<double> energymin [16];
112 
113  for (int i=0;i<16;i++) {
114  depthplus[i].clear();
115  depthmin[i].clear();
116  fhotplus[i].clear();
117  fhotmin[i].clear();
118  energyplus[i].clear();
119  energymin[i].clear();
120  }
121  */
122 
123  //cout << "declared everything" << endl;
124 
125  // start particle loop
126  for (size_t i = 0; i < genParticles->size(); ++i) {
127  const Candidate& p = (*genParticles)[i];
128 
129  // select particles in castor
130  if (fabs(p.eta()) > 5.2 && fabs(p.eta()) < 6.6) {
131  //cout << "found particle in castor, start calculating" << endl;
132 
133  // declare energies
134  double gaus_E = -1.;
135  double emEnergy = 0.;
136  double hadEnergy = 0.;
137  //double fhot = 0.;
138  //double depth = 0.;
139 
140  // add energies - em: if particle is e- or gamma
141  if (p.pdgId() == 11 || p.pdgId() == 22) {
142  while (gaus_E < 0.) {
143  // apply energy smearing with gaussian random generator
144  TRandom3 r(0);
145  // use sigma/E parametrization for the EM sections of CASTOR TB 2007 results
146  double sigma = p.energy() * (sqrt(pow(0.044, 2) + pow(0.513 / sqrt(p.energy()), 2)));
147  gaus_E = r.Gaus(p.energy(), sigma);
148  }
149 
150  // calculate electromagnetic electron/photon energy leakage
151  double tmax;
152  double a;
153  double cte;
154  if (p.pdgId() == 11) {
155  cte = -0.5;
156  } else {
157  cte = 0.5;
158  }
159  tmax = 1.0 * (log(gaus_E / 0.0015) + cte);
160  a = tmax * 0.5 + 1;
161  double leakage;
162  double x = 0.5 * 19.38;
163  leakage = gaus_E - gaus_E * Gamma(a, x);
164 
165  // add emEnergy
166  emEnergy = gaus_E - leakage;
167  // add hadEnergy leakage
168  hadEnergy = leakage;
169 
170  // make cluster
172  if (p.eta() > 0.) {
173  ClusterPoint temp(88.5, 5.9, p.phi());
174  pt1 = temp;
175  }
176  if (p.eta() < 0.) {
177  ClusterPoint temp(88.5, -5.9, p.phi());
178  pt1 = temp;
179  }
180  Point pt2(pt1);
181  CastorTowerRefVector refvector;
182  CastorClusters->push_back(
183  reco::CastorCluster(gaus_E, pt2, emEnergy, hadEnergy, emEnergy / gaus_E, 0., 0., 0., 0., refvector));
184 
185  } else {
186  while (gaus_E < 0.) {
187  // apply energy smearing with gaussian random generator
188  TRandom3 r(0);
189  // use sigma/E parametrization for the HAD sections of CASTOR TB 2007 results
190  double sigma = p.energy() * (sqrt(pow(0.121, 2) + pow(1.684 / sqrt(p.energy()), 2)));
191  gaus_E = r.Gaus(p.energy(), sigma);
192  }
193 
194  // add hadEnergy
195  hadEnergy = gaus_E;
196 
197  // make cluster
199  if (p.eta() > 0.) {
200  ClusterPoint temp(88.5, 5.9, p.phi());
201  pt1 = temp;
202  }
203  if (p.eta() < 0.) {
204  ClusterPoint temp(88.5, -5.9, p.phi());
205  pt1 = temp;
206  }
207  Point pt2(pt1);
208  CastorTowerRefVector refvector;
209  CastorClusters->push_back(reco::CastorCluster(gaus_E, pt2, 0., hadEnergy, 0., 0., 0., 0., 0., refvector));
210  }
211 
212  /*
213  // make tower
214 
215  // set sector
216  int sector = -1;
217  for (int j = 0; j < 16; j++) {
218  double a = -M_PI + j*0.3927;
219  double b = -M_PI + (j+1)*0.3927;
220  if ( (p.phi() > a) && (p.phi() < b)) {
221  sector = j;
222  }
223  }
224 
225  // set eta
226  if (p.eta() > 0) {
227  castorplus[0][sector] = castorplus[0][sector] + gaus_E;
228  castorplus[1][sector] = castorplus[1][sector] + emEnergy;
229  castorplus[2][sector] = castorplus[2][sector] + hadEnergy;
230 
231  depthplus[sector].push_back(depth);
232  fhotplus[sector].push_back(fhot);
233  energyplus[sector].push_back(gaus_E);
234  //cout << "filled vectors" << endl;
235  //cout << "energyplus size = " << energyplus[sector].size() << endl;
236  //cout << "depthplus size = " << depthplus[sector].size() << endl;
237  //cout << "fhotplus size = " << fhotplus[sector].size() << endl;
238 
239  } else {
240  castormin[0][sector] = castormin[0][sector] + gaus_E;
241  castormin[1][sector] = castormin[1][sector] + emEnergy;
242  castormin[2][sector] = castormin[2][sector] + hadEnergy;
243 
244 
245  depthmin[sector].push_back(depth);
246  fhotmin[sector].push_back(fhot);
247  energymin[sector].push_back(gaus_E);
248  //cout << "filled vectors" << endl;
249 
250  }
251  */
252  }
253  }
254 
255  /*
256  // substract pedestals/noise
257  for (int j = 0; j < 16; j++) {
258  double hadnoise = 0.;
259  for (int i=0;i<12;i++) {
260  hadnoise = hadnoise + make_noise();
261  }
262  castorplus[0][j] = castorplus[0][j] - hadnoise - make_noise() - make_noise();
263  castormin[0][j] = castormin[0][j] - hadnoise - make_noise() - make_noise();
264  castorplus[1][j] = castorplus[1][j] - make_noise() - make_noise();
265  castormin[1][j] = castormin[1][j] - make_noise() - make_noise();
266  castorplus[2][j] = castorplus[2][j] - hadnoise;
267  castormin[2][j] = castormin[2][j] - hadnoise;
268 
269  // set possible negative values to zero
270  if (castorplus[0][j] < 0.) castorplus[0][j] = 0.;
271  if (castormin[0][j] < 0.) castormin[0][j] = 0.;
272  if (castorplus[1][j] < 0.) castorplus[1][j] = 0.;
273  if (castormin[1][j] < 0.) castormin[1][j] = 0.;
274  if (castorplus[2][j] < 0.) castorplus[2][j] = 0.;
275  if (castormin[2][j] < 0.) castormin[2][j] = 0.;
276  }
277  */
278 
279  /*
280  // store towers from castor arrays
281  // eta = 5.9
282  for (int j=0;j<16;j++) {
283  if (castorplus[0][j] > 0.) {
284 
285  double fem = 0.;
286  fem = castorplus[1][j]/castorplus[0][j];
287  ClusterPoint pt1(88.5,5.9,castorplus[3][j]);
288  Point pt2(pt1);
289 
290  // parametrize depth and fhot from full sim
291  // get fit parameters from energy
292  // get random number according to distribution with fit parameters
293  double depth_mean = 0.;
294  double fhot_mean = 0.;
295  double sum_energy = 0.;
296 
297  //cout << "energyplus size = " << energyplus[j].size()<< endl;
298  for (size_t p = 0; p<energyplus[j].size();p++) {
299  depth_mean = depth_mean + depthplus[j][p]*energyplus[j][p];
300  fhot_mean = fhot_mean + fhotplus[j][p]*energyplus[j][p];
301  sum_energy = sum_energy + energyplus[j][p];
302  }
303  depth_mean = depth_mean/sum_energy;
304  fhot_mean = fhot_mean/sum_energy;
305  cout << "computed depth/fhot" << endl;
306 
307 
308  edm::RefVector<edm::SortedCollection<CastorRecHit> > refvector;
309  CastorClusters->push_back(reco::CastorCluster(castorplus[0][j],pt2,castorplus[1][j],castorplus[2][j],fem,depth_mean,fhot_mean,refvector));
310  }
311  }
312  // eta = -5.9
313  for (int j=0;j<16;j++) {
314  if (castormin[0][j] > 0.) {
315  double fem = 0.;
316  fem = castormin[1][j]/castormin[0][j];
317  ClusterPoint pt1(88.5,-5.9,castormin[3][j]);
318  Point pt2(pt1);
319 
320  // parametrize depth and fhot from full sim
321  // get fit parameters from energy
322  // get random number according to distribution with fit parameters
323  double depth_mean = 0.;
324  double fhot_mean = 0.;
325  double sum_energy = 0.;
326 
327 
328  for (size_t p = 0; p<energymin[j].size();p++) {
329  depth_mean = depth_mean + depthmin[j][p]*energymin[j][p];
330  fhot_mean = fhot_mean + fhotmin[j][p]*energymin[j][p];
331  sum_energy = sum_energy + energymin[j][p];
332  }
333  depth_mean = depth_mean/sum_energy;
334  fhot_mean = fhot_mean/sum_energy;
335 
336 
337  edm::RefVector<edm::SortedCollection<CastorRecHit> > refvector;
338  CastorClusters->push_back(reco::CastorCluster(castormin[0][j],pt2,castormin[1][j],castormin[2][j],fem,depth_mean,fhot_mean,refvector));
339  }
340  }
341  */
342 
343  iEvent.put(std::move(CastorClusters));
344 }
345 
347  double result = -1.;
348  TRandom3 r2(0);
349  double mu_noise = 0.053; // GeV (from 1.214 ADC) per channel
350  double sigma_noise = 0.027; // GeV (from 0.6168 ADC) per channel
351 
352  while (result < 0.) {
353  result = r2.Gaus(mu_noise, sigma_noise);
354  }
355 
356  return result;
357 }
358 
359 //define this as a plug-in
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
void produce(edm::Event &, const edm::EventSetup &) override
const edm::EDGetTokenT< reco::GenParticleCollection > tokGenPart_
int iEvent
Definition: GenABIO.cc:224
T sqrt(T t)
Definition: SSEVec.h:19
CastorFastClusterProducer(const edm::ParameterSet &)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::vector< reco::CastorCluster > CastorClusterCollection
static const double tmax[3]
fixed size matrix
HLT enums.
Structure Point Contains parameters of Gaussian fits to DMRs.
double a
Definition: hdecay.h:121
void push_back(value_type const &ref)
Add a Ref<C, T> to the RefVector.
Definition: RefVector.h:67
ROOT::Math::RhoEtaPhiPoint ClusterPoint
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
def move(src, dest)
Definition: eostools.py:511