CMS 3D CMS Logo

TrackClusterRemover Class Reference

Inheritance diagram for TrackClusterRemover:

edm::EDProducer edm::ProducerBase edm::ProductRegistryHelper

List of all members.

Public Member Functions

void produce (edm::Event &iEvent, const edm::EventSetup &iSetup)
 TrackClusterRemover (const edm::ParameterSet &iConfig)
 ~TrackClusterRemover ()

Private Member Functions

template<typename T>
std::auto_ptr
< edmNew::DetSetVector< T > > 
cleanup (const edmNew::DetSetVector< T > &oldClusters, const std::vector< uint8_t > &isGood, reco::ClusterRemovalInfo::Indices &refs, const reco::ClusterRemovalInfo::Indices *oldRefs)
void mergeOld (reco::ClusterRemovalInfo::Indices &refs, const reco::ClusterRemovalInfo::Indices &oldRefs)
void process (const SiStripRecHit2D *hit2D, uint32_t subdet)
void process (const TrackingRecHit *hit, float chi2)
void readPSet (const edm::ParameterSet &iConfig, const std::string &name, int id1=-1, int id2=-1, int id3=-1, int id4=-1, int id5=-1, int id6=-1)

Private Attributes

bool mergeOld_
edm::InputTag oldRemovalInfo_
ParamBlock pblocks_ [NumberOfParamBlocks]
edm::InputTag pixelClusters_
std::vector< uint8_t > pixels
edm::ProductID pixelSourceProdID
edm::InputTag stripClusters_
std::vector< uint8_t > strips
edm::ProductID stripSourceProdID
edm::InputTag trajectories_

Static Private Attributes

static const unsigned int NumberOfParamBlocks = 6

Classes

struct  ParamBlock


Detailed Description

Definition at line 32 of file TrackClusterRemover.cc.


Constructor & Destructor Documentation

TrackClusterRemover::TrackClusterRemover ( const edm::ParameterSet iConfig  ) 

Definition at line 100 of file TrackClusterRemover.cc.

References Exception, edm::pset::fill(), i, NumberOfParamBlocks, pblocks_, and readPSet().

00100                                                                    :
00101     trajectories_(iConfig.getParameter<InputTag>("trajectories")),
00102     stripClusters_(iConfig.getParameter<InputTag>("stripClusters")),
00103     pixelClusters_(iConfig.getParameter<InputTag>("pixelClusters")),
00104     mergeOld_(iConfig.exists("oldClusterRemovalInfo")),
00105     oldRemovalInfo_(mergeOld_ ? iConfig.getParameter<InputTag>("oldClusterRemovalInfo") : InputTag("NONE"))
00106 {
00107     produces< edmNew::DetSetVector<SiPixelCluster> >();
00108     produces< edmNew::DetSetVector<SiStripCluster> >();
00109     produces< ClusterRemovalInfo >();
00110 
00111     fill(pblocks_, pblocks_+NumberOfParamBlocks, ParamBlock());
00112     readPSet(iConfig, "Common",-1);
00113     readPSet(iConfig, "Pixel" ,0,1);
00114     readPSet(iConfig, "PXB" ,0);
00115     readPSet(iConfig, "PXE" ,1);
00116     readPSet(iConfig, "Strip" ,2,3,4,5);
00117     readPSet(iConfig, "StripInner" ,2,3);
00118     readPSet(iConfig, "StripOuter" ,4,5);
00119     readPSet(iConfig, "TIB" ,2);
00120     readPSet(iConfig, "TID" ,3);
00121     readPSet(iConfig, "TOB" ,4);
00122     readPSet(iConfig, "TEC" ,5);
00123 
00124     bool usingCharge = false;
00125     for (size_t i = 0; i < NumberOfParamBlocks; ++i) {
00126         if (!pblocks_[i].isSet_) throw cms::Exception("Configuration Error") << "TrackClusterRemover: Missing configuration for detector with subDetID = " << (i+1);
00127         if (pblocks_[i].usesCharge_ && !usingCharge) {
00128             throw cms::Exception("Configuration Error") << "TrackClusterRemover: Configuration for subDetID = " << (i+1) << " uses cluster charge, which is not enabled.";
00129         }
00130     }
00131 }

TrackClusterRemover::~TrackClusterRemover (  ) 

Definition at line 134 of file TrackClusterRemover.cc.

00135 {
00136 }


Member Function Documentation

