CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DeDxEstimatorProducerPixelTripplet.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: DeDxEstimatorProducerPixelTripplet
4 // Class: DeDxEstimatorProducerPixelTripplet
5 //
13 //
14 // Original Author: loic Quertenmont (querten)
15 // Created: Fri Nov 19 14:09:02 CEST 2010
16 
17 
18 // system include files
19 #include <memory>
21 
23 //#include "RecoTracker/DeDx/interface/DeDxTools.h"
29 
34 
38 
41 
42 
43 using namespace reco;
44 using namespace std;
45 using namespace edm;
46 
48 {
49 
50  produces<ValueMap<DeDxData> >();
51 
52 
53  string estimatorName = iConfig.getParameter<string>("estimator");
54  if(estimatorName == "median") m_estimator = new MedianDeDxEstimator(-2.);
55  if(estimatorName == "generic") m_estimator = new GenericAverageDeDxEstimator (iConfig.getParameter<double>("exponent"));
56  if(estimatorName == "truncated") m_estimator = new TruncatedAverageDeDxEstimator(iConfig.getParameter<double>("fraction"));
57  if(estimatorName == "unbinnedFit") m_estimator = new UnbinnedFitDeDxEstimator();
58 
59  MaxNrStrips = iConfig.getUntrackedParameter<unsigned>("maxNrStrips" , 255);
60  MinTrackHits = iConfig.getUntrackedParameter<unsigned>("MinTrackHits" , 4);
61 
62  m_tracksTag = iConfig.getParameter<edm::InputTag>("tracks");
63  m_trajTrackAssociationTag = iConfig.getParameter<edm::InputTag>("trajectoryTrackAssociation");
64 
65  usePixel = iConfig.getParameter<bool>("UsePixel");
66  useStrip = iConfig.getParameter<bool>("UseStrip");
67  MeVperADCPixel = iConfig.getParameter<double>("MeVperADCPixel");
68  MeVperADCStrip = iConfig.getParameter<double>("MeVperADCStrip");
69 
70  shapetest = iConfig.getParameter<bool>("ShapeTest");
71  useCalibration = iConfig.getParameter<bool>("UseCalibration");
72  m_calibrationPath = iConfig.getParameter<string>("calibrationPath");
73 
74  if(!usePixel && !useStrip)
75  edm::LogWarning("DeDxHitsProducer") << "Pixel Hits AND Strip Hits will not be used to estimate dEdx --> BUG, Please Update the config file";
76 }
77 
78 
80 {
81  delete m_estimator;
82 }
83 
84 
85 
86 // ------------ method called once each job just before starting event loop ------------
88 {
89  if(MODsColl.size()!=0)return;
90 
91 
93  iSetup.get<TrackerDigiGeometryRecord>().get( tkGeom );
94 
95  vector<GeomDet*> Det = tkGeom->dets();
96  for(unsigned int i=0;i<Det.size();i++){
97  DetId Detid = Det[i]->geographicalId();
98 
99  StripGeomDetUnit* StripDetUnit = dynamic_cast<StripGeomDetUnit*> (Det[i]);
100  PixelGeomDetUnit* PixelDetUnit = dynamic_cast<PixelGeomDetUnit*> (Det[i]);
101 
102  stModInfo* MOD = new stModInfo;
103  double Thick=-1, Dist=-1, Norma=-1;
104  if(StripDetUnit){
105  Dist = StripDetUnit->position().mag();
106  Thick = StripDetUnit->surface().bounds().thickness();
107  Norma = MeVperADCStrip/Thick;
108  MOD->Normal = StripDetUnit->surface().normalVector();
109  }else if(PixelDetUnit){
110  Dist = PixelDetUnit->position().mag();
111  Thick = PixelDetUnit->surface().bounds().thickness();
112  Norma = MeVperADCPixel/Thick;
113  MOD->Normal = PixelDetUnit->surface().normalVector();
114  }
115 
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 
124  MakeCalibrationMap();
125 }
126 
127 // ------------ method called once each job just after ending the event loop ------------
129  MODsColl.clear();
130 }
131 
132 
133 
134 
136 {
137  auto_ptr<ValueMap<DeDxData> > trackDeDxEstimateAssociation(new ValueMap<DeDxData> );
138  ValueMap<DeDxData>::Filler filler(*trackDeDxEstimateAssociation);
139 
140  Handle<TrackCollection> trackCollHandle;
141  iEvent.getByLabel(m_trajTrackAssociationTag, trackCollHandle);
142  const TrackCollection trackColl = *trackCollHandle.product();
143 
144  size_t n = trackColl.size();
145  std::vector<DeDxData> dedxEstimate(n);
146 
147  //assume trajectory collection size is equal to track collection size and that order is kept
148  for(unsigned int j=0;j<trackColl.size();j++){
149  const reco::TrackRef track = reco::TrackRef( trackCollHandle.product(), j );
150 
151  DeDxHitCollection dedxHits;
152  vector<DeDxTools::RawHits> hits;
153 // DeDxTools::trajectoryRawHits(traj, hits, usePixel, useStrip);
154 
155 
156  int NClusterSaturating = 0;
157  for(unsigned int h=0;h<track->recHitsSize();h++){
158  //SiStripDetId detid = SiStripDetId((track->recHit(h))->geographicalId());
159  //TrackingRecHit* recHit = (track->recHit(h))->clone();
160 
161  TrackingRecHit* recHit= (track->recHit(h))->clone();
162 
163  if(const SiPixelRecHit* pixelHit=dynamic_cast<const SiPixelRecHit*>(recHit)){
164  if(!usePixel) continue;
165 
166  unsigned int detid = pixelHit->geographicalId();
167  stModInfo* MOD = MODsColl[detid];
168 
169  double cosine = (track->px()*MOD->Normal.x()+track->py()*MOD->Normal.y()+track->pz()*MOD->Normal.z())/track->p();
170  float pathLen = MOD->Thickness/std::abs(cosine);
171  float charge = MOD->Normalization*pixelHit->cluster()->charge()*std::abs(cosine);
172  dedxHits.push_back( DeDxHit( charge, MOD->Distance, pathLen, detid) );
173 
174  }
175  delete recHit;
176  }
178 
179 
180  sort(dedxHits.begin(),dedxHits.end(),less<DeDxHit>());
181  std::pair<float,float> val_and_error = m_estimator->dedx(dedxHits);
182 
183  //WARNING: Since the dEdX Error is not properly computed for the moment
184  //It was decided to store the number of saturating cluster in that dataformat
185  val_and_error.second = NClusterSaturating;
186 
187  dedxEstimate[j] = DeDxData(val_and_error.first, val_and_error.second, dedxHits.size() );
188  }
189  filler.insert(trackCollHandle, dedxEstimate.begin(), dedxEstimate.end());
190 
191  // really fill the association map
192  filler.fill();
193  // put into the event
194  iEvent.put(trackDeDxEstimateAssociation);
195 }
196 
197 
198 
200 {
201  if(!useCalibration)return;
202 
203  TChain* t1 = new TChain("SiStripCalib/APVGain");
204  t1->Add(m_calibrationPath.c_str());
205 
206  unsigned int tree_DetId;
207  unsigned char tree_APVId;
208  double tree_Gain;
209 
210  t1->SetBranchAddress("DetId" ,&tree_DetId );
211  t1->SetBranchAddress("APVId" ,&tree_APVId );
212  t1->SetBranchAddress("Gain" ,&tree_Gain );
213 
214 
215 
216  for (unsigned int ientry = 0; ientry < t1->GetEntries(); ientry++) {
217  t1->GetEntry(ientry);
218  stModInfo* MOD = MODsColl[tree_DetId];
219  MOD->Gain = tree_Gain;
220  }
221 
222  delete t1;
223 
224 }
225 
226 
227 //define this as a plug-in
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
virtual void beginRun(edm::Run &run, const edm::EventSetup &)
GlobalVector normalVector() const
Definition: Plane.h:47
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:10
T y() const
Definition: PV3DBase.h:57
std::vector< DeDxHit > DeDxHitCollection
Definition: DeDxHit.h:49
#define abs(x)
Definition: mlp_lapack.h:159
virtual void produce(edm::Event &, const edm::EventSetup &)
double charge(const std::vector< uint8_t > &Ampls)
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
virtual float thickness() const =0
int iEvent
Definition: GenABIO.cc:243
T mag() const
Definition: PV3DBase.h:61
const Surface::PositionType & position() const
The position (origin of the R.F.)
Definition: GeomDet.h:43
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:84
T z() const
Definition: PV3DBase.h:58
int j
Definition: DBlmapReader.cc:9
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:355
DEFINE_FWK_MODULE(CosmicTrackingParticleSelector)
Definition: DetId.h:20
const Bounds & bounds() const
Definition: BoundSurface.h:89
T * clone(const T *tp)
Definition: Ptr.h:42
const T & get() const
Definition: EventSetup.h:55
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:14
T const * product() const
Definition: Handle.h:74
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
T x() const
Definition: PV3DBase.h:56
virtual const BoundPlane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
Definition: Run.h:32
Our base class.
Definition: SiPixelRecHit.h:27