CMS 3D CMS Logo

Public Member Functions | Private Types | Private Member Functions | Private Attributes

CastorTowerProducer Class Reference

#include <RecoLocalCalo/Castor/src/CastorTowerProducer.cc>

Inheritance diagram for CastorTowerProducer:
edm::EDProducer edm::ProducerBase edm::ProductRegistryHelper

List of all members.

Public Member Functions

 CastorTowerProducer (const edm::ParameterSet &)
 ~CastorTowerProducer ()

Private Types

typedef edm::SortedCollection
< CastorRecHit
CastorRecHitCollection
typedef edm::RefVector
< CastorRecHitCollection
CastorRecHitRefVector
typedef std::vector
< reco::CastorTower
CastorTowerCollection
typedef ROOT::Math::RhoZPhiPoint CellPoint
typedef math::XYZPointD Point
typedef ROOT::Math::RhoEtaPhiPoint TowerPoint

Private Member Functions

virtual void beginJob ()
virtual void ComputeTowerVariable (const edm::RefVector< edm::SortedCollection< CastorRecHit > > &usedRecHits, double &Ehot, double &depth)
virtual void endJob ()
virtual void produce (edm::Event &, const edm::EventSetup &)

Private Attributes

std::string input_
double maxtime_
double mintime_
double towercut_

Detailed Description

Description: CastorTower Reconstruction Producer. Produce CastorTowers from CastorCells. Implementation:

Definition at line 52 of file CastorTowerProducer.cc.


Member Typedef Documentation

Definition at line 67 of file CastorTowerProducer.cc.

Definition at line 69 of file CastorTowerProducer.cc.

Definition at line 68 of file CastorTowerProducer.cc.

typedef ROOT::Math::RhoZPhiPoint CastorTowerProducer::CellPoint [private]

Definition at line 66 of file CastorTowerProducer.cc.

Definition at line 64 of file CastorTowerProducer.cc.

typedef ROOT::Math::RhoEtaPhiPoint CastorTowerProducer::TowerPoint [private]

Definition at line 65 of file CastorTowerProducer.cc.


Constructor & Destructor Documentation

CastorTowerProducer::CastorTowerProducer ( const edm::ParameterSet iConfig) [explicit]

Definition at line 90 of file CastorTowerProducer.cc.

                                                                       :
  input_(iConfig.getUntrackedParameter<std::string>("inputprocess","castorreco")),
  towercut_(iConfig.getUntrackedParameter<double>("towercut",0.65)),
  mintime_(iConfig.getUntrackedParameter<double>("mintime",-999)),
  maxtime_(iConfig.getUntrackedParameter<double>("maxtime",999))
{
  //register your products
  produces<CastorTowerCollection>();
  //now do what ever other initialization is needed
}
CastorTowerProducer::~CastorTowerProducer ( )

Definition at line 102 of file CastorTowerProducer.cc.

{
   // do anything here that needs to be done at desctruction time
   // (e.g. close files, deallocate resources etc.)
}

Member Function Documentation

void CastorTowerProducer::beginJob ( void  ) [private, virtual]

Reimplemented from edm::EDProducer.

Definition at line 272 of file CastorTowerProducer.cc.

References LogDebug.

                                   {
  LogDebug("CastorTowerProducer")
    <<"Starting CastorTowerProducer";
}
void CastorTowerProducer::ComputeTowerVariable ( const edm::RefVector< edm::SortedCollection< CastorRecHit > > &  usedRecHits,
double &  Ehot,
double &  depth 
) [private, virtual]

Definition at line 283 of file CastorTowerProducer.cc.

References edm::Ref< C, T, F >::id(), module::module(), and dt_dqm_sourceclient_common_cff::reco.

Referenced by produce().

                                                                                                                                                {

  using namespace reco;

  double Etot = 0;

  // loop over the cells used in the tower k
  for (CastorRecHitRefVector::iterator it = usedRecHits.begin(); it != usedRecHits.end(); it++) {
    edm::Ref<CastorRecHitCollection> rechit_p = *it;

    double Erechit = rechit_p->energy();
    HcalCastorDetId id = rechit_p->id();
    int module = id.module();
    double zrechit = 0;
    if (module < 3) zrechit = -14390 - 24.75 - 49.5*(module-1);
    if (module > 2) zrechit = -14390 - 99 - 49.5 - 99*(module-3); 

    if(Erechit > Ehot) Ehot = Erechit;
    depth+=Erechit*zrechit;
    Etot+=Erechit;
  }

  depth/=Etot;
  Ehot/=Etot;
}
void CastorTowerProducer::endJob ( void  ) [private, virtual]

