CMS 3D CMS Logo

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