CMS 3D CMS Logo

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