CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DeDxEstimatorProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: DeDxEstimatorProducer
4 // Class: DeDxEstimatorProducer
5 //
13 //
14 // Original Author: andrea
15 // Created: Thu May 31 14:09:02 CEST 2007
16 // Code Updates: loic Quertenmont (querten)
17 // Created: Thu May 10 14:09:02 CEST 2008
18 //
19 //
20 
21 
22 // system include files
24 
25 
26 using namespace reco;
27 using namespace std;
28 using namespace edm;
29 
30 
33  desc.add<string>("estimator","generic");
34  desc.add<edm::InputTag>("tracks",edm::InputTag("generalTracks"));
35  desc.add<edm::InputTag>("trajectoryTrackAssociation",edm::InputTag("generalTracks"));
36  desc.add<bool>("UseTrajectory",true);
37  desc.add<bool>("UsePixel",false);
38  desc.add<bool>("UseStrip",true);
39  desc.add<double>("MeVperADCPixel",3.61e-06*265);
40  desc.add<double>("MeVperADCStrip",3.61e-06);
41  desc.add<bool>("ShapeTest",true);
42  desc.add<bool>("UseCalibration",false);
43  desc.add<string>("calibrationPath", "");
44  desc.add<string>("Reccord", "SiStripDeDxMip_3D_Rcd");
45  desc.add<string>("ProbabilityMode", "Accumulation");
46  desc.add<double>("fraction", 0.4);
47  desc.add<double>("exponent",-2.0);
48 
49  descriptions.add("DeDxEstimatorProducer",desc);
50 }
51 
52 
54 {
55 
56  produces<ValueMap<DeDxData> >();
57 
58  string estimatorName = iConfig.getParameter<string>("estimator");
59  if (estimatorName == "median") m_estimator = new MedianDeDxEstimator(iConfig);
60  else if(estimatorName == "generic") m_estimator = new GenericAverageDeDxEstimator (iConfig);
61  else if(estimatorName == "truncated") m_estimator = new TruncatedAverageDeDxEstimator(iConfig);
62  else if(estimatorName == "unbinnedFit") m_estimator = new UnbinnedFitDeDxEstimator(iConfig);
63  else if(estimatorName == "productDiscrim") m_estimator = new ProductDeDxDiscriminator(iConfig);
64  else if(estimatorName == "btagDiscrim") m_estimator = new BTagLikeDeDxDiscriminator(iConfig);
65  else if(estimatorName == "smirnovDiscrim") m_estimator = new SmirnovDeDxDiscriminator(iConfig);
66  else if(estimatorName == "asmirnovDiscrim") m_estimator = new ASmirnovDeDxDiscriminator(iConfig);
67 
68  //Commented for now, might be used in the future
69 // MaxNrStrips = iConfig.getUntrackedParameter<unsigned>("maxNrStrips" , 255);
70 
71  m_tracksTag = consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("tracks"));
72  m_trajTrackAssociationTag = consumes<TrajTrackAssociationCollection>(iConfig.getParameter<edm::InputTag>("trajectoryTrackAssociation"));
73  useTrajectory = iConfig.getParameter<bool>("UseTrajectory");
74 
75  usePixel = iConfig.getParameter<bool>("UsePixel");
76  useStrip = iConfig.getParameter<bool>("UseStrip");
77  meVperADCPixel = iConfig.getParameter<double>("MeVperADCPixel");
78  meVperADCStrip = iConfig.getParameter<double>("MeVperADCStrip");
79 
80  shapetest = iConfig.getParameter<bool>("ShapeTest");
81  useCalibration = iConfig.getParameter<bool>("UseCalibration");
82  m_calibrationPath = iConfig.getParameter<string>("calibrationPath");
83 
84  if(!usePixel && !useStrip)
85  edm::LogWarning("DeDxHitsProducer") << "Pixel Hits AND Strip Hits will not be used to estimate dEdx --> BUG, Please Update the config file";
86 
87 }
88 
89 
91 {
92  delete m_estimator;
93 }
94 
95 // ------------ method called once each job just before starting event loop ------------
97 {
98  if(useCalibration && calibGains.size()==0){
100  iSetup.get<TrackerDigiGeometryRecord>().get( tkGeom );
101  m_off = tkGeom->offsetDU(GeomDetEnumerators::PixelBarrel); //index start at the first pixel
102 
103  DeDxTools::makeCalibrationMap(m_calibrationPath, *tkGeom, calibGains, m_off);
104  }
105 
106  m_estimator->beginRun(run, iSetup);
107 }
108 
109 
110 
112 {
113  auto_ptr<ValueMap<DeDxData> > trackDeDxEstimateAssociation(new ValueMap<DeDxData> );
114  ValueMap<DeDxData>::Filler filler(*trackDeDxEstimateAssociation);
115 
116  edm::Handle<reco::TrackCollection> trackCollectionHandle;
117  iEvent.getByToken(m_tracksTag,trackCollectionHandle);
118 
119  Handle<TrajTrackAssociationCollection> trajTrackAssociationHandle;
120  if(useTrajectory)iEvent.getByToken(m_trajTrackAssociationTag, trajTrackAssociationHandle);
121 
122  std::vector<DeDxData> dedxEstimate( trackCollectionHandle->size() );
123 
125  if(useTrajectory)cit = trajTrackAssociationHandle->begin();
126  for(unsigned int j=0;j<trackCollectionHandle->size();j++){
127  const reco::TrackRef track = reco::TrackRef( trackCollectionHandle.product(), j );
128 
129  int NClusterSaturating = 0;
130  DeDxHitCollection dedxHits;
131 
132  if(useTrajectory){ //trajectory allows to take into account the local direction of the particle on the module sensor --> muc much better 'dx' measurement
133  const edm::Ref<std::vector<Trajectory> > traj = cit->key; cit++;
134  const vector<TrajectoryMeasurement> & measurements = traj->measurements();
135  dedxHits.reserve(measurements.size()/2);
136  for(vector<TrajectoryMeasurement>::const_iterator it = measurements.begin(); it!=measurements.end(); it++){
137  TrajectoryStateOnSurface trajState=it->updatedState();
138  if( !trajState.isValid()) continue;
139 
140  const TrackingRecHit * recHit=(*it->recHit()).hit();
141  if(!recHit || !recHit->isValid())continue;
142  LocalVector trackDirection = trajState.localDirection();
143  float cosine = trackDirection.z()/trackDirection.mag();
144 
145  processHit(recHit, trajState.localMomentum().mag(), cosine, dedxHits, NClusterSaturating);
146  }
147  }else{ //assume that the particles trajectory is a straight line originating from the center of the detector (can be improved)
148  dedxHits.reserve(track->recHitsSize()/2);
149  for(unsigned int h=0;h<track->recHitsSize();h++){
150  const TrackingRecHit* recHit = &(*(track->recHit(h)));
151  if(!recHit || !recHit->isValid())continue;
152  auto const & thit = static_cast<BaseTrackerRecHit const&>(*recHit);
153  if(!thit.isValid())continue;//make sure it's a tracker hit
154 
155  const GlobalVector& ModuleNormal = recHit->detUnit()->surface().normalVector();
156  float cosine = (track->px()*ModuleNormal.x()+track->py()*ModuleNormal.y()+track->pz()*ModuleNormal.z())/track->p();
157 
158  processHit(recHit, track->p(), cosine, dedxHits, NClusterSaturating);
159  }
160  }
161 
162  sort(dedxHits.begin(),dedxHits.end(),less<DeDxHit>());
163  std::pair<float,float> val_and_error = m_estimator->dedx(dedxHits);
164 
165  //WARNING: Since the dEdX Error is not properly computed for the moment
166  //It was decided to store the number of saturating cluster in that dataformat
167  val_and_error.second = NClusterSaturating;
168  dedxEstimate[j] = DeDxData(val_and_error.first, val_and_error.second, dedxHits.size() );
169  }
171 
172  filler.insert(trackCollectionHandle, dedxEstimate.begin(), dedxEstimate.end());
173 
174  // fill the association map and put it into the event
175  filler.fill();
176  iEvent.put(trackDeDxEstimateAssociation);
177 }
178 
179 
180 void DeDxEstimatorProducer::processHit(const TrackingRecHit* recHit, float trackMomentum, float& cosine, reco::DeDxHitCollection& dedxHits, int& NClusterSaturating){
181  auto const & thit = static_cast<BaseTrackerRecHit const&>(*recHit);
182  if(!thit.isValid())return;
183 
184  auto const & clus = thit.firstClusterRef();
185  if(!clus.isValid())return;
186 
187  if(clus.isPixel()){
188  if(!usePixel) return;
189 
190  auto& detUnit = *(recHit->detUnit());
191  float pathLen = detUnit.surface().bounds().thickness()/fabs(cosine);
192  float chargeAbs = clus.pixelCluster().charge();
193  float charge = meVperADCPixel*chargeAbs/pathLen;
194  dedxHits.push_back( DeDxHit( charge, trackMomentum, pathLen, thit.geographicalId()) );
195  }else if(clus.isStrip() && !thit.isMatched()){
196  if(!useStrip) return;
197 
198  auto& detUnit = *(recHit->detUnit());
199  int NSaturating = 0;
200  float pathLen = detUnit.surface().bounds().thickness()/fabs(cosine);
201  float chargeAbs = DeDxTools::getCharge(&(clus.stripCluster()),NSaturating, detUnit, calibGains, m_off);
202  float charge = meVperADCStrip*chargeAbs/pathLen;
203  if(!shapetest || (shapetest && DeDxTools::shapeSelection(clus.stripCluster()))){
204  dedxHits.push_back( DeDxHit( charge, trackMomentum, pathLen, thit.geographicalId()) );
205  if(NSaturating>0)NClusterSaturating++;
206  }
207  }else if(clus.isStrip() && thit.isMatched()){
208  if(!useStrip) return;
209  const SiStripMatchedRecHit2D* matchedHit=dynamic_cast<const SiStripMatchedRecHit2D*>(recHit);
210  if(!matchedHit)return;
211  const GluedGeomDet* gdet = static_cast<const GluedGeomDet*>(matchedHit->det());
212 
213  auto& detUnitM = *(gdet->monoDet());
214  int NSaturating = 0;
215  float pathLen = detUnitM.surface().bounds().thickness()/fabs(cosine);
216  float chargeAbs = DeDxTools::getCharge(&(matchedHit->monoCluster()),NSaturating, detUnitM, calibGains, m_off);
217  float charge = meVperADCStrip*chargeAbs/pathLen;
218  if(!shapetest || (shapetest && DeDxTools::shapeSelection(matchedHit->monoCluster()))){
219  dedxHits.push_back( DeDxHit( charge, trackMomentum, pathLen, matchedHit->monoId()) );
220  if(NSaturating>0)NClusterSaturating++;
221  }
222 
223  auto& detUnitS = *(gdet->stereoDet());
224  NSaturating = 0;
225  pathLen = detUnitS.surface().bounds().thickness()/fabs(cosine);
226  chargeAbs = DeDxTools::getCharge(&(matchedHit->stereoCluster()),NSaturating, detUnitS, calibGains, m_off);
227  charge = meVperADCStrip*chargeAbs/pathLen;
228  if(!shapetest || (shapetest && DeDxTools::shapeSelection(matchedHit->stereoCluster()))){
229  dedxHits.push_back( DeDxHit( charge, trackMomentum, pathLen, matchedHit->stereoId()) );
230  if(NSaturating>0)NClusterSaturating++;
231  }
232  }
233 }
234 
235 
236 
237 //define this as a plug-in
T getParameter(std::string const &) const
DeDxEstimatorProducer(const edm::ParameterSet &)
unsigned int stereoId() const
int getCharge(const SiStripCluster *cluster, int &nSatStrip, const GeomDetUnit &detUnit, const std::vector< std::vector< float > > &calibGains, const unsigned int &m_off)
Definition: DeDxTools.cc:161
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const GeomDetUnit * monoDet() const
Definition: GluedGeomDet.h:20
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
SiStripCluster const & monoCluster() const
LocalVector localDirection() const
GlobalVector normalVector() const
Definition: Plane.h:45
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:52
T y() const
Definition: PV3DBase.h:63
std::vector< DeDxHit > DeDxHitCollection
Definition: DeDxHit.h:56
const Bounds & bounds() const
Definition: Surface.h:128
key_type key() const
Accessor for product key.
Definition: Ref.h:264
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:40
void makeCalibrationMap(const std::string &m_calibrationPath, const TrackerGeometry &tkGeom, std::vector< std::vector< float > > &calibGains, const unsigned int &m_off)
Definition: DeDxTools.cc:196
LocalVector localMomentum() const
virtual float thickness() const =0
virtual void beginRun(edm::Run const &run, const edm::EventSetup &) override
int iEvent
Definition: GenABIO.cc:230
T mag() const
Definition: PV3DBase.h:67
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:120
const GeomDet * det() const
bool shapeSelection(const SiStripCluster &ampls)
Definition: DeDxTools.cc:10
T z() const
Definition: PV3DBase.h:64
int j
Definition: DBlmapReader.cc:9
void processHit(const TrackingRecHit *recHit, float trackMomentum, float &cosine, reco::DeDxHitCollection &dedxHits, int &NClusterSaturating)
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
ParameterDescriptionBase * add(U const &iLabel, T const &value)
T const * product() const
Definition: Handle.h:81
const T & get() const
Definition: EventSetup.h:56
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:20
bool isValid() const
string const
Definition: compareJSON.py:14
void add(std::string const &label, ParameterSetDescription const &psetDescription)
SiStripCluster const & stereoCluster() const
virtual const GeomDetUnit * detUnit() const
virtual void produce(edm::Event &, const edm::EventSetup &) override
unsigned int monoId() const
T x() const
Definition: PV3DBase.h:62
const GeomDetUnit * stereoDet() const
Definition: GluedGeomDet.h:21
Definition: Run.h:43