CMS 3D CMS Logo

Public Member Functions | Private Attributes

UncleanSCRecoveryProducer Class Reference

#include <UncleanSCRecoveryProducer.h>

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

List of all members.

Public Member Functions

virtual void produce (edm::Event &, const edm::EventSetup &)
 UncleanSCRecoveryProducer (const edm::ParameterSet &ps)
 ~UncleanSCRecoveryProducer ()

Private Attributes

std::string bcCollection_
edm::InputTag cleanBcCollection_
edm::InputTag cleanScCollection_
std::string scCollection_
edm::InputTag uncleanBcCollection_
edm::InputTag uncleanScCollection_

Detailed Description

Definition at line 17 of file UncleanSCRecoveryProducer.h.


Constructor & Destructor Documentation

UncleanSCRecoveryProducer::UncleanSCRecoveryProducer ( const edm::ParameterSet ps)

Definition at line 39 of file UncleanSCRecoveryProducer.cc.

References bcCollection_, cleanBcCollection_, cleanScCollection_, edm::ParameterSet::getParameter(), scCollection_, AlCaHLTBitMon_QueryRunRegistry::string, uncleanBcCollection_, and uncleanScCollection_.

{

        // get the parameters
        // the cleaned collection:
        cleanBcCollection_ = ps.getParameter<edm::InputTag>("cleanBcCollection");
        cleanScCollection_ = ps.getParameter<edm::InputTag>("cleanScCollection");
        // the uncleaned collection
        uncleanBcCollection_ = ps.getParameter<edm::InputTag>("uncleanBcCollection");
        uncleanScCollection_ = ps.getParameter<edm::InputTag>("uncleanScCollection");
        // the names of the products to be produced:
        bcCollection_ = ps.getParameter<std::string>("bcCollection");
        scCollection_ = ps.getParameter<std::string>("scCollection");
        // the products:
        produces< reco::BasicClusterCollection >(bcCollection_);
        produces< reco::SuperClusterCollection >(scCollection_);


}
UncleanSCRecoveryProducer::~UncleanSCRecoveryProducer ( )

Definition at line 59 of file UncleanSCRecoveryProducer.cc.

{;}

Member Function Documentation

void UncleanSCRecoveryProducer::produce ( edm::Event evt,
const edm::EventSetup es 
) [virtual]

Implements edm::EDProducer.

Definition at line 61 of file UncleanSCRecoveryProducer.cc.

References bcCollection_, cleanScCollection_, reco::SuperCluster::clustersBegin(), reco::SuperCluster::clustersEnd(), reco::CaloCluster::common, reco::CaloCluster::energy(), reco::CaloCluster::eta(), edm::Event::getByLabel(), i, reco::CaloCluster::isInClean(), reco::CaloCluster::isInUnclean(), edm::HandleBase::isValid(), edm::OrphanHandleBase::isValid(), LogTrace, reco::CaloCluster::position(), edm::Handle< T >::product(), edm::PtrVector< T >::push_back(), edm::Event::put(), scCollection_, reco::SuperCluster::seed(), reco::CaloCluster::setFlags(), uncleanBcCollection_, reco::CaloCluster::uncleanOnly, and uncleanScCollection_.

