CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
EcalPreshowerRecHitsMaker Class Reference

#include <EcalPreshowerRecHitsMaker.h>

Public Member Functions

 EcalPreshowerRecHitsMaker (edm::ParameterSet const &p)
 
void init (const edm::EventSetup &es)
 
void loadEcalPreshowerRecHits (edm::Event &iEvent, ESRecHitCollection &esRecHits, RandomEngineAndDistribution const *)
 
 ~EcalPreshowerRecHitsMaker ()
 

Private Member Functions

void clean ()
 
unsigned createVectorsOfCells (const edm::EventSetup &es)
 
void Fill (uint32_t id, float energy, std::map< uint32_t, std::pair< float, bool > > &myHits, RandomEngineAndDistribution const *, bool signal=true)
 
void loadPCaloHits (const edm::Event &iEvent, RandomEngineAndDistribution const *)
 
void noisify (RandomEngineAndDistribution const *)
 
void noisifySignal (std::map< uint32_t, std::pair< float, bool > > &theMap, RandomEngineAndDistribution const *)
 
void noisifySubdet (std::map< uint32_t, std::pair< float, bool > > &theMap, const std::vector< uint32_t > &thecells, unsigned ncells, RandomEngineAndDistribution const *)
 

Private Attributes

std::map< uint32_t, std::pair
< float, bool > > 
ecalsRecHits_
 
std::vector< uint32_t > escells_
 
bool initialized_
 
edm::InputTag inputCol_
 
const GaussianTailmyGaussianTailGenerator_
 
unsigned ncells_
 
double noise_
 
double preshowerHotFraction_
 
double threshold_
 

Detailed Description

Definition at line 21 of file EcalPreshowerRecHitsMaker.h.

Constructor & Destructor Documentation

EcalPreshowerRecHitsMaker::EcalPreshowerRecHitsMaker ( edm::ParameterSet const &  p)

Definition at line 19 of file EcalPreshowerRecHitsMaker.cc.

References edm::ParameterSet::getParameter(), initialized_, inputCol_, myGaussianTailGenerator_, noise_, preshowerHotFraction_, mathSSE::sqrt(), and threshold_.

21  :
23 {
24  edm::ParameterSet RecHitsParameters
25  = p.getParameter<edm::ParameterSet>("ECALPreshower");
26  noise_ = RecHitsParameters.getParameter<double>("Noise");
27  threshold_ = RecHitsParameters.getParameter<double>("Threshold");
28  inputCol_=RecHitsParameters.getParameter<edm::InputTag>("MixedSimHits");
29 
30  initialized_=false;
31 
32  Genfun::Erf myErf;
33  if( noise_>0. ) {
34  preshowerHotFraction_ = 0.5-0.5*myErf(threshold_/noise_/sqrt(2.));
35  myGaussianTailGenerator_ = new GaussianTail(noise_, threshold_);
36  } else {
38  }
39 }
T getParameter(std::string const &) const
const GaussianTail * myGaussianTailGenerator_
T sqrt(T t)
Definition: SSEVec.h:48
EcalPreshowerRecHitsMaker::~EcalPreshowerRecHitsMaker ( )

Definition at line 41 of file EcalPreshowerRecHitsMaker.cc.

References initialized_, and myGaussianTailGenerator_.

42 {
43  initialized_=false;
45 }
const GaussianTail * myGaussianTailGenerator_

Member Function Documentation

void EcalPreshowerRecHitsMaker::clean ( )
private

Definition at line 47 of file EcalPreshowerRecHitsMaker.cc.

References ecalsRecHits_.

Referenced by loadPCaloHits().

48 {
49 
50  ecalsRecHits_.clear();
51 }
std::map< uint32_t, std::pair< float, bool > > ecalsRecHits_
unsigned EcalPreshowerRecHitsMaker::createVectorsOfCells ( const edm::EventSetup es)
private

Definition at line 107 of file EcalPreshowerRecHitsMaker.cc.

References DetId::Ecal, EcalPreshower, escells_, relativeConstraints::geom, edm::EventSetup::get(), CaloSubdetectorGeometry::getValidDetIds(), i, and pileupDistInMC::total.

Referenced by init().

108 {
110  es.get<CaloGeometryRecord>().get(pG);
111  unsigned total=0;
112 
113  escells_.reserve(137728);
114 
115  const CaloSubdetectorGeometry* geom=pG->getSubdetectorGeometry(DetId::Ecal,EcalPreshower);
116  if(geom==0) return 0;
117  const std::vector<DetId>& ids(geom->getValidDetIds(DetId::Ecal,EcalPreshower));
118  for (std::vector<DetId>::const_iterator i=ids.begin(); i!=ids.end(); i++)
119  {
120  escells_.push_back(i->rawId());
121  ++total;
122  }
123  return escells_.size();
124 }
int i
Definition: DBlmapReader.cc:9
std::vector< uint32_t > escells_
virtual const std::vector< DetId > & getValidDetIds(DetId::Detector det=DetId::Detector(0), int subdet=0) const
Get a list of valid detector ids (for the given subdetector)
const T & get() const
Definition: EventSetup.h:55
void EcalPreshowerRecHitsMaker::Fill ( uint32_t  id,
float  energy,
std::map< uint32_t, std::pair< float, bool > > &  myHits,
RandomEngineAndDistribution const *  random,
bool  signal = true 
)
private

