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 = consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("tracks"));
39  m_trajTrackAssociationTag = consumes<TrajTrackAssociationCollection>(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  auto const & 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  auto DetUnit = dynamic_cast<StripGeomDetUnit const*> (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.getByToken(m_trajTrackAssociationTag, trajTrackAssociationHandle);
141  const TrajTrackAssociationCollection TrajToTrackMap = *trajTrackAssociationHandle.product();
142 
143  edm::Handle<reco::TrackCollection> trackCollectionHandle;
144  iEvent.getByToken(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 = 0; // zero since long time 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
ClusterRef cluster() const
double path(double cosine, double thickness)
double p() const
momentum vector magnitude
Definition: TrackBase.h:127
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:188
const_iterator end() const
last iterator over the map (read only)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
SiStripCluster const & monoCluster() const
LocalVector localDirection() const
const TrackerGeometry * m_tracker
uint16_t firstStrip() const
double charge(const std::vector< uint8_t > &Ampls)
void Learn(const SiStripCluster *cluster, TrajectoryStateOnSurface trajState)
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
LocalVector localMomentum() const
DataContainer const & measurements() const
Definition: Trajectory.h:203
int iEvent
Definition: GenABIO.cc:230
T mag() const
Definition: PV3DBase.h:67
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:139
virtual void algoBeginJob(const edm::EventSetup &)
tuple path
else: Piece not in the list, fine.
Histogram3D< double > HistogramD3D
Definition: Histogram3D.h:187
bool IsFarFromBorder(TrajectoryStateOnSurface trajState, const GeomDetUnit *it)
T z() const
Definition: PV3DBase.h:64
bool IsSpanningOver2APV(unsigned int FirstStrip, unsigned int ClusterSize)
ClusterRef cluster() const
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:37
Definition: DetId.h:18
__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
string const
Definition: compareJSON.py:14
T const * product() const
Definition: Handle.h:81
virtual const GeomDetUnit * idToDetUnit(DetId) const
Return the pointer to the GeomDetUnit corresponding to a given DetId.
SiStripCluster const & stereoCluster() const
#define Output(cl)
Definition: vmac.h:192
unsigned short found() const
Number of valid hits on track.
Definition: Track.h:100
edm::EDGetTokenT< TrajTrackAssociationCollection > m_trajTrackAssociationTag
const_iterator begin() const
first iterator over the map (read only)
edm::EDGetTokenT< reco::TrackCollection > m_tracksTag
const std::vector< uint8_t > & amplitudes() const
void setBinContent(int bin, Value_t value)
PhysicsTools::Calibration::HistogramD3D * getNewObject()
DeDxDiscriminatorLearner(const edm::ParameterSet &)