CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Member Functions | Private Member Functions | Private Attributes
DeDxEstimatorProducer Class Reference

#include <RecoTracker/DeDxEstimatorProducer/src/DeDxEstimatorProducer.cc>

Inheritance diagram for DeDxEstimatorProducer:
edm::EDProducer edm::ProducerBase edm::ProductRegistryHelper

Classes

class  isEqual
 
struct  stModInfo
 

Public Member Functions

 DeDxEstimatorProducer (const edm::ParameterSet &)
 
 ~DeDxEstimatorProducer ()
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
virtual ~EDProducer ()
 
- Public Member Functions inherited from edm::ProducerBase
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
boost::function< void(const
BranchDescription &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 

Private Member Functions

virtual void beginRun (edm::Run &run, const edm::EventSetup &)
 
virtual void endJob ()
 
int getCharge (const SiStripCluster *Cluster, int &Saturating_Strips)
 
void MakeCalibrationMap ()
 
virtual void produce (edm::Event &, const edm::EventSetup &)
 

Private Attributes

std::string m_calibrationPath
 
BaseDeDxEstimatorm_estimator
 
edm::InputTag m_tracksTag
 
edm::InputTag m_trajTrackAssociationTag
 
unsigned int MaxNrStrips
 
double MeVperADCPixel
 
double MeVperADCStrip
 
unsigned int MinTrackHits
 
__gnu_cxx::hash_map< unsigned
int, stModInfo
*, __gnu_cxx::hash< unsigned
int >, isEqual
MODsColl
 
bool shapetest
 
bool useCalibration
 
bool usePixel
 
bool useStrip
 

Additional Inherited Members

- Public Types inherited from edm::EDProducer
typedef EDProducer ModuleType
 
typedef WorkerT< EDProducerWorkerType
 
- Public Types inherited from edm::ProducerBase
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 
- Static Public Member Functions inherited from edm::EDProducer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDProducer
CurrentProcessingContext const * currentContext () const
 
- Protected Member Functions inherited from edm::ProducerBase
template<class TProducer , class TMethod >
void callWhenNewProductsRegistered (TProducer *iProd, TMethod iMethod)
 

Detailed Description

Description: <one line="" class="" summary>="">

Implementation: <Notes on="" implementation>="">

Definition at line 33 of file DeDxEstimatorProducer.h.

Constructor & Destructor Documentation

DeDxEstimatorProducer::DeDxEstimatorProducer ( const edm::ParameterSet iConfig)
explicit

Definition at line 52 of file DeDxEstimatorProducer.cc.

References edm::ParameterSet::getParameter(), and edm::ParameterSet::getUntrackedParameter().

53 {
54 
55  produces<ValueMap<DeDxData> >();
56 
57 
58  string estimatorName = iConfig.getParameter<string>("estimator");
59  if(estimatorName == "median") m_estimator = new MedianDeDxEstimator(-2.);
60  if(estimatorName == "generic") m_estimator = new GenericAverageDeDxEstimator (iConfig.getParameter<double>("exponent"));
61  if(estimatorName == "truncated") m_estimator = new TruncatedAverageDeDxEstimator(iConfig.getParameter<double>("fraction"));
62  if(estimatorName == "unbinnedFit") m_estimator = new UnbinnedFitDeDxEstimator();
63 
64  MaxNrStrips = iConfig.getUntrackedParameter<unsigned>("maxNrStrips" , 255);
65  MinTrackHits = iConfig.getUntrackedParameter<unsigned>("MinTrackHits" , 4);
66 
67  m_tracksTag = iConfig.getParameter<edm::InputTag>("tracks");
68  m_trajTrackAssociationTag = iConfig.getParameter<edm::InputTag>("trajectoryTrackAssociation");
69 
70  usePixel = iConfig.getParameter<bool>("UsePixel");
71  useStrip = iConfig.getParameter<bool>("UseStrip");
72  MeVperADCPixel = iConfig.getParameter<double>("MeVperADCPixel");
73  MeVperADCStrip = iConfig.getParameter<double>("MeVperADCStrip");
74 
75  shapetest = iConfig.getParameter<bool>("ShapeTest");
76  useCalibration = iConfig.getParameter<bool>("UseCalibration");
77  m_calibrationPath = iConfig.getParameter<string>("calibrationPath");
78 
79  if(!usePixel && !useStrip)
80  edm::LogWarning("DeDxHitsProducer") << "Pixel Hits AND Strip Hits will not be used to estimate dEdx --> BUG, Please Update the config file";
81 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
edm::InputTag m_trajTrackAssociationTag
BaseDeDxEstimator * m_estimator
DeDxEstimatorProducer::~DeDxEstimatorProducer ( )

Definition at line 84 of file DeDxEstimatorProducer.cc.

85 {
86  delete m_estimator;
87 }
BaseDeDxEstimator * m_estimator

Member Function Documentation

void DeDxEstimatorProducer::beginRun ( edm::Run run,
const edm::EventSetup iSetup 
)
privatevirtual

Reimplemented from edm::EDProducer.

Definition at line 92 of file DeDxEstimatorProducer.cc.

References BoundSurface::bounds(), DeDxEstimatorProducer::stModInfo::DetId, DeDxEstimatorProducer::stModInfo::Distance, DeDxEstimatorProducer::stModInfo::Gain, edm::EventSetup::get(), i, PV3DBase< T, PVType, FrameType >::mag(), DeDxEstimatorProducer::stModInfo::Normalization, GeomDet::position(), DetId::rawId(), GeomDet::surface(), Bounds::thickness(), and DeDxEstimatorProducer::stModInfo::Thickness.

93 {
94  if(MODsColl.size()!=0)return;
95 
96 
98  iSetup.get<TrackerDigiGeometryRecord>().get( tkGeom );
99 
100  vector<GeomDet*> Det = tkGeom->dets();
101  for(unsigned int i=0;i<Det.size();i++){
102  DetId Detid = Det[i]->geographicalId();
103 
104  StripGeomDetUnit* StripDetUnit = dynamic_cast<StripGeomDetUnit*> (Det[i]);
105  PixelGeomDetUnit* PixelDetUnit = dynamic_cast<PixelGeomDetUnit*> (Det[i]);
106 
107  double Thick=-1, Dist=-1, Norma=-1;
108  if(StripDetUnit){
109  Dist = StripDetUnit->position().mag();
110  Thick = StripDetUnit->surface().bounds().thickness();
111  Norma = MeVperADCStrip/Thick;
112  }else if(PixelDetUnit){
113  Dist = PixelDetUnit->position().mag();
114  Thick = PixelDetUnit->surface().bounds().thickness();
115  Norma = MeVperADCPixel/Thick;
116  }
117 
118  stModInfo* MOD = new stModInfo;
119  MOD->DetId = Detid.rawId();
120  MOD->Thickness = Thick;
121  MOD->Distance = Dist;
122  MOD->Normalization = Norma;
123  MOD->Gain = 1;
124  MODsColl[MOD->DetId] = MOD;
125  }
126 
128 }
int i
Definition: DBlmapReader.cc:9
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
virtual float thickness() const =0
T mag() const
Definition: PV3DBase.h:61
const Surface::PositionType & position() const
The position (origin of the R.F.)
Definition: GeomDet.h:43
Definition: DetId.h:20
const Bounds & bounds() const
Definition: BoundSurface.h:89
const T & get() const
Definition: EventSetup.h:55
__gnu_cxx::hash_map< unsigned int, stModInfo *, __gnu_cxx::hash< unsigned int >, isEqual > MODsColl
virtual const BoundPlane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
void DeDxEstimatorProducer::endJob ( void  )
privatevirtual

Reimplemented from edm::EDProducer.

Definition at line 131 of file DeDxEstimatorProducer.cc.

131  {
132  MODsColl.clear();
133 }
__gnu_cxx::hash_map< unsigned int, stModInfo *, __gnu_cxx::hash< unsigned int >, isEqual > MODsColl
int DeDxEstimatorProducer::getCharge ( const SiStripCluster Cluster,
int &  Saturating_Strips 
)
private

Definition at line 293 of file DeDxEstimatorProducer.cc.

References SiStripCluster::amplitudes(), DeDxEstimatorProducer::stModInfo::Gain, SiStripCluster::geographicalId(), and i.

294 {
295  const vector<uint8_t>& Ampls = Cluster->amplitudes();
296  uint32_t DetId = Cluster->geographicalId();
297 
298 // float G=1.0f;
299 
300  int toReturn = 0;
301  Saturating_Strips = 0;
302  for(unsigned int i=0;i<Ampls.size();i++){
303  int CalibratedCharge = Ampls[i];
304 
305  if(useCalibration){
306  stModInfo* MOD = MODsColl[DetId];
307 // G = MOD->Gain;
308  CalibratedCharge = (int)(CalibratedCharge / MOD->Gain );
309  if(CalibratedCharge>=1024){
310  CalibratedCharge = 255;
311  }else if(CalibratedCharge>=255){
312  CalibratedCharge = 254;
313  }
314  }
315 
316  toReturn+=CalibratedCharge;
317  if(CalibratedCharge>=254)Saturating_Strips++;
318  }
319 
320 // printf("Charge = %i --> %i (Gain=%f)\n", accumulate(Ampls.begin(), Ampls.end(), 0), toReturn, G);
321 
322 
323  return toReturn;
324 }
int i
Definition: DBlmapReader.cc:9
uint32_t geographicalId() const
Definition: DetId.h:20
__gnu_cxx::hash_map< unsigned int, stModInfo *, __gnu_cxx::hash< unsigned int >, isEqual > MODsColl
const std::vector< uint8_t > & amplitudes() const
void DeDxEstimatorProducer::MakeCalibrationMap ( )
private

Definition at line 265 of file DeDxEstimatorProducer.cc.

References DeDxEstimatorProducer::stModInfo::Gain.

266 {
267  if(!useCalibration)return;
268 
269  TChain* t1 = new TChain("SiStripCalib/APVGain");
270  t1->Add(m_calibrationPath.c_str());
271 
272  unsigned int tree_DetId;
273  unsigned char tree_APVId;
274  double tree_Gain;
275 
276  t1->SetBranchAddress("DetId" ,&tree_DetId );
277  t1->SetBranchAddress("APVId" ,&tree_APVId );
278  t1->SetBranchAddress("Gain" ,&tree_Gain );
279 
280 
281 
282  for (unsigned int ientry = 0; ientry < t1->GetEntries(); ientry++) {
283  t1->GetEntry(ientry);
284  stModInfo* MOD = MODsColl[tree_DetId];
285  MOD->Gain = tree_Gain;
286  }
287 
288  delete t1;
289 
290 }
__gnu_cxx::hash_map< unsigned int, stModInfo *, __gnu_cxx::hash< unsigned int >, isEqual > MODsColl
void DeDxEstimatorProducer::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
privatevirtual

Implements edm::EDProducer.

Definition at line 138 of file DeDxEstimatorProducer.cc.

References abs, DeDxTools::RawHits::angleCosine, edm::AssociationMap< Tag >::begin(), DeDxTools::RawHits::charge, DeDxDiscriminatorTools::charge(), SiStripRecHit2D::cluster(), DeDxTools::RawHits::detId, DeDxEstimatorProducer::stModInfo::Distance, edm::AssociationMap< Tag >::end(), edm::helper::Filler< Map >::fill(), TrackingRecHit::geographicalId(), edm::Event::getByLabel(), i, edm::helper::Filler< Map >::insert(), TrajectoryStateOnSurface::isValid(), j, edm::Ref< C, T, F >::key(), TrajectoryStateOnSurface::localDirection(), PV3DBase< T, PVType, FrameType >::mag(), n, DeDxEstimatorProducer::stModInfo::Normalization, DeDxTools::RawHits::NSaturating, edm::Handle< T >::product(), edm::Event::put(), DeDxTools::shapeSelection(), edm::AssociationMap< Tag >::size(), python.multivaluedict::sort(), DeDxEstimatorProducer::stModInfo::Thickness, DeDxTools::RawHits::trajectoryMeasurement, and PV3DBase< T, PVType, FrameType >::z().

139 {
140  auto_ptr<ValueMap<DeDxData> > trackDeDxEstimateAssociation(new ValueMap<DeDxData> );
141  ValueMap<DeDxData>::Filler filler(*trackDeDxEstimateAssociation);
142 
143  Handle<TrajTrackAssociationCollection> trajTrackAssociationHandle;
144  iEvent.getByLabel(m_trajTrackAssociationTag, trajTrackAssociationHandle);
145  const TrajTrackAssociationCollection & TrajToTrackMap = *trajTrackAssociationHandle.product();
146 
147  edm::Handle<reco::TrackCollection> trackCollectionHandle;
148  iEvent.getByLabel(m_tracksTag,trackCollectionHandle);
149 
150  size_t n = TrajToTrackMap.size();
151  std::vector<DeDxData> dedxEstimate(n);
152 
153  //assume trajectory collection size is equal to track collection size and that order is kept
154  int j=0;
155  for(TrajTrackAssociationCollection::const_iterator cit=TrajToTrackMap.begin(); cit!=TrajToTrackMap.end(); cit++,j++){
156 
157  const edm::Ref<std::vector<Trajectory> > traj = cit->key;
158  const reco::TrackRef track = cit->val;
159 
160  DeDxHitCollection dedxHits;
161  vector<DeDxTools::RawHits> hits;
162 // DeDxTools::trajectoryRawHits(traj, hits, usePixel, useStrip);
163 
164  const vector<TrajectoryMeasurement> & measurements = traj->measurements();
165  for(vector<TrajectoryMeasurement>::const_iterator it = measurements.begin(); it!=measurements.end(); it++){
166  TrajectoryStateOnSurface trajState=it->updatedState();
167  if( !trajState.isValid()) continue;
168 
169  const TrackingRecHit * recHit=(*it->recHit()).hit();
170  LocalVector trackDirection = trajState.localDirection();
171  double cosine = trackDirection.z()/trackDirection.mag();
172 
173  if(const SiStripMatchedRecHit2D* matchedHit=dynamic_cast<const SiStripMatchedRecHit2D*>(recHit)){
174  if(!useStrip) continue;
175  DeDxTools::RawHits mono,stereo;
176  mono.trajectoryMeasurement = &(*it);
177  stereo.trajectoryMeasurement = &(*it);
178  mono.angleCosine = cosine;
179  stereo.angleCosine = cosine;
180 
181  mono.charge = getCharge((matchedHit->monoHit()->cluster()).get(),mono.NSaturating);
182  stereo.charge = getCharge((matchedHit->stereoHit()->cluster()).get(),stereo.NSaturating);
183 
184  mono.detId= matchedHit->monoHit()->geographicalId();
185  stereo.detId= matchedHit->stereoHit()->geographicalId();
186 
187  if(shapetest && !(DeDxTools::shapeSelection(((matchedHit->stereoHit()->cluster()).get())->amplitudes()))) hits.push_back(stereo);
188  if(shapetest && !(DeDxTools::shapeSelection(((matchedHit->monoHit ()->cluster()).get())->amplitudes()))) hits.push_back(mono);
189  }else if(const ProjectedSiStripRecHit2D* projectedHit=dynamic_cast<const ProjectedSiStripRecHit2D*>(recHit)) {
190  if(!useStrip) continue;
191  const SiStripRecHit2D* singleHit=&(projectedHit->originalHit());
192  DeDxTools::RawHits mono;
193 
194  mono.trajectoryMeasurement = &(*it);
195  mono.angleCosine = cosine;
196  mono.charge = getCharge((singleHit->cluster()).get(),mono.NSaturating);
197  mono.detId= singleHit->geographicalId();
198  if(shapetest && !(DeDxTools::shapeSelection(((singleHit->cluster()).get())->amplitudes()))) continue;
199  hits.push_back(mono);
200  }else if(const SiStripRecHit2D* singleHit=dynamic_cast<const SiStripRecHit2D*>(recHit)){
201  if(!useStrip) continue;
202  DeDxTools::RawHits mono;
203 
204  mono.trajectoryMeasurement = &(*it);
205  mono.angleCosine = cosine;
206  mono.charge = getCharge((singleHit->cluster()).get(),mono.NSaturating);
207  mono.detId= singleHit->geographicalId();
208  if(shapetest && !(DeDxTools::shapeSelection(((singleHit->cluster()).get())->amplitudes()))) continue;
209  hits.push_back(mono);
210  }else if(const SiStripRecHit1D* single1DHit=dynamic_cast<const SiStripRecHit1D*>(recHit)){
211  if(!useStrip) continue;
212  DeDxTools::RawHits mono;
213 
214  mono.trajectoryMeasurement = &(*it);
215  mono.angleCosine = cosine;
216  mono.charge = getCharge((single1DHit->cluster()).get(),mono.NSaturating);
217  mono.detId= single1DHit->geographicalId();
218  if(shapetest && !(DeDxTools::shapeSelection(((single1DHit->cluster()).get())->amplitudes()))) continue;
219  hits.push_back(mono);
220  }else if(const SiPixelRecHit* pixelHit=dynamic_cast<const SiPixelRecHit*>(recHit)){
221  if(!usePixel) continue;
222 
223  DeDxTools::RawHits pixel;
224 
225  pixel.trajectoryMeasurement = &(*it);
226  pixel.angleCosine = cosine;
227  pixel.charge = pixelHit->cluster()->charge();
228  pixel.NSaturating=-1;
229  pixel.detId= pixelHit->geographicalId();
230  hits.push_back(pixel);
231  }
232  }
234 
235  int NClusterSaturating = 0;
236  for(size_t i=0; i < hits.size(); i++)
237  {
238  stModInfo* MOD = MODsColl[hits[i].detId];
239  float pathLen = MOD->Thickness/std::abs(hits[i].angleCosine);
240  float charge = MOD->Normalization*hits[i].charge*std::abs(hits[i].angleCosine);
241  dedxHits.push_back( DeDxHit( charge, MOD->Distance, pathLen, hits[i].detId) );
242 
243  if(hits[i].NSaturating>0)NClusterSaturating++;
244  }
245 
246  sort(dedxHits.begin(),dedxHits.end(),less<DeDxHit>());
247  std::pair<float,float> val_and_error = m_estimator->dedx(dedxHits);
248 
249  //WARNING: Since the dEdX Error is not properly computed for the moment
250  //It was decided to store the number of saturating cluster in that dataformat
251  val_and_error.second = NClusterSaturating;
252 
253  dedxEstimate[j] = DeDxData(val_and_error.first, val_and_error.second, dedxHits.size() );
254  }
255  filler.insert(trackCollectionHandle, dedxEstimate.begin(), dedxEstimate.end());
256 
257  // really fill the association map
258  filler.fill();
259  // put into the event
260  iEvent.put(trackDeDxEstimateAssociation);
261 }
int i
Definition: DBlmapReader.cc:9
edm::InputTag m_trajTrackAssociationTag
const_iterator end() const
last iterator over the map (read only)
LocalVector localDirection() const
std::vector< DeDxHit > DeDxHitCollection
Definition: DeDxHit.h:49
#define abs(x)
Definition: mlp_lapack.h:159
double charge(const std::vector< uint8_t > &Ampls)
T mag() const
Definition: PV3DBase.h:61
double angleCosine
Definition: DeDxTools.h:14
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:84
int getCharge(const SiStripCluster *Cluster, int &Saturating_Strips)
T z() const
Definition: PV3DBase.h:58
int j
Definition: DBlmapReader.cc:9
BaseDeDxEstimator * m_estimator
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:355
virtual std::pair< float, float > dedx(const reco::DeDxHitCollection &Hits)=0
bool shapeSelection(const std::vector< uint8_t > &ampls)
Definition: DeDxTools.cc:141
size_type size() const
map size
const TrajectoryMeasurement * trajectoryMeasurement
Definition: DeDxTools.h:16
ClusterRef const & cluster() const
key_type key() const
Accessor for product key.
Definition: Ref.h:265
T const * product() const
Definition: Handle.h:74
__gnu_cxx::hash_map< unsigned int, stModInfo *, __gnu_cxx::hash< unsigned int >, isEqual > MODsColl
const_iterator begin() const
first iterator over the map (read only)
DetId geographicalId() const
Our base class.
Definition: SiPixelRecHit.h:27

Member Data Documentation

std::string DeDxEstimatorProducer::m_calibrationPath
private

Definition at line 64 of file DeDxEstimatorProducer.h.

BaseDeDxEstimator* DeDxEstimatorProducer::m_estimator
private

Definition at line 51 of file DeDxEstimatorProducer.h.

edm::InputTag DeDxEstimatorProducer::m_tracksTag
private

Definition at line 54 of file DeDxEstimatorProducer.h.

edm::InputTag DeDxEstimatorProducer::m_trajTrackAssociationTag
private

Definition at line 53 of file DeDxEstimatorProducer.h.

unsigned int DeDxEstimatorProducer::MaxNrStrips
private

Definition at line 61 of file DeDxEstimatorProducer.h.

double DeDxEstimatorProducer::MeVperADCPixel
private

Definition at line 58 of file DeDxEstimatorProducer.h.

double DeDxEstimatorProducer::MeVperADCStrip
private

Definition at line 59 of file DeDxEstimatorProducer.h.

unsigned int DeDxEstimatorProducer::MinTrackHits
private

Definition at line 62 of file DeDxEstimatorProducer.h.

__gnu_cxx::hash_map<unsigned int, stModInfo*, __gnu_cxx::hash<unsigned int>, isEqual > DeDxEstimatorProducer::MODsColl
private

Definition at line 76 of file DeDxEstimatorProducer.h.

bool DeDxEstimatorProducer::shapetest
private

Definition at line 66 of file DeDxEstimatorProducer.h.

bool DeDxEstimatorProducer::useCalibration
private

Definition at line 65 of file DeDxEstimatorProducer.h.

bool DeDxEstimatorProducer::usePixel
private

Definition at line 56 of file DeDxEstimatorProducer.h.

bool DeDxEstimatorProducer::useStrip
private

Definition at line 57 of file DeDxEstimatorProducer.h.