CMS 3D CMS Logo

TkAlCaOverlapTagger.cc
Go to the documentation of this file.
6 
10 
14 
19 
25 
28 //#include <boost/regex.hpp>
29 
31  public:
32  TkAlCaOverlapTagger(const edm::ParameterSet &iConfig);
33  ~TkAlCaOverlapTagger() override;
34  void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override;
35 
36  private:
40  std::vector<unsigned int> BadModsList_;
41 
42 
43  int layerFromId (const DetId& id, const TrackerTopology* tTopo) const;
44 };
45 
47  src_( iConfig.getParameter<edm::InputTag>("src") ),
48  srcClust_( iConfig.getParameter<edm::InputTag>("Clustersrc") ),
49  rejectBadMods_( iConfig.getParameter<bool>("rejectBadMods")),
50  BadModsList_( iConfig.getParameter<std::vector<uint32_t> >("BadMods"))
51 {
52 
53  produces<AliClusterValueMap>(); //produces the ValueMap (VM) to be stored in the Event at the end
54 }
55 
57 
58 
60  //Retrieve tracker topology from geometry
62  iSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
63  const TrackerTopology* const tTopo = tTopoHandle.product();
64 
66  iEvent.getByLabel(src_, assoMap);
67  // cout<<"\n\n############################\n### Starting a new TkAlCaOverlapTagger - Ev "<<iEvent.id().run()<<", "<<iEvent.id().event()<<endl;
68 
69  AlignmentClusterFlag iniflag;
71  iEvent.getByLabel(srcClust_, pixelclusters);//same label as tracks
72  std::vector<AlignmentClusterFlag> pixelvalues(pixelclusters->dataSize(), iniflag);//vector where to store value to be fileld in the VM
73 
75  iEvent.getByLabel(srcClust_, stripclusters);//same label as tracks
76  std::vector<AlignmentClusterFlag> stripvalues(stripclusters->dataSize(), iniflag);//vector where to store value to be fileld in the VM
77 
78 
79 
80  //start doing the thing!
81 
82  //loop over trajectories
83  for (TrajTrackAssociationCollection::const_iterator itass = assoMap->begin(); itass != assoMap->end(); ++itass){
84 
85  int nOverlaps=0;
86  const edm::Ref<std::vector<Trajectory> >traj = itass->key;//trajectory in the collection
87  const Trajectory * myTrajectory= &(*traj);
88  std::vector<TrajectoryMeasurement> tmColl =myTrajectory->measurements();
89 
90  const reco::TrackRef tkref = itass->val;//associated track track in the collection
91  // const Track * trk = &(*tkref);
92  int hitcnt=-1;
93 
94  //loop over traj meas
95  const TrajectoryMeasurement* previousTM(nullptr);
96  DetId previousId(0);
97 
98  for(std::vector<TrajectoryMeasurement>::const_iterator itTrajMeas = tmColl.begin(); itTrajMeas!=tmColl.end(); ++itTrajMeas){
99  hitcnt++;
100 
101  if ( previousTM!=nullptr ) {
102  // std::cout<<"Checking TrajMeas ("<<hitcnt+1<<"):"<<std::endl;
103  if(!previousTM->recHit()->isValid()){
104  //std::cout<<"Previous RecHit invalid !"<<std::endl;
105  continue;}
106  //else std::cout<<"\nDetId: "<<std::flush<<previousTM->recHit()->geographicalId().rawId()<<"\t Local x of hit: "<<previousTM->recHit()->localPosition().x()<<std::endl;
107  }
108  else{
109  //std::cout<<"This is the first Traj Meas of the Trajectory! The Trajectory contains "<< tmColl.size()<<" TrajMeas"<<std::endl;
110  }
111 
112 
113  TrackingRecHit::ConstRecHitPointer hitpointer = itTrajMeas->recHit();
114  const TrackingRecHit *hit=&(* hitpointer);
115  if(!hit->isValid())continue;
116 
117  //std::cout << " hit number " << (ith - itt->recHits().begin()) << std::endl;
118  DetId detid = hit->geographicalId();
119  int layer(layerFromId(detid, tTopo));//layer 1-4=TIB, layer 5-10=TOB
120  int subDet = detid.subdetId();
121 
122  if ( ( previousTM!=nullptr )&& (layer!=-1 )) {
123  for (std::vector<TrajectoryMeasurement>::const_iterator itmCompare =itTrajMeas-1;itmCompare >= tmColl.begin() && itmCompare > itTrajMeas - 4;--itmCompare){
124  DetId compareId = itmCompare->recHit()->geographicalId();
125  if ( subDet != compareId.subdetId() || layer != layerFromId(compareId, tTopo)) break;
126  if (!itmCompare->recHit()->isValid()) continue;
127  if ( (subDet<=2) || (subDet > 2 && SiStripDetId(detid).stereo()==SiStripDetId(compareId).stereo())){//if either pixel or strip stereo module
128 
129  //
130  //WOW, we have an overlap!!!!!!
131  //
132  AlignmentClusterFlag hitflag(hit->geographicalId());
133  hitflag.SetOverlapFlag();
134  // cout<<"Overlap found in SubDet "<<subDet<<"!!!"<<flush;
135 
136  bool hitInStrip=(subDet==SiStripDetId::TIB) || (subDet==SiStripDetId::TID) ||(subDet==SiStripDetId::TOB) ||(subDet==SiStripDetId::TEC);
137  if (hitInStrip){
138  //cout<<" TypeId of the RecHit: "<<className(*hit)<<endl;
139  // const std::type_info &type = typeid(*hit);
140  const SiStripRecHit2D* transstriphit2D = dynamic_cast<const SiStripRecHit2D*>(hit);
141  const SiStripRecHit1D* transstriphit1D = dynamic_cast<const SiStripRecHit1D*>(hit);
142 
143  // if (type == typeid(SiStripRecHit1D)) {
144  if(transstriphit1D!=nullptr){
145  // const SiStripRecHit1D* striphit=dynamic_cast<const SiStripRecHit1D*>(hit);
146  const SiStripRecHit1D* striphit=transstriphit1D;
147  if(striphit!=nullptr){
148  SiStripRecHit1D::ClusterRef stripclust(striphit->cluster());
149 
150  if(stripclust.id()==stripclusters.id()){//ensure that the stripclust is really present in the original cluster collection!!!
151  stripvalues[stripclust.key()]=hitflag;
152  }
153  else{
154  edm::LogError("TkAlCaOverlapTagger")<<"ERROR in <TkAlCaOverlapTagger::produce>: ProdId of Strip clusters mismatched: "<<stripclust.id()<<" vs "<<stripclusters.id();
155  }
156  }
157  else{
158  edm::LogError("TkAlCaOverlapTagger")<<"ERROR in <TkAlCaOverlapTagger::produce>: Dynamic cast of Strip RecHit failed! TypeId of the RecHit: "<<className(*hit);
159  }
160  }//end if sistriprechit1D
161  else if(transstriphit2D!=nullptr){
162  //else if (type == typeid(SiStripRecHit2D)) {
163  // const SiStripRecHit2D* striphit=dynamic_cast<const SiStripRecHit2D*>(hit);
164  const SiStripRecHit2D* striphit=transstriphit2D;
165  if(striphit!=nullptr){
166  SiStripRecHit2D::ClusterRef stripclust(striphit->cluster());
167 
168  if(stripclust.id()==stripclusters.id()){//ensure that the stripclust is really present in the original cluster collection!!!
169  stripvalues[stripclust.key()]=hitflag;
170 
171  //cout<<">>> Storing in the ValueMap a StripClusterRef with Cluster.Key: "<<stripclust.key()<<" ("<<striphit->cluster().key() <<"), Cluster.Id: "<<stripclust.id()<<" (DetId is "<<hit->geographicalId().rawId()<<")"<<endl;
172  }
173  else{
174  edm::LogError("TkAlCaOverlapTagger")<<"ERROR in <TkAlCaOverlapTagger::produce>: ProdId of Strip clusters mismatched: "<<stripclust.id()<<" vs "<<stripclusters.id();
175  }
176 
177  // cout<<"Cluster baricentre: "<<stripclust->barycenter()<<endl;
178  }
179  else{
180  edm::LogError("TkAlCaOverlapTagger")<<"ERROR in <TkAlCaOverlapTagger::produce>: Dynamic cast of Strip RecHit failed! TypeId of the RecHit: "<<className(*hit);
181  }
182  }//end if Sistriprechit2D
183  else{
184  edm::LogError("TkAlCaOverlapTagger")<<"ERROR in <TkAlCaOverlapTagger::produce>: Impossible to determine the type of SiStripRecHit. TypeId of the RecHit: "<<className(*hit);
185  }
186 
187  }//end if hit in Strips
188  else {//pixel hit
189  const SiPixelRecHit* transpixelhit = dynamic_cast<const SiPixelRecHit*>(hit);
190  if(transpixelhit!=nullptr){
191  const SiPixelRecHit* pixelhit=transpixelhit;
192  SiPixelClusterRefNew pixclust(pixelhit->cluster());
193 
194  if(pixclust.id()==pixelclusters.id()){
195  pixelvalues[pixclust.key()]=hitflag;
196  //cout<<">>> Storing in the ValueMap a PixelClusterRef with ProdID: "<<pixclust.id()<<" (DetId is "<<hit->geographicalId().rawId()<<")" <<endl;//" and a Val with ID: "<<flag.id()<<endl;
197  }
198  else{
199  edm::LogError("TkAlCaOverlapTagger")<<"ERROR in <TkAlCaOverlapTagger::produce>: ProdId of Pixel clusters mismatched: "<<pixclust.id()<<" vs "<<pixelclusters.id();
200  }
201  }
202  else{
203  edm::LogError("TkAlCaOverlapTagger")<<"ERROR in <TkAlCaOverlapTagger::produce>: Dynamic cast of Pixel RecHit failed! TypeId of the RecHit: "<<className(*hit);
204  }
205  }//end 'else' it is a pixel hit
206 
207  nOverlaps++;
208  break;
209  }
210  }//end second loop on TM
211  }//end if a previous TM exists
212 
213  previousTM = &(* itTrajMeas);
214  previousId = detid;
215  }//end loop over traj meas
216  //std::cout<<"Found "<<nOverlaps<<" overlaps in this trajectory"<<std::endl;
217 
218  }//end loop over trajectories
219 
220 
221 
222  // prepare output
223  auto hitvalmap = std::make_unique<AliClusterValueMap>();
224  AliClusterValueMap::Filler mapfiller(*hitvalmap);
225 
226  edm::TestHandle<std::vector<AlignmentClusterFlag> > fakePixelHandle( &pixelvalues,pixelclusters.id());
227  mapfiller.insert(fakePixelHandle, pixelvalues.begin(), pixelvalues.end());
228 
229  edm::TestHandle<std::vector<AlignmentClusterFlag> > fakeStripHandle( &stripvalues,stripclusters.id());
230  mapfiller.insert(fakeStripHandle, stripvalues.begin(), stripvalues.end());
231  mapfiller.fill();
232 
233 
234 
235 
236 
237  // iEvent.put(std::move(stripmap));
238  iEvent.put(std::move(hitvalmap));
239 }//end TkAlCaOverlapTagger::produce
240 int TkAlCaOverlapTagger::layerFromId (const DetId& id, const TrackerTopology* tTopo) const
241 {
242  if ( uint32_t(id.subdetId())==PixelSubdetector::PixelBarrel ) {
243 
244  return tTopo->pxbLayer(id);
245  }
246  else if ( uint32_t(id.subdetId())==PixelSubdetector::PixelEndcap ) {
247 
248  return tTopo->pxfDisk(id) + (3*(tTopo->pxfSide(id)-1));
249  }
250  else if ( id.subdetId()==StripSubdetector::TIB ) {
251 
252  return tTopo->tibLayer(id);
253  }
254  else if ( id.subdetId()==StripSubdetector::TOB ) {
255 
256  return tTopo->tobLayer(id);
257  }
258  else if ( id.subdetId()==StripSubdetector::TEC ) {
259 
260  return tTopo->tecWheel(id) + (9*(tTopo->tecSide(id)-1));
261  }
262  else if ( id.subdetId()==StripSubdetector::TID ) {
263 
264  return tTopo->tidWheel(id) + (3*(tTopo->tidSide(id)-1));
265  }
266  return -1;
267 
268 }//end layerfromId
269 
270 // ========= MODULE DEF ==============
273 
ClusterRef cluster() const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
unsigned int tibLayer(const DetId &id) const
ConstRecHitPointer const & recHit() const
uint32_t stereo() const
Definition: SiStripDetId.h:163
const_iterator end() const
last iterator over the map (read only)
ProductID id() const
Definition: HandleBase.cc:15
unsigned int pxfDisk(const DetId &id) const
int layerFromId(const DetId &id, const TrackerTopology *tTopo) const
unsigned int tidWheel(const DetId &id) const
std::vector< unsigned int > BadModsList_
key_type key() const
Accessor for product key.
Definition: Ref.h:263
DataContainer const & measurements() const
Definition: Trajectory.h:196
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
unsigned int tidSide(const DetId &id) const
std::shared_ptr< TrackingRecHit const > ConstRecHitPointer
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:41
TkAlCaOverlapTagger(const edm::ParameterSet &iConfig)
ClusterRef cluster() const
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:480
unsigned int pxbLayer(const DetId &id) const
Detector identifier class for the strip tracker.
Definition: SiStripDetId.h:17
Definition: DetId.h:18
ClusterRef cluster() const
Definition: SiPixelRecHit.h:49
bool isValid() const
HLT enums.
T get() const
Definition: EventSetup.h:71
unsigned int pxfSide(const DetId &id) const
const_iterator begin() const
first iterator over the map (read only)
DetId geographicalId() const
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
unsigned int tecWheel(const DetId &id) const
T const * product() const
Definition: ESHandle.h:86
def move(src, dest)
Definition: eostools.py:511
std::string className(const T &t)
Definition: ClassName.h:30
unsigned int tobLayer(const DetId &id) const
unsigned int tecSide(const DetId &id) const
Our base class.
Definition: SiPixelRecHit.h:23