CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

EcalBarrelRecHitsMaker Class Reference

#include <EcalBarrelRecHitsMaker.h>

List of all members.

Public Member Functions

 EcalBarrelRecHitsMaker (edm::ParameterSet const &p, const RandomEngine *)
void init (const edm::EventSetup &es, bool dodigis, bool doMiscalib)
void loadEcalBarrelRecHits (edm::Event &iEvent, EBRecHitCollection &ecalHits, EBDigiCollection &ecaldigis)
 ~EcalBarrelRecHitsMaker ()

Private Member Functions

void clean ()
void geVtoGainAdc (float e, unsigned &gain, unsigned &adc) const
bool isHighInterest (int tthi)
void loadPCaloHits (const edm::Event &iEvent)
bool noisifyTriggerTower (unsigned tthi)
void noisifyTriggerTowers ()
void randomNoisifier ()

Private Attributes

float adcToGeV_
std::vector< int > applyZSCells_
std::vector< uint32_t > barrelRawId_
double calibfactor_
std::vector< std::vector< int > > crystalsinTT_
bool doCustomHighNoise_
bool doDigis_
bool doMisCalib_
double EBHotFraction_
const
EcalTrigTowerConstituentsMap
eTTmap_
float geVToAdc1_
float geVToAdc2_
float geVToAdc3_
std::vector< double > highNoiseParameters_
const std::vector< float > * ICMC_
edm::InputTag inputCol_
unsigned maxAdc_
double meanNoiseSigmaEt_
unsigned minAdc_
const GaussianTailmyGaussianTailGenerator_
std::vector< std::vector< int > > neighboringTTs_
double noise_
double noiseADC_
std::vector< float > noisesigma_
bool noisified_
const RandomEnginerandom_
double refactor_
double refactor_mean_
float sat_
std::vector< float > sinTheta_
int SREtaSize_
int SRPhiSize_
float SRThreshold_
float t1_
float t2_
std::vector< float > theCalibConstants_
std::vector< float > theCalorimeterHits_
std::vector< int > theFiredCells_
std::vector< unsigned > theFiredTTs_
std::vector< EcalTrigTowerDetIdtheTTDetIds_
std::vector< int > theTTofHighInterest_
double threshold_
std::vector< bool > treatedTTs_
std::vector< int > TTHighInterest_
std::vector< float > TTTEnergy_

Detailed Description

Definition at line 20 of file EcalBarrelRecHitsMaker.h.


Constructor & Destructor Documentation

EcalBarrelRecHitsMaker::EcalBarrelRecHitsMaker ( edm::ParameterSet const &  p,
const RandomEngine myrandom 
)

Definition at line 31 of file EcalBarrelRecHitsMaker.cc.

References applyZSCells_, alignmentValidation::c1, calibfactor_, crystalsinTT_, doCustomHighNoise_, EBHotFraction_, edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), highNoiseParameters_, inputCol_, EBDetId::kSizeForDenseIndexing, myGaussianTailGenerator_, neighboringTTs_, noise_, noiseADC_, noisified_, random_, refactor_, refactor_mean_, sinTheta_, mathSSE::sqrt(), SREtaSize_, SRPhiSize_, SRThreshold_, theCalorimeterHits_, theTTDetIds_, threshold_, treatedTTs_, TTHighInterest_, and TTTEnergy_.

  : random_(myrandom)
{
  edm::ParameterSet RecHitsParameters=p.getParameter<edm::ParameterSet>("ECALBarrel");
  inputCol_=RecHitsParameters.getParameter<edm::InputTag>("MixedSimHits");
  noise_ = RecHitsParameters.getParameter<double>("Noise");
  threshold_ = RecHitsParameters.getParameter<double>("Threshold");
  refactor_ = RecHitsParameters.getParameter<double> ("Refactor");
  refactor_mean_ = RecHitsParameters.getParameter<double> ("Refactor_mean");
  noiseADC_ = RecHitsParameters.getParameter<double>("NoiseADC");
  highNoiseParameters_ = RecHitsParameters.getParameter<std::vector<double> > ("HighNoiseParameters");
  SRThreshold_ = RecHitsParameters.getParameter<double> ("SRThreshold");
  SREtaSize_ = RecHitsParameters.getUntrackedParameter<int> ("SREtaSize",1);
  SRPhiSize_ = RecHitsParameters.getUntrackedParameter<int> ("SRPhiSize",1);
  applyZSCells_.resize(EBDetId::kSizeForDenseIndexing,true);
  theCalorimeterHits_.resize(EBDetId::kSizeForDenseIndexing,0.);
  crystalsinTT_.resize(2448);
  TTTEnergy_.resize(2448,0.);
  TTHighInterest_.resize(2448,0);
  treatedTTs_.resize(2448,false);
  theTTDetIds_.resize(2448);
  neighboringTTs_.resize(2448);
  sinTheta_.resize(86,0.); 
  doCustomHighNoise_=false;
  // Initialize the Gaussian tail generator
  // Two options : noise is set by the user (to a positive value). In this case, this value is taken
  // or the user chose to use the noise from DB. In this case, the noise is flat in pT and not in energy
  // but the threshold is in energy and not in pT.
  doCustomHighNoise_=highNoiseParameters_.size()>=3;
  Genfun::Erf myErf; 
  if(  noise_>0. ) {
    EBHotFraction_ = 0.5-0.5*myErf(threshold_/noise_/sqrt(2.));
    myGaussianTailGenerator_ = new GaussianTail(random_, noise_, threshold_);
    edm::LogInfo("CaloRecHitsProducer") <<"Uniform noise simulation selected in the barrel";
  } else if (noise_==-1 && doCustomHighNoise_)
    {
      if(highNoiseParameters_.size()==4)
        EBHotFraction_ = 0.5-0.5*myErf(highNoiseParameters_[3]/highNoiseParameters_[2]/sqrt(2.));
      if(highNoiseParameters_.size()==3)
        EBHotFraction_ = highNoiseParameters_[2] ;
      edm::LogInfo("CaloRecHitsProducer")<< " The gaussian model for high noise fluctuation cells after ZS is selected (best model), hot fraction " << EBHotFraction_  << std::endl;
    }
  
  noisified_ = (noise_==0.);
  edm::ParameterSet CalibParameters = RecHitsParameters.getParameter<edm::ParameterSet>("ContFact"); 
  double c1=CalibParameters.getParameter<double>("EBs25notContainment"); 
  calibfactor_=1./c1;


}
EcalBarrelRecHitsMaker::~EcalBarrelRecHitsMaker ( )

