CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DeDxDiscriminatorLearner.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: DeDxDiscriminatorLearner
4 // Class: DeDxDiscriminatorLearner
5 //
13 //
14 // Original Author: Loic Quertenmont(querten)
15 // Created: Mon October 20 10:09:02 CEST 2008
16 //
17 
18 
19 // system include files
20 #include <memory>
21 
23 
24 //#include "DataFormats/TrackReco/interface/DeDxData.h"
27 
31 
32 using namespace reco;
33 using namespace std;
34 using namespace edm;
35 
37 {
38  m_tracksTag = iConfig.getParameter<edm::InputTag>("tracks");
39  m_trajTrackAssociationTag = iConfig.getParameter<edm::InputTag>("trajectoryTrackAssociation");
40 
41  usePixel = iConfig.getParameter<bool>("UsePixel");
42  useStrip = iConfig.getParameter<bool>("UseStrip");
43  if(!usePixel && !useStrip)
44  edm::LogWarning("DeDxDiscriminatorLearner") << "Pixel Hits AND Strip Hits will not be used to estimate dEdx --> BUG, Please Update the config file";
45 
46  P_Min = iConfig.getParameter<double> ("P_Min" );
47  P_Max = iConfig.getParameter<double> ("P_Max" );
48  P_NBins = iConfig.getParameter<int> ("P_NBins");
49  Path_Min = iConfig.getParameter<double> ("Path_Min" );
50  Path_Max = iConfig.getParameter<double> ("Path_Max" );
51  Path_NBins = iConfig.getParameter<int> ("Path_NBins");
52  Charge_Min = iConfig.getParameter<double> ("Charge_Min" );
53  Charge_Max = iConfig.getParameter<double> ("Charge_Max" );
54  Charge_NBins = iConfig.getParameter<int> ("Charge_NBins");
55 
56  MinTrackMomentum = iConfig.getUntrackedParameter<double> ("minTrackMomentum" , 3.0);
57  MaxTrackMomentum = iConfig.getUntrackedParameter<double> ("maxTrackMomentum" , 99999.0);
58  MinTrackEta = iConfig.getUntrackedParameter<double> ("minTrackEta" , -5.0);
59  MaxTrackEta = iConfig.getUntrackedParameter<double> ("maxTrackEta" , 5.0);
60  MaxNrStrips = iConfig.getUntrackedParameter<unsigned>("maxNrStrips" , 255);
61  MinTrackHits = iConfig.getUntrackedParameter<unsigned>("MinTrackHits" , 4);
62 
63  algoMode = iConfig.getUntrackedParameter<string> ("AlgoMode" , "SingleJob");
64  HistoFile = iConfig.getUntrackedParameter<string> ("HistoFile" , "out.root");
65 }
66 
67 
69 
70 // ------------ method called once each job just before starting event loop ------------
71 
73 {
74 // Charge_Vs_Path = new TH2F ("Charge_Vs_Path" , "Charge_Vs_Path" , 24, 0.2, 1.4, 250, 0, 5000);
75  Charge_Vs_Path = new TH3F ("Charge_Vs_Path" , "Charge_Vs_Path" , P_NBins, P_Min, P_Max, Path_NBins, Path_Min, Path_Max, Charge_NBins, Charge_Min, Charge_Max);
76 
77 
79  iSetup.get<TrackerDigiGeometryRecord>().get( tkGeom );
80  m_tracker = tkGeom.product();
81 
82  vector<GeomDet*> Det = tkGeom->dets();
83  for(unsigned int i=0;i<Det.size();i++){
84  DetId Detid = Det[i]->geographicalId();
85  int SubDet = Detid.subdetId();
86 
87  if( SubDet == StripSubdetector::TIB || SubDet == StripSubdetector::TID ||
88  SubDet == StripSubdetector::TOB || SubDet == StripSubdetector::TEC ){
89 
90  StripGeomDetUnit* DetUnit = dynamic_cast<StripGeomDetUnit*> (Det[i]);
91  if(!DetUnit)continue;
92 
93  const StripTopology& Topo = DetUnit->specificTopology();
94  unsigned int NAPV = Topo.nstrips()/128;
95 
96  double Eta = DetUnit->position().basicVector().eta();
97  double R = DetUnit->position().basicVector().transverse();
98  double Thick = DetUnit->surface().bounds().thickness();
99 
100  stModInfo* MOD = new stModInfo;
101  MOD->DetId = Detid.rawId();
102  MOD->SubDet = SubDet;
103  MOD->Eta = Eta;
104  MOD->R = R;
105  MOD->Thickness = Thick;
106  MOD->NAPV = NAPV;
107  MODsColl[MOD->DetId] = MOD;
108  }
109  }
110 
111 }
112 
113 // ------------ method called once each job just after ending the event loop ------------
114 
116 {
117 
118  if( strcmp(algoMode.c_str(),"MultiJob")==0){
119  TFile* Output = new TFile(HistoFile.c_str(), "RECREATE");
120  Charge_Vs_Path->Write();
121  Output->Write();
122  Output->Close();
123  }else if( strcmp(algoMode.c_str(),"WriteOnDB")==0){
124  TFile* Input = new TFile(HistoFile.c_str() );
125  Charge_Vs_Path = (TH3F*)(Input->FindObjectAny("Charge_Vs_Path"))->Clone();
126  Input->Close();
127  }
128 
129 }
130 
132 {
134  iSetup.get<TrackerDigiGeometryRecord>().get( tkGeom );
135  m_tracker = tkGeom.product();
136 
137 
138 
139  Handle<TrajTrackAssociationCollection> trajTrackAssociationHandle;
140  iEvent.getByLabel(m_trajTrackAssociationTag, trajTrackAssociationHandle);
141  const TrajTrackAssociationCollection TrajToTrackMap = *trajTrackAssociationHandle.product();
142 
143  edm::Handle<reco::TrackCollection> trackCollectionHandle;
144  iEvent.getByLabel(m_tracksTag,trackCollectionHandle);
145 
146  unsigned track_index = 0;
147  for(TrajTrackAssociationCollection::const_iterator it = TrajToTrackMap.begin(); it!=TrajToTrackMap.end(); ++it, track_index++) {
148 
149  const Track track = *it->val;
150  const Trajectory traj = *it->key;
151 
152  if(track.eta() <MinTrackEta || track.eta()>MaxTrackEta ){continue;}
153  if(track.p() <MinTrackMomentum || track.p() >MaxTrackMomentum){continue;}
154  if(track.found()<MinTrackHits ){continue;}
155 
156  vector<TrajectoryMeasurement> measurements = traj.measurements();
157  for(vector<TrajectoryMeasurement>::const_iterator measurement_it = measurements.begin(); measurement_it!=measurements.end(); measurement_it++)
158  {
159  TrajectoryStateOnSurface trajState = measurement_it->updatedState();
160  if( !trajState.isValid() ) continue;
161 
162  const TrackingRecHit* hit = (*measurement_it->recHit()).hit();
163  const SiStripRecHit2D* sistripsimplehit = dynamic_cast<const SiStripRecHit2D*>(hit);
164  const SiStripMatchedRecHit2D* sistripmatchedhit = dynamic_cast<const SiStripMatchedRecHit2D*>(hit);
165  const SiStripRecHit1D* sistripsimple1dhit = dynamic_cast<const SiStripRecHit1D*>(hit);
166 
167  if(sistripsimplehit){
168  Learn((sistripsimplehit->cluster()).get(), trajState);
169  }else if(sistripmatchedhit){
170  Learn(&sistripmatchedhit->monoCluster(),trajState);
171  Learn(&sistripmatchedhit->stereoCluster(),trajState);
172  }else if(sistripsimple1dhit){
173  Learn((sistripsimple1dhit->cluster()).get(), trajState);
174  }else{
175  }
176 
177  }
178  }
179 
180 }
181 
182 
184 {
185  // Get All needed variables
186  LocalVector trackDirection = trajState.localDirection();
187  double cosine = trackDirection.z()/trackDirection.mag();
188  const vector<uint8_t>& ampls = cluster->amplitudes();
189  uint32_t detId = cluster->geographicalId();
190  int firstStrip = cluster->firstStrip();
191  stModInfo* MOD = MODsColl[detId];
192  // Sanity Checks
193  if( ampls.size()>MaxNrStrips) { return; }
194 // if( DeDxDiscriminatorTools::IsSaturatingStrip (ampls)) { return; }
195  if( DeDxDiscriminatorTools::IsSpanningOver2APV (firstStrip, ampls.size())) { return; }
196  if(!DeDxDiscriminatorTools::IsFarFromBorder (trajState, m_tracker->idToDetUnit(DetId(detId)) )) { return; }
197  // Fill Histo Path Vs Charge/Path
198  double charge = DeDxDiscriminatorTools::charge(ampls);
199  double path = DeDxDiscriminatorTools::path(cosine,MOD->Thickness);
200  Charge_Vs_Path->Fill(trajState.localMomentum().mag(),path,charge/path);
201 }
202 
203 
205 {
206 // if( strcmp(algoMode.c_str(),"MultiJob")==0)return NULL;
207 
210  Charge_Vs_Path->GetNbinsX(), Charge_Vs_Path->GetXaxis()->GetXmin(), Charge_Vs_Path->GetXaxis()->GetXmax(),
211  Charge_Vs_Path->GetNbinsY(), Charge_Vs_Path->GetYaxis()->GetXmin(), Charge_Vs_Path->GetYaxis()->GetXmax(),
212  Charge_Vs_Path->GetNbinsZ(), Charge_Vs_Path->GetZaxis()->GetXmin(), Charge_Vs_Path->GetZaxis()->GetXmax());
213 
214  for(int ix=0; ix<=Charge_Vs_Path->GetNbinsX()+1; ix++){
215  for(int iy=0; iy<=Charge_Vs_Path->GetNbinsY()+1; iy++){
216  for(int iz=0; iz<=Charge_Vs_Path->GetNbinsZ()+1; iz++){
217  obj->setBinContent(ix, iy, iz, Charge_Vs_Path->GetBinContent(ix,iy, iz) );
218 // if(Charge_Vs_Path->GetBinContent(ix,iy)!=0)printf("%i %i %i --> %f\n",ix,iy, iz, Charge_Vs_Path->GetBinContent(ix,iy,iz));
219  }
220  }
221  }
222 
223  return obj;
224 }
225 
226 
227 
228 //define this as a plug-in
double path(double cosine, double thickness)
double p() const
momentum vector magnitude
Definition: TrackBase.h:129
T getParameter(std::string const &) const
virtual int nstrips() const =0
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
#define Input(cl)
Definition: vmac.h:189
const_iterator end() const
last iterator over the map (read only)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
LocalVector localDirection() const
const TrackerGeometry * m_tracker
const Bounds & bounds() const
Definition: Surface.h:128
uint16_t firstStrip() const
virtual const StripTopology & specificTopology() const
Returns a reference to the strip proxy topology.
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:35
double charge(const std::vector< uint8_t > &Ampls)
void Learn(const SiStripCluster *cluster, TrajectoryStateOnSurface trajState)
uint32_t geographicalId() const
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
LocalVector localMomentum() const
virtual float thickness() const =0
DataContainer const & measurements() const
Definition: Trajectory.h:215
int iEvent
Definition: GenABIO.cc:243
T mag() const
Definition: PV3DBase.h:67
const Surface::PositionType & position() const
The position (origin of the R.F.)
Definition: GeomDet.h:41
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:141
virtual void algoBeginJob(const edm::EventSetup &)
Histogram3D< double > HistogramD3D
Definition: Histogram3D.h:175
bool IsFarFromBorder(TrajectoryStateOnSurface trajState, const GeomDetUnit *it)
T z() const
Definition: PV3DBase.h:64
bool IsSpanningOver2APV(unsigned int FirstStrip, unsigned int ClusterSize)
virtual void algoAnalyze(const edm::Event &, const edm::EventSetup &)
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:39
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
Definition: DetId.h:20
__gnu_cxx::hash_map< unsigned int, stModInfo *, __gnu_cxx::hash< unsigned int >, isEqual > MODsColl
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
T const * product() const
Definition: Handle.h:74
virtual const GeomDetUnit * idToDetUnit(DetId) const
Return the pointer to the GeomDetUnit corresponding to a given DetId.
#define Output(cl)
Definition: vmac.h:193
unsigned short found() const
Number of valid hits on track.
Definition: Track.h:100
T transverse() const
Another name for perp()
const_iterator begin() const
first iterator over the map (read only)
const BasicVectorType & basicVector() const
Definition: PV3DBase.h:56
const std::vector< uint8_t > & amplitudes() const
void setBinContent(int bin, Value_t value)
PhysicsTools::Calibration::HistogramD3D * getNewObject()
DeDxDiscriminatorLearner(const edm::ParameterSet &)