Definition at line 170 of file EcalPreshowerRecHitsMaker.cc.

References relval_parameters_module::energy, RandomEngineAndDistribution::gaussShoot(), and noise_.

Referenced by loadPCaloHits().

172 {
173  // The signal hits are singletons (no need to look into a map)
174  if(signal)
175  {
176  // a new hit is created
177  // we can give a hint for the insert
178  // Add the noise at this point. We are sure that it won't be added several times
179  energy += random->gaussShoot(0.,noise_);
180  std::pair<float,bool> hit(energy,false);
181  // if it is signal, it is already ordered, so we can give a hint for the
182  // insert
183  if(signal)
184  myHits.insert(myHits.end(),std::pair<uint32_t,std::pair<float,bool> >(id,hit));
185  }
186  else // In this case,there is a risk of duplication. Need to look into the map
187  {
188  std::map<uint32_t,std::pair<float,bool> >::iterator itcheck=myHits.find(id);
189  if(itcheck==myHits.end())
190  {
191  energy += random->gaussShoot(0.,noise_);
192  std::pair<float,bool> hit(energy,false);
193  myHits.insert(std::pair<uint32_t,std::pair<float,bool> >(id,hit));
194  }
195  else
196  {
197  itcheck->second.first += energy;
198  }
199  }
200 }
TRandom random
Definition: MVATrainer.cc:138
void EcalPreshowerRecHitsMaker::init ( const edm::EventSetup es)

Definition at line 99 of file EcalPreshowerRecHitsMaker.cc.

References createVectorsOfCells(), initialized_, and ncells_.

Referenced by CaloRecHitsProducer::beginRun().

100 {
101  if(initialized_) return;
103  edm::LogInfo("CaloRecHitsProducer") << "Total number of cells in Preshower " << ncells_ << std::endl;
104  initialized_=true;
105 }
unsigned createVectorsOfCells(const edm::EventSetup &es)
void EcalPreshowerRecHitsMaker::loadEcalPreshowerRecHits ( edm::Event iEvent,
ESRecHitCollection esRecHits,
RandomEngineAndDistribution const *  random 
)

Definition at line 54 of file EcalPreshowerRecHitsMaker.cc.

References cond::rpcobgas::detid, ecalsRecHits_, loadPCaloHits(), myGaussianTailGenerator_, ncells_, noisify(), edm::SortedCollection< T, SORT >::push_back(), and threshold_.

Referenced by CaloRecHitsProducer::produce().

56 {
57  // if no preshower, do nothing
58 
59  if(ncells_==0) return;
60  loadPCaloHits(iEvent, random);
62 
63  std::map<uint32_t,std::pair<float,bool> >::const_iterator
64  it=ecalsRecHits_.begin();
65  std::map<uint32_t,std::pair<float,bool> >::const_iterator
66  itend=ecalsRecHits_.end();
67 
68  for(;it!=itend;++it)
69  {
70  // check if the hit has been killed
71  if(it->second.second) continue;
72  // check if it is above the threshold
73  if(it->second.first<threshold_) continue;
74  ESDetId detid(it->first);
75  // std::cout << detid << " " << it->second.first << std::endl;
76  ecalHits.push_back(EcalRecHit(detid,it->second.first,0.));
77  }
78 }
std::map< uint32_t, std::pair< float, bool > > ecalsRecHits_
TRandom random
Definition: MVATrainer.cc:138
const GaussianTail * myGaussianTailGenerator_
void loadPCaloHits(const edm::Event &iEvent, RandomEngineAndDistribution const *)
void noisify(RandomEngineAndDistribution const *)
void EcalPreshowerRecHitsMaker::loadPCaloHits ( const edm::Event iEvent,
RandomEngineAndDistribution const *  random 
)
private

Definition at line 80 of file EcalPreshowerRecHitsMaker.cc.

References clean(), ecalsRecHits_, Fill(), edm::Event::getByLabel(), inputCol_, edm::Handle< T >::product(), and random.

Referenced by loadEcalPreshowerRecHits().

82 {
83 
84  clean();
85 
87  iEvent.getByLabel(inputCol_,cf);
88  std::auto_ptr<MixCollection<PCaloHit> > colcalo(new MixCollection<PCaloHit>(cf.product(),std::pair<int,int>(0,0) ));
89 
90  MixCollection<PCaloHit>::iterator it=colcalo->begin();
91  MixCollection<PCaloHit>::iterator itend=colcalo->end();
92  for(;it!=itend;++it)
93  {
94  Fill(it->id(),it->energy(),ecalsRecHits_, random, it.getTrigger());
95  // Fill(it->id(),it->energy(),ecalsRecHits_);
96  }
97 }
std::map< uint32_t, std::pair< float, bool > > ecalsRecHits_
TRandom random
Definition: MVATrainer.cc:138
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:402
void Fill(uint32_t id, float energy, std::map< uint32_t, std::pair< float, bool > > &myHits, RandomEngineAndDistribution const *, bool signal=true)
T const * product() const
Definition: Handle.h:81
void EcalPreshowerRecHitsMaker::noisify ( RandomEngineAndDistribution const *  random)
private