Definition at line 83 of file EcalBarrelRecHitsMaker.cc.

{;
}

Member Function Documentation

void EcalBarrelRecHitsMaker::clean ( ) [private]

Definition at line 88 of file EcalBarrelRecHitsMaker.cc.

References applyZSCells_, noise_, noisified_, findQualityFiles::size, theCalorimeterHits_, theFiredCells_, theFiredTTs_, theTTofHighInterest_, treatedTTs_, TTHighInterest_, and TTTEnergy_.

Referenced by loadEcalBarrelRecHits().

{
  //  std::cout << " clean " << std::endl;
  unsigned size=theFiredCells_.size();
  for(unsigned ic=0;ic<size;++ic)
    {
      theCalorimeterHits_[theFiredCells_[ic]] = 0.;
      applyZSCells_[theFiredCells_[ic]] = true;
    }
  theFiredCells_.clear();
  // If the noise is set to 0. No need to simulate it. 
  noisified_ = (noise_==0.);
  //  std::cout << " Finished to clean "  << std::endl;
  
  size=theFiredTTs_.size();
  //  std::cout << " Number of barrel TT " << size << std::endl;
  for(unsigned itt=0;itt<size;++itt)
    {
      //      std::cout << " TT " << theFiredTTs_[itt] << " " << TTTEnergy_[theFiredTTs_[itt]] << std::endl;
      TTTEnergy_[theFiredTTs_[itt]]=0.;
      treatedTTs_[theFiredTTs_[itt]]=false;
    }  
  theFiredTTs_.clear();
  
  size=theTTofHighInterest_.size();
  for(unsigned itt=0;itt<size;++itt)
    TTHighInterest_[theTTofHighInterest_[itt]]=0;
  theTTofHighInterest_.clear();

//  std::cout << " Check cleaning " << std::endl;
//  for(unsigned ic=0;ic<TTTEnergy_.size();++ic)
//    if(TTTEnergy_[ic]!=0.) std::cout << " TT " << ic << " not cleaned " << std::endl;
//  for(unsigned ic=0;ic<TTHighInterest_.size();++ic)
//    if(TTHighInterest_[ic]!=0) std::cout << " TTHighInterest " << ic << TTHighInterest_[ic] << " not cleaned " << std::endl;
//  for(unsigned ic=0;ic<treatedTTs_.size();++ic)
//    if(treatedTTs_[ic]) std::cout << " treatedTT " << ic << treatedTTs_[ic] << " not cleaned " << std::endl;
  
}
void EcalBarrelRecHitsMaker::geVtoGainAdc ( float  e,
unsigned &  gain,
unsigned &  adc 
) const [private]

Definition at line 559 of file EcalBarrelRecHitsMaker.cc.

References geVToAdc1_, geVToAdc2_, geVToAdc3_, maxAdc_, min, minAdc_, t1_, and t2_.

Referenced by loadEcalBarrelRecHits().

{
  if(e<t1_)
    {
      gain = 1; // x1 
      //      std::cout << " E " << e << std::endl;
      adc = minAdc_ + (unsigned)(e*geVToAdc1_);
      //      std::cout << " e*geVtoAdc1_ " << e*geVToAdc1_ << " " <<(unsigned)(e*geVToAdc1_) << std::endl;
    } 
  else if (e<t2_)
    {
      gain = 2; 
      adc = minAdc_ + (unsigned)(e*geVToAdc2_);
    }
  else 
    {
      gain = 3; 
      adc = std::min(minAdc_+(unsigned)(e*geVToAdc3_),maxAdc_);
    }
}
void EcalBarrelRecHitsMaker::init ( const edm::EventSetup es,
bool  dodigis,
bool  doMiscalib 
)

Definition at line 390 of file EcalBarrelRecHitsMaker.cc.

