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