CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/CalibTracker/SiStripCommon/plugins/ShallowTrackClustersProducer.cc

Go to the documentation of this file.
00001 #include "CalibTracker/SiStripCommon/interface/ShallowTrackClustersProducer.h"
00002 
00003 #include "CalibTracker/SiStripCommon/interface/ShallowTools.h"
00004 
00005 #include "TrackingTools/PatternTools/interface/Trajectory.h"
00006 #include "TrackingTools/PatternTools/interface/TrajTrackAssociation.h"
00007 #include "TrackingTools/TrackFitters/interface/TrajectoryStateCombiner.h"
00008 #include "DataFormats/TrackerRecHit2D/interface/SiStripRecHit1D.h"
00009 #include "DataFormats/TrackerRecHit2D/interface/SiStripRecHit2D.h"
00010 #include "DataFormats/TrackerRecHit2D/interface/SiStripMatchedRecHit2D.h"
00011 
00012 #include "MagneticField/Engine/interface/MagneticField.h"
00013 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00014 #include "CondFormats/SiStripObjects/interface/SiStripLorentzAngle.h"
00015 #include "CondFormats/DataRecord/interface/SiStripLorentzAngleRcd.h"
00016 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00017 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00018 #include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetUnit.h"
00019 #include "Geometry/CommonTopologies/interface/StripTopology.h"
00020 #include "FWCore/Framework/interface/ESHandle.h"
00021 #include "FWCore/Framework/interface/Event.h"
00022 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00023 #include "boost/foreach.hpp"
00024 
00025 #include "CalibTracker/Records/interface/SiStripDependentRecords.h"
00026 
00027 ShallowTrackClustersProducer::ShallowTrackClustersProducer(const edm::ParameterSet& iConfig)
00028   :  theTracksLabel( iConfig.getParameter<edm::InputTag>("Tracks") ),
00029      theClustersLabel( iConfig.getParameter<edm::InputTag>("Clusters") ),
00030      Suffix       ( iConfig.getParameter<std::string>("Suffix")    ),
00031      Prefix       ( iConfig.getParameter<std::string>("Prefix") )
00032 {
00033   produces <std::vector<unsigned int> > ( Prefix + "trackmulti"  + Suffix );
00034   produces <std::vector<int> >          ( Prefix + "trackindex"  + Suffix );
00035   produces <std::vector<float> >        ( Prefix + "localtheta"  + Suffix );  
00036   produces <std::vector<float> >        ( Prefix + "localphi"    + Suffix );  
00037   produces <std::vector<float> >        ( Prefix + "localpitch"  + Suffix );  
00038   produces <std::vector<float> >        ( Prefix + "localx"      + Suffix );  
00039   produces <std::vector<float> >        ( Prefix + "localy"      + Suffix );  
00040   produces <std::vector<float> >        ( Prefix + "localz"      + Suffix );  
00041   produces <std::vector<float> >        ( Prefix + "strip"       + Suffix );  
00042   produces <std::vector<float> >        ( Prefix + "globaltheta" + Suffix );  
00043   produces <std::vector<float> >        ( Prefix + "globalphi"   + Suffix );
00044   produces <std::vector<float> >        ( Prefix + "globalx"     + Suffix );
00045   produces <std::vector<float> >        ( Prefix + "globaly"     + Suffix );
00046   produces <std::vector<float> >        ( Prefix + "globalz"     + Suffix );
00047   produces <std::vector<float> >        ( Prefix + "insidistance"+ Suffix );
00048   produces <std::vector<float> >        ( Prefix + "covered"     + Suffix );
00049   produces <std::vector<float> >        ( Prefix + "projwidth"   + Suffix );
00050   produces <std::vector<float> >        ( Prefix + "BdotY"       + Suffix );
00051 
00052   produces <std::vector<float> >        ( Prefix + "rhlocalx"     + Suffix );   
00053   produces <std::vector<float> >        ( Prefix + "rhlocaly"     + Suffix );   
00054   produces <std::vector<float> >        ( Prefix + "rhlocalxerr"  + Suffix );   
00055   produces <std::vector<float> >        ( Prefix + "rhlocalyerr"  + Suffix );   
00056   produces <std::vector<float> >        ( Prefix + "rhglobalx"    + Suffix );   
00057   produces <std::vector<float> >        ( Prefix + "rhglobaly"    + Suffix );   
00058   produces <std::vector<float> >        ( Prefix + "rhglobalz"    + Suffix );
00059   produces <std::vector<float> >        ( Prefix + "rhstrip"      + Suffix );   
00060   produces <std::vector<float> >        ( Prefix + "rhmerr"       + Suffix );   
00061 
00062   produces <std::vector<float> >        ( Prefix + "ubstrip"      + Suffix );   
00063   produces <std::vector<float> >        ( Prefix + "ubmerr"       + Suffix );   
00064 
00065   produces <std::vector<float> >       ( Prefix + "driftx"        + Suffix );
00066   produces <std::vector<float> >       ( Prefix + "drifty"        + Suffix );
00067   produces <std::vector<float> >       ( Prefix + "driftz"        + Suffix );
00068   produces <std::vector<float> >       ( Prefix + "globalZofunitlocalY" + Suffix );            
00069 }
00070 
00071 void ShallowTrackClustersProducer::
00072 produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
00073   shallow::CLUSTERMAP clustermap = shallow::make_cluster_map(iEvent,theClustersLabel);
00074 
00075   int size = clustermap.size();
00076   std::auto_ptr<std::vector<unsigned int> > trackmulti   ( new std::vector<unsigned int>(size,    0)   );
00077   std::auto_ptr<std::vector<int> >          trackindex   ( new std::vector<int>         (size,   -1)   );
00078   std::auto_ptr<std::vector<float> >        localtheta   ( new std::vector<float>       (size, -100)   );
00079   std::auto_ptr<std::vector<float> >        localphi     ( new std::vector<float>       (size, -100)   );
00080   std::auto_ptr<std::vector<float> >        localpitch   ( new std::vector<float>       (size, -100)   );
00081   std::auto_ptr<std::vector<float> >        localx       ( new std::vector<float>       (size, -100)   );
00082   std::auto_ptr<std::vector<float> >        localy       ( new std::vector<float>       (size, -100)   );
00083   std::auto_ptr<std::vector<float> >        localz       ( new std::vector<float>       (size, -100)   );
00084   std::auto_ptr<std::vector<float> >        strip        ( new std::vector<float>       (size, -100)   );
00085   std::auto_ptr<std::vector<float> >        globaltheta  ( new std::vector<float>       (size, -100)   );
00086   std::auto_ptr<std::vector<float> >        globalphi    ( new std::vector<float>       (size, -100)   );
00087   std::auto_ptr<std::vector<float> >        globalx      ( new std::vector<float>       (size, -10000) );
00088   std::auto_ptr<std::vector<float> >        globaly      ( new std::vector<float>       (size, -10000) );
00089   std::auto_ptr<std::vector<float> >        globalz      ( new std::vector<float>       (size, -10000) );
00090   std::auto_ptr<std::vector<float> >        insidistance ( new std::vector<float>       (size,     -1) );
00091   std::auto_ptr<std::vector<float> >        projwidth    ( new std::vector<float>       (size,  -1000) );
00092   std::auto_ptr<std::vector<float> >        BdotY        ( new std::vector<float>       (size,  -1000) );
00093   std::auto_ptr<std::vector<float> >        covered      ( new std::vector<float>       (size,  -1000) );
00094   std::auto_ptr<std::vector<float> >  rhlocalx      ( new std::vector<float>(size,  -10000  ));   
00095   std::auto_ptr<std::vector<float> >  rhlocaly      ( new std::vector<float>(size,  -10000  ));   
00096   std::auto_ptr<std::vector<float> >  rhlocalxerr   ( new std::vector<float>(size,  -1  ));   
00097   std::auto_ptr<std::vector<float> >  rhlocalyerr   ( new std::vector<float>(size,  -1  ));     
00098   std::auto_ptr<std::vector<float> >  rhglobalx     ( new std::vector<float>(size,  -10000  ));   
00099   std::auto_ptr<std::vector<float> >  rhglobaly     ( new std::vector<float>(size,  -10000  ));   
00100   std::auto_ptr<std::vector<float> >  rhglobalz     ( new std::vector<float>(size,  -10000  ));   
00101   std::auto_ptr<std::vector<float> >  rhstrip       ( new std::vector<float>(size,  -10000  ));   
00102   std::auto_ptr<std::vector<float> >  rhmerr        ( new std::vector<float>(size,  -10000  ));   
00103   std::auto_ptr<std::vector<float> >  ubstrip       ( new std::vector<float>(size,  -10000  ));   
00104   std::auto_ptr<std::vector<float> >  ubmerr        ( new std::vector<float>(size,  -10000  ));   
00105   std::auto_ptr<std::vector<float> >  driftx        ( new std::vector<float>(size,  -10000  ));
00106   std::auto_ptr<std::vector<float> >  drifty        ( new std::vector<float>(size,  -10000  ));
00107   std::auto_ptr<std::vector<float> >  driftz        ( new std::vector<float>(size,  -10000  ));
00108   std::auto_ptr<std::vector<float> >  globalZofunitlocalY ( new std::vector<float>(size, -1000));
00109 
00110   edm::ESHandle<TrackerGeometry> theTrackerGeometry;         iSetup.get<TrackerDigiGeometryRecord>().get( theTrackerGeometry );  
00111   edm::ESHandle<MagneticField> magfield;                     iSetup.get<IdealMagneticFieldRecord>().get(magfield);                    
00112   edm::ESHandle<SiStripLorentzAngle> SiStripLorentzAngle;    iSetup.get<SiStripLorentzAngleDepRcd>().get(SiStripLorentzAngle);      
00113 
00114   edm::Handle<edm::View<reco::Track> > tracks;               iEvent.getByLabel(theTracksLabel, tracks);   
00115   edm::Handle<TrajTrackAssociationCollection> associations;  iEvent.getByLabel(theTracksLabel, associations);
00116 
00117   TrajectoryStateCombiner combiner;
00118 
00119   for( TrajTrackAssociationCollection::const_iterator association = associations->begin(); 
00120        association != associations->end(); association++) {
00121     const Trajectory*  traj  = association->key.get();
00122     const reco::Track* track = association->val.get();
00123 
00124     BOOST_FOREACH( const TrajectoryMeasurement measurement, traj->measurements() ) {
00125       const TrajectoryStateOnSurface tsos = measurement.updatedState();
00126       const TrajectoryStateOnSurface unbiased = combiner(measurement.forwardPredictedState(), measurement.backwardPredictedState());
00127 
00128       const TrackingRecHit*         hit        = measurement.recHit()->hit();
00129       const SiStripRecHit1D*        hit1D      = dynamic_cast<const SiStripRecHit1D*>(hit);
00130       const SiStripRecHit2D*        hit2D      = dynamic_cast<const SiStripRecHit2D*>(hit);
00131       const SiStripMatchedRecHit2D* matchedhit = dynamic_cast<const SiStripMatchedRecHit2D*>(hit);
00132 
00133       for(unsigned h=0; h<2; h++) {
00134         const SiStripCluster* cluster_ptr;
00135         if(!matchedhit && h==1) continue; else 
00136         if( matchedhit && h==0) cluster_ptr = &matchedhit->monoCluster(); else 
00137         if( matchedhit && h==1) cluster_ptr = &matchedhit->stereoCluster(); else 
00138         if(hit2D) cluster_ptr = (hit2D->cluster()).get(); else 
00139         if(hit1D) cluster_ptr = (hit1D->cluster()).get(); 
00140         else continue;
00141 
00142         shallow::CLUSTERMAP::const_iterator cluster = clustermap.find( std::make_pair( hit->geographicalId().rawId(), cluster_ptr->firstStrip() ));
00143         if(cluster == clustermap.end() ) throw cms::Exception("Logic Error") << "Cluster not found: this could be a configuration error" << std::endl;
00144         
00145         unsigned i = cluster->second;
00146         if( 0 == (trackmulti->at(i))++ ) {
00147           const StripGeomDetUnit* theStripDet = dynamic_cast<const StripGeomDetUnit*>( theTrackerGeometry->idToDet( hit->geographicalId() ) );
00148           LocalVector drift = shallow::drift( theStripDet, *magfield, *SiStripLorentzAngle);
00149           
00150           trackindex->at(i)   = shallow::findTrackIndex(tracks, track); 
00151           localtheta->at(i)   = (theStripDet->toLocal(tsos.globalDirection())).theta(); 
00152           localphi->at(i)     = (theStripDet->toLocal(tsos.globalDirection())).phi();   
00153           localpitch->at(i)   = (theStripDet->specificTopology()).localPitch(theStripDet->toLocal(tsos.globalPosition())); 
00154           localx->at(i)       = (theStripDet->toLocal(tsos.globalPosition())).x();    
00155           localy->at(i)       = (theStripDet->toLocal(tsos.globalPosition())).y();    
00156           localz->at(i)       = (theStripDet->toLocal(tsos.globalPosition())).z();    
00157           strip->at(i)        = (theStripDet->specificTopology()).strip(theStripDet->toLocal(tsos.globalPosition()));
00158           globaltheta->at(i)  = tsos.globalDirection().theta();                       
00159           globalphi->at(i)    = tsos.globalDirection().phi();                         
00160           globalx->at(i)      = tsos.globalPosition().x();                            
00161           globaly->at(i)      = tsos.globalPosition().y();                            
00162           globalz->at(i)      = tsos.globalPosition().z();                            
00163           insidistance->at(i) = 1./fabs(cos(localtheta->at(i)));                      
00164           projwidth->at(i)    = tan(localtheta->at(i))*cos(localphi->at(i));         
00165           BdotY->at(i)        = (theStripDet->surface()).toLocal( magfield->inTesla(theStripDet->surface().position())).y();
00166           covered->at(i)      = drift.z()/localpitch->at(i) * fabs(projwidth->at(i) - drift.x()/drift.z());
00167           rhlocalx->at(i)     = hit->localPosition().x();
00168           rhlocaly->at(i)     = hit->localPosition().y();
00169           rhlocalxerr->at(i)  = sqrt(hit->localPositionError().xx());
00170           rhlocalyerr->at(i)  = sqrt(hit->localPositionError().yy());
00171           rhglobalx->at(i)    = theStripDet->toGlobal(hit->localPosition()).x();
00172           rhglobaly->at(i)    = theStripDet->toGlobal(hit->localPosition()).y();
00173           rhglobalz->at(i)    = theStripDet->toGlobal(hit->localPosition()).z();
00174           rhstrip->at(i)      = theStripDet->specificTopology().strip(hit->localPosition());
00175           rhmerr->at(i)       = sqrt(theStripDet->specificTopology().measurementError(hit->localPosition(), hit->localPositionError()).uu());
00176           ubstrip->at(i)      = theStripDet->specificTopology().strip(unbiased.localPosition());
00177           ubmerr->at(i)       = sqrt(theStripDet->specificTopology().measurementError(unbiased.localPosition(), unbiased.localError().positionError()).uu());
00178           driftx->at(i)       = drift.x();
00179           drifty->at(i)       = drift.y();
00180           driftz->at(i)       = drift.z();
00181           globalZofunitlocalY->at(i) = (theStripDet->toGlobal(LocalVector(0,1,0))).z();
00182         }
00183       }
00184     }
00185   }
00186 
00187   iEvent.put(trackmulti,  Prefix + "trackmulti"  + Suffix );
00188   iEvent.put(trackindex,  Prefix + "trackindex"  + Suffix );
00189   iEvent.put(localtheta,  Prefix + "localtheta"  + Suffix );
00190   iEvent.put(localphi,    Prefix + "localphi"    + Suffix );
00191   iEvent.put(localpitch,  Prefix + "localpitch"  + Suffix );
00192   iEvent.put(localx,      Prefix + "localx"      + Suffix );
00193   iEvent.put(localy,      Prefix + "localy"      + Suffix );
00194   iEvent.put(localz,      Prefix + "localz"      + Suffix );
00195   iEvent.put(strip,       Prefix + "strip"       + Suffix );
00196   iEvent.put(globaltheta, Prefix + "globaltheta" + Suffix );
00197   iEvent.put(globalphi,   Prefix + "globalphi"   + Suffix );
00198   iEvent.put(globalx,     Prefix + "globalx"     + Suffix );
00199   iEvent.put(globaly,     Prefix + "globaly"     + Suffix );
00200   iEvent.put(globalz,     Prefix + "globalz"     + Suffix );  
00201   iEvent.put(insidistance,Prefix + "insidistance"+ Suffix );
00202   iEvent.put(covered,     Prefix + "covered"     + Suffix );
00203   iEvent.put(projwidth,   Prefix + "projwidth"   + Suffix );
00204   iEvent.put(BdotY,       Prefix + "BdotY"       + Suffix );
00205   iEvent.put(rhlocalx,    Prefix + "rhlocalx"    + Suffix );   
00206   iEvent.put(rhlocaly,    Prefix + "rhlocaly"    + Suffix );   
00207   iEvent.put(rhlocalxerr, Prefix + "rhlocalxerr" + Suffix );   
00208   iEvent.put(rhlocalyerr, Prefix + "rhlocalyerr" + Suffix );   
00209   iEvent.put(rhglobalx,   Prefix + "rhglobalx"   + Suffix );   
00210   iEvent.put(rhglobaly,   Prefix + "rhglobaly"   + Suffix );   
00211   iEvent.put(rhglobalz,   Prefix + "rhglobalz"   + Suffix );   
00212   iEvent.put(rhstrip,     Prefix + "rhstrip"     + Suffix );   
00213   iEvent.put(rhmerr,      Prefix + "rhmerr"      + Suffix );   
00214   iEvent.put(ubstrip,     Prefix + "ubstrip"     + Suffix );   
00215   iEvent.put(ubmerr,      Prefix + "ubmerr"      + Suffix );   
00216   iEvent.put( driftx,     Prefix + "driftx"      + Suffix );
00217   iEvent.put( drifty,     Prefix + "drifty"      + Suffix );
00218   iEvent.put( driftz,     Prefix + "driftz"      + Suffix );
00219   iEvent.put( globalZofunitlocalY, Prefix + "globalZofunitlocalY" + Suffix );
00220 }