References abs, adcToGeV_, EcalCondObjectContainer< T >::barrelItems(), barrelRawId_, calibfactor_, crystalsinTT_, doDigis_, doMisCalib_, DetId::Ecal, EcalBarrel, eTTmap_, edm::EventSetup::get(), CaloSubdetectorGeometry::getGeometry(), CaloCellGeometry::getPosition(), CaloSubdetectorGeometry::getValidDetIds(), geVToAdc1_, geVToAdc2_, geVToAdc3_, EcalTrigTowerDetId::hashedIndex(), EBDetId::hashedIndex(), ICMC_, EBDetId::ietaAbs(), EBDetId::kSizeForDenseIndexing, max(), maxAdc_, timingPdfMaker::mean, min, minAdc_, neighboringTTs_, noise_, noiseADC_, noisesigma_, edm::ESHandle< T >::product(), refactor_, refactor_mean_, plotscripts::rms(), sat_, funct::sin(), sinTheta_, findQualityFiles::size, mathSSE::sqrt(), SREtaSize_, SRPhiSize_, t1_, t2_, theCalibConstants_, PV3DBase< T, PVType, FrameType >::theta(), theTTDetIds_, and EcalTrigTowerConstituentsMap::towerOf().

Referenced by CaloRecHitsProducer::beginRun().

{
  //  std::cout << " Initializing EcalBarrelRecHitsMaker " << std::endl;
  doDigis_=doDigis;
  doMisCalib_=doMiscalib;

  edm::ESHandle<EcalADCToGeVConstant> agc;
  es.get<EcalADCToGeVConstantRcd>().get(agc);

  adcToGeV_= agc->getEBValue();// 0.035 ;
  minAdc_ = 200;
  maxAdc_ = 4085;

  geVToAdc1_ = 1./adcToGeV_;
  geVToAdc2_ = geVToAdc1_/2.;
  geVToAdc3_ = geVToAdc1_/12.;
  
  t1_ = ((int)maxAdc_-(int)minAdc_)*adcToGeV_;
  t2_ = 2.* t1_ ; 

  // Saturation value. Not needed in the digitization
  sat_ = 12.*t1_*calibfactor_;

  barrelRawId_.resize(EBDetId::kSizeForDenseIndexing);
  if (doMisCalib_ || noise_==-1.) theCalibConstants_.resize(EBDetId::kSizeForDenseIndexing);
  edm::ESHandle<CaloGeometry> pG;
  es.get<CaloGeometryRecord>().get(pG);   

//  edm::ESHandle<CaloTopology> theCaloTopology;
//  es.get<CaloTopologyRecord>().get(theCaloTopology);     

  edm::ESHandle<EcalTrigTowerConstituentsMap> hetm;
  es.get<IdealGeometryRecord>().get(hetm);
  eTTmap_ = &(*hetm);
  
  const EcalBarrelGeometry * myEcalBarrelGeometry = dynamic_cast<const EcalBarrelGeometry*>(pG->getSubdetectorGeometry(DetId::Ecal,EcalBarrel));
  //  std::cout << " Got the geometry " << myEcalBarrelGeometry << std::endl;
  const std::vector<DetId>& vec(myEcalBarrelGeometry->getValidDetIds(DetId::Ecal,EcalBarrel));
  unsigned size=vec.size();    
  for(unsigned ic=0; ic<size; ++ic) 
    {
      EBDetId myDetId(vec[ic]);
      int crystalHashedIndex=myDetId.hashedIndex();
      barrelRawId_[crystalHashedIndex]=vec[ic].rawId();
      // save the Trigger tower DetIds
      EcalTrigTowerDetId towid= eTTmap_->towerOf(EBDetId(vec[ic]));
      int TThashedindex=towid.hashedIndex();      
      theTTDetIds_[TThashedindex]=towid;                  
      crystalsinTT_[TThashedindex].push_back(crystalHashedIndex);
      int ietaAbs=myDetId.ietaAbs();
      if(sinTheta_[ietaAbs]==0.)
        {
          sinTheta_[ietaAbs]=std::sin(myEcalBarrelGeometry->getGeometry(myDetId)->getPosition().theta());
          //      std::cout << " Ieta abs " << ietaAbs << " " << sinTheta_[ietaAbs] << std::endl;
        }
    }


  unsigned nTTs=theTTDetIds_.size();

//  EBDetId myDetId(-58,203);
//  EcalTrigTowerDetId towid= eTTmap_->towerOf(myDetId);
//  const std::vector<int> & xtals(crystalsinTT_[towid.hashedIndex()]);
//  unsigned Size=xtals.size();
//  for(unsigned i=0;i<Size;++i)
//    {
//      std::cout << EBDetId(barrelRawId_[xtals[i]]) << std::endl;
//    }

  // now loop on each TT and save its neighbors. 
  for(unsigned iTT=0;iTT<nTTs;++iTT)
    {
      int ietaPivot=theTTDetIds_[iTT].ieta();
      int iphiPivot=theTTDetIds_[iTT].iphi();
      int TThashedIndex=theTTDetIds_[iTT].hashedIndex();
      //      std::cout << " TT Pivot " << TThashedIndex << " " << ietaPivot << " " << iphiPivot << " iz " << theTTDetIds_[iTT].zside() << std::endl;
      int ietamin=std::max(ietaPivot-SREtaSize_,-17);
      if(ietamin==0) ietamin=-1;
      int ietamax=std::min(ietaPivot+SREtaSize_,17);
      if(ietamax==0) ietamax=1;
      int iphimin=iphiPivot-SRPhiSize_;
      int iphimax=iphiPivot+SRPhiSize_;
      for(int ieta=ietamin;ieta<=ietamax;)
        {
          int iz=(ieta>0)? 1 : -1; 
          for(int iphi=iphimin;iphi<=iphimax;)
            {
              int riphi=iphi;
              if(riphi<1) riphi+=72;
              else if(riphi>72) riphi-=72;
              EcalTrigTowerDetId neighborTTDetId(iz,EcalBarrel,abs(ieta),riphi);
              //      std::cout << " Voisin " << ieta << " " << riphi << " " <<neighborTTDetId.hashedIndex()<< " " << neighborTTDetId.ieta() << " " << neighborTTDetId.iphi() << std::endl;
              if(ieta!=ietaPivot||riphi!=iphiPivot)
                {
                  neighboringTTs_[TThashedIndex].push_back(neighborTTDetId.hashedIndex());
                }
              ++iphi;

            }
          ++ieta;
          if(ieta==0) ieta=1;
        }
    }

  //  std::cout << " Made the array " << std::endl;

  // Stores the miscalibration constants
  if(doMisCalib_ || noise_==-1.)
    {
      double rms=0.;
      double mean=0.;
      unsigned ncells=0;

      if(noise_==-1.)
        noisesigma_.resize(EBDetId::kSizeForDenseIndexing);

      // Intercalib MC constants IC_MC_i
      edm::ESHandle<EcalIntercalibConstantsMC> pJcal;
      es.get<EcalIntercalibConstantsMCRcd>().get(pJcal); 
      const EcalIntercalibConstantsMC* jcal = pJcal.product(); 
      const std::vector<float>& ICMC = jcal->barrelItems();

       // should be saved, used by the zero suppression
      ICMC_ = &ICMC;

      // Intercalib constants IC_i 
      // IC = IC_MC * (1+delta)
      // where delta is the miscalib
      edm::ESHandle<EcalIntercalibConstants> pIcal;
      es.get<EcalIntercalibConstantsRcd>().get(pIcal);
      const EcalIntercalibConstants* ical = pIcal.product();
      const std::vector<float> & IC = ical->barrelItems();
      
      float meanIC=0.;
      unsigned nic = IC.size();
      for ( unsigned ic=0; ic <nic ; ++ic ) {
        // the miscalibration factor is 
        float factor = IC[ic]/ICMC[ic];
        meanIC+=(IC[ic]-1.);
        // Apply Refactor & refactor_mean
        theCalibConstants_[ic] = refactor_mean_+(factor-1.)*refactor_;
        
        rms+=(factor-1.)*(factor-1.);
        mean+=(factor-1.);
        ++ncells;       
        if(noise_==-1.)
          { 
            // the calibfactor will be applied later on 
            noisesigma_[ic]=noiseADC_*adcToGeV_*ICMC[ic]/calibfactor_;
          }

      }

      mean/=(float)ncells;
      rms/=(float)ncells;

      rms=sqrt(rms-mean*mean);
      meanIC = 1.+ meanIC/ncells;
      // The following should be on LogInfo
      //      float NoiseSigma = 1.26 * meanIC * adcToGeV_ ;
      //      std::cout << " Found " << ncells << 
      edm::LogInfo("CaloRecHitsProducer") << "Found  " << ncells << " cells in the barrel calibration map. RMS is " << rms << std::endl;
      //      std::cout << "Found  " << ncells << " cells in the barrel calibration map. RMS is " << rms << std::endl;
    }  
}
bool EcalBarrelRecHitsMaker::isHighInterest ( int  tthi) [private]

