Go to the documentation of this file.00001 #include "FWCore/Framework/interface/EDProducer.h"
00002 #include "FWCore/Framework/interface/EventPrincipal.h"
00003 #include "FWCore/Framework/interface/Event.h"
00004 #include "FWCore/Framework/interface/EventSetup.h"
00005 #include "FWCore/Framework/interface/ESHandle.h"
00006
00007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00009 #include "FWCore/Utilities/interface/InputTag.h"
00010
00011 #include "DataFormats/Common/interface/View.h"
00012 #include "DataFormats/SiPixelDetId/interface/PXBDetId.h"
00013 #include "DataFormats/SiPixelDetId/interface/PXBDetId.h"
00014 #include "DataFormats/SiPixelDetId/interface/PXFDetId.h"
00015 #include "DataFormats/SiStripDetId/interface/TIBDetId.h"
00016 #include "DataFormats/SiStripDetId/interface/TIDDetId.h"
00017 #include "DataFormats/SiStripDetId/interface/TOBDetId.h"
00018 #include "DataFormats/SiStripDetId/interface/TECDetId.h"
00019
00020 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
00021 #include "DataFormats/TrackReco/interface/Track.h"
00022 #include "TrackingTools/PatternTools/interface/Trajectory.h"
00023 #include "TrackingTools/PatternTools/interface/TrajTrackAssociation.h"
00024
00025 #include "DataFormats/TrackerRecHit2D/interface/SiStripRecHit1D.h"
00026 #include "DataFormats/TrackerRecHit2D/interface/SiStripRecHit2D.h"
00027 #include "DataFormats/TrackerRecHit2D/interface/SiPixelRecHit.h"
00028 #include "RecoTracker/TransientTrackingRecHit/interface/TSiStripRecHit1D.h"
00029 #include "RecoTracker/TransientTrackingRecHit/interface/TSiStripRecHit2DLocalPos.h"
00030 #include "RecoTracker/TransientTrackingRecHit/interface/TSiPixelRecHit.h"
00031 #include "Utilities/General/interface/ClassName.h"
00032
00033 #include "DataFormats/Alignment/interface/AlignmentClusterFlag.h"
00034 #include "DataFormats/Alignment/interface/AliClusterValueMap.h"
00035
00036
00037 class TkAlCaOverlapTagger : public edm::EDProducer {
00038 public:
00039 TkAlCaOverlapTagger(const edm::ParameterSet &iConfig);
00040 ~TkAlCaOverlapTagger();
00041 void produce(edm::Event &iEvent, const edm::EventSetup &iSetup);
00042
00043 private:
00044 edm::InputTag src_;
00045 edm::InputTag srcClust_;
00046 bool rejectBadMods_;
00047 std::vector<unsigned int> BadModsList_;
00048
00049
00050 int layerFromId (const DetId& id) const;
00051 };
00052
00053 TkAlCaOverlapTagger::TkAlCaOverlapTagger(const edm::ParameterSet& iConfig):
00054 src_( iConfig.getParameter<edm::InputTag>("src") ),
00055 srcClust_( iConfig.getParameter<edm::InputTag>("Clustersrc") ),
00056 rejectBadMods_( iConfig.getParameter<bool>("rejectBadMods")),
00057 BadModsList_( iConfig.getParameter<std::vector<uint32_t> >("BadMods"))
00058 {
00059
00060 produces<AliClusterValueMap>();
00061 }
00062
00063 TkAlCaOverlapTagger::~TkAlCaOverlapTagger(){}
00064
00065
00066 void TkAlCaOverlapTagger::produce(edm::Event &iEvent, const edm::EventSetup &iSetup){
00067 edm::Handle<TrajTrackAssociationCollection> assoMap;
00068 iEvent.getByLabel(src_, assoMap);
00069
00070
00071 AlignmentClusterFlag iniflag;
00072 edm::Handle<edmNew::DetSetVector<SiPixelCluster> > pixelclusters;
00073 iEvent.getByLabel(srcClust_, pixelclusters);
00074 std::vector<AlignmentClusterFlag> pixelvalues(pixelclusters->dataSize(), iniflag);
00075
00076 edm::Handle<edmNew::DetSetVector<SiStripCluster> > stripclusters;
00077 iEvent.getByLabel(srcClust_, stripclusters);
00078 std::vector<AlignmentClusterFlag> stripvalues(stripclusters->dataSize(), iniflag);
00079
00080
00081
00082
00083
00084
00085 for (TrajTrackAssociationCollection::const_iterator itass = assoMap->begin(); itass != assoMap->end(); ++itass){
00086
00087 int nOverlaps=0;
00088 const edm::Ref<std::vector<Trajectory> >traj = itass->key;
00089 const Trajectory * myTrajectory= &(*traj);
00090 std::vector<TrajectoryMeasurement> tmColl =myTrajectory->measurements();
00091
00092 const reco::TrackRef tkref = itass->val;
00093
00094 int hitcnt=-1;
00095
00096
00097 const TrajectoryMeasurement* previousTM(0);
00098 DetId previousId(0);
00099 int previousLayer(-1);
00100
00101 for(std::vector<TrajectoryMeasurement>::const_iterator itTrajMeas = tmColl.begin(); itTrajMeas!=tmColl.end(); ++itTrajMeas){
00102 hitcnt++;
00103
00104 if ( previousTM!=0 ) {
00105
00106 if(!previousTM->recHit()->isValid()){
00107
00108 continue;}
00109
00110 }
00111 else{
00112
00113 }
00114
00115
00116 TransientTrackingRecHit::ConstRecHitPointer hitpointer = itTrajMeas->recHit();
00117 const TrackingRecHit *hit=&(* hitpointer);
00118 if(!hit->isValid())continue;
00119
00120
00121 DetId detid = hit->geographicalId();
00122 int layer(layerFromId(detid));
00123 int subDet = detid.subdetId();
00124
00125 if ( ( previousTM!=0 )&& (layer!=-1 )) {
00126 for (std::vector<TrajectoryMeasurement>::const_iterator itmCompare =itTrajMeas-1;itmCompare >= tmColl.begin() && itmCompare > itTrajMeas - 4;--itmCompare){
00127 DetId compareId = itmCompare->recHit()->geographicalId();
00128 if ( subDet != compareId.subdetId() || layer != layerFromId(compareId)) break;
00129 if (!itmCompare->recHit()->isValid()) continue;
00130 if ( (subDet<=2) || (subDet > 2 && SiStripDetId(detid).stereo()==SiStripDetId(compareId).stereo())){
00131
00132
00133
00134
00135 AlignmentClusterFlag hitflag(hit->geographicalId());
00136 hitflag.SetOverlapFlag();
00137
00138
00139 bool hitInStrip=(subDet==SiStripDetId::TIB) || (subDet==SiStripDetId::TID) ||(subDet==SiStripDetId::TOB) ||(subDet==SiStripDetId::TEC);
00140 if (hitInStrip){
00141
00142
00143 const TSiStripRecHit2DLocalPos* transstriphit2D = dynamic_cast<const TSiStripRecHit2DLocalPos*>(hit);
00144 const TSiStripRecHit1D* transstriphit1D = dynamic_cast<const TSiStripRecHit1D*>(hit);
00145
00146
00147 if(transstriphit1D!=0){
00148
00149 const SiStripRecHit1D* striphit=transstriphit1D->specificHit();
00150 if(striphit!=0){
00151 SiStripRecHit1D::ClusterRef stripclust(striphit->cluster());
00152
00153 if(stripclust.id()==stripclusters.id()){
00154 stripvalues[stripclust.key()]=hitflag;
00155 }
00156 else{
00157 edm::LogError("TkAlCaOverlapTagger")<<"ERROR in <TkAlCaOverlapTagger::produce>: ProdId of Strip clusters mismatched: "<<stripclust.id()<<" vs "<<stripclusters.id();
00158 }
00159 }
00160 else{
00161 edm::LogError("TkAlCaOverlapTagger")<<"ERROR in <TkAlCaOverlapTagger::produce>: Dynamic cast of Strip RecHit failed! TypeId of the RecHit: "<<className(*hit);
00162 }
00163 }
00164 else if(transstriphit2D!=0){
00165
00166
00167 const SiStripRecHit2D* striphit=transstriphit2D->specificHit();
00168 if(striphit!=0){
00169 SiStripRecHit2D::ClusterRef stripclust(striphit->cluster());
00170
00171 if(stripclust.id()==stripclusters.id()){
00172 stripvalues[stripclust.key()]=hitflag;
00173
00174
00175 }
00176 else{
00177 edm::LogError("TkAlCaOverlapTagger")<<"ERROR in <TkAlCaOverlapTagger::produce>: ProdId of Strip clusters mismatched: "<<stripclust.id()<<" vs "<<stripclusters.id();
00178 }
00179
00180
00181 }
00182 else{
00183 edm::LogError("TkAlCaOverlapTagger")<<"ERROR in <TkAlCaOverlapTagger::produce>: Dynamic cast of Strip RecHit failed! TypeId of the RecHit: "<<className(*hit);
00184 }
00185 }
00186 else{
00187 edm::LogError("TkAlCaOverlapTagger")<<"ERROR in <TkAlCaOverlapTagger::produce>: Impossible to determine the type of SiStripRecHit. TypeId of the RecHit: "<<className(*hit);
00188 }
00189
00190 }
00191 else {
00192 const TSiPixelRecHit* transpixelhit = dynamic_cast<const TSiPixelRecHit*>(hit);
00193 if(transpixelhit!=0){
00194 const SiPixelRecHit* pixelhit=transpixelhit->specificHit();
00195 SiPixelClusterRefNew pixclust(pixelhit->cluster());
00196
00197 if(pixclust.id()==pixelclusters.id()){
00198 pixelvalues[pixclust.key()]=hitflag;
00199
00200 }
00201 else{
00202 edm::LogError("TkAlCaOverlapTagger")<<"ERROR in <TkAlCaOverlapTagger::produce>: ProdId of Pixel clusters mismatched: "<<pixclust.id()<<" vs "<<pixelclusters.id();
00203 }
00204 }
00205 else{
00206 edm::LogError("TkAlCaOverlapTagger")<<"ERROR in <TkAlCaOverlapTagger::produce>: Dynamic cast of Pixel RecHit failed! TypeId of the RecHit: "<<className(*hit);
00207 }
00208 }
00209
00210 nOverlaps++;
00211 break;
00212 }
00213 }
00214 }
00215
00216 previousTM = &(* itTrajMeas);
00217 previousId = detid;
00218 previousLayer = layer;
00219 }
00220
00221
00222 }
00223
00224
00225
00226
00227 std::auto_ptr<AliClusterValueMap> hitvalmap( new AliClusterValueMap);
00228 AliClusterValueMap::Filler mapfiller(*hitvalmap);
00229
00230 edm::TestHandle<std::vector<AlignmentClusterFlag> > fakePixelHandle( &pixelvalues,pixelclusters.id());
00231 mapfiller.insert(fakePixelHandle, pixelvalues.begin(), pixelvalues.end());
00232
00233 edm::TestHandle<std::vector<AlignmentClusterFlag> > fakeStripHandle( &stripvalues,stripclusters.id());
00234 mapfiller.insert(fakeStripHandle, stripvalues.begin(), stripvalues.end());
00235 mapfiller.fill();
00236
00237
00238
00239
00240
00241
00242 iEvent.put(hitvalmap);
00243 }
00244 int TkAlCaOverlapTagger::layerFromId (const DetId& id) const
00245 {
00246 if ( uint32_t(id.subdetId())==PixelSubdetector::PixelBarrel ) {
00247 PXBDetId tobId(id);
00248 return tobId.layer();
00249 }
00250 else if ( uint32_t(id.subdetId())==PixelSubdetector::PixelEndcap ) {
00251 PXFDetId tobId(id);
00252 return tobId.disk() + (3*(tobId.side()-1));
00253 }
00254 else if ( id.subdetId()==StripSubdetector::TIB ) {
00255 TIBDetId tibId(id);
00256 return tibId.layer();
00257 }
00258 else if ( id.subdetId()==StripSubdetector::TOB ) {
00259 TOBDetId tobId(id);
00260 return tobId.layer();
00261 }
00262 else if ( id.subdetId()==StripSubdetector::TEC ) {
00263 TECDetId tobId(id);
00264 return tobId.wheel() + (9*(tobId.side()-1));
00265 }
00266 else if ( id.subdetId()==StripSubdetector::TID ) {
00267 TIDDetId tobId(id);
00268 return tobId.wheel() + (3*(tobId.side()-1));
00269 }
00270 return -1;
00271
00272 }
00273
00274
00275 #include "FWCore/PluginManager/interface/ModuleDef.h"
00276 #include "FWCore/Framework/interface/MakerMacros.h"
00277
00278 DEFINE_FWK_MODULE(TkAlCaOverlapTagger);