Definition at line 126 of file EcalPreshowerRecHitsMaker.cc.

References ecalsRecHits_, escells_, ncells_, and noisifySubdet().

Referenced by loadEcalPreshowerRecHits().

127 {
128  if(ecalsRecHits_.size()<ncells_)
129  {
130  // Not needed anymore, the noise is added when loading the PCaloHits
131  // noisifySignal(ecalsRecHits_);
133  }
134  else
135  edm::LogWarning("CaloRecHitsProducer") << "All Preshower cells on ! " << std::endl;
136 }
std::vector< uint32_t > escells_
std::map< uint32_t, std::pair< float, bool > > ecalsRecHits_
TRandom random
Definition: MVATrainer.cc:138
void noisifySubdet(std::map< uint32_t, std::pair< float, bool > > &theMap, const std::vector< uint32_t > &thecells, unsigned ncells, RandomEngineAndDistribution const *)
void EcalPreshowerRecHitsMaker::noisifySignal ( std::map< uint32_t, std::pair< float, bool > > &  theMap,
RandomEngineAndDistribution const *   
)
private
void EcalPreshowerRecHitsMaker::noisifySubdet ( std::map< uint32_t, std::pair< float, bool > > &  theMap,
const std::vector< uint32_t > &  thecells,
unsigned  ncells,
RandomEngineAndDistribution const *  random 
)
private

Definition at line 139 of file EcalPreshowerRecHitsMaker.cc.

References RandomEngineAndDistribution::flatShoot(), timingPdfMaker::mean, myGaussianTailGenerator_, RandomEngineAndDistribution::poissonShoot(), preshowerHotFraction_, and GaussianTail::shoot().

Referenced by noisify().

141 {
142  // noise won't be injected in cells that contain signal
143  double mean = (double)(ncells-theMap.size())*preshowerHotFraction_;
144  unsigned nps = random->poissonShoot(mean);
145 
146  unsigned ncell=0;
147  unsigned cellindex=0;
148  uint32_t cellnumber=0;
149  std::map<uint32_t,std::pair<float,bool> >::const_iterator itcheck;
150 
151  while(ncell < nps)
152  {
153  cellindex = (unsigned)(random->flatShoot()*ncells);
154  cellnumber = thecells[cellindex];
155  itcheck=theMap.find(cellnumber);
156  if(itcheck==theMap.end()) // inject only in empty cells
157  {
158  std::pair <float,bool> noisehit(myGaussianTailGenerator_->shoot(random),
159  false);
160  theMap.insert(std::pair<uint32_t,std::pair<float,bool> >
161  (cellnumber,noisehit));
162  ++ncell;
163  }
164  }
165  // edm::LogInfo("CaloRecHitsProducer") << "CaloRecHitsProducer : added noise in "<< ncell << " HCAL cells " << std::endl;
166 }
TRandom random
Definition: MVATrainer.cc:138
double shoot(RandomEngineAndDistribution const *) const
Definition: GaussianTail.cc:18
const GaussianTail * myGaussianTailGenerator_

Member Data Documentation

std::map<uint32_t,std::pair<float,bool> > EcalPreshowerRecHitsMaker::ecalsRecHits_
private
std::vector<uint32_t> EcalPreshowerRecHitsMaker::escells_
private

Definition at line 56 of file EcalPreshowerRecHitsMaker.h.

Referenced by createVectorsOfCells(), and noisify().

bool EcalPreshowerRecHitsMaker::initialized_
private
edm::InputTag EcalPreshowerRecHitsMaker::inputCol_
private

Definition at line 49 of file EcalPreshowerRecHitsMaker.h.

Referenced by EcalPreshowerRecHitsMaker(), and loadPCaloHits().

const GaussianTail* EcalPreshowerRecHitsMaker::myGaussianTailGenerator_
private
unsigned EcalPreshowerRecHitsMaker::ncells_
private

Definition at line 54 of file EcalPreshowerRecHitsMaker.h.

Referenced by init(), loadEcalPreshowerRecHits(), and noisify().

double EcalPreshowerRecHitsMaker::noise_
private

Definition at line 51 of file EcalPreshowerRecHitsMaker.h.

Referenced by EcalPreshowerRecHitsMaker(), and Fill().

double EcalPreshowerRecHitsMaker::preshowerHotFraction_
private

Definition at line 52 of file EcalPreshowerRecHitsMaker.h.

Referenced by EcalPreshowerRecHitsMaker(), and noisifySubdet().

double EcalPreshowerRecHitsMaker::threshold_
private