Definition at line 580 of file EcalBarrelRecHitsMaker.cc.

References neighboringTTs_, query::result, findQualityFiles::size, SRThreshold_, theTTofHighInterest_, TTHighInterest_, and TTTEnergy_.

Referenced by loadEcalBarrelRecHits().

{

  if(TTHighInterest_[tthi]!=0) return (TTHighInterest_[tthi]>0);

  TTHighInterest_[tthi]=(TTTEnergy_[tthi] > SRThreshold_) ? 1:-1;
  // if high interest, can leave ; otherwise look at the neighbours)
  if( TTHighInterest_[tthi]==1) 
    {
      theTTofHighInterest_.push_back(tthi);
      return true;
    }

  // now look if a neighboring TT is of high interest
  const std::vector<int> & tts(neighboringTTs_[tthi]);
  // a tower is of high interest if it or one of its neighbour is above the SR threshold
  unsigned size=tts.size();
  bool result=false;
  for(unsigned itt=0;itt<size&&!result;++itt)
    {
      if(TTTEnergy_[tts[itt]] > SRThreshold_) result=true;
    }
  TTHighInterest_[tthi]=(result)? 1:-1;
  theTTofHighInterest_.push_back(tthi);
  return result;
}
void EcalBarrelRecHitsMaker::loadEcalBarrelRecHits ( edm::Event iEvent,
EBRecHitCollection ecalHits,
EBDigiCollection ecaldigis 
)

Definition at line 127 of file EcalBarrelRecHitsMaker.cc.

References ecalMGPA::adc(), applyZSCells_, edm::DataFrameContainer::back(), barrelRawId_, clean(), doDigis_, relval_parameters_module::energy, eTTmap_, geVtoGainAdc(), EcalTrigTowerDetId::hashedIndex(), isHighInterest(), loadPCaloHits(), edm::DataFrameContainer::push_back(), edm::SortedCollection< T, SORT >::push_back(), edm::SortedCollection< T, SORT >::reserve(), edm::DataFrameContainer::reserve(), sat_, SRThreshold_, theCalorimeterHits_, theFiredCells_, threshold_, and EcalTrigTowerConstituentsMap::towerOf().

Referenced by CaloRecHitsProducer::produce().

