CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/Alignment/TrackerAlignment/plugins/TkAlCaOverlapTagger.cc

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 //#include <boost/regex.hpp>
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>(); //produces the ValueMap (VM) to be stored in the Event at the end
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   // cout<<"\n\n############################\n###  Starting a new TkAlCaOverlapTagger - Ev "<<iEvent.id().run()<<", "<<iEvent.id().event()<<endl;
00070 
00071   AlignmentClusterFlag iniflag;
00072   edm::Handle<edmNew::DetSetVector<SiPixelCluster> > pixelclusters;
00073   iEvent.getByLabel(srcClust_,  pixelclusters);//same label as tracks
00074   std::vector<AlignmentClusterFlag> pixelvalues(pixelclusters->dataSize(), iniflag);//vector where to store value to be fileld in the VM
00075 
00076   edm::Handle<edmNew::DetSetVector<SiStripCluster> > stripclusters;
00077   iEvent.getByLabel(srcClust_,  stripclusters);//same label as tracks
00078   std::vector<AlignmentClusterFlag> stripvalues(stripclusters->dataSize(), iniflag);//vector where to store value to be fileld in the VM
00079 
00080 
00081 
00082   //start doing the thing!
00083 
00084   //loop over trajectories
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;//trajectory in the collection
00089     const Trajectory * myTrajectory= &(*traj);
00090     std::vector<TrajectoryMeasurement> tmColl =myTrajectory->measurements();
00091 
00092     const reco::TrackRef tkref = itass->val;//associated track track in the collection
00093     // const Track * trk = &(*tkref);
00094     int hitcnt=-1;
00095 
00096     //loop over traj meas
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         //      std::cout<<"Checking TrajMeas ("<<hitcnt+1<<"):"<<std::endl;
00106         if(!previousTM->recHit()->isValid()){
00107           //std::cout<<"Previous RecHit invalid !"<<std::endl; 
00108         continue;}
00109         //else std::cout<<"\nDetId: "<<std::flush<<previousTM->recHit()->geographicalId().rawId()<<"\t Local x of hit: "<<previousTM->recHit()->localPosition().x()<<std::endl;
00110       }
00111       else{
00112         //std::cout<<"This is the first Traj Meas of the Trajectory! The Trajectory contains "<< tmColl.size()<<" TrajMeas"<<std::endl;
00113       }
00114       
00115       
00116       TransientTrackingRecHit::ConstRecHitPointer hitpointer = itTrajMeas->recHit();
00117       const TrackingRecHit *hit=&(* hitpointer);
00118       if(!hit->isValid())continue;
00119 
00120       //std::cout << "         hit number " << (ith - itt->recHitsBegin()) << std::endl;
00121       DetId detid = hit->geographicalId();
00122       int layer(layerFromId(detid));//layer 1-4=TIB, layer 5-10=TOB
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())){//if either pixel or strip stereo module
00131             
00132             //
00133             //WOW, we have an overlap!!!!!!
00134             //
00135             AlignmentClusterFlag hitflag(hit->geographicalId());
00136             hitflag.SetOverlapFlag();
00137             // cout<<"Overlap found in SubDet "<<subDet<<"!!!"<<flush;
00138 
00139             bool hitInStrip=(subDet==SiStripDetId::TIB) || (subDet==SiStripDetId::TID) ||(subDet==SiStripDetId::TOB) ||(subDet==SiStripDetId::TEC);
00140             if (hitInStrip){
00141               //cout<<"  TypeId of the RecHit: "<<className(*hit)<<endl;
00142               // const std::type_info &type = typeid(*hit);
00143               const TSiStripRecHit2DLocalPos* transstriphit2D = dynamic_cast<const  TSiStripRecHit2DLocalPos*>(hit);
00144               const TSiStripRecHit1D* transstriphit1D = dynamic_cast<const  TSiStripRecHit1D*>(hit);
00145            
00146               //   if (type == typeid(SiStripRecHit1D)) {
00147               if(transstriphit1D!=0){
00148                 //      const SiStripRecHit1D* striphit=dynamic_cast<const  SiStripRecHit1D*>(hit);
00149                 const SiStripRecHit1D* striphit=transstriphit1D->specificHit();
00150                 if(striphit!=0){
00151                   SiStripRecHit1D::ClusterRef stripclust(striphit->cluster());
00152                   
00153                   if(stripclust.id()==stripclusters.id()){//ensure that the stripclust is really present in the original cluster collection!!!
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               }//end if sistriprechit1D
00164               else if(transstriphit2D!=0){
00165               //else if (type == typeid(SiStripRecHit2D)) {
00166                 //              const SiStripRecHit2D* striphit=dynamic_cast<const  SiStripRecHit2D*>(hit);
00167                 const SiStripRecHit2D* striphit=transstriphit2D->specificHit();   
00168                 if(striphit!=0){
00169                   SiStripRecHit2D::ClusterRef stripclust(striphit->cluster());
00170                   
00171                   if(stripclust.id()==stripclusters.id()){//ensure that the stripclust is really present in the original cluster collection!!!
00172                     stripvalues[stripclust.key()]=hitflag;
00173               
00174                     //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;
00175                   }
00176                   else{
00177                     edm::LogError("TkAlCaOverlapTagger")<<"ERROR in <TkAlCaOverlapTagger::produce>: ProdId of Strip clusters mismatched: "<<stripclust.id()<<" vs "<<stripclusters.id();
00178                   }
00179                   
00180                   // cout<<"Cluster baricentre: "<<stripclust->barycenter()<<endl;
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               }//end if Sistriprechit2D
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             }//end if hit in Strips
00191             else {//pixel hit
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                   //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;
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             }//end 'else' it is a pixel hit
00209 
00210             nOverlaps++;
00211             break;
00212           }
00213         }//end second loop on TM
00214       }//end if a previous TM exists
00215 
00216       previousTM = &(* itTrajMeas);
00217       previousId = detid;
00218       previousLayer = layer;
00219     }//end loop over traj meas
00220     //std::cout<<"Found "<<nOverlaps<<" overlaps in this trajectory"<<std::endl; 
00221 
00222   }//end loop over trajectories
00223 
00224 
00225 
00226   // prepare output 
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   // iEvent.put(stripmap);
00242   iEvent.put(hitvalmap);
00243 }//end  TkAlCaOverlapTagger::produce
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 }//end layerfromId
00273 
00274 // ========= MODULE DEF ==============
00275 #include "FWCore/PluginManager/interface/ModuleDef.h"
00276 #include "FWCore/Framework/interface/MakerMacros.h"
00277 
00278 DEFINE_FWK_MODULE(TkAlCaOverlapTagger);