CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiClusterTranslator.cc
Go to the documentation of this file.
1 
10 // SiTracker Gaussian Smearing
11 #include "SiClusterTranslator.h"
12 
13 // Geometry
23 
24 //CPEs
27 #include "FastPixelCPE.h"
28 #include "FastStripCPE.h"
29 
30 // Framework
37 
38 // Data Formats
45 
46 //for the SimHit
51 
52 // STL
53 #include <memory>
54 #include <string>
55 
57  fastTrackerClusterCollectionTag_(conf.getParameter<edm::InputTag>("fastTrackerClusterCollectionTag"))
58 {
59  produces<edmNew::DetSetVector<SiStripCluster> >();
60  produces<edmNew::DetSetVector<SiPixelCluster> >();
61  produces<edm::DetSetVector<StripDigiSimLink> >();
62  produces<edm::DetSetVector<PixelDigiSimLink> >();
63 }
64 
65 // Destructor
67 
68 void
70 
71  // Initialize the Tracker Geometry
73  es.get<TrackerDigiGeometryRecord> ().get (theGeometry);
74  geometry = &(*theGeometry);
75 }
76 
77 void
79 {
80  // Step A: Get Inputs (FastGSRecHit's)
82  e.getByLabel(fastTrackerClusterCollectionTag_, theFastClusters);
83 
85  es.get<TrackerDigiGeometryRecord>().get( tkgeom );
86  const TrackerGeometry &tracker(*tkgeom);
87 
89  es.get<TkPixelCPERecord>().get("FastPixelCPE",pixelCPE);
90  auto pixelcpe = pixelCPE->clone();
91  pixelcpe->clearParameters();
92 
94  es.get<TkStripCPERecord>().get("FastStripCPE", stripCPE);
95  auto stripcpe = stripCPE->clone();
96 
98  std::vector<const CrossingFrame<PSimHit> *> cf_simhitvec;
99  e.getByLabel("mix","famosSimHitsTrackerHits", cf_simhit);
100  cf_simhitvec.push_back(cf_simhit.product());
101 
102  std::auto_ptr<MixCollection<PSimHit> > allTrackerHits(new MixCollection<PSimHit>(cf_simhitvec));
103  int counter =0;
104 
105  //Clearing vector to hopefully make it run faster.
106  theNewSimHitList.clear();
107  thePixelDigiLinkVector.clear();
108  theStripDigiLinkVector.clear();
109 
110  for(MixCollection<PSimHit>::iterator it = allTrackerHits->begin(); it!= allTrackerHits->end();it++){
111  counter++;
112  theNewSimHitList.push_back(std::make_pair((*it), counter));
113  }
114 
115  // Step B: fill a temporary full Cluster collection from the fast Cluster collection
116  FastTrackerClusterCollection::const_iterator aCluster = theFastClusters->begin();
117  FastTrackerClusterCollection::const_iterator theLastHit = theFastClusters->end();
118  std::map< DetId, std::vector<SiPixelCluster> > temporaryPixelClusters;
119  std::map< DetId, std::vector<SiStripCluster> > temporaryStripClusters;
120 
121  //Clearing CPE maps from previous event.
122  stripcpe->clearParameters();
123  pixelcpe->clearParameters();
124 
125  int ClusterNum = 0;
126 
127  // loop on Fast GS Hits
128  for ( ; aCluster != theLastHit; ++aCluster ) {
129  ClusterNum++;
130 
131  //Finding SubDet Id of cluster: 1 & 2 = Pixel, 3 & 4 & 5 & 6 = Strip, >6 = ?
132  DetId det = aCluster->id();
133  unsigned int subdet = det.subdetId();
134  int sim_counter = 0;
135  for (std::vector<std::pair<PSimHit,int> >::const_iterator
136  simcount = theNewSimHitList.begin() ; simcount != theNewSimHitList.end(); simcount ++){
137  if((aCluster->simtrackId() == (int)(*simcount).first.trackId())&&(det.rawId() == (*simcount).first.detUnitId())&&(aCluster->eeId() == (*simcount).first.eventId().rawId()))
138  sim_counter = (*simcount).second;
139  }
140  if (sim_counter == 0) throw cms::Exception("SiClusterTranslator") << "No Matching SimHit found.";
141 
142  //Separating into Pixels and Strips
143 
144  //Pixel
145  if (subdet < 3) {
146  //Here is the hard part. From the position of the FastSim Cluster I need to figure out the Pixel location for the Cluster.
147  LocalPoint position = aCluster->localPosition();
148  LocalError error = aCluster->localPositionError();
149  //std::cout << "The pixel charge is " << aCluster->charge() << std::endl;
150  int charge = (int)(aCluster->charge() + 0.5);
151  //std::cout << "The pixel charge after integer conversion is " << charge << std::endl;
152 
153  //std::vector<int> digi_vec;
154  //while (charge > 255) {
155  //digi_vec.push_back(charge);
156  //charge -= 256;
157  //}
158  //digi_vec.push_back(charge);
159 
160  const GeomDetUnit * geoDet = tracker.idToDetUnit(det);
161  const PixelGeomDetUnit * pixelDet=(const PixelGeomDetUnit*)(geoDet);
162  const PixelTopology& topol=(const PixelTopology&)pixelDet->topology();
163 
164  //Out of pixel is float, but input of pixel is int. Hopeful it works...
165  std::pair<float,float> pixelPos_out = topol.pixel(position);
166  SiPixelCluster::PixelPos pixelPos((int)pixelPos_out.first, (int)pixelPos_out.second);
167 
168  //Filling Pixel CPE with information.
169  std::pair<int,int> row_col((int)pixelPos_out.first,(int)pixelPos_out.second);
170  pixelcpe->enterLocalParameters((unsigned int) det.rawId() , row_col, std::make_pair(position,error));
171 
172  unsigned int ch = PixelChannelIdentifier::pixelToChannel((int)pixelPos_out.first, (int)pixelPos_out.second);
173 
174  //Creating a new pixel cluster.
175  SiPixelCluster temporaryPixelCluster(pixelPos, charge);
176  temporaryPixelClusters[det].push_back(temporaryPixelCluster);
177 
178  //Making a PixelDigiSimLink.
179  edm::DetSet<PixelDigiSimLink> pixelDetSet;
180  pixelDetSet.id = det.rawId();
181  pixelDetSet.data.push_back(PixelDigiSimLink(ch,
182  aCluster->simtrackId(),
183  EncodedEventId(aCluster->eeId()),
184  1.0));
185  thePixelDigiLinkVector.push_back(pixelDetSet);
186  }
187 
188  //Strips
189  else if ((subdet > 2) && (subdet < 7)) {
190  //Getting pos/err info from the cluster
191  LocalPoint position = aCluster->localPosition();
192  LocalError error = aCluster->localPositionError();
193 
194  //Will have to make charge into ADC eventually...
195  uint16_t charge = (uint16_t)(aCluster->charge() + 0.5);
196 
197  //std::cout << "The charge is " << charge << std::endl;
198 
199  uint16_t strip_num = 0;
200  std::vector<uint16_t> digi_vec;
201  while (charge > 255) {
202  digi_vec.push_back(255);
203  charge -= 255;
204  }
205  if (charge > 0) digi_vec.push_back(charge);
206  //std::cout << "The digi_vec size is " << digi_vec.size() << std::endl;
207  //int totcharge = 0;
208  //for(int i = 0; i < digi_vec.size(); ++i) {
209  //totcharge += digi_vec[i];
210  //}
211  const GeomDetUnit * geoDet = tracker.idToDetUnit(det);
212  const StripGeomDetUnit * stripDet = (const StripGeomDetUnit*)(geoDet);
213 
214  //3 = TIB, 4 = TID, 5 = TOB, 6 = TEC
215  if((subdet == 3) || (subdet == 5)) {
216  const RectangularStripTopology& topol=(const RectangularStripTopology&)stripDet->type().topology();
217  strip_num = (uint16_t)topol.strip(position);
218  } else if ((subdet == 4) || (subdet == 6)) {
219  const RadialStripTopology& topol=(const RadialStripTopology&)stripDet->type().topology();
220  strip_num = (uint16_t)topol.strip(position);
221  }
222 
223  //Filling Strip CPE with info.
224  stripcpe->enterLocalParameters(det.rawId(), strip_num, std::make_pair(position,error));
225 
226  //Creating a new strip cluster
227  SiStripCluster temporaryStripCluster(det.rawId(), strip_num, digi_vec.begin(), digi_vec.end());
228  temporaryStripClusters[det].push_back(temporaryStripCluster);
229 
230  //Making a StripDigiSimLink
231  edm::DetSet<StripDigiSimLink> stripDetSet;
232  stripDetSet.id = det.rawId();
233  stripDetSet.data.push_back(StripDigiSimLink(strip_num,
234  aCluster->simtrackId(),
235  sim_counter,
236  EncodedEventId(aCluster->eeId()),
237  1.0));
238  theStripDigiLinkVector.push_back(stripDetSet);
239  }
240 
241  //?????
242  else {
243  throw cms::Exception("SiClusterTranslator") <<
244  "Trying to build a cluster that is not in the SiStripTracker or Pixels.\n";
245  }
246 
247  }//Cluster loop
248 
249  // Step C: from the temporary Cluster collections, create the real ones.
250 
251  //Pixels
252  std::auto_ptr<edmNew::DetSetVector<SiPixelCluster> >
253  siPixelClusterCollection(new edmNew::DetSetVector<SiPixelCluster>);
254  loadPixelClusters(temporaryPixelClusters, *siPixelClusterCollection);
255  std::auto_ptr<edm::DetSetVector<StripDigiSimLink> > stripoutputlink(new edm::DetSetVector<StripDigiSimLink>(theStripDigiLinkVector) );
256 
257 
258  //Strips
259  std::auto_ptr<edmNew::DetSetVector<SiStripCluster> >
260  siStripClusterCollection(new edmNew::DetSetVector<SiStripCluster>);
261  loadStripClusters(temporaryStripClusters, *siStripClusterCollection);
262  std::auto_ptr<edm::DetSetVector<PixelDigiSimLink> > pixeloutputlink(new edm::DetSetVector<PixelDigiSimLink>(thePixelDigiLinkVector) );
263 
264  // Step D: write output to file
265  e.put(siPixelClusterCollection);
266  e.put(siStripClusterCollection);
267  e.put(stripoutputlink);
268  e.put(pixeloutputlink);
269 }
270 
271 void
273  std::map<DetId,std::vector<SiStripCluster> >& theClusters,
274  edmNew::DetSetVector<SiStripCluster>& theClusterCollection) const
275 {
276  std::map<DetId,std::vector<SiStripCluster> >::const_iterator
277  it = theClusters.begin();
278  std::map<DetId,std::vector<SiStripCluster> >::const_iterator
279  lastDet = theClusters.end();
280  for( ; it != lastDet ; ++it ) {
281  edmNew::DetSetVector<SiStripCluster>::FastFiller cluster_col(theClusterCollection, it->first);
282 
283  std::vector<SiStripCluster>::const_iterator clust_it = it->second.begin();
284  std::vector<SiStripCluster>::const_iterator clust_end = it->second.end();
285  for( ; clust_it != clust_end ; ++clust_it) {
286  cluster_col.push_back(*clust_it);
287  }
288  }
289 }
290 
291 void
293  std::map<DetId,std::vector<SiPixelCluster> >& theClusters,
294  edmNew::DetSetVector<SiPixelCluster>& theClusterCollection) const
295 {
296 
297  std::map<DetId,std::vector<SiPixelCluster> >::const_iterator
298  it = theClusters.begin();
299  std::map<DetId,std::vector<SiPixelCluster> >::const_iterator
300  lastCluster = theClusters.end();
301  for( ; it != lastCluster ; ++it ) {
302  edmNew::DetSetVector<SiPixelCluster>::FastFiller spc(theClusterCollection, it->first);
303 
304  std::vector<SiPixelCluster>::const_iterator clust_it = it->second.begin();
305  std::vector<SiPixelCluster>::const_iterator clust_end = it->second.end();
306  for( ; clust_it != clust_end ; ++clust_it) {
307  spc.push_back(*clust_it);
308  }
309  }
310 }
virtual const Topology & topology() const
Returns a reference to the pixel proxy topology.
void push_back(data_type const &d)
std::vector< edm::DetSet< PixelDigiSimLink > > thePixelDigiLinkVector
const TrackerGeometry * geometry
virtual void produce(edm::Event &e, const edm::EventSetup &c) override
double charge(const std::vector< uint8_t > &Ampls)
static int position[TOTALCHAMBERS][3]
Definition: ReadPGInfo.cc:509
SiClusterTranslator(const edm::ParameterSet &conf)
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
edm::InputTag fastTrackerClusterCollectionTag_
virtual std::pair< float, float > pixel(const LocalPoint &p) const =0
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
void loadPixelClusters(std::map< DetId, std::vector< SiPixelCluster > > &theClusters, SiPixelClusterCollectionNew &theClusterCollection) const
std::vector< edm::DetSet< StripDigiSimLink > > theStripDigiLinkVector
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
tuple conf
Definition: dbtoconf.py:185
virtual float strip(const LocalPoint &) const =0
Definition: DetId.h:18
virtual const GeomDetType & type() const
const T & get() const
Definition: EventSetup.h:55
std::vector< std::pair< PSimHit, int > > theNewSimHitList
T const * product() const
Definition: Handle.h:81
virtual const Topology & topology() const =0
virtual const GeomDetUnit * idToDetUnit(DetId) const
Return the pointer to the GeomDetUnit corresponding to a given DetId.
collection_type data
Definition: DetSet.h:78
Pixel cluster – collection of neighboring pixels above threshold.
static std::atomic< unsigned int > counter
det_id_type id
Definition: DetSet.h:77
void loadStripClusters(std::map< DetId, std::vector< SiStripCluster > > &theClusters, edmNew::DetSetVector< SiStripCluster > &theClusterCollection) const
static int pixelToChannel(int row, int col)
Definition: Run.h:41
virtual void beginRun(edm::Run const &run, const edm::EventSetup &es) override