{

  clean();
  loadPCaloHits(iEvent);
  
  unsigned nhit=theFiredCells_.size();
  //  std::cout << " loadEcalBarrelRecHits " << nhit << std::endl;
  unsigned gain, adc;
  ecalDigis.reserve(nhit);
  ecalHits.reserve(nhit);
  for(unsigned ihit=0;ihit<nhit;++ihit)
    {      
      unsigned icell = theFiredCells_[ihit];

      EBDetId myDetId(barrelRawId_[icell]);
      EcalTrigTowerDetId towid= eTTmap_->towerOf(myDetId);
      int TThashedindex=towid.hashedIndex();      

      if(doDigis_)
        {
          ecalDigis.push_back( myDetId );
          EBDataFrame myDataFrame( ecalDigis.back() );
          // myDataFrame.setSize(1);  // now useless - by construction fixed at 1 frame - FIXME
          //  The real work is in the following line
          geVtoGainAdc(theCalorimeterHits_[icell],gain,adc);
          myDataFrame.setSample(0,EcalMGPASample(adc,gain));
          
          //      std::cout << "myDataFrame" << myDataFrame.sample(0).raw() << std::endl;
          //ecalDigis.push_back(myDataFrame);
        }
      
      // If the energy+noise is below the threshold, a hit is nevertheless created, otherwise, there is a risk that a "noisy" hit 
      // is afterwards put in this cell which would not be correct. 
      float energy=theCalorimeterHits_[icell];
      //      std::cout << myDetId << " Energy " << theCalorimeterHits_[icell] << " " << TTTEnergy_[TThashedindex] << " " << isHighInterest(TThashedindex) << std::endl;
      if ( SRThreshold_ && energy < threshold_  && !isHighInterest(TThashedindex) && applyZSCells_[icell])
        {
          //      std::cout << " Killed " << std::endl;
          theCalorimeterHits_[icell]=0.;
          energy=0.;
        } 
      //      else
        //      std::cout << " SR " <<  TTTEnergy_[TThashedindex] << " Cell energy " << energy << " 1" << std::endl;
//      if( TTTEnergy_[TThashedindex] < SRThreshold_ && energy > threshold_)
//      std::cout << " SR " << TTTEnergy_[TThashedindex] << " Cell energy " << energy << std::endl;
      if (energy > sat_)
        {
          theCalorimeterHits_[icell]=sat_;
          energy=sat_;
        }
//      std::cout << " Threshold ok " << std::endl;
//      std::cout << " Raw Id " << barrelRawId_[icell] << std::endl;
//      std::cout << " Adding " << icell << " " << barrelRawId_[icell] << " " << energy << std::endl;
      if(energy!=0.)
        ecalHits.push_back(EcalRecHit(myDetId,energy,0.));
      //      std::cout << " Hit stored " << std::endl;
    }
  //  std::cout << " Done " << std::endl;

}
void EcalBarrelRecHitsMaker::loadPCaloHits ( const edm::Event iEvent) [private]

Definition at line 189 of file EcalBarrelRecHitsMaker.cc.

References calib, calibfactor_, doMisCalib_, relval_parameters_module::energy, eTTmap_, RandomEngine::gaussShoot(), edm::Event::getByLabel(), EcalTrigTowerDetId::hashedIndex(), ecalpyutils::hashedIndex(), EBDetId::ietaAbs(), inputCol_, noise_, noisesigma_, noisified_, noisifyTriggerTowers(), edm::Handle< T >::product(), random_, sinTheta_, theCalibConstants_, theCalorimeterHits_, theFiredCells_, theFiredTTs_, EcalTrigTowerConstituentsMap::towerOf(), and TTTEnergy_.

Referenced by loadEcalBarrelRecHits().

{

  edm::Handle<CrossingFrame<PCaloHit> > cf;
  iEvent.getByLabel(inputCol_,cf);
  std::auto_ptr<MixCollection<PCaloHit> > colcalo(new MixCollection<PCaloHit>(cf.product(),std::pair<int,int>(0,0) ));


  theFiredCells_.reserve(colcalo->size());

  MixCollection<PCaloHit>::iterator cficalo;
  MixCollection<PCaloHit>::iterator cficaloend=colcalo->end();

  for (cficalo=colcalo->begin(); cficalo!=cficaloend;cficalo++) 
    {
      unsigned hashedindex = EBDetId(cficalo->id()).hashedIndex();      
      // the famous 1/0.97 calibration factor is applied here ! 
      // the miscalibration is applied here:
      float calib = (doMisCalib_) ? calibfactor_*theCalibConstants_[hashedindex]:calibfactor_;
      // Check if the hit already exists
      if(theCalorimeterHits_[hashedindex]==0.)
        {
          theFiredCells_.push_back(hashedindex);
          float noise=(noise_==-1.) ? noisesigma_[hashedindex] : noise_ ;
          if (!noisified_ )  theCalorimeterHits_[hashedindex] += random_->gaussShoot(0.,noise*calib); 
        }


      // cficalo->energy can be 0 (a 7x7 grid is always built) if there is no noise simulated, in this case the cells should
      // not be added several times. 
      float energy=(cficalo->energy()==0.) ? 0.000001 : cficalo->energy() ;
      energy*=calib;
      theCalorimeterHits_[hashedindex]+=energy;         

      // Now deal with the TTs. 
      EBDetId myDetId(EBDetId(cficalo->id()));
      EcalTrigTowerDetId towid= eTTmap_->towerOf(myDetId);
//      std::cout << " Added " << energy << " in " << EBDetId(cficalo->id()) << std::endl;
      int TThashedindex=towid.hashedIndex();
      if(TTTEnergy_[TThashedindex]==0.)
        {
          theFiredTTs_.push_back(TThashedindex);           
//        std::cout << " Creating " ;
        }
      //      std::cout << " Updating " << TThashedindex << " " << energy << " " << sinTheta_[myDetId.ietaAbs()] <<std::endl;
       TTTEnergy_[TThashedindex]+=energy*sinTheta_[myDetId.ietaAbs()];
       //       std::cout << " TT " << TThashedindex  << " updated, now contains " << TTTEnergy_[TThashedindex] << std::endl;
    }
  noisifyTriggerTowers();  
  noisified_ = true;
}
bool EcalBarrelRecHitsMaker::noisifyTriggerTower ( unsigned  tthi) [private]

