51 produces<ValueMap<DeDxData> >();
54 m_trajTrackAssociationTag = consumes<TrajTrackAssociationCollection>(iConfig.
getParameter<
edm::InputTag>(
"trajectoryTrackAssociation"));
58 if(!usePixel && !useStrip)
59 edm::LogWarning(
"DeDxHitsProducer") <<
"Pixel Hits AND Strip Hits will not be used to estimate dEdx --> BUG, Please Update the config file";
74 useCalibration = iConfig.
getParameter<
bool>(
"UseCalibration");
75 m_calibrationPath = iConfig.
getParameter<
string>(
"calibrationPath");
77 Prob_ChargePath =
NULL;
87 if( strcmp(Reccord.c_str(),
"SiStripDeDxMip_3D_Rcd")==0){
89 }
else if(strcmp(Reccord.c_str(),
"SiStripDeDxPion_3D_Rcd")==0){
91 }
else if(strcmp(Reccord.c_str(),
"SiStripDeDxKaon_3D_Rcd")==0){
93 }
else if(strcmp(Reccord.c_str(),
"SiStripDeDxProton_3D_Rcd")==0){
95 }
else if(strcmp(Reccord.c_str(),
"SiStripDeDxElectron_3D_Rcd")==0){
102 DeDxMap_ = *DeDxMapHandle_.
product();
104 double xmin = DeDxMap_.rangeX().min;
105 double xmax = DeDxMap_.rangeX().max;
106 double ymin = DeDxMap_.rangeY().min;
107 double ymax = DeDxMap_.rangeY().max;
108 double zmin = DeDxMap_.rangeZ().min;
109 double zmax = DeDxMap_.rangeZ().max;
111 if(Prob_ChargePath)
delete Prob_ChargePath;
112 Prob_ChargePath =
new TH3D (
"Prob_ChargePath" ,
"Prob_ChargePath" , DeDxMap_.numberOfBinsX(),
xmin,
xmax, DeDxMap_.numberOfBinsY() ,
ymin,
ymax, DeDxMap_.numberOfBinsZ(),
zmin,
zmax);
116 if(strcmp(ProbabilityMode.c_str(),
"Accumulation")==0){
118 for(
int i=0;
i<=Prob_ChargePath->GetXaxis()->GetNbins()+1;
i++){
120 for(
int j=0;
j<=Prob_ChargePath->GetYaxis()->GetNbins()+1;
j++){
124 for(
int k=0;
k<=Prob_ChargePath->GetZaxis()->GetNbins()+1;
k++){ Ni+=DeDxMap_.binContent(
i,
j,
k);}
126 for(
int k=0;
k<=Prob_ChargePath->GetZaxis()->GetNbins()+1;
k++){
128 for(
int l=0;
l<=
k;
l++){ tmp+=DeDxMap_.binContent(
i,
j,
l);}
131 Prob_ChargePath->SetBinContent (
i,
j,
k, tmp/Ni);
134 Prob_ChargePath->SetBinContent (
i,
j,
k, 0);
139 }
else if(strcmp(ProbabilityMode.c_str(),
"Integral")==0){
141 for(
int i=0;
i<=Prob_ChargePath->GetXaxis()->GetNbins()+1;
i++){
143 for(
int j=0;
j<=Prob_ChargePath->GetYaxis()->GetNbins()+1;
j++){
147 for(
int k=0;
k<=Prob_ChargePath->GetZaxis()->GetNbins()+1;
k++){ Ni+=DeDxMap_.binContent(
i,
j,
k);}
149 for(
int k=0;
k<=Prob_ChargePath->GetZaxis()->GetNbins()+1;
k++){
150 double tmp = DeDxMap_.binContent(
i,
j,
k);
153 Prob_ChargePath->SetBinContent (
i,
j,
k, tmp/Ni);
156 Prob_ChargePath->SetBinContent (
i,
j,
k, 0);
181 if(MODsColl.size()==0){
186 auto const &
Det = tkGeom->dets();
187 for(
unsigned int i=0;
i<
Det.size();
i++){
195 if(!DetUnit)
continue;
198 unsigned int NAPV = Topo.
nstrips()/128;
200 double Eta = DetUnit->position().basicVector().eta();
201 double R = DetUnit->position().basicVector().transverse();
202 double Thick = DetUnit->surface().bounds().thickness();
211 MODsColl[MOD->
DetId] = MOD;
215 MakeCalibrationMap();
233 iEvent.
getByToken(m_trajTrackAssociationTag, trajTrackAssociationHandle);
237 iEvent.
getByToken(m_tracksTag,trackCollectionHandle);
243 std::vector<DeDxData> dEdxDiscrims( TrajToTrackMap.
size() );
245 unsigned track_index = 0;
247 dEdxDiscrims[track_index] =
DeDxData(-1, -2, 0 );
249 const Track track = *it->val;
252 if(track.
eta() <MinTrackEta || track.
eta()>MaxTrackEta ){
continue;}
253 if(track.
p() <MinTrackMomentum || track.
p() >MaxTrackMomentum){
continue;}
254 if(track.
found()<MinTrackHits ){
continue;}
256 std::vector<double> vect_probs;
257 vector<TrajectoryMeasurement> measurements = traj.
measurements();
259 unsigned int NClusterSaturating = 0;
260 for(vector<TrajectoryMeasurement>::const_iterator measurement_it = measurements.begin(); measurement_it!=measurements.end(); measurement_it++){
263 if( !trajState.
isValid() )
continue;
266 const SiStripRecHit2D* sistripsimplehit =
dynamic_cast<const SiStripRecHit2D*
>(hit);
267 const SiStripMatchedRecHit2D* sistripmatchedhit =
dynamic_cast<const SiStripMatchedRecHit2D*
>(hit);
268 const SiStripRecHit1D* sistripsimple1dhit =
dynamic_cast<const SiStripRecHit1D*
>(hit);
271 if(sistripsimplehit){
272 Prob = GetProbability(
DeDxTools::GetCluster(sistripsimplehit), trajState,sistripsimplehit->geographicalId());
274 if(Prob>=0) vect_probs.push_back(Prob);
276 if(ClusterSaturatingStrip(
DeDxTools::GetCluster(sistripsimplehit),sistripsimplehit->geographicalId())>0)NClusterSaturating++;
278 }
else if(sistripmatchedhit){
279 Prob = GetProbability(
DeDxTools::GetCluster(sistripmatchedhit->monoHit()), trajState, sistripmatchedhit->monoId());
281 if(Prob>=0) vect_probs.push_back(Prob);
283 Prob = GetProbability(
DeDxTools::GetCluster(sistripmatchedhit->stereoHit()), trajState,sistripmatchedhit->stereoId());
284 if(Prob>=0) vect_probs.push_back(Prob);
286 if(ClusterSaturatingStrip(
DeDxTools::GetCluster(sistripmatchedhit->monoHit()),sistripmatchedhit->monoId()) >0)NClusterSaturating++;
287 if(ClusterSaturatingStrip(
DeDxTools::GetCluster(sistripmatchedhit->stereoHit()),sistripmatchedhit->stereoId())>0)NClusterSaturating++;
288 }
else if(sistripsimple1dhit){
289 Prob = GetProbability(
DeDxTools::GetCluster(sistripsimple1dhit), trajState, sistripsimple1dhit->geographicalId());
291 if(Prob>=0) vect_probs.push_back(Prob);
292 if(ClusterSaturatingStrip(
DeDxTools::GetCluster(sistripsimple1dhit),sistripsimple1dhit->geographicalId())>0)NClusterSaturating++;
297 double estimator = ComputeDiscriminator(vect_probs);
298 int size = vect_probs.size();
303 Error = NClusterSaturating;
304 dEdxDiscrims[track_index] =
DeDxData(estimator, Error, size );
309 filler.
insert(trackCollectionHandle, dEdxDiscrims.begin(), dEdxDiscrims.end());
311 iEvent.
put(trackDeDxDiscrimAssociation);
316 const uint32_t & detId){
317 const vector<uint8_t>& ampls = cluster->
amplitudes();
320 if(useCalibration)MOD = MODsColl[detId];
322 int SaturatingStrip = 0;
323 for(
unsigned int i=0;
i<ampls.size();
i++){
324 int StripCharge = ampls[
i];
325 if(MOD){StripCharge = (int)(StripCharge / MOD->
Gain);}
326 if(StripCharge>=254)SaturatingStrip++;
328 return SaturatingStrip;
332 const uint32_t & detId)
336 double cosine = trackDirection.
z()/trackDirection.
mag();
337 const vector<uint8_t>& ampls = cluster->
amplitudes();
344 if( ampls.size()>MaxNrStrips) {
return -1;}
353 for(
unsigned int i=0;
i<ampls.size();
i++){
354 int CalibratedCharge = ampls[
i];
355 CalibratedCharge = (int)(CalibratedCharge / MOD->
Gain);
356 if(CalibratedCharge>=1024){
357 CalibratedCharge = 255;
358 }
else if(CalibratedCharge>254){
359 CalibratedCharge = 254;
361 charge+=CalibratedCharge;
369 int BinY = Prob_ChargePath->GetYaxis()->FindBin(path);
370 int BinZ = Prob_ChargePath->GetZaxis()->FindBin(charge/path);
371 return Prob_ChargePath->GetBinContent(BinX,BinY,BinZ);
377 double estimator = -1;
378 int size = vect_probs.size();
379 if(size<=0)
return estimator;
384 if(vect_probs[
i]<=0.0001){P *=
pow(0.0001 , 1.0/size);}
385 else {P *=
pow(vect_probs[
i], 1.0/size);}
388 }
else if(Formula==1){
389 std::sort(vect_probs.begin(), vect_probs.end(), std::less<double>() );
390 for(
int i=0;
i<
size;
i++){
if(vect_probs[
i]<=0.0001)vect_probs[
i] = 0.0001; }
393 for(
int i=0;
i<
size;
i++){ SumJet+=
log(vect_probs[
i]); }
395 double Loginvlog=
log(-SumJet);
401 Prob+=
exp(
l*Loginvlog-
log(1.*lfact));
404 double LogProb=
log(Prob);
406 estimator = -log10(ProbJet)/4.;
407 estimator = 1-estimator;
408 }
else if(Formula==2){
409 std::sort(vect_probs.begin(), vect_probs.end(), std::less<double>() );
410 double P = 1.0/(12*
size);
412 P +=
pow(vect_probs[
i-1] - ((2.0*
i-1.0)/(2.0*size)),2);
417 std::sort(vect_probs.begin(), vect_probs.end(), std::less<double>() );
418 double P = 1.0/(12*
size);
420 P += vect_probs[
i-1] *
pow(vect_probs[
i-1] - ((2.0*
i-1.0)/(2.0*size)),2);
431 if(!useCalibration)
return;
434 TChain* t1 =
new TChain(
"SiStripCalib/APVGain");
435 t1->Add(m_calibrationPath.c_str());
437 unsigned int tree_DetId;
438 unsigned char tree_APVId;
441 t1->SetBranchAddress(
"DetId" ,&tree_DetId );
442 t1->SetBranchAddress(
"APVId" ,&tree_APVId );
443 t1->SetBranchAddress(
"Gain" ,&tree_Gain );
445 for (
unsigned int ientry = 0; ientry < t1->GetEntries(); ientry++) {
446 t1->GetEntry(ientry);
448 MOD->
Gain = tree_Gain;
double p() const
momentum vector magnitude
T getParameter(std::string const &) const
virtual int nstrips() const =0
T getUntrackedParameter(std::string const &, T const &) const
virtual void produce(edm::Event &, const edm::EventSetup &) override
friend struct const_iterator
~DeDxDiscriminatorProducer()
const_iterator end() const
last iterator over the map (read only)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
LocalVector localDirection() const
double GetProbability(const SiStripCluster *cluster, TrajectoryStateOnSurface trajState, const uint32_t &)
void insert(const H &h, I begin, I end)
DeDxDiscriminatorProducer(const edm::ParameterSet &)
virtual void beginRun(edm::Run const &run, const edm::EventSetup &) override
uint32_t rawId() const
get the raw id
LocalVector localMomentum() const
DataContainer const & measurements() const
double eta() const
pseudorapidity of momentum vector
tuple path
else: Piece not in the list, fine.
const T & max(const T &a, const T &b)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
void MakeCalibrationMap()
DEFINE_FWK_MODULE(CosmicTrackingParticleSelector)
size_type size() const
map size
T const * product() const
int ClusterSaturatingStrip(const SiStripCluster *cluster, const uint32_t &)
T const * product() const
virtual void endStream() override
std::vector< std::vector< double > > tmp
unsigned short found() const
Number of valid hits on track.
double ComputeDiscriminator(std::vector< double > &vect_probs)
const_iterator begin() const
first iterator over the map (read only)
tuple size
Write out results.
const std::vector< uint8_t > & amplitudes() const
Power< A, B >::type pow(const A &a, const B &b)