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, const RandomEngine *random)
 
void init (const edm::EventSetup &es)
 
void loadEcalPreshowerRecHits (edm::Event &iEvent, ESRecHitCollection &esRecHits)
 
 ~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, bool signal=true)
 
void loadPCaloHits (const edm::Event &iEvent)
 
void noisify ()
 
void noisifySignal (std::map< uint32_t, std::pair< float, bool > > &theMap)
 
void noisifySubdet (std::map< uint32_t, std::pair< float, bool > > &theMap, const std::vector< uint32_t > &thecells, unsigned ncells)
 

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_
 
const RandomEnginerandom_
 
double threshold_
 

Detailed Description

Definition at line 21 of file EcalPreshowerRecHitsMaker.h.

Constructor & Destructor Documentation

EcalPreshowerRecHitsMaker::EcalPreshowerRecHitsMaker ( edm::ParameterSet const &  p,
const RandomEngine random 
)

Definition at line 19 of file EcalPreshowerRecHitsMaker.cc.

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

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

Definition at line 43 of file EcalPreshowerRecHitsMaker.cc.

References initialized_, and myGaussianTailGenerator_.

44 {
45  initialized_=false;
47 }
const GaussianTail * myGaussianTailGenerator_

Member Function Documentation

void EcalPreshowerRecHitsMaker::clean ( )
private

Definition at line 49 of file EcalPreshowerRecHitsMaker.cc.

References ecalsRecHits_.

Referenced by loadPCaloHits().

50 {
51 
52  ecalsRecHits_.clear();
53 }
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,
bool  signal = true 
)
private

Definition at line 169 of file EcalPreshowerRecHitsMaker.cc.

References relval_parameters_module::energy, RandomEngine::gaussShoot(), errorMatrix2Lands_multiChannel::id, noise_, and random_.

Referenced by loadPCaloHits().

170 {
171  // The signal hits are singletons (no need to look into a map)
172  if(signal)
173  {
174  // a new hit is created
175  // we can give a hint for the insert
176  // Add the noise at this point. We are sure that it won't be added several times
178  std::pair<float,bool> hit(energy,false);
179  // if it is signal, it is already ordered, so we can give a hint for the
180  // insert
181  if(signal)
182  myHits.insert(myHits.end(),std::pair<uint32_t,std::pair<float,bool> >(id,hit));
183  }
184  else // In this case,there is a risk of duplication. Need to look into the map
185  {
186  std::map<uint32_t,std::pair<float,bool> >::iterator itcheck=myHits.find(id);
187  if(itcheck==myHits.end())
188  {
190  std::pair<float,bool> hit(energy,false);
191  myHits.insert(std::pair<uint32_t,std::pair<float,bool> >(id,hit));
192  }
193  else
194  {
195  itcheck->second.first += energy;
196  }
197  }
198 }
double gaussShoot(double mean=0.0, double sigma=1.0) const
Definition: RandomEngine.h:37
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 
)

Definition at line 56 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().

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

Definition at line 81 of file EcalPreshowerRecHitsMaker.cc.

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

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_,it.getTrigger());
95  // Fill(it->id(),it->energy(),ecalsRecHits_);
96  }
97 }
std::map< uint32_t, std::pair< float, bool > > ecalsRecHits_
void Fill(uint32_t id, float energy, std::map< uint32_t, std::pair< float, bool > > &myHits, bool signal=true)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
T const * product() const
Definition: Handle.h:74
void EcalPreshowerRecHitsMaker::noisify ( )
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_
void noisifySubdet(std::map< uint32_t, std::pair< float, bool > > &theMap, const std::vector< uint32_t > &thecells, unsigned ncells)
void EcalPreshowerRecHitsMaker::noisifySignal ( std::map< uint32_t, std::pair< float, bool > > &  theMap)
private
void EcalPreshowerRecHitsMaker::noisifySubdet ( std::map< uint32_t, std::pair< float, bool > > &  theMap,
const std::vector< uint32_t > &  thecells,
unsigned  ncells 
)
private

Definition at line 139 of file EcalPreshowerRecHitsMaker.cc.

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

Referenced by noisify().

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

Member Data Documentation

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

Definition at line 55 of file EcalPreshowerRecHitsMaker.h.

Referenced by createVectorsOfCells(), and noisify().

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

Definition at line 48 of file EcalPreshowerRecHitsMaker.h.

Referenced by EcalPreshowerRecHitsMaker(), and loadPCaloHits().

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

Definition at line 53 of file EcalPreshowerRecHitsMaker.h.

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

double EcalPreshowerRecHitsMaker::noise_
private

Definition at line 50 of file EcalPreshowerRecHitsMaker.h.

Referenced by EcalPreshowerRecHitsMaker(), and Fill().

double EcalPreshowerRecHitsMaker::preshowerHotFraction_
private

Definition at line 51 of file EcalPreshowerRecHitsMaker.h.

Referenced by EcalPreshowerRecHitsMaker(), and noisifySubdet().

const RandomEngine* EcalPreshowerRecHitsMaker::random_
private

Definition at line 56 of file EcalPreshowerRecHitsMaker.h.

Referenced by EcalPreshowerRecHitsMaker(), Fill(), and noisifySubdet().

double EcalPreshowerRecHitsMaker::threshold_
private