Definition at line 284 of file EcalBarrelRecHitsMaker.cc.

References barrelRawId_, calib, calibfactor_, crystalsinTT_, doMisCalib_, relval_parameters_module::energy, RandomEngine::gaussShoot(), EBDetId::ietaAbs(), noise_, noisesigma_, random_, sinTheta_, theCalibConstants_, theCalorimeterHits_, theFiredCells_, theFiredTTs_, treatedTTs_, and TTTEnergy_.

Referenced by noisifyTriggerTowers().

{
  // check if the TT has already been treated or not
  if(treatedTTs_[tthi]) return false;
  // get the crystals in the TT (this info might need to be cached)
  //  const std::vector<DetId> & xtals=eTTmap_->constituentsOf(theTTDetIds_[tthi]);
  const std::vector<int> & xtals(crystalsinTT_[tthi]);
  unsigned nxtals=xtals.size();
  unsigned counter =0 ; 
  float energy=0.;
  for(unsigned ic=0;ic<nxtals;++ic)
    {
      unsigned hashedindex=xtals[ic];
      // check if the crystal has been already hit
//      std::cout << " Checking " << EBDetId(barrelRawId_[xtals[ic]]) << " " << theCalorimeterHits_[hashedindex] << std::endl;
      if(theCalorimeterHits_[hashedindex]==0)
        {
          float calib = (doMisCalib_) ? calibfactor_*theCalibConstants_[hashedindex]:calibfactor_;
          float noise = (noise_==-1.) ? noisesigma_[hashedindex]:noise_;
          float energy = calib*random_->gaussShoot(0.,noise);
          theCalorimeterHits_[hashedindex]=energy;
          //      std::cout << " Updating with noise " << tthi << " " << energy << " " << sinTheta_[EBDetId(barrelRawId_[hashedindex]).ietaAbs()] << std::endl;
          if(TTTEnergy_[tthi]==0.)
            theFiredTTs_.push_back(tthi);
          TTTEnergy_[tthi]+=energy*sinTheta_[EBDetId(barrelRawId_[hashedindex]).ietaAbs()];
          
          theFiredCells_.push_back(hashedindex);
          ++counter;
        }
      else
        energy+=theCalorimeterHits_[hashedindex];
    }
//  std::cout << " Energy " << energy  << " Added noise in " << counter << " cells" << std::endl;
  treatedTTs_[tthi]=true;
  return true;
}
void EcalBarrelRecHitsMaker::noisifyTriggerTowers ( ) [private]

Definition at line 241 of file EcalBarrelRecHitsMaker.cc.

References recoMuon::in, neighboringTTs_, noise_, noisifyTriggerTower(), nTT, randomNoisifier(), theFiredTTs_, treatedTTs_, and TTTEnergy_.

Referenced by loadPCaloHits().

{
  if(noise_==0.) return;
//  std::cout << " List of TT before" << std::endl;
//  for(unsigned itt=0;itt<theFiredTTs_.size();++itt)
//    std::cout << " TT " << theFiredTTs_[itt] << " " << TTTEnergy_[theFiredTTs_[itt]] << std::endl;

  //  std::cout << " Starting to noisify the trigger towers " << std::endl;
  unsigned nTT=theFiredTTs_.size();
  for(unsigned itt=0;itt<nTT;++itt)
    {      
      //      std::cout << "Treating " << theFiredTTs_[itt] << " " << theTTDetIds_[theFiredTTs_[itt]].ieta() << " " <<  theTTDetIds_[theFiredTTs_[itt]].iphi() << " " << TTTEnergy_[theFiredTTs_[itt]] << std::endl;
      // shoot noise in the trigger tower 
      noisifyTriggerTower(theFiredTTs_[itt]);
      // get the neighboring TTs
      const std::vector<int>& neighbors=neighboringTTs_[theFiredTTs_[itt]];
      unsigned nneighbors=neighbors.size();
      // inject noise in those towers only if they have not been looked at yet
      //      std::cout << " Now looking at the neighbours " << std::endl;
      for(unsigned in=0;in<nneighbors;++in)
        {
          //      std::cout << " TT " << neighbors[in] << " " << theTTDetIds_[neighbors[in]] << " has been treated " << treatedTTs_[neighbors[in]] << std::endl;
          if(!treatedTTs_[neighbors[in]])
            {
              noisifyTriggerTower(neighbors[in]);
              if(TTTEnergy_[neighbors[in]]==0.)
                theFiredTTs_.push_back(neighbors[in]);
              //              std::cout << " Added " << neighbors[in] << " in theFiredTTs_ " << std::endl;;
            }
        }
    }
//  std::cout << " List of TT after" << std::endl;
//  for(unsigned itt=0;itt<theFiredTTs_.size();++itt)
//    {
//      std::cout << " TT " << theFiredTTs_[itt] << " " << TTTEnergy_[theFiredTTs_[itt]] << std::endl;
//      const std::vector<int> & xtals=crystalsinTT_[theFiredTTs_[itt]];
//      for(unsigned ic=0;ic<xtals.size();++ic)
//      std::cout << EBDetId::unhashIndex(xtals[ic]) << " " << theCalorimeterHits_[xtals[ic]] << std::endl;
//    }

  randomNoisifier();
}
void EcalBarrelRecHitsMaker::randomNoisifier ( ) [private]

