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  for(vector<TrajectoryMeasurement>::const_iterator it = measurements.begin(); it!=measurements.end(); it++){
136  TrajectoryStateOnSurface trajState=it->updatedState();
137  if( !trajState.isValid()) continue;
138 
139  const TrackingRecHit * recHit=(*it->recHit()).hit();
140  if(!recHit || !recHit->isValid())continue;
141  LocalVector trackDirection = trajState.localDirection();
142  float cosine = trackDirection.z()/trackDirection.mag();
143 
144  processHit(recHit, trajState.localMomentum().mag(), cosine, dedxHits, NClusterSaturating);
145  }
146 
147  }else{ //assume that the particles trajectory is a straight line originating from the center of the detector (can be improved)
148  for(unsigned int h=0;h<track->recHitsSize();h++){
149  const TrackingRecHit* recHit = &(*(track->recHit(h)));
150  if(!recHit || !recHit->isValid())continue;
151  auto const & thit = static_cast<BaseTrackerRecHit const&>(*recHit);
152  if(!thit.isValid())continue;//make sure it's a tracker hit
153 
154  const GlobalVector& ModuleNormal = recHit->detUnit()->surface().normalVector();
155  float cosine = (track->px()*ModuleNormal.x()+track->py()*ModuleNormal.y()+track->pz()*ModuleNormal.z())/track->p();
156 
157  processHit(recHit, track->p(), cosine, dedxHits, NClusterSaturating);
158  }
159  }
160 
161  sort(dedxHits.begin(),dedxHits.end(),less<DeDxHit>());
162  std::pair<float,float> val_and_error = m_estimator->dedx(dedxHits);
163 
164  //WARNING: Since the dEdX Error is not properly computed for the moment
165  //It was decided to store the number of saturating cluster in that dataformat
166  val_and_error.second = NClusterSaturating;
167  dedxEstimate[j] = DeDxData(val_and_error.first, val_and_error.second, dedxHits.size() );
168  }
170 
171  filler.insert(trackCollectionHandle, dedxEstimate.begin(), dedxEstimate.end());
172 
173  // fill the association map and put it into the event
174  filler.fill();
175  iEvent.put(trackDeDxEstimateAssociation);
176 }
177 
178 
179 void DeDxEstimatorProducer::processHit(const TrackingRecHit* recHit, float trackMomentum, float& cosine, reco::DeDxHitCollection& dedxHits, int& NClusterSaturating){
180  auto const & thit = static_cast<BaseTrackerRecHit const&>(*recHit);
181  if(!thit.isValid())return;
182 
183  auto const & clus = thit.firstClusterRef();
184  if(!clus.isValid())return;
185 
186  if(clus.isPixel()){
187  if(!usePixel) return;
188 
189  auto& detUnit = *(recHit->detUnit());
190  float pathLen = detUnit.surface().bounds().thickness()/fabs(cosine);
191  float chargeAbs = clus.pixelCluster().charge();
192  float charge = meVperADCPixel*chargeAbs/pathLen;
193  dedxHits.push_back( DeDxHit( charge, trackMomentum, pathLen, thit.geographicalId()) );
194  }else if(clus.isStrip() && !thit.isMatched()){
195  if(!useStrip) return;
196 
197  auto& detUnit = *(recHit->detUnit());
198  int NSaturating = 0;
199  float pathLen = detUnit.surface().bounds().thickness()/fabs(cosine);
200  float chargeAbs = DeDxTools::getCharge(&(clus.stripCluster()),NSaturating, detUnit, calibGains, m_off);
201  float charge = meVperADCStrip*chargeAbs/pathLen;
202  if(!shapetest || (shapetest && DeDxTools::shapeSelection(clus.stripCluster().amplitudes()))){
203  dedxHits.push_back( DeDxHit( charge, trackMomentum, pathLen, thit.geographicalId()) );
204  if(NSaturating>0)NClusterSaturating++;
205  }
206  }else if(clus.isStrip() && thit.isMatched()){
207  if(!useStrip) return;
208  const SiStripMatchedRecHit2D* matchedHit=dynamic_cast<const SiStripMatchedRecHit2D*>(recHit);
209  if(!matchedHit)return;
210  const GluedGeomDet* gdet = static_cast<const GluedGeomDet*>(matchedHit->det());
211 
212  auto& detUnitM = *(gdet->monoDet());
213  int NSaturating = 0;
214  float pathLen = detUnitM.surface().bounds().thickness()/fabs(cosine);
215  float chargeAbs = DeDxTools::getCharge(&(matchedHit->monoCluster()),NSaturating, detUnitM, calibGains, m_off);
216  float charge = meVperADCStrip*chargeAbs/pathLen;
217  if(!shapetest || (shapetest && DeDxTools::shapeSelection(matchedHit->monoCluster().amplitudes()))){
218  dedxHits.push_back( DeDxHit( charge, trackMomentum, pathLen, matchedHit->monoId()) );
219  if(NSaturating>0)NClusterSaturating++;
220  }
221 
222  auto& detUnitS = *(gdet->stereoDet());
223  NSaturating = 0;
224  pathLen = detUnitS.surface().bounds().thickness()/fabs(cosine);
225  chargeAbs = DeDxTools::getCharge(&(matchedHit->stereoCluster()),NSaturating, detUnitS, calibGains, m_off);
226  charge = meVperADCStrip*chargeAbs/pathLen;
227  if(!shapetest || (shapetest && DeDxTools::shapeSelection(matchedHit->stereoCluster().amplitudes()))){
228  dedxHits.push_back( DeDxHit( charge, trackMomentum, pathLen, matchedHit->stereoId()) );
229  if(NSaturating>0)NClusterSaturating++;
230  }
231  }
232 }
233 
234 
235 
236 //define this as a plug-in
T getParameter(std::string const &) const
DeDxEstimatorProducer(const edm::ParameterSet &)
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:160
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:446
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:67
const Bounds & bounds() const
Definition: Surface.h:128
key_type key() const
Accessor for product key.
Definition: Ref.h:266
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:187
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:113
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)
DEFINE_FWK_MODULE(CosmicTrackingParticleSelector)
bool shapeSelection(const std::vector< uint8_t > &ampls)
Definition: DeDxTools.cc:10
T const * product() const
Definition: Handle.h:81
const T & get() const
Definition: EventSetup.h:55
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:19
bool isValid() const
string const
Definition: compareJSON.py:14
void add(std::string const &label, ParameterSetDescription const &psetDescription)
virtual const GeomDetUnit * detUnit() const
virtual void produce(edm::Event &, const edm::EventSetup &) override
T x() const
Definition: PV3DBase.h:62
const GeomDetUnit * stereoDet() const
Definition: GluedGeomDet.h:21
Definition: Run.h:41