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);
38  desc.add<double>("MeVperADCStrip",3.61e-06*265);
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 == "genericTruncated") m_estimator = new GenericTruncatedAverageDeDxEstimator(iConfig);
61  else if(estimatorName == "unbinnedFit") m_estimator = new UnbinnedFitDeDxEstimator(iConfig);
62  else if(estimatorName == "productDiscrim") m_estimator = new ProductDeDxDiscriminator(iConfig);
63  else if(estimatorName == "btagDiscrim") m_estimator = new BTagLikeDeDxDiscriminator(iConfig);
64  else if(estimatorName == "smirnovDiscrim") m_estimator = new SmirnovDeDxDiscriminator(iConfig);
65  else if(estimatorName == "asmirnovDiscrim") m_estimator = new ASmirnovDeDxDiscriminator(iConfig);
66 
67  //Commented for now, might be used in the future
68 // MaxNrStrips = iConfig.getUntrackedParameter<unsigned>("maxNrStrips" , 255);
69 
70  m_tracksTag = consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("tracks"));
71 
72  usePixel = iConfig.getParameter<bool>("UsePixel");
73  useStrip = iConfig.getParameter<bool>("UseStrip");
74  meVperADCPixel = iConfig.getParameter<double>("MeVperADCPixel");
75  meVperADCStrip = iConfig.getParameter<double>("MeVperADCStrip");
76 
77  shapetest = iConfig.getParameter<bool>("ShapeTest");
78  useCalibration = iConfig.getParameter<bool>("UseCalibration");
79  m_calibrationPath = iConfig.getParameter<string>("calibrationPath");
80 
81  if(!usePixel && !useStrip)
82  edm::LogWarning("DeDxHitsProducer") << "Pixel Hits AND Strip Hits will not be used to estimate dEdx --> BUG, Please Update the config file";
83 
84 }
85 
86 
88 {
89  delete m_estimator;
90 }
91 
92 // ------------ method called once each job just before starting event loop ------------
94 {
95  iSetup.get<TrackerDigiGeometryRecord>().get( tkGeom );
96  if(useCalibration && calibGains.empty()){
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  const auto * detUnit = recHit->detUnit();
166  if (detUnit == nullptr) detUnit = tkGeom->idToDet(thit.geographicalId());
167  float pathLen = detUnit->surface().bounds().thickness()/fabs(cosine);
168  float chargeAbs = clus.pixelCluster().charge();
169  float charge = meVperADCPixel*chargeAbs/pathLen;
170  dedxHits.push_back( DeDxHit( charge, trackMomentum, pathLen, thit.geographicalId()) );
171  }else if(clus.isStrip() && !thit.isMatched()){
172  if(!useStrip) return;
173 
174  const auto * detUnit = recHit->detUnit();
175  if (detUnit == nullptr) detUnit = tkGeom->idToDet(thit.geographicalId());
176  int NSaturating = 0;
177  float pathLen = detUnit->surface().bounds().thickness()/fabs(cosine);
178  float chargeAbs = DeDxTools::getCharge(&(clus.stripCluster()),NSaturating, *detUnit, calibGains, m_off);
179  float charge = meVperADCStrip*chargeAbs/pathLen;
180  if(!shapetest || (shapetest && DeDxTools::shapeSelection(clus.stripCluster()))){
181  dedxHits.push_back( DeDxHit( charge, trackMomentum, pathLen, thit.geographicalId()) );
182  if(NSaturating>0)NClusterSaturating++;
183  }
184  }else if(clus.isStrip() && thit.isMatched()){
185  if(!useStrip) return;
186  const SiStripMatchedRecHit2D* matchedHit=dynamic_cast<const SiStripMatchedRecHit2D*>(recHit);
187  if(!matchedHit)return;
188  const GluedGeomDet* gdet = static_cast<const GluedGeomDet*>(matchedHit->det());
189  if (gdet == nullptr) gdet = static_cast<const GluedGeomDet*>(tkGeom->idToDet(thit.geographicalId()));
190 
191  auto& detUnitM = *(gdet->monoDet());
192  int NSaturating = 0;
193  float pathLen = detUnitM.surface().bounds().thickness()/fabs(cosine);
194  float chargeAbs = DeDxTools::getCharge(&(matchedHit->monoCluster()),NSaturating, detUnitM, calibGains, m_off);
195  float charge = meVperADCStrip*chargeAbs/pathLen;
196  if(!shapetest || (shapetest && DeDxTools::shapeSelection(matchedHit->monoCluster()))){
197  dedxHits.push_back( DeDxHit( charge, trackMomentum, pathLen, matchedHit->monoId()) );
198  if(NSaturating>0)NClusterSaturating++;
199  }
200 
201  auto& detUnitS = *(gdet->stereoDet());
202  NSaturating = 0;
203  pathLen = detUnitS.surface().bounds().thickness()/fabs(cosine);
204  chargeAbs = DeDxTools::getCharge(&(matchedHit->stereoCluster()),NSaturating, detUnitS, calibGains, m_off);
205  charge = meVperADCStrip*chargeAbs/pathLen;
206  if(!shapetest || (shapetest && DeDxTools::shapeSelection(matchedHit->stereoCluster()))){
207  dedxHits.push_back( DeDxHit( charge, trackMomentum, pathLen, matchedHit->stereoId()) );
208  if(NSaturating>0)NClusterSaturating++;
209  }
210  }
211 }
212 
213 
214 
215 //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:136
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:519
#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
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
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:59
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
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:43