Definition at line 324 of file EcalBarrelRecHitsMaker.cc.

References adcToGeV_, applyZSCells_, calib, calibfactor_, doCustomHighNoise_, doMisCalib_, EBHotFraction_, relval_parameters_module::energy, eTTmap_, RandomEngine::flatShoot(), RandomEngine::gaussShoot(), ecalpyutils::hashedIndex(), highNoiseParameters_, ICMC_, EBDetId::ietaAbs(), EBDetId::kSizeForDenseIndexing, timingPdfMaker::mean, myGaussianTailGenerator_, noise_, noisesigma_, RandomEngine::poissonShoot(), random_, GaussianTail::shoot(), sinTheta_, theCalibConstants_, theCalorimeterHits_, theFiredCells_, theFiredTTs_, EcalTrigTowerConstituentsMap::towerOf(), TTTEnergy_, and EBDetId::unhashIndex().

Referenced by noisifyTriggerTowers().

{
  // first number of cells where some noise will be injected
  double mean = (double)(EBDetId::kSizeForDenseIndexing-theFiredCells_.size())*EBHotFraction_;
  unsigned ncells= random_->poissonShoot(mean);

 // if hot fraction is high (for example, no ZS, inject everywhere)
  bool fullInjection=(noise_==-1. && !doCustomHighNoise_);
  if(fullInjection)
    ncells = EBDetId::kSizeForDenseIndexing;
  // for debugging
  //  std::vector<int> listofNewTowers;

  unsigned icell=0;
  while(icell < ncells)
    {
      unsigned cellindex= (unsigned)(floor(random_->flatShoot()*EBDetId::kSizeForDenseIndexing));
      if(theCalorimeterHits_[cellindex]==0.)
        {
          float energy=0.;
          if(noise_>0.) 
            energy=myGaussianTailGenerator_->shoot();
          if(noise_==-1.) 
            {
              // in this case the generated noise might be below the threshold but it 
              // does not matter, the threshold will be applied anyway
              //              energy/=sinTheta_[(cellindex<EEDetId::kEEhalf)?cellindex : cellindex-EEDetId::kEEhalf];    
              float noisemean  = (doCustomHighNoise_)? highNoiseParameters_[0]*(*ICMC_)[cellindex]*adcToGeV_: 0.;
              float noisesigma = (doCustomHighNoise_)? highNoiseParameters_[1]*(*ICMC_)[cellindex]*adcToGeV_ : noisesigma_[cellindex]; 
              energy=random_->gaussShoot(noisemean,noisesigma); 
              
              // in the case of high noise fluctuation, the ZS should not be applied later 
              if(doCustomHighNoise_) applyZSCells_[cellindex]=false;
            }
          float calib = (doMisCalib_) ? calibfactor_*theCalibConstants_[cellindex]:calibfactor_;
          energy *= calib;
          theCalorimeterHits_[cellindex]=energy;
          theFiredCells_.push_back(cellindex);
          EBDetId myDetId(EBDetId::unhashIndex(cellindex));
          // now get the TT       
          int TThashedindex=(eTTmap_->towerOf(myDetId)).hashedIndex();
          //      std::cout << " myDetIds " << myDetId << " "TTHI " << TThashedindex<< std::endl;
          if(TTTEnergy_[TThashedindex]==0.)
            {
              theFiredTTs_.push_back(TThashedindex);
              TTTEnergy_[TThashedindex]+=energy*sinTheta_[myDetId.ietaAbs()];         
              //              listofNewTowers.push_back(TThashedindex);
            }
//        else
//          {
//            std::vector<int>::const_iterator itcheck=std::find(listofNewTowers.begin(),listofNewTowers.end(),
//                                                             TThashedindex);
//            if(itcheck==listofNewTowers.end())
//              {
//                std::cout << " EcalBarrelRecHitsMaker : this tower has already been treated " << TTTEnergy_[TThashedindex] << std::endl;
//                const std::vector<int> & xtals=crystalsinTT_[TThashedindex];
//                for(unsigned ic=0;ic<xtals.size();++ic)
//                  std::cout << EBDetId::unhashIndex(xtals[ic]) << " " << theCalorimeterHits_[xtals[ic]] << std::endl;
//              }
//          }
          ++icell;
        }
    }
  //  std::cout << " Injected random noise in " << ncells << " cells " << std::endl;
}

Member Data Documentation

Definition at line 65 of file EcalBarrelRecHitsMaker.h.

Referenced by init(), and randomNoisifier().

std::vector<int> EcalBarrelRecHitsMaker::applyZSCells_ [private]
std::vector<uint32_t> EcalBarrelRecHitsMaker::barrelRawId_ [private]

Definition at line 64 of file EcalBarrelRecHitsMaker.h.

Referenced by init(), loadEcalBarrelRecHits(), and noisifyTriggerTower().

std::vector<std::vector<int> > EcalBarrelRecHitsMaker::crystalsinTT_ [private]