template<typename T>
auto_ptr< edmNew::DetSetVector< T > > TrackClusterRemover::cleanup ( const edmNew::DetSetVector< T > &  oldClusters,
const std::vector< uint8_t > &  isGood,
reco::ClusterRemovalInfo::Indices refs,
const reco::ClusterRemovalInfo::Indices oldRefs 
) [inline, private]

Definition at line 149 of file TrackClusterRemover.cc.

References edmNew::DetSetVector< T >::begin(), edmNew::DetSetVector< T >::data(), edmNew::DetSetVector< T >::dataSize(), edmNew::DetSetVector< T >::end(), index, it, mergeOld(), output(), and edmNew::DetSetVector< T >::size().

Referenced by produce().

00150                                                                                                                    {  
00151     typedef typename edmNew::DetSetVector<T>             DSV;
00152     typedef typename edmNew::DetSetVector<T>::FastFiller DSF;
00153     typedef typename edmNew::DetSet<T>                   DS;
00154     auto_ptr<DSV> output(new DSV());
00155     output->reserve(oldClusters.size(), oldClusters.dataSize());
00156 
00157     // cluster removal loop
00158     const T * firstOffset = & oldClusters.data().front();
00159     for (typename DSV::const_iterator itdet = oldClusters.begin(), enddet = oldClusters.end(); itdet != enddet; ++itdet) {
00160         DS oldDS = *itdet;
00161 
00162         if (oldDS.empty()) continue; // skip empty detsets
00163 
00164         uint32_t id = oldDS.detId();
00165         DSF outds(*output, id);
00166 
00167         for (typename DS::const_iterator it = oldDS.begin(), ed = oldDS.end(); it != ed; ++it) {
00168             uint32_t index = ((&*it) - firstOffset);
00169             if (isGood[index]) { 
00170                 outds.push_back(*it);
00171                 refs.push_back(index); 
00172                 //std::cout << "TrackClusterRemover::cleanup " << typeid(T).name() << " reference " << index << " to " << (refs.size() - 1) << std::endl;
00173             }
00174         }
00175         if (outds.empty()) outds.abort(); // not write in an empty DSV
00176     }
00177     if (oldRefs != 0) mergeOld(refs, *oldRefs);
00178     return output;
00179 }

void TrackClusterRemover::mergeOld ( reco::ClusterRemovalInfo::Indices refs,
const reco::ClusterRemovalInfo::Indices oldRefs 
) [private]

Referenced by cleanup().

void TrackClusterRemover::process ( const SiStripRecHit2D hit2D,
uint32_t  subdet 
) [inline, private]

Definition at line 181 of file TrackClusterRemover.cc.

References SiStripRecHit2D::cluster(), edm::Ref< C, T, F >::id(), edm::Ref< C, T, F >::key(), TrackClusterRemover::ParamBlock::maxSize_, pblocks_, strips, and stripSourceProdID.

00181                                                                              {
00182     SiStripRecHit2D::ClusterRef cluster = hit->cluster();
00183 
00184     if (cluster.id() != stripSourceProdID) throw cms::Exception("Inconsistent Data") << 
00185             "TrackClusterRemover: strip cluster ref from Product ID = " << cluster.id() << 
00186             " does not match with source cluster collection (ID = " << stripSourceProdID << ")\n.";
00187 
00188     assert(cluster.id() == stripSourceProdID);
00189     if (pblocks_[subdet-1].usesSize_ && (cluster->amplitudes().size() > pblocks_[subdet-1].maxSize_)) return;
00190 
00191 //DBG// cout << "Individual HIT " << cluster.key().first << ", INDEX = " << cluster.key().second << endl;
00192     strips[cluster.key()] = false;
00193 }

void TrackClusterRemover::process ( const TrackingRecHit hit,
float  chi2 
) [inline, private]

Definition at line 195 of file TrackClusterRemover.cc.

References SiPixelRecHit::cluster(), Exception, TrackingRecHit::geographicalId(), edm::Ref< C, T, F >::id(), edm::Ref< C, T, F >::key(), TrackClusterRemover::ParamBlock::maxSize_, SiStripMatchedRecHit2D::monoHit(), NumberOfParamBlocks, ProjectedSiStripRecHit2D::originalHit(), pblocks_, PixelSubdetector::PixelBarrel, PixelSubdetector::PixelEndcap, pixels, pixelSourceProdID, projHit, DetId::rawId(), SiStripMatchedRecHit2D::stereoHit(), and DetId::subdetId().

Referenced by produce().