Reimplemented from edm::EDProducer.

Definition at line 278 of file CastorTowerProducer.cc.

References LogDebug.

                                 {
  LogDebug("CastorTowerProducer")
    <<"Ending CastorTowerProducer";
}
void CastorTowerProducer::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
) [private, virtual]

Implements edm::EDProducer.

Definition at line 114 of file CastorTowerProducer.cc.

References cond::ecalcond::bad(), ComputeTowerVariable(), edm::EventSetup::get(), edm::Event::getByLabel(), i, edm::Ref< C, T, F >::id(), input_, j, gen::k, LogDebug, maxtime_, mintime_, module::module(), AlCaHLTBitMon_ParallelJobs::p, edm::Event::put(), DetId::rawId(), dt_dqm_sourceclient_common_cff::reco, findQualityFiles::size, mathSSE::sqrt(), and towercut_.

                                                                               {

  using namespace edm;
  using namespace reco;
  using namespace TMath;
  
  // Produce CastorTowers from CastorCells
  
  edm::Handle<CastorRecHitCollection> InputRecHits;
  iEvent.getByLabel(input_,InputRecHits);

  std::auto_ptr<CastorTowerCollection> OutputTowers (new CastorTowerCollection);
   
  // get and check input size
  int nRecHits = InputRecHits->size();

  LogDebug("CastorTowerProducer")
    <<"2. entering CastorTowerProducer"<<std::endl;

  if (nRecHits==0)
    LogDebug("CastorTowerProducer") <<"Warning: You are trying to run the Tower algorithm with 0 input rechits.";
  
  // declare castor array
  // (0,x): Energies - (1,x): emEnergies - (2,x): hadEnergies - (3,x): phi position
  
  double poscastortowerarray[4][16]; 
  double negcastortowerarray[4][16];

  CastorRecHitRefVector poscastorusedrechits[16];
  CastorRecHitRefVector negcastorusedrechits[16];

  // set phi values and everything else to zero
  for (int j = 0; j < 16; j++) {
    poscastortowerarray[3][j] = -2.94524 + j*0.3927;
    poscastortowerarray[0][j] = 0.;
    poscastortowerarray[1][j] = 0.;
    poscastortowerarray[2][j] = 0.;

    negcastortowerarray[3][j] = -2.94524 + j*0.3927;
    negcastortowerarray[0][j] = 0.;
    negcastortowerarray[1][j] = 0.;
    negcastortowerarray[2][j] = 0.;
  }
  
  // retrieve the channel quality lists from database
  edm::ESHandle<CastorChannelQuality> p;
  iSetup.get<CastorChannelQualityRcd>().get(p);
  std::vector<DetId> channels = p->getAllChannels();

  // loop over rechits to build castortowerarray[4][16] and castorusedrechits[16] 
  for (unsigned int i = 0; i < InputRecHits->size(); i++) {
    
    edm::Ref<CastorRecHitCollection> rechit_p = edm::Ref<CastorRecHitCollection>(InputRecHits, i);
    
    HcalCastorDetId id = rechit_p->id();
    DetId genericID=(DetId)id;
    
    // first check if the rechit is in the BAD channel list
    bool bad = false;
    for (std::vector<DetId>::iterator channel = channels.begin();channel !=  channels.end();channel++) {        
        if (channel->rawId() == genericID.rawId()) {
                // if the rechit is found in the list, set it bad
          bad = true; break;
        }
    }
    // if bad, continue the loop to the next rechit
    if (bad) continue;
    
    double Erechit = rechit_p->energy();
    int module = id.module();
    int sector = id.sector();
    double zrechit = 0;
    if (module < 3) zrechit = -14390 - 24.75 - 49.5*(module-1);
    if (module > 2) zrechit = -14390 - 99 - 49.5 - 99*(module-3); 
    double phirechit = -100;
    if (sector < 9) phirechit = 0.19635 + (sector-1)*0.3927;
    if (sector > 8) phirechit = -2.94524 + (sector - 9)*0.3927;

    // add time conditions for the rechit
    if (rechit_p->time() > mintime_ && rechit_p->time() < maxtime_) {

        // loop over the 16 towers possibilities
        for ( int j=0;j<16;j++) {
      
                // phi matching condition
                if (TMath::Abs(phirechit - poscastortowerarray[3][j]) < 0.0001) {

                        // condition over rechit z value
                        if (zrechit > 0.) {
                                poscastortowerarray[0][j]+=Erechit;
                                if (module < 3) {poscastortowerarray[1][j]+=Erechit;} else {poscastortowerarray[2][j]+=Erechit;}
                                poscastorusedrechits[j].push_back(rechit_p);
                        } else {
                                negcastortowerarray[0][j]+=Erechit;
                                if (module < 3) {negcastortowerarray[1][j]+=Erechit;} else {negcastortowerarray[2][j]+=Erechit;}
                                negcastorusedrechits[j].push_back(rechit_p);
                        } // end condition over rechit z value
                } // end phi matching condition
        } // end loop over the 16 towers possibilities
    } // end time conditions
    
  } // end loop over rechits to build castortowerarray[4][16] and castorusedrechits[16]
  
  // make towers of the arrays

  double fem, Ehot, depth;
  double rhoTower = 88.5;

  // loop over the 16 towers possibilities
  for (int k=0;k<16;k++) {
    
    fem = 0;
    Ehot = 0;
    depth = 0;

    // select the positive towers with E > sqrt(Nusedrechits)*Ecut
    if (poscastortowerarray[0][k] > sqrt(poscastorusedrechits[k].size())*towercut_) {
      
      fem = poscastortowerarray[1][k]/poscastortowerarray[0][k];
      CastorRecHitRefVector usedRecHits = poscastorusedrechits[k];
      ComputeTowerVariable(usedRecHits,Ehot,depth);

      LogDebug("CastorTowerProducer")
        <<"tower "<<k+1<<": fem = "<<fem<<" ,depth = "<<depth<<" ,Ehot = "<<Ehot<<std::endl;

      TowerPoint temptowerposition(rhoTower,5.9,poscastortowerarray[3][k]);
      Point towerposition(temptowerposition);

      CastorTower newtower(poscastortowerarray[0][k],towerposition,poscastortowerarray[1][k],poscastortowerarray[2][k],fem,depth,Ehot,
                           poscastorusedrechits[k]);
      OutputTowers->push_back(newtower);
    } // end select the positive towers with E > Ecut
    
    // select the negative towers with E > sqrt(Nusedrechits)*Ecut
    if (negcastortowerarray[0][k] > sqrt(negcastorusedrechits[k].size())*towercut_) {
      
      fem = negcastortowerarray[1][k]/negcastortowerarray[0][k];
      CastorRecHitRefVector usedRecHits = negcastorusedrechits[k];
      ComputeTowerVariable(usedRecHits,Ehot,depth);

      LogDebug("CastorTowerProducer")
         <<"tower "<<k+1 << " energy = " << negcastortowerarray[0][k] << "EM = " << negcastortowerarray[1][k] << "HAD = " << negcastortowerarray[2][k] << "phi = " << negcastortowerarray[3][k] << ": fem = "<<fem<<" ,depth = "<<depth<<" ,Ehot = "<<Ehot<<std::endl;

      TowerPoint temptowerposition(rhoTower,-5.9,negcastortowerarray[3][k]);
      Point towerposition(temptowerposition);

      CastorTower newtower(negcastortowerarray[0][k],towerposition,negcastortowerarray[1][k],negcastortowerarray[2][k],fem,depth,Ehot,
                           negcastorusedrechits[k]);
      OutputTowers->push_back(newtower);
    } // end select the negative towers with E > Ecut
    
  } // end loop over the 16 towers possibilities
  
  iEvent.put(OutputTowers);
} 

Member Data Documentation

std::string CastorTowerProducer::input_ [private]

Definition at line 70 of file CastorTowerProducer.cc.

Referenced by produce().

Definition at line 73 of file CastorTowerProducer.cc.

Referenced by produce().

Definition at line 72 of file CastorTowerProducer.cc.

Referenced by produce().

Definition at line 71 of file CastorTowerProducer.cc.

Referenced by produce().