{
        // __________________________________________________________________________
        //
        // cluster collections:
        edm::Handle<reco::BasicClusterCollection> pCleanBC;
        edm::Handle<reco::SuperClusterCollection> pCleanSC;
        //
        edm::Handle<reco::BasicClusterCollection> pUncleanBC;
        edm::Handle<reco::SuperClusterCollection> pUncleanSC;
        // clean collections ________________________________________________________
        evt.getByLabel(cleanScCollection_, pCleanSC);
        if (!(pCleanSC.isValid())) 
        {
                edm::LogWarning("MissingInput") << "could not handle clean super clusters";
                return;
        }
        const  reco::SuperClusterCollection cleanSC = *(pCleanSC.product());

        // unclean collections ______________________________________________________
        evt.getByLabel(uncleanBcCollection_, pUncleanBC);
        if (!(pUncleanBC.isValid())) 
        {
                edm::LogWarning("MissingInput") << "could not handle unclean Basic Clusters!";
                return;
        }
        const  reco::BasicClusterCollection uncleanBC = *(pUncleanBC.product());
        //
        evt.getByLabel(uncleanScCollection_, pUncleanSC);
        if (!(pUncleanSC.isValid())) 
        {

                edm::LogWarning("MissingInput") << "could not handle unclean super clusters!";
                return;
        }
        const  reco::SuperClusterCollection uncleanSC = *(pUncleanSC.product());
        int uncleanSize = pUncleanSC->size();
        int cleanSize =   pCleanSC->size();

        LogTrace("EcalCleaning")  << "Size of Clean Collection: " << cleanSize 
                << ", uncleanSize: " << uncleanSize;

        // collections are all taken now ____________________________________________
        //
        // the collections to be produced ___________________________________________
        reco::BasicClusterCollection basicClusters;
        reco::SuperClusterCollection superClusters;
        //
        //
        // collect all the basic clusters of the SC that belong to the unclean
        // collection and put them into the basicClusters vector
        // keep the information of which SC they belong to
        //
        // loop over the unclean sc: all SC will join the new collection
        std::vector< std::pair<int, int> > basicClusterOwner; // counting all

        std::vector<DetId> scUncleanSeedDetId;  // counting the unclean
        for (int isc =0; isc< uncleanSize; ++isc) {
                const reco::SuperCluster unsc = uncleanSC[isc];    
                scUncleanSeedDetId.push_back(unsc.seed()->seed());
                reco::CaloCluster_iterator bciter = unsc.clustersBegin();
                for (; bciter != unsc.clustersEnd(); ++bciter) {
                        // the basic clusters
                        basicClusters.push_back(**bciter);
                        // index of the unclean SC
                        basicClusterOwner.push_back( std::make_pair(isc,0) ); 
                }
        }
        // loop over the clean: only the ones which are in common with the unclean
        // are taken into account

        std::vector<DetId> scCleanSeedDetId;  // counting the clean
        std::vector<int> isToBeKept;
        for (int isc =0; isc< cleanSize; ++isc) {
                reco::SuperClusterRef cscRef( pCleanSC, isc );    
                scCleanSeedDetId.push_back(cscRef->seed()->seed());
                for (reco::CaloCluster_iterator bciter = cscRef->clustersBegin(); bciter != cscRef->clustersEnd(); ++bciter) {
                        // the basic clusters
                        basicClusters.push_back(**bciter);
                        // index of the clean SC
                        basicClusterOwner.push_back( std::make_pair(isc,1) ); 
                }
                if (cscRef->isInUnclean()) isToBeKept.push_back(1);
                else isToBeKept.push_back(0);
        }
        //
        // now export the basic clusters into the event and get them back
        std::auto_ptr< reco::BasicClusterCollection> basicClusters_p(new reco::BasicClusterCollection);
        basicClusters_p->assign(basicClusters.begin(), basicClusters.end());
        edm::OrphanHandle<reco::BasicClusterCollection> bccHandle =  
                evt.put(basicClusters_p, bcCollection_);
        if (!(bccHandle.isValid())) {

                edm::LogWarning("MissingInput") << "could not handle the new BasicClusters!";
                return;
        }
        reco::BasicClusterCollection basicClustersProd = *bccHandle;

        LogTrace("EcalCleaning") <<"Got the BasicClusters from the event again";
        int bcSize = bccHandle->size();
        //
        // now we can create the SC collection
        //
        // run over the unclean SC: all to be kept here
        for (int isc=0; isc< uncleanSize; ++isc) {
                reco::CaloClusterPtrVector clusterPtrVector;
                // the seed is the basic cluster with the highest energy
                reco::CaloClusterPtr seed; 
                for (int jbc=0; jbc< bcSize; ++jbc) {
                        std::pair<int,int> theBcOwner = basicClusterOwner[jbc];
                        if (theBcOwner.first == isc && theBcOwner.second == 0) {
                                reco::CaloClusterPtr currentClu=reco::CaloClusterPtr(bccHandle,jbc);
                                clusterPtrVector.push_back(currentClu);
                                if (scUncleanSeedDetId[isc] == currentClu->seed()) {
                                        seed = currentClu;
                                }
                        }
                }
                const reco::SuperCluster unsc = uncleanSC[isc]; 
                reco::SuperCluster newSC(unsc.energy(), unsc.position(), seed, clusterPtrVector );
                newSC.setFlags(reco::CaloCluster::uncleanOnly);
                superClusters.push_back(newSC);
        }
        // run over the clean SC: only those who are in common between the
        // clean and unclean collection are kept
        for (int isc=0; isc< cleanSize; ++isc) {
                reco::SuperClusterRef cscRef( pCleanSC, isc); 
                if (not cscRef->isInUnclean()) continue;
                reco::CaloClusterPtrVector clusterPtrVector;
                // the seed is the basic cluster with the highest energy
                reco::CaloClusterPtr seed; 
                for (int jbc=0; jbc< bcSize; ++jbc) {
                        std::pair<int,int> theBcOwner = basicClusterOwner[jbc];
                        if (theBcOwner.first == isc && theBcOwner.second == 1) {
                                reco::CaloClusterPtr currentClu=reco::CaloClusterPtr(bccHandle,jbc);
                                clusterPtrVector.push_back(currentClu);
                                if (scCleanSeedDetId[isc] == currentClu->seed()) {
                                        seed = currentClu;
                                }
                        }
                }
                reco::SuperCluster newSC(cscRef->energy(), cscRef->position(), 
                                         seed, clusterPtrVector );
                newSC.setFlags(reco::CaloCluster::common);
                superClusters.push_back(newSC);
        }

        std::auto_ptr< reco::SuperClusterCollection> 
                superClusters_p(new reco::SuperClusterCollection);
        superClusters_p->assign(superClusters.begin(), superClusters.end());

        evt.put(superClusters_p, scCollection_);

        LogTrace("EcalCleaning")<<"Clusters (Basic/Super) added to the Event! :-)";

        // ----- debugging ----------
        // print the new collection SC quantities
        // print out the clean collection SC
        LogTrace("EcalCleaning") << "Clean Collection SC ";
        for (int i=0; i < cleanSize; ++i) {
                const reco::SuperCluster csc = cleanSC[i];
                LogTrace("EcalCleaning") << " >>> clean    #" << i << "; Energy: " << csc.energy()
                        << " eta: " << csc.eta() 
                        << " sc seed detid: " << csc.seed()->seed().rawId();
        }
        // the unclean SC
        LogTrace("EcalCleaning") << "Unclean Collection SC ";
        for (int i=0; i < uncleanSize; ++i) {
                const reco::SuperCluster usc = uncleanSC[i];
                LogTrace("EcalCleaning") << " >>> unclean  #" << i << "; Energy: " << usc.energy()
                        << " eta: " << usc.eta() 
                        << " sc seed detid: " << usc.seed()->seed().rawId();
        }
        // the new collection
        LogTrace("EcalCleaning")<<"The new SC clean collection with size "<< superClusters.size();
        for (unsigned int i=0; i <  superClusters.size(); ++i) {
                const reco::SuperCluster nsc = superClusters[i];
                LogTrace("EcalCleaning")<< " >>> newSC    #" << i << "; Energy: " << nsc.energy()
                        << " eta: " << nsc.eta()  << " isClean=" 
                        << nsc.isInClean() << " isUnclean=" << nsc.isInUnclean()
                        << " sc seed detid: " << nsc.seed()->seed().rawId();
        }
}

Member Data Documentation

Definition at line 36 of file UncleanSCRecoveryProducer.h.

Referenced by produce(), and UncleanSCRecoveryProducer().

Definition at line 30 of file UncleanSCRecoveryProducer.h.

Referenced by UncleanSCRecoveryProducer().

Definition at line 31 of file UncleanSCRecoveryProducer.h.

Referenced by produce(), and UncleanSCRecoveryProducer().

Definition at line 37 of file UncleanSCRecoveryProducer.h.

Referenced by produce(), and UncleanSCRecoveryProducer().

Definition at line 33 of file UncleanSCRecoveryProducer.h.

Referenced by produce(), and UncleanSCRecoveryProducer().

Definition at line 34 of file UncleanSCRecoveryProducer.h.

Referenced by produce(), and UncleanSCRecoveryProducer().