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, const uint32_t &)
 
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)
 
static void prevalidate (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 51 of file DeDxEstimatorProducer.cc.

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

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

84 {
85  delete m_estimator;
86 }
BaseDeDxEstimator * m_estimator

Member Function Documentation

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

Reimplemented from edm::EDProducer.

Definition at line 89 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.

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

Reimplemented from edm::EDProducer.

Definition at line 128 of file DeDxEstimatorProducer.cc.

128  {
129  MODsColl.clear();
130 }
__gnu_cxx::hash_map< unsigned int, stModInfo *, __gnu_cxx::hash< unsigned int >, isEqual > MODsColl
int DeDxEstimatorProducer::getCharge ( const SiStripCluster Cluster,
int &  Saturating_Strips,
const uint32_t &  DetId 
)
private

Definition at line 290 of file DeDxEstimatorProducer.cc.

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

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

References DeDxEstimatorProducer::stModInfo::Gain.

263 {
264  if(!useCalibration)return;
265 
266  TChain* t1 = new TChain("SiStripCalib/APVGain");
267  t1->Add(m_calibrationPath.c_str());
268 
269  unsigned int tree_DetId;
270  unsigned char tree_APVId;
271  double tree_Gain;
272 
273  t1->SetBranchAddress("DetId" ,&tree_DetId );
274  t1->SetBranchAddress("APVId" ,&tree_APVId );
275  t1->SetBranchAddress("Gain" ,&tree_Gain );
276 
277 
278 
279  for (unsigned int ientry = 0; ientry < t1->GetEntries(); ientry++) {
280  t1->GetEntry(ientry);
281  stModInfo* MOD = MODsColl[tree_DetId];
282  MOD->Gain = tree_Gain;
283  }
284 
285  delete t1;
286 
287 }
__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 135 of file DeDxEstimatorProducer.cc.

References abs, DeDxTools::RawHits::angleCosine, edm::AssociationMap< Tag >::begin(), DeDxTools::RawHits::charge, DeDxDiscriminatorTools::charge(), DeDxTools::RawHits::detId, DeDxEstimatorProducer::stModInfo::Distance, edm::AssociationMap< Tag >::end(), edm::helper::Filler< Map >::fill(), edm::Event::getByLabel(), DeDxTools::GetCluster(), 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().

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

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.