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 
28 
33 
37 
40 
41 
42 using namespace reco;
43 using namespace std;
44 using namespace edm;
45 
47 {
48 
49  produces<ValueMap<DeDxData> >();
50 
51 
52  string estimatorName = iConfig.getParameter<string>("estimator");
53  if(estimatorName == "median") m_estimator = new MedianDeDxEstimator(-2.);
54  if(estimatorName == "generic") m_estimator = new GenericAverageDeDxEstimator (iConfig.getParameter<double>("exponent"));
55  if(estimatorName == "truncated") m_estimator = new TruncatedAverageDeDxEstimator(iConfig.getParameter<double>("fraction"));
56  if(estimatorName == "unbinnedFit") m_estimator = new UnbinnedFitDeDxEstimator();
57 
58  MaxNrStrips = iConfig.getUntrackedParameter<unsigned>("maxNrStrips" , 255);
59  MinTrackHits = iConfig.getUntrackedParameter<unsigned>("MinTrackHits" , 4);
60 
61  m_tracksTag = consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("tracks"));
62  m_trajTrackAssociationTag = consumes<TrajTrackAssociationCollection>(iConfig.getParameter<edm::InputTag>("trajectoryTrackAssociation"));
63 
64  usePixel = iConfig.getParameter<bool>("UsePixel");
65  useStrip = iConfig.getParameter<bool>("UseStrip");
66  MeVperADCPixel = iConfig.getParameter<double>("MeVperADCPixel");
67  MeVperADCStrip = iConfig.getParameter<double>("MeVperADCStrip");
68 
69  shapetest = iConfig.getParameter<bool>("ShapeTest");
70  useCalibration = iConfig.getParameter<bool>("UseCalibration");
71  m_calibrationPath = iConfig.getParameter<string>("calibrationPath");
72 
73  if(!usePixel && !useStrip)
74  edm::LogWarning("DeDxHitsProducer") << "Pixel Hits AND Strip Hits will not be used to estimate dEdx --> BUG, Please Update the config file";
75 }
76 
77 
79 {
80  delete m_estimator;
81 }
82 
83 
84 
85 // ------------ method called once each job just before starting event loop ------------
87 {
88  if(MODsColl.size()!=0)return;
89 
90 
92  iSetup.get<TrackerDigiGeometryRecord>().get( tkGeom );
93 
94  auto const & Det = tkGeom->dets();
95  for(unsigned int i=0;i<Det.size();i++){
96  DetId Detid = Det[i]->geographicalId();
97 
98  auto StripDetUnit = dynamic_cast<StripGeomDetUnit const*> (Det[i]);
99  auto PixelDetUnit = dynamic_cast<PixelGeomDetUnit const*> (Det[i]);
100 
101  stModInfo* MOD = new stModInfo;
102  double Thick=-1, Dist=-1, Norma=-1;
103  if(StripDetUnit){
104  Dist = StripDetUnit->position().mag();
105  Thick = StripDetUnit->surface().bounds().thickness();
106  Norma = MeVperADCStrip/Thick;
107  MOD->Normal = StripDetUnit->surface().normalVector();
108  }else if(PixelDetUnit){
109  Dist = PixelDetUnit->position().mag();
110  Thick = PixelDetUnit->surface().bounds().thickness();
111  Norma = MeVperADCPixel/Thick;
112  MOD->Normal = PixelDetUnit->surface().normalVector();
113  }
114 
115  MOD->DetId = Detid.rawId();
116  MOD->Thickness = Thick;
117  MOD->Distance = Dist;
118  MOD->Normalization = Norma;
119  MOD->Gain = 1;
120  MODsColl[MOD->DetId] = MOD;
121  }
122 
123  MakeCalibrationMap();
124 }
125 
126 // ------------ method called once each job just after ending the event loop ------------
128  MODsColl.clear();
129 }
130 
131 
132 
133 
135 {
136  auto_ptr<ValueMap<DeDxData> > trackDeDxEstimateAssociation(new ValueMap<DeDxData> );
137  ValueMap<DeDxData>::Filler filler(*trackDeDxEstimateAssociation);
138 
139  Handle<TrackCollection> trackCollHandle;
140  iEvent.getByToken(m_trajTrackAssociationTag, trackCollHandle);
141  const TrackCollection trackColl = *trackCollHandle.product();
142 
143  size_t n = trackColl.size();
144  std::vector<DeDxData> dedxEstimate(n);
145 
146  //assume trajectory collection size is equal to track collection size and that order is kept
147  for(unsigned int j=0;j<trackColl.size();j++){
148  const reco::TrackRef track = reco::TrackRef( trackCollHandle.product(), j );
149 
150  DeDxHitCollection dedxHits;
151  vector<DeDxTools::RawHits> hits;
152 // DeDxTools::trajectoryRawHits(traj, hits, usePixel, useStrip);
153 
154 
155  int NClusterSaturating = 0;
156  for(unsigned int h=0;h<track->recHitsSize();h++){
157  //SiStripDetId detid = SiStripDetId((track->recHit(h))->geographicalId());
158  //TrackingRecHit* recHit = (track->recHit(h))->clone();
159 
160  TrackingRecHit* recHit= (track->recHit(h))->clone();
161 
162  if(const SiPixelRecHit* pixelHit=dynamic_cast<const SiPixelRecHit*>(recHit)){
163  if(!usePixel) continue;
164 
165  unsigned int detid = pixelHit->geographicalId();
166  stModInfo* MOD = MODsColl[detid];
167 
168  double cosine = (track->px()*MOD->Normal.x()+track->py()*MOD->Normal.y()+track->pz()*MOD->Normal.z())/track->p();
169  float pathLen = MOD->Thickness/std::abs(cosine);
170  float charge = MOD->Normalization*pixelHit->cluster()->charge()*std::abs(cosine);
171  dedxHits.push_back( DeDxHit( charge, MOD->Distance, pathLen, detid) );
172 
173  }
174  delete recHit;
175  }
177 
178 
179  sort(dedxHits.begin(),dedxHits.end(),less<DeDxHit>());
180  std::pair<float,float> val_and_error = m_estimator->dedx(dedxHits);
181 
182  //WARNING: Since the dEdX Error is not properly computed for the moment
183  //It was decided to store the number of saturating cluster in that dataformat
184  val_and_error.second = NClusterSaturating;
185 
186  dedxEstimate[j] = DeDxData(val_and_error.first, val_and_error.second, dedxHits.size() );
187  }
188  filler.insert(trackCollHandle, dedxEstimate.begin(), dedxEstimate.end());
189 
190  // really fill the association map
191  filler.fill();
192  // put into the event
193  iEvent.put(trackDeDxEstimateAssociation);
194 }
195 
196 
197 
199 {
200  if(!useCalibration)return;
201 
202  TChain* t1 = new TChain("SiStripCalib/APVGain");
203  t1->Add(m_calibrationPath.c_str());
204 
205  unsigned int tree_DetId;
206  unsigned char tree_APVId;
207  double tree_Gain;
208 
209  t1->SetBranchAddress("DetId" ,&tree_DetId );
210  t1->SetBranchAddress("APVId" ,&tree_APVId );
211  t1->SetBranchAddress("Gain" ,&tree_Gain );
212 
213 
214 
215  for (unsigned int ientry = 0; ientry < t1->GetEntries(); ientry++) {
216  t1->GetEntry(ientry);
217  stModInfo* MOD = MODsColl[tree_DetId];
218  MOD->Gain = tree_Gain;
219  }
220 
221  delete t1;
222 
223 }
224 
225 
226 //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
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:52
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:10
T y() const
Definition: PV3DBase.h:63
std::vector< DeDxHit > DeDxHitCollection
Definition: DeDxHit.h:49
double charge(const std::vector< uint8_t > &Ampls)
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
int iEvent
Definition: GenABIO.cc:230
T mag() const
Definition: PV3DBase.h:67
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
T z() const
Definition: PV3DBase.h:64
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int j
Definition: DBlmapReader.cc:9
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
DEFINE_FWK_MODULE(CosmicTrackingParticleSelector)
Definition: DetId.h:18
const T & get() const
Definition: EventSetup.h:55
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:14
string const
Definition: compareJSON.py:14
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
T const * product() const
Definition: Handle.h:81
virtual void produce(edm::Event &, const edm::EventSetup &) override
T x() const
Definition: PV3DBase.h:62
Definition: Run.h:41
Pixel Reconstructed Hit.
virtual void beginRun(edm::Run const &run, const edm::EventSetup &) override