Definition at line 83 of file EcalBarrelRecHitsMaker.h.

Referenced by EcalBarrelRecHitsMaker(), init(), and noisifyTriggerTower().

Definition at line 92 of file EcalBarrelRecHitsMaker.h.

Referenced by EcalBarrelRecHitsMaker(), and randomNoisifier().

Definition at line 40 of file EcalBarrelRecHitsMaker.h.

Referenced by init(), and loadEcalBarrelRecHits().

Definition at line 41 of file EcalBarrelRecHitsMaker.h.

Referenced by init(), loadPCaloHits(), noisifyTriggerTower(), and randomNoisifier().

Definition at line 48 of file EcalBarrelRecHitsMaker.h.

Referenced by EcalBarrelRecHitsMaker(), and randomNoisifier().

Definition at line 66 of file EcalBarrelRecHitsMaker.h.

Referenced by geVtoGainAdc(), and init().

Definition at line 66 of file EcalBarrelRecHitsMaker.h.

Referenced by geVtoGainAdc(), and init().

Definition at line 66 of file EcalBarrelRecHitsMaker.h.

Referenced by geVtoGainAdc(), and init().

std::vector<double> EcalBarrelRecHitsMaker::highNoiseParameters_ [private]

Definition at line 91 of file EcalBarrelRecHitsMaker.h.

Referenced by EcalBarrelRecHitsMaker(), and randomNoisifier().

const std::vector<float>* EcalBarrelRecHitsMaker::ICMC_ [private]

Definition at line 106 of file EcalBarrelRecHitsMaker.h.

Referenced by init(), and randomNoisifier().

Definition at line 53 of file EcalBarrelRecHitsMaker.h.

Referenced by EcalBarrelRecHitsMaker(), and loadPCaloHits().

unsigned EcalBarrelRecHitsMaker::maxAdc_ [private]

Definition at line 68 of file EcalBarrelRecHitsMaker.h.

Referenced by geVtoGainAdc(), and init().

Definition at line 102 of file EcalBarrelRecHitsMaker.h.

unsigned EcalBarrelRecHitsMaker::minAdc_ [private]

Definition at line 67 of file EcalBarrelRecHitsMaker.h.

Referenced by geVtoGainAdc(), and init().

Definition at line 50 of file EcalBarrelRecHitsMaker.h.

Referenced by EcalBarrelRecHitsMaker(), and randomNoisifier().

std::vector<std::vector<int> > EcalBarrelRecHitsMaker::neighboringTTs_ [private]

Definition at line 104 of file EcalBarrelRecHitsMaker.h.

Referenced by EcalBarrelRecHitsMaker(), and init().

std::vector<float> EcalBarrelRecHitsMaker::noisesigma_ [private]

Definition at line 52 of file EcalBarrelRecHitsMaker.h.

Referenced by clean(), EcalBarrelRecHitsMaker(), and loadPCaloHits().

Definition at line 42 of file EcalBarrelRecHitsMaker.h.

Referenced by EcalBarrelRecHitsMaker(), and init().

Definition at line 43 of file EcalBarrelRecHitsMaker.h.

Referenced by EcalBarrelRecHitsMaker(), and init().

Definition at line 69 of file EcalBarrelRecHitsMaker.h.

Referenced by init(), and loadEcalBarrelRecHits().

std::vector<float> EcalBarrelRecHitsMaker::sinTheta_ [private]

Definition at line 96 of file EcalBarrelRecHitsMaker.h.

Referenced by EcalBarrelRecHitsMaker(), and init().

Definition at line 97 of file EcalBarrelRecHitsMaker.h.

Referenced by EcalBarrelRecHitsMaker(), and init().

float EcalBarrelRecHitsMaker::t1_ [private]

Definition at line 69 of file EcalBarrelRecHitsMaker.h.

Referenced by geVtoGainAdc(), and init().

float EcalBarrelRecHitsMaker::t2_ [private]

Definition at line 69 of file EcalBarrelRecHitsMaker.h.

Referenced by geVtoGainAdc(), and init().

std::vector<float> EcalBarrelRecHitsMaker::theCalibConstants_ [private]

Definition at line 61 of file EcalBarrelRecHitsMaker.h.

Referenced by init(), loadPCaloHits(), noisifyTriggerTower(), and randomNoisifier().

std::vector<float> EcalBarrelRecHitsMaker::theCalorimeterHits_ [private]
std::vector<int> EcalBarrelRecHitsMaker::theFiredCells_ [private]
std::vector<unsigned> EcalBarrelRecHitsMaker::theFiredTTs_ [private]

Definition at line 73 of file EcalBarrelRecHitsMaker.h.

Referenced by EcalBarrelRecHitsMaker(), and init().

Definition at line 85 of file EcalBarrelRecHitsMaker.h.

Referenced by clean(), and isHighInterest().

Definition at line 45 of file EcalBarrelRecHitsMaker.h.

Referenced by EcalBarrelRecHitsMaker(), and loadEcalBarrelRecHits().

std::vector<bool> EcalBarrelRecHitsMaker::treatedTTs_ [private]
std::vector<int> EcalBarrelRecHitsMaker::TTHighInterest_ [private]

Definition at line 87 of file EcalBarrelRecHitsMaker.h.

Referenced by clean(), EcalBarrelRecHitsMaker(), and isHighInterest().

std::vector<float> EcalBarrelRecHitsMaker::TTTEnergy_ [private]