CMS 3D CMS Logo

ShallowSimhitClustersProducer.cc
Go to the documentation of this file.
2 
5 
17 #include "boost/foreach.hpp"
18 
20  : clusters_token_( consumes< edmNew::DetSetVector<SiStripCluster> >(iConfig.getParameter<edm::InputTag>("Clusters"))),
21  Prefix( iConfig.getParameter<std::string>("Prefix") ),
22  runningmode_( iConfig.getParameter<std::string>("runningMode") )
23 {
24  std::vector<edm::InputTag> simhits_tags = iConfig.getParameter<std::vector<edm::InputTag> >("InputTags");
25  for(auto itag : simhits_tags) {
26  simhits_tokens_.push_back(
27  consumes< std::vector<PSimHit> >(itag)
28  );
29  }
30 
31  produces <std::vector<unsigned> > ( Prefix + "hits" );
32  produces <std::vector<float> > ( Prefix + "strip" );
33  produces <std::vector<float> > ( Prefix + "localtheta" );
34  produces <std::vector<float> > ( Prefix + "localphi" );
35  produces <std::vector<float> > ( Prefix + "localx" );
36  produces <std::vector<float> > ( Prefix + "localy" );
37  produces <std::vector<float> > ( Prefix + "localz" );
38  produces <std::vector<float> > ( Prefix + "momentum" );
39  produces <std::vector<float> > ( Prefix + "energyloss" );
40  produces <std::vector<float> > ( Prefix + "time" );
41  produces <std::vector<int> > ( Prefix + "particle" );
42  produces <std::vector<unsigned short> > ( Prefix + "process" );
43 }
44 
48 
49  int size = clustermap.size();
50  auto hits = std::make_unique <std::vector<unsigned>> (size, 0);
51  auto strip = std::make_unique <std::vector<float>> (size, -100);
52  auto localtheta = std::make_unique <std::vector<float>> (size, -100);
53  auto localphi = std::make_unique <std::vector<float>> (size, -100);
54  auto localx = std::make_unique <std::vector<float>> (size, -100);
55  auto localy = std::make_unique <std::vector<float>> (size, -100);
56  auto localz = std::make_unique <std::vector<float>> (size, -100);
57  auto momentum = std::make_unique <std::vector<float>> (size, 0);
58  auto energyloss = std::make_unique <std::vector<float>> (size, -1);
59  auto time = std::make_unique <std::vector<float>> (size, -1);
60  auto particle = std::make_unique <std::vector<int>> (size, -500);
61  auto process = std::make_unique <std::vector<unsigned short>> (size, 0);
62 
63  edm::ESHandle<TrackerGeometry> theTrackerGeometry; iSetup.get<TrackerDigiGeometryRecord>().get( theTrackerGeometry );
64  edm::ESHandle<MagneticField> magfield; iSetup.get<IdealMagneticFieldRecord>().get(magfield);
66  edm::Handle<edmNew::DetSetVector<SiStripCluster> > clusters; iEvent.getByLabel("siStripClusters", "", clusters);
67 
68  for(auto& simhit_token : simhits_tokens_) {
70  iEvent.getByToken(simhit_token, simhits);
71  BOOST_FOREACH( const PSimHit hit, *simhits ) {
72 
73  const uint32_t id = hit.detUnitId();
74  const StripGeomDetUnit* theStripDet = dynamic_cast<const StripGeomDetUnit*>( theTrackerGeometry->idToDet( id ) );
75  const LocalVector drift = shallow::drift(theStripDet, *magfield, *SiStripLorentzAngle);
76 
77  const float driftedstrip_ = theStripDet->specificTopology().strip( hit.localPosition()+0.5*drift );
78  const float hitstrip_ = theStripDet->specificTopology().strip( hit.localPosition() );
79 
80  shallow::CLUSTERMAP::const_iterator cluster = match_cluster( id, driftedstrip_, clustermap, *clusters);
81  if(cluster != clustermap.end()) {
82  unsigned i = cluster->second;
83  hits->at(i)+=1;
84  if(hits->at(i) == 1) {
85  strip->at(i) = hitstrip_;
86  localtheta->at(i) = hit.thetaAtEntry();
87  localphi->at(i) = hit.phiAtEntry();
88  localx->at(i) = hit.localPosition().x();
89  localy->at(i) = hit.localPosition().y();
90  localz->at(i) = hit.localPosition().z();
91  momentum->at(i) = hit.pabs();
92  energyloss->at(i) = hit.energyLoss();
93  time->at(i) = hit.timeOfFlight();
94  particle->at(i) = hit.particleType();
95  process->at(i) = hit.processType();
96  }
97  }
98  }
99  }
100 
101  iEvent.put(std::move(hits), Prefix + "hits" );
102  iEvent.put(std::move(strip), Prefix + "strip" );
103  iEvent.put(std::move(localtheta), Prefix + "localtheta" );
104  iEvent.put(std::move(localphi), Prefix + "localphi" );
105  iEvent.put(std::move(localx), Prefix + "localx" );
106  iEvent.put(std::move(localy), Prefix + "localy" );
107  iEvent.put(std::move(localz), Prefix + "localz" );
108  iEvent.put(std::move(momentum), Prefix + "momentum" );
109  iEvent.put(std::move(energyloss), Prefix + "energyloss" );
110  iEvent.put(std::move(time), Prefix + "time" );
111  iEvent.put(std::move(particle), Prefix + "particle" );
112  iEvent.put(std::move(process), Prefix + "process" );
113 }
114 
115 shallow::CLUSTERMAP::const_iterator ShallowSimhitClustersProducer::
116 match_cluster( const unsigned& id, const float& strip_, const shallow::CLUSTERMAP& clustermap, const edmNew::DetSetVector<SiStripCluster>& clusters) const {
117  shallow::CLUSTERMAP::const_iterator cluster = clustermap.end();
118  edmNew::DetSetVector<SiStripCluster>::const_iterator clustersDetSet = clusters.find(id);
119  if( clustersDetSet != clusters.end() ) {
120  edmNew::DetSet<SiStripCluster>::const_iterator left, right=clustersDetSet->begin();
121  while( right != clustersDetSet->end() && strip_ > right->barycenter() )
122  right++;
123  left = right-1;
124  if(right!=clustersDetSet->end() && right!=clustersDetSet->begin()) {
125  unsigned firstStrip = (right->barycenter()-strip_) < (strip_-left->barycenter()) ? right->firstStrip() : left->firstStrip();
126  cluster = clustermap.find( std::make_pair( id, firstStrip));
127  }
128  else if(right != clustersDetSet->begin())
129  cluster = clustermap.find( std::make_pair( id, left->firstStrip()));
130  else
131  cluster = clustermap.find( std::make_pair( id, right->firstStrip()));
132  }
133  return cluster;
134 }
135 
size
Write out results.
T getParameter(std::string const &) const
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
const_iterator end(bool update=false) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
shallow::CLUSTERMAP::const_iterator match_cluster(const unsigned &, const float &, const shallow::CLUSTERMAP &, const edmNew::DetSetVector< SiStripCluster > &) const
Geom::Theta< float > thetaAtEntry() const
fast and more accurate access to momentumAtEntry().theta()
Definition: PSimHit.h:57
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
LocalVector drift(const StripGeomDetUnit *, const MagneticField &, const SiStripLorentzAngle &)
Definition: ShallowTools.cc:38
T y() const
Definition: PV3DBase.h:63
virtual float strip(const LocalPoint &) const =0
data_type const * const_iterator
Definition: DetSetNew.h:30
virtual const StripTopology & specificTopology() const
Returns a reference to the strip proxy topology.
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
int iEvent
Definition: GenABIO.cc:230
float timeOfFlight() const
Definition: PSimHit.h:69
Local3DPoint localPosition() const
Definition: PSimHit.h:44
ShallowSimhitClustersProducer(const edm::ParameterSet &)
T z() const
Definition: PV3DBase.h:64
const edm::EDGetTokenT< edmNew::DetSetVector< SiStripCluster > > clusters_token_
float pabs() const
fast and more accurate access to momentumAtEntry().mag()
Definition: PSimHit.h:63
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:535
void produce(edm::Event &, const edm::EventSetup &) override
unsigned short processType() const
Definition: PSimHit.h:118
const_iterator find(id_type i, bool update=false) const
CLUSTERMAP make_cluster_map(const edm::Event &, const edm::EDGetTokenT< edmNew::DetSetVector< SiStripCluster > > &)
Definition: ShallowTools.cc:14
float energyLoss() const
The energy deposit in the PSimHit, in ???.
Definition: PSimHit.h:75
HLT enums.
int particleType() const
Definition: PSimHit.h:85
std::map< std::pair< uint32_t, uint16_t >, unsigned int > CLUSTERMAP
Definition: ShallowTools.h:19
T get() const
Definition: EventSetup.h:63
Geom::Phi< float > phiAtEntry() const
fast and more accurate access to momentumAtEntry().phi()
Definition: PSimHit.h:60
T x() const
Definition: PV3DBase.h:62
std::vector< edm::EDGetTokenT< std::vector< PSimHit > > > simhits_tokens_
def move(src, dest)
Definition: eostools.py:510
const_iterator begin(bool update=false) const
unsigned int detUnitId() const
Definition: PSimHit.h:93