00195                                                                        {
00196     DetId detid = hit->geographicalId(); 
00197     uint32_t subdet = detid.subdetId();
00198 
00199     assert ((subdet > 0) && (subdet <= NumberOfParamBlocks));
00200 
00201     // chi2 cut
00202     if (chi2 > pblocks_[subdet-1].maxChi2_) return;
00203 
00204     if ((subdet == PixelSubdetector::PixelBarrel) || (subdet == PixelSubdetector::PixelEndcap)) {
00205         // this is a pixel, and i *know* it is
00206         const SiPixelRecHit *pixelHit = static_cast<const SiPixelRecHit *>(hit);
00207 
00208         SiPixelRecHit::ClusterRef cluster = pixelHit->cluster();
00209 
00210         if (cluster.id() != pixelSourceProdID) throw cms::Exception("Inconsistent Data") << 
00211                 "TrackClusterRemover: pixel cluster ref from Product ID = " << cluster.id() << 
00212                 " does not match with source cluster collection (ID = " << pixelSourceProdID << ")\n.";
00213 
00214         assert(cluster.id() == pixelSourceProdID);
00215 //DBG// cout << "HIT NEW PIXEL DETID = " << detid.rawId() << ", Cluster [ " << cluster.key().first << " / " <<  cluster.key().second << " ] " << endl;
00216 
00217         // if requested, cut on cluster size
00218         if (pblocks_[subdet-1].usesSize_ && (cluster->pixels().size() > pblocks_[subdet-1].maxSize_)) return;
00219 
00220         // mark as used
00221         pixels[cluster.key()] = false;
00222     } else { // aka Strip
00223 #define HIT_SPLITTING_TYPEID
00224 #if defined(ASSUME_HIT_SPLITTING)
00225         const SiStripRecHit2D *stripHit = static_cast<const SiStripRecHit2D *>(hit);
00226         process(stripHit,subdet);
00227 #elif defined(HIT_SPLITTING_TYPEID)
00228         const type_info &hitType = typeid(*hit);
00229         if (hitType == typeid(SiStripRecHit2D)) {
00230             const SiStripRecHit2D *stripHit = static_cast<const SiStripRecHit2D *>(hit);
00231 //DBG//     cout << "Plain RecHit 2D: " << endl;
00232             process(stripHit,subdet);
00233         } else if (hitType == typeid(SiStripMatchedRecHit2D)) {
00234             const SiStripMatchedRecHit2D *matchHit = static_cast<const SiStripMatchedRecHit2D *>(hit);
00235 //DBG//     cout << "Matched RecHit 2D: " << endl;
00236             process(matchHit->monoHit(),subdet);
00237             process(matchHit->stereoHit(),subdet);
00238         } else if (hitType == typeid(ProjectedSiStripRecHit2D)) {
00239             const ProjectedSiStripRecHit2D *projHit = static_cast<const ProjectedSiStripRecHit2D *>(hit);
00240 //DBG//     cout << "Projected RecHit 2D: " << endl;
00241             process(&projHit->originalHit(),subdet);
00242         } else throw cms::Exception("NOT IMPLEMENTED") << "Don't know how to handle " << hitType.name() << " on detid " << detid.rawId() << "\n";
00243 #else 
00244         //TODO: optimize using layer info to do the correct dyn_cast ?
00245         if (const SiStripRecHit2D *stripHit = dynamic_cast<const SiStripRecHit2D *>(hit)) {
00246 //DBG//     cout << "Plain RecHit 2D: " << endl;
00247             process(stripHit,subdet);
00248         } else if (const SiStripMatchedRecHit2D *matchHit = dynamic_cast<const SiStripMatchedRecHit2D *>(hit)) {
00249 //DBG//     cout << "Matched RecHit 2D: " << endl;
00250             process(matchHit->monoHit(),subdet);
00251             process(matchHit->stereoHit(),subdet);
00252         } else if (const ProjectedSiStripRecHit2D *projHit = dynamic_cast<const ProjectedSiStripRecHit2D *>(hit)) {
00253 //DBG//     cout << "Projected RecHit 2D: " << endl;
00254             process(&projHit->originalHit(),subdet);
00255         } else throw cms::Exception("NOT IMPLEMENTED") << "Don't know how to handle " << typeid(*hit).name() << " on detid " << detid.rawId() << "\n";
00256 #endif
00257     }

void TrackClusterRemover::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
) [virtual]

Implements edm::EDProducer.

Definition at line 271 of file TrackClusterRemover.cc.

References cleanup(), edm::InputTag::encode(), Exception, edm::pset::fill(), edm::Event::getByLabel(), edm::OrphanHandle< T >::id(), edm::Handle< T >::id(), TrackingRecHit::isValid(), it, Trajectory::measurements(), mergeOld_, oldRemovalInfo_, pixelClusters_, pixels, pixelSourceProdID, process(), edm::Event::put(), stripClusters_, strips, stripSourceProdID, and trajectories_.

00273 {
00274     ProductID pixelOldProdID, stripOldProdID;
00275 
00276     Handle<edmNew::DetSetVector<SiPixelCluster> > pixelClusters;
00277     iEvent.getByLabel(pixelClusters_, pixelClusters);
00278     pixelSourceProdID = pixelClusters.id();
00279 //DBG// std::cout << "TrackClusterRemover: Read pixel " << pixelClusters_.encode() << " = ID " << pixelSourceProdID << std::endl;
00280 
00281     Handle<edmNew::DetSetVector<SiStripCluster> > stripClusters;
00282     iEvent.getByLabel(stripClusters_, stripClusters);
00283     stripSourceProdID = stripClusters.id();
00284 //DBG// std::cout << "TrackClusterRemover: Read strip " << stripClusters_.encode() << " = ID " << stripSourceProdID << std::endl;
00285 
00286     Handle<ClusterRemovalInfo> oldRemovalInfo;
00287     if (mergeOld_) { 
00288         iEvent.getByLabel(oldRemovalInfo_, oldRemovalInfo); 
00289         // Check ProductIDs
00290         if ( (oldRemovalInfo->stripNewProdID() == stripClusters.id()) &&
00291              (oldRemovalInfo->pixelNewProdID() == pixelClusters.id()) ) {
00292 
00293             pixelOldProdID = oldRemovalInfo->pixelProdID();
00294             stripOldProdID = oldRemovalInfo->stripProdID();
00295 
00296             // if Hits in the Trajectory are already rekeyed you need the following
00297             //    pixelSourceProdID = oldRemovalInfo->pixelProdID();
00298             //    stripSourceProdID = oldRemovalInfo->stripProdID();
00299             // but also some other parts of the index logic must be changed
00300         } else {
00301             throw cms::Exception("Inconsistent Data") << "TrackClusterRemover: " <<
00302                 "Input collection product IDs are [pixel: " << pixelClusters.id() << ", strip: " << stripClusters.id() << "] \n" <<
00303                 "\t but the *old* ClusterRemovalInfo " << oldRemovalInfo_.encode() << " refers as 'new product ids' to " <<
00304                     "[pixel: " << oldRemovalInfo->pixelNewProdID() << ", strip: " << oldRemovalInfo->stripNewProdID() << "]\n" << 
00305                 "NOTA BENE: when running TrackClusterRemover with an old ClusterRemovalInfo the hits in the trajectory MUST be already re-keyed.\n";
00306         }
00307     } else { // then Old == Source
00308         pixelOldProdID = pixelSourceProdID;
00309         stripOldProdID = stripSourceProdID;
00310     }
00311 
00312     //Handle<TrajTrackAssociationCollection> trajectories; 
00313     Handle<vector<Trajectory> > trajectories; 
00314     iEvent.getByLabel(trajectories_, trajectories);
00315 
00316     strips.resize(stripClusters->dataSize()); fill(strips.begin(), strips.end(), true);
00317     pixels.resize(pixelClusters->dataSize()); fill(pixels.begin(), pixels.end(), true);
00318 
00319     //for (TrajTrackAssociationCollection::const_iterator it = trajectories->begin(), ed = trajectories->end(); it != ed; ++it)  {
00320     //    const Trajectory &tj = * it->key;
00321     for (vector<Trajectory>::const_iterator it = trajectories->begin(), ed = trajectories->end(); it != ed; ++it)  {
00322         const Trajectory &tj = * it;
00323         const vector<TrajectoryMeasurement> &tms = tj.measurements();
00324         vector<TrajectoryMeasurement>::const_iterator itm, endtm;
00325         for (itm = tms.begin(), endtm = tms.end(); itm != endtm; ++itm) {
00326             const TrackingRecHit *hit = itm->recHit()->hit();
00327             if (!hit->isValid()) continue; 
00328             process( hit, itm->estimate() );
00329         }
00330     }
00331 
00332     auto_ptr<ClusterRemovalInfo> cri(new ClusterRemovalInfo(pixelOldProdID, stripOldProdID));
00333     auto_ptr<edmNew::DetSetVector<SiPixelCluster> > newPixelClusters = cleanup(*pixelClusters, pixels, 
00334                 cri->pixelIndices(), mergeOld_ ? &oldRemovalInfo->pixelIndices() : 0);
00335     auto_ptr<edmNew::DetSetVector<SiStripCluster> > newStripClusters = cleanup(*stripClusters, strips, 
00336                 cri->stripIndices(), mergeOld_ ? &oldRemovalInfo->stripIndices() : 0);
00337 
00338     OrphanHandle<edmNew::DetSetVector<SiPixelCluster> > newPixels = iEvent.put(newPixelClusters); 
00339     cri->setNewPixelProdID(newPixels.id());
00340 //DBG// std::cout << "TrackClusterRemover: Wrote pixel " << newPixels.id() << " from " << pixelSourceProdID << std::endl;
00341     OrphanHandle<edmNew::DetSetVector<SiStripCluster> > newStrips = iEvent.put(newStripClusters); 
00342     cri->setNewStripProdID(newStrips.id());
00343 //DBG// std::cout << "TrackClusterRemover: Wrote strip " << newStrips.id() << " from " << stripSourceProdID << std::endl;
00344 
00345     iEvent.put(cri);
00346 
00347     pixels.clear(); strips.clear(); 

void TrackClusterRemover::readPSet ( const edm::ParameterSet iConfig,
const std::string &  name,
int  id1 = -1,
int  id2 = -1,
int  id3 = -1,
int  id4 = -1,
int  id5 = -1,
int  id6 = -1 
) [private]

Definition at line 82 of file TrackClusterRemover.cc.

References edm::ParameterSet::exists(), edm::pset::fill(), edm::ParameterSet::getParameter(), NumberOfParamBlocks, and pblocks_.

Referenced by TrackClusterRemover().

00084 {
00085     if (iConfig.exists(name)) {
00086         ParamBlock pblock(iConfig.getParameter<ParameterSet>(name));
00087         if (id1 == -1) {
00088             fill(pblocks_, pblocks_+NumberOfParamBlocks, pblock);
00089         } else {
00090             pblocks_[id1] = pblock;
00091             if (id2 != -1) pblocks_[id2] = pblock;
00092             if (id3 != -1) pblocks_[id3] = pblock;
00093             if (id4 != -1) pblocks_[id4] = pblock;
00094             if (id5 != -1) pblocks_[id5] = pblock;
00095             if (id6 != -1) pblocks_[id6] = pblock;
00096         }
00097     }
00098 }


Member Data Documentation

bool TrackClusterRemover::mergeOld_ [private]

Definition at line 54 of file TrackClusterRemover.cc.

Referenced by produce().

const unsigned int TrackClusterRemover::NumberOfParamBlocks = 6 [static, private]

Definition at line 51 of file TrackClusterRemover.cc.

Referenced by process(), readPSet(), and TrackClusterRemover().

edm::InputTag TrackClusterRemover::oldRemovalInfo_ [private]

Definition at line 55 of file TrackClusterRemover.cc.

Referenced by produce().

ParamBlock TrackClusterRemover::pblocks_[NumberOfParamBlocks] [private]

Definition at line 57 of file TrackClusterRemover.cc.

Referenced by process(), readPSet(), and TrackClusterRemover().

edm::InputTag TrackClusterRemover::pixelClusters_ [private]

Definition at line 53 of file TrackClusterRemover.cc.

Referenced by produce().

std::vector<uint8_t> TrackClusterRemover::pixels [private]

Definition at line 61 of file TrackClusterRemover.cc.

Referenced by process(), and produce().

edm::ProductID TrackClusterRemover::pixelSourceProdID [private]

Definition at line 62 of file TrackClusterRemover.cc.

Referenced by process(), and produce().

edm::InputTag TrackClusterRemover::stripClusters_ [private]

Definition at line 53 of file TrackClusterRemover.cc.

Referenced by produce().

std::vector<uint8_t> TrackClusterRemover::strips [private]

Definition at line 61 of file TrackClusterRemover.cc.

Referenced by process(), and produce().

edm::ProductID TrackClusterRemover::stripSourceProdID [private]

Definition at line 62 of file TrackClusterRemover.cc.

Referenced by process(), and produce().

edm::InputTag TrackClusterRemover::trajectories_ [private]

Definition at line 53 of file TrackClusterRemover.cc.

Referenced by produce().


The documentation for this class was generated from the following file:
Generated on Tue Jun 9 18:34:00 2009 for CMSSW by  doxygen 1.5.4