CMS 3D CMS Logo

FastTrackDeDxProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: FastTrackDeDxProducer
4 // Class: FastTrackDeDxProducer
5 //
13 // Original author: Sam Bein
14 // Created: Wednesday Dec 26 14:17:19 CEST 2018
15 // Author of derivative code: andrea
16 // Created: Thu May 31 14:09:02 CEST 2007
17 // Code Updates: loic Quertenmont (querten)
18 // Created: Thu May 10 14:09:02 CEST 2008
19 //
20 //
21 
22 
23 #include <memory>
24 
31 
36 
43 
44 
54 
56 
58 
63 
64 
65 
66 //
67 // class declaration
68 //
69 
71 public:
73  ~FastTrackDeDxProducer() override = default;
74  static void fillDescriptions(edm::ConfigurationDescriptions & descriptions);
75 
76 private:
77  void beginRun(edm::Run const& run, const edm::EventSetup&) override;
78  void produce(edm::Event&, const edm::EventSetup&) override;
79 
80  void makeCalibrationMap(const TrackerGeometry& tkGeom);
81  void processHit(const FastTrackerRecHit & recHit, float trackMomentum, float& cosine, reco::DeDxHitCollection& dedxHits, int& NClusterSaturating);
82 
83  // ----------member data ---------------------------
84 //BaseDeDxEstimator* m_estimator;
85 
86 std::unique_ptr<BaseDeDxEstimator> m_estimator;
87 
89 
90 
91 
94 
95  unsigned int MaxNrStrips;
96 
98 
99  std::vector< std::vector<float> > calibGains;
100  unsigned int m_off;
101 
104 
105  bool usePixel;
106  bool useStrip;
108  bool shapetest;
110  bool nothick;
111 
112 
113 };
114 
115 using namespace reco;
116 using namespace std;
117 using namespace edm;
118 
121  desc.add<string>("estimator","generic");
122  desc.add<edm::InputTag>("tracks",edm::InputTag("generalTracks"));
123  desc.add<bool>("UsePixel",false);
124  desc.add<bool>("UseStrip",true);
125  desc.add<double>("MeVperADCStrip",3.61e-06*265);
126  desc.add<double>("MeVperADCPixel",3.61e-06);
127  desc.add<bool>("ShapeTest",true);
128  desc.add<bool>("UseCalibration",false);
129  desc.add<string>("calibrationPath", "");
130  desc.add<string>("Reccord", "SiStripDeDxMip_3D_Rcd");
131  desc.add<string>("ProbabilityMode", "Accumulation");
132  desc.add<double>("fraction", 0.4);
133  desc.add<double>("exponent",-2.0);
134  desc.add<bool>("convertFromGeV2MeV",true);
135  desc.add<bool>("nothick",false);
136  desc.add<edm::InputTag>("simHits");
137  desc.add<edm::InputTag>("simHit2RecHitMap");
138  descriptions.add("FastTrackDeDxProducer",desc);
139 }
140 
141 
143 : simHitsToken(consumes<edm::PSimHitContainer>(iConfig.getParameter<edm::InputTag>("simHits")))
144 , simHit2RecHitMapToken(consumes<FastTrackerRecHitRefCollection>(iConfig.getParameter<edm::InputTag>("simHit2RecHitMap")))
145 {
146  produces<ValueMap<DeDxData> >();
147 
148  string estimatorName = iConfig.getParameter<string>("estimator");
149  if (estimatorName == "median") m_estimator = std::unique_ptr<BaseDeDxEstimator> (new MedianDeDxEstimator(iConfig));
150  else if(estimatorName == "generic") m_estimator = std::unique_ptr<BaseDeDxEstimator> (new GenericAverageDeDxEstimator (iConfig));
151  else if(estimatorName == "truncated") m_estimator = std::unique_ptr<BaseDeDxEstimator> (new TruncatedAverageDeDxEstimator(iConfig));
152  //else if(estimatorName == "unbinnedFit") m_estimator = std::unique_ptr<BaseDeDxEstimator> (new UnbinnedFitDeDxEstimator(iConfig));//estimator used in FullSimVersion
153  else if(estimatorName == "productDiscrim") m_estimator = std::unique_ptr<BaseDeDxEstimator> (new ProductDeDxDiscriminator(iConfig));
154  else if(estimatorName == "btagDiscrim") m_estimator = std::unique_ptr<BaseDeDxEstimator> (new BTagLikeDeDxDiscriminator(iConfig));
155  else if(estimatorName == "smirnovDiscrim") m_estimator = std::unique_ptr<BaseDeDxEstimator> (new SmirnovDeDxDiscriminator(iConfig));
156  else if(estimatorName == "asmirnovDiscrim") m_estimator = std::unique_ptr<BaseDeDxEstimator> (new ASmirnovDeDxDiscriminator(iConfig));
157  else throw cms::Exception("fastsim::SimplifiedGeometry::FastTrackDeDxProducer.cc") << " estimator name does not exist";
158 
159  //Commented for now, might be used in the future
160  // MaxNrStrips = iConfig.getUntrackedParameter<unsigned>("maxNrStrips" , 255);
161 
162  m_tracksTag = consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("tracks"));
163 
164  usePixel = iConfig.getParameter<bool>("UsePixel");
165  useStrip = iConfig.getParameter<bool>("UseStrip");
166  meVperADCPixel = iConfig.getParameter<double>("MeVperADCPixel");
167  meVperADCStrip = iConfig.getParameter<double>("MeVperADCStrip");
168 
169  shapetest = iConfig.getParameter<bool>("ShapeTest");
170  useCalibration = iConfig.getParameter<bool>("UseCalibration");
171  m_calibrationPath = iConfig.getParameter<string>("calibrationPath");
172 
173  convertFromGeV2MeV = iConfig.getParameter<bool>("convertFromGeV2MeV");
174  nothick = iConfig.getParameter<bool>("nothick");
175 
176  if(!usePixel && !useStrip)
177  throw cms::Exception("fastsim::SimplifiedGeometry::FastTrackDeDxProducer.cc") << " neither pixel hits nor strips hits will be used to compute de/dx";
178 
179 
180 }
181 
182 // ------------ method called once each job just before starting event loop ------------
184 {
185  if(useCalibration && calibGains.empty()){
187  iSetup.get<TrackerDigiGeometryRecord>().get( tkGeom );
188  m_off = tkGeom->offsetDU(GeomDetEnumerators::PixelBarrel); //index start at the first pixel
189 
191  }
192 
193  m_estimator->beginRun(run, iSetup);
194 }
195 
196 
197 
199 {
200 
201  auto trackDeDxEstimateAssociation = std::make_unique<ValueMap<DeDxData>>();
202  ValueMap<DeDxData>::Filler filler(*trackDeDxEstimateAssociation);
203 
204  edm::Handle<reco::TrackCollection> trackCollectionHandle;
205  iEvent.getByToken(m_tracksTag,trackCollectionHandle);
206  const auto& trackCollection = *trackCollectionHandle;
207  std::vector<DeDxData> dedxEstimate( trackCollection.size() );
208 
209 
210 
211  for(unsigned int j=0;j<trackCollection.size();j++){
212  const reco::TrackRef track = reco::TrackRef( trackCollectionHandle.product(), j );
213 
214  int NClusterSaturating = 0;
215  DeDxHitCollection dedxHits;
216 
217  auto const & trajParams = track->extra()->trajParams();
218  assert(trajParams.size()==track->recHitsSize());
219 
220  auto hb = track->recHitsBegin();
221  dedxHits.reserve(track->recHitsSize()/2);
222 
223 
224 
225  for(unsigned int h=0;h<track->recHitsSize();h++){
226  const FastTrackerRecHit& recHit = static_cast< const FastTrackerRecHit & >(*(*(hb+h)));
227  if(!recHit.isValid()) continue;//FastTrackerRecHit recHit = *(hb+h);
228  auto trackDirection = trajParams[h].direction();
229  float cosine = trackDirection.z()/trackDirection.mag();
230  processHit(recHit, track->p(), cosine, dedxHits, NClusterSaturating);
231  }
232 
233  sort(dedxHits.begin(),dedxHits.end(),less<DeDxHit>());
234  std::pair<float,float> val_and_error = m_estimator->dedx(dedxHits);
235  //WARNING: Since the dEdX Error is not properly computed for the moment
236  //It was decided to store the number of saturating cluster in that dataformat
237  val_and_error.second = NClusterSaturating;
238  dedxEstimate[j] = DeDxData(val_and_error.first, val_and_error.second, dedxHits.size() );
239  }
240 
241 
242  filler.insert(trackCollectionHandle, dedxEstimate.begin(), dedxEstimate.end());
243  // fill the association map and put it into the event
244  filler.fill();
245  iEvent.put(std::move(trackDeDxEstimateAssociation));
246 }
247 
248 
249 void FastTrackDeDxProducer::processHit(const FastTrackerRecHit &recHit, float trackMomentum, float& cosine, reco::DeDxHitCollection& dedxHits, int& NClusterSaturating){
250 
251  if (!recHit.isValid()) return;
252 
253  auto const& thit = static_cast<BaseTrackerRecHit const&>(recHit);
254  if (!thit.isValid()) return;
255 
256  if (!thit.hasPositionAndError()) return;
257 
258  if(recHit.isPixel()){
259  if(!usePixel) return;
260 
261  auto& detUnit = *(recHit.detUnit());
262  float pathLen = detUnit.surface().bounds().thickness()/fabs(cosine);
263  if (nothick) pathLen = 1.0;
264  float charge = recHit.energyLoss()/pathLen;
265  if (convertFromGeV2MeV) charge*=1000;
266  dedxHits.push_back( DeDxHit( charge, trackMomentum, pathLen, recHit.geographicalId()) );
267  }
268  else if(!recHit.isPixel()){// && !recHit.isMatched()){//check what recHit.isMatched is doing
269  if(!useStrip) return;
270  auto& detUnit = *(recHit.detUnit());
271  float pathLen = detUnit.surface().bounds().thickness()/fabs(cosine);
272  if (nothick) pathLen = 1.0;
273  float dedxOfRecHit = recHit.energyLoss()/pathLen;
274  if (convertFromGeV2MeV) dedxOfRecHit*=1000;
275  if(!shapetest ){
276  dedxHits.push_back( DeDxHit( dedxOfRecHit, trackMomentum, pathLen, recHit.geographicalId()) );
277  }
278  }
279 }
280 
281 
282 
283 //define this as a plug-in
T getParameter(std::string const &) const
void makeCalibrationMap(const TrackerGeometry &tkGeom)
FastTrackDeDxProducer(const edm::ParameterSet &)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void processHit(const FastTrackerRecHit &recHit, float trackMomentum, float &cosine, reco::DeDxHitCollection &dedxHits, int &NClusterSaturating)
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
edm::EDGetTokenT< reco::TrackCollection > m_tracksTag
std::vector< DeDxHit > DeDxHitCollection
Definition: DeDxHit.h:58
const Bounds & bounds() const
Definition: Surface.h:120
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
int iEvent
Definition: GenABIO.cc:230
~FastTrackDeDxProducer() override=default
unsigned int offsetDU(SubDetector sid) const
edm::EDGetTokenT< FastTrackerRecHitRefCollection > simHit2RecHitMapToken
ParameterDescriptionBase * add(U const &iLabel, T const &value)
float energyLoss() const
edm::EDGetTokenT< edm::PSimHitContainer > simHitsToken
void beginRun(edm::Run const &run, const edm::EventSetup &) override
T const * product() const
Definition: Handle.h:81
virtual float thickness() const =0
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:21
bool isValid() const
void add(std::string const &label, ParameterSetDescription const &psetDescription)
bool isPixel() const override
pixel or strip?
std::vector< std::vector< float > > calibGains
const Surface * surface() const final
std::vector< FastTrackerRecHitRef > FastTrackerRecHitRefCollection
fixed size matrix
HLT enums.
virtual const GeomDetUnit * detUnit() const
T get() const
Definition: EventSetup.h:63
std::unique_ptr< BaseDeDxEstimator > m_estimator
std::vector< PSimHit > PSimHitContainer
DetId geographicalId() const
void produce(edm::Event &, const edm::EventSetup &) override
def move(src, dest)
Definition: eostools.py:510
Definition: Run.h:44