CMS 3D CMS Logo

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<bool>("UsePixel",false);
36  desc.add<bool>("UseStrip",true);
37  desc.add<double>("MeVperADCPixel",3.61e-06*265);
38  desc.add<double>("MeVperADCStrip",3.61e-06);
39  desc.add<bool>("ShapeTest",true);
40  desc.add<bool>("UseCalibration",false);
41  desc.add<string>("calibrationPath", "");
42  desc.add<string>("Reccord", "SiStripDeDxMip_3D_Rcd");
43  desc.add<string>("ProbabilityMode", "Accumulation");
44  desc.add<double>("fraction", 0.4);
45  desc.add<double>("exponent",-2.0);
46 
47  descriptions.add("DeDxEstimatorProducer",desc);
48 }
49 
50 
52 {
53 
54  produces<ValueMap<DeDxData> >();
55 
56  string estimatorName = iConfig.getParameter<string>("estimator");
57  if (estimatorName == "median") m_estimator = new MedianDeDxEstimator(iConfig);
58  else if(estimatorName == "generic") m_estimator = new GenericAverageDeDxEstimator (iConfig);
59  else if(estimatorName == "truncated") m_estimator = new TruncatedAverageDeDxEstimator(iConfig);
60  else if(estimatorName == "unbinnedFit") m_estimator = new UnbinnedFitDeDxEstimator(iConfig);
61  else if(estimatorName == "productDiscrim") m_estimator = new ProductDeDxDiscriminator(iConfig);
62  else if(estimatorName == "btagDiscrim") m_estimator = new BTagLikeDeDxDiscriminator(iConfig);
63  else if(estimatorName == "smirnovDiscrim") m_estimator = new SmirnovDeDxDiscriminator(iConfig);
64  else if(estimatorName == "asmirnovDiscrim") m_estimator = new ASmirnovDeDxDiscriminator(iConfig);
65 
66  //Commented for now, might be used in the future
67 // MaxNrStrips = iConfig.getUntrackedParameter<unsigned>("maxNrStrips" , 255);
68 
69  m_tracksTag = consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("tracks"));
70 
71  usePixel = iConfig.getParameter<bool>("UsePixel");
72  useStrip = iConfig.getParameter<bool>("UseStrip");
73  meVperADCPixel = iConfig.getParameter<double>("MeVperADCPixel");
74  meVperADCStrip = iConfig.getParameter<double>("MeVperADCStrip");
75 
76  shapetest = iConfig.getParameter<bool>("ShapeTest");
77  useCalibration = iConfig.getParameter<bool>("UseCalibration");
78  m_calibrationPath = iConfig.getParameter<string>("calibrationPath");
79 
80  if(!usePixel && !useStrip)
81  edm::LogWarning("DeDxHitsProducer") << "Pixel Hits AND Strip Hits will not be used to estimate dEdx --> BUG, Please Update the config file";
82 
83 }
84 
85 
87 {
88  delete m_estimator;
89 }
90 
91 // ------------ method called once each job just before starting event loop ------------
93 {
94  if(useCalibration && calibGains.size()==0){
96  iSetup.get<TrackerDigiGeometryRecord>().get( tkGeom );
97  m_off = tkGeom->offsetDU(GeomDetEnumerators::PixelBarrel); //index start at the first pixel
98 
99  DeDxTools::makeCalibrationMap(m_calibrationPath, *tkGeom, calibGains, m_off);
100  }
101 
102  m_estimator->beginRun(run, iSetup);
103 }
104 
105 
106 
108 {
109  auto trackDeDxEstimateAssociation = std::make_unique<ValueMap<DeDxData>>();
110  ValueMap<DeDxData>::Filler filler(*trackDeDxEstimateAssociation);
111 
112  edm::Handle<reco::TrackCollection> trackCollectionHandle;
113  iEvent.getByToken(m_tracksTag,trackCollectionHandle);
114 
115 
116  std::vector<DeDxData> dedxEstimate( trackCollectionHandle->size() );
117 
118  for(unsigned int j=0;j<trackCollectionHandle->size();j++){
119  const reco::TrackRef track = reco::TrackRef( trackCollectionHandle.product(), j );
120 
121  int NClusterSaturating = 0;
122  DeDxHitCollection dedxHits;
123 
124  auto const & trajParams = track->extra()->trajParams();
125  assert(trajParams.size()==track->recHitsSize());
126  auto hb = track->recHitsBegin();
127  dedxHits.reserve(track->recHitsSize()/2);
128  for(unsigned int h=0;h<track->recHitsSize();h++){
129  auto recHit = *(hb+h);
130  if(!recHit->isValid()) continue;
131 
132  auto trackDirection = trajParams[h].direction();
133  float cosine = trackDirection.z()/trackDirection.mag();
134  processHit(recHit, track->p(), cosine, dedxHits, NClusterSaturating);
135  }
136 
137  sort(dedxHits.begin(),dedxHits.end(),less<DeDxHit>());
138  std::pair<float,float> val_and_error = m_estimator->dedx(dedxHits);
139 
140  //WARNING: Since the dEdX Error is not properly computed for the moment
141  //It was decided to store the number of saturating cluster in that dataformat
142  val_and_error.second = NClusterSaturating;
143  dedxEstimate[j] = DeDxData(val_and_error.first, val_and_error.second, dedxHits.size() );
144  }
146 
147  filler.insert(trackCollectionHandle, dedxEstimate.begin(), dedxEstimate.end());
148 
149  // fill the association map and put it into the event
150  filler.fill();
151  iEvent.put(std::move(trackDeDxEstimateAssociation));
152 }
153 
154 
155 void DeDxEstimatorProducer::processHit(const TrackingRecHit* recHit, float trackMomentum, float& cosine, reco::DeDxHitCollection& dedxHits, int& NClusterSaturating){
156  auto const & thit = static_cast<BaseTrackerRecHit const&>(*recHit);
157  if(!thit.isValid())return;
158 
159  auto const & clus = thit.firstClusterRef();
160  if(!clus.isValid())return;
161 
162  if(clus.isPixel()){
163  if(!usePixel) return;
164 
165  auto& detUnit = *(recHit->detUnit());
166  float pathLen = detUnit.surface().bounds().thickness()/fabs(cosine);
167  float chargeAbs = clus.pixelCluster().charge();
168  float charge = meVperADCPixel*chargeAbs/pathLen;
169  dedxHits.push_back( DeDxHit( charge, trackMomentum, pathLen, thit.geographicalId()) );
170  }else if(clus.isStrip() && !thit.isMatched()){
171  if(!useStrip) return;
172 
173  auto& detUnit = *(recHit->detUnit());
174  int NSaturating = 0;
175  float pathLen = detUnit.surface().bounds().thickness()/fabs(cosine);
176  float chargeAbs = DeDxTools::getCharge(&(clus.stripCluster()),NSaturating, detUnit, calibGains, m_off);
177  float charge = meVperADCStrip*chargeAbs/pathLen;
178  if(!shapetest || (shapetest && DeDxTools::shapeSelection(clus.stripCluster()))){
179  dedxHits.push_back( DeDxHit( charge, trackMomentum, pathLen, thit.geographicalId()) );
180  if(NSaturating>0)NClusterSaturating++;
181  }
182  }else if(clus.isStrip() && thit.isMatched()){
183  if(!useStrip) return;
184  const SiStripMatchedRecHit2D* matchedHit=dynamic_cast<const SiStripMatchedRecHit2D*>(recHit);
185  if(!matchedHit)return;
186  const GluedGeomDet* gdet = static_cast<const GluedGeomDet*>(matchedHit->det());
187 
188  auto& detUnitM = *(gdet->monoDet());
189  int NSaturating = 0;
190  float pathLen = detUnitM.surface().bounds().thickness()/fabs(cosine);
191  float chargeAbs = DeDxTools::getCharge(&(matchedHit->monoCluster()),NSaturating, detUnitM, calibGains, m_off);
192  float charge = meVperADCStrip*chargeAbs/pathLen;
193  if(!shapetest || (shapetest && DeDxTools::shapeSelection(matchedHit->monoCluster()))){
194  dedxHits.push_back( DeDxHit( charge, trackMomentum, pathLen, matchedHit->monoId()) );
195  if(NSaturating>0)NClusterSaturating++;
196  }
197 
198  auto& detUnitS = *(gdet->stereoDet());
199  NSaturating = 0;
200  pathLen = detUnitS.surface().bounds().thickness()/fabs(cosine);
201  chargeAbs = DeDxTools::getCharge(&(matchedHit->stereoCluster()),NSaturating, detUnitS, calibGains, m_off);
202  charge = meVperADCStrip*chargeAbs/pathLen;
203  if(!shapetest || (shapetest && DeDxTools::shapeSelection(matchedHit->stereoCluster()))){
204  dedxHits.push_back( DeDxHit( charge, trackMomentum, pathLen, matchedHit->stereoId()) );
205  if(NSaturating>0)NClusterSaturating++;
206  }
207  }
208 }
209 
210 
211 
212 //define this as a plug-in
T getParameter(std::string const &) const
DeDxEstimatorProducer(const edm::ParameterSet &)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
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
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
SiStripCluster const & monoCluster() const
std::vector< DeDxHit > DeDxHitCollection
Definition: DeDxHit.h:58
const Bounds & bounds() const
Definition: Surface.h:120
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:42
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
virtual void beginRun(edm::Run const &run, const edm::EventSetup &) override
int iEvent
Definition: GenABIO.cc:230
const GeomDet * det() const
bool shapeSelection(const SiStripCluster &ampls)
Definition: DeDxTools.cc:10
unsigned int offsetDU(SubDetector sid) const
void processHit(const TrackingRecHit *recHit, float trackMomentum, float &cosine, reco::DeDxHitCollection &dedxHits, int &NClusterSaturating)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
T const * product() const
Definition: Handle.h:81
virtual float thickness() const =0
const T & get() const
Definition: EventSetup.h:56
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:20
void add(std::string const &label, ParameterSetDescription const &psetDescription)
SiStripCluster const & stereoCluster() const
fixed size matrix
HLT enums.
virtual const GeomDetUnit * detUnit() const
virtual void produce(edm::Event &, const edm::EventSetup &) override
virtual OmniClusterRef const & firstClusterRef() const =0
unsigned int monoId() const
def move(src, dest)
Definition: eostools.py:510
const GeomDetUnit * stereoDet() const
Definition: GluedGeomDet.h:21
Definition: Run.h:42