47 #include <boost/regex.hpp>
166 static const boost::regex rule(
"(keep|drop)\\s+([A-Z]+)(\\s+(\\d+))?");
172 if (!regex_match(str.c_str(),
match, rule)) {
173 throw cms::Exception(
"Configuration") <<
"Rule '" << str <<
"' not understood.\n";
176 edm::LogInfo(
"TrackerTrackHitFilter") <<
"*** Rule Command given to TrackerTrackHitFilter:\t"<<str;
181 keep_ = (strncmp(match[1].
first,
"keep",4 )== 0);
192 throw cms::Exception(
"Configuration") <<
"Detector '" << match[2].first <<
"' not understood. Should be PXB, PXE, TIB, TID, TOB, TEC.\n";
195 if (match[4].first != match[4].
second) {
196 layer_ = atoi(match[4].first);
203 return tTopo->
layer(detid);
211 static const boost::regex rule(
"([A-Z]+)"
212 "\\s*(\\d+\\.*\\d*)?"
213 "\\s*(\\d+\\.*\\d*)?");
221 if (!regex_match(str.c_str(),
match, rule)) {
222 throw cms::Exception(
"Configuration") <<
"Rule for S to N cut '" << str <<
"' not understood.\n";
226 match_1=match[1].second;
227 match_2=match[2].second;
228 match_3=match[3].second;
234 for(cnt=0;cnt<6;cnt++ ){
235 subdet_ind[cnt]=-1.0;
241 if (strncmp(match[1].first,
"ALL", 3) == 0) doALL=
true;
242 if (doALL || strncmp(match[1].first,
"PXB", 3) == 0) subdet_ind[0] = +1.0;
243 if (doALL || strncmp(match[1].first,
"PXE", 3) == 0) subdet_ind[1] = +1.0;
244 if (doALL || strncmp(match[1].first,
"TIB", 3) == 0) subdet_ind[2] = +1.0;
245 if (doALL || strncmp(match[1].first,
"TID", 3) == 0) subdet_ind[3] = +1.0;
246 if (doALL || strncmp(match[1].first,
"TOB", 3) == 0) subdet_ind[4] = +1.0;
247 if (doALL || strncmp(match[1].first,
"TEC", 3) == 0) subdet_ind[5] = +1.0;
249 for(cnt=0;cnt<6;cnt++ ){
250 if(subdet_ind[cnt]>0.0){
252 if (match[2].first != match[2].second) {
255 if (match[3].first != match[3].second ) {
262 bool correct_regex=
false;
263 for(cnt=0;cnt<6;cnt++ ){
267 if (!correct_regex) {
268 throw cms::Exception(
"Configuration") <<
"Detector '" << match_1a <<
"' not understood in parseStoN. Should be PXB, PXE, TIB, TID, TOB, TEC.\n";
277 minimumHits_(iConfig.getParameter<uint32_t>(
"minimumHits")),
284 detsToIgnore_( iConfig.getParameter<std::vector<uint32_t> >(
"detsToIgnore") ),
289 pxlTPLProbXY_(iConfig.getParameter<double>(
"PxlTemplateProbXYCut")),
290 pxlTPLProbXYQ_(iConfig.getParameter<double>(
"PxlTemplateProbXYChargeCut")),
291 pxlTPLqBin_(iConfig.getParameter<std::vector<int32_t> >(
"PxlTemplateqBinCut")),
293 tagOverlaps_( iConfig.getParameter<bool>(
"tagOverlaps") )
301 throw cms::Exception(
"Configuration") <<
"Inconsistent Configuration: you can't set both 'stripAllInvalidHits' and 'replaceWithInactiveHits' to true\n";
304 throw cms::Exception(
"Configuration") <<
"Wrong configuration of TrackerTrackHitFilter. You cannot apply the cut on the track angle without using Trajectories!\n";
307 throw cms::Exception(
"Configuration") <<
"Wrong configuration of TrackerTrackHitFilter. You cannot apply the cut on the corrected pixel cluster charge without using Trajectories!\n";
311 edm::LogInfo(
"TrackerTrackHitFIlter")<<
"Warning from TrackerTrackHitFilter: vector with qBin cuts has size > 2. Additional items will be ignored.";
317 std::vector<std::string> str_rules = iConfig.
getParameter<std::vector<std::string> >(
"commands");
318 rules_.reserve(str_rules.size());
319 for (std::vector<std::string>::const_iterator it = str_rules.begin(), ed = str_rules.end(); it != ed; ++it) {
329 for(cnt=0;cnt<6;cnt++ ){
335 std::vector<std::string> str_StoNrules = iConfig.
getParameter<std::vector<std::string> >(
"StoNcommands");
336 for (std::vector<std::string>::const_iterator str_StoN = str_StoNrules.begin(); str_StoN != str_StoNrules.end(); ++str_StoN) {
340 edm::LogInfo(
"TrackerTrackHitFilter")<<
"Finished parsing S/N. Applying following cuts to subdets:";
341 for(cnt=0;cnt<6;cnt++ ){
355 produces<TrackCandidateCollection>();
382 else candcollsize=tracks->size();
385 output->reserve(candcollsize);
388 std::vector<TrackingRecHit *> hits;
397 const Track *trk = &(*tkref);
401 std::vector<TrackingRecHit *>::iterator
begin = hits.begin(),
end = hits.end();
405 while ( (begin !=
end) && ( (*begin)->isValid() ==
false ) ) ++
begin;
410 while ( (begin !=
end) && ( (*end)->isValid() ==
false ) ) --
end;
417 for( std::vector<TrackingRecHit *>::iterator ithit=begin;ithit!=
end;++ithit){
418 if( (*ithit)->isValid())nvalidhits++;
438 for (begin = hits.begin(),
end = hits.end(); begin !=
end; ++
begin) {
439 if (*begin)
delete *
begin;
449 for (std::vector<reco::Track>::const_iterator ittrk = tracks->begin(), edtrk = tracks->end(); ittrk != edtrk; ++ittrk) {
453 const Track *trk = &(*ittrk);
479 std::vector<TrackingRecHit *>::iterator
begin = hits.begin(),
end = hits.end();
483 while ( (begin !=
end) && ( (*begin)->isValid() ==
false ) ) ++
begin;
488 while ( (begin !=
end) && ( (*end)->isValid() ==
false ) ) --
end;
495 for( std::vector<TrackingRecHit *>::iterator ithit=begin;ithit!=
end;++ithit){
496 if( (*ithit)->isValid())nvalidhits++;
510 for (begin = hits.begin(),
end = hits.end(); begin !=
end; ++
begin) {
511 if (*begin)
delete *
begin;
528 if ( pdir ==
anyDirection )
throw cms::Exception(
"UnimplementedFeature") <<
"Cannot work with tracks that have 'anyDirecton' \n";
544 ownHits.
reserve(hitsEnd - hitsBegin);
545 for ( ; hitsBegin != hitsEnd; ++hitsBegin) {
566 if(hit->
isValid() && hit==0 && detid.
rawId()==0)
continue;
568 int verdict=
checkHit(iSetup,detid,hit);
571 hits.push_back(hit->
clone());
579 else if(verdict==-2) hits.push_back(hit->
clone());
580 else if(verdict==-1){
582 hits.push_back(hit->
clone());
600 std::vector<TrajectoryMeasurement> tmColl =itt->
measurements();
610 for(std::vector<TrajectoryMeasurement>::const_iterator itTrajMeas = tmColl.begin(); itTrajMeas!=tmColl.end(); itTrajMeas++){
614 if(hitpointer->isValid() && hitpointer->hit()==0){constrhits++;
continue;}
618 int verdict=
checkHit(iSetup,detid,hit);
646 if ( ( previousTM!=0 )&& (layer!=-1 )) {
648 for (std::vector<TrajectoryMeasurement>::const_iterator itmCompare =itTrajMeas-1;itmCompare >= tmColl.begin() && itmCompare > itTrajMeas - 4;--itmCompare){
650 DetId compareId = itmCompare->recHit()->geographicalId();
651 if ( subDet != compareId.
subdetId() ||
654 if (!itmCompare->recHit()->isValid())
continue;
676 previousTM = &(* itTrajMeas);
682 hits.push_back(hit->
clone());
690 else if(verdict==-2) hits.push_back(hit->
clone());
691 else if(verdict==-1){
693 hits.push_back(hit->
clone());
698 std::reverse(hits.begin(),hits.end());
715 for (std::vector<Rule>::const_iterator itr =
rules_.begin(), edr =
rules_.end(); itr != edr; ++itr) {
716 itr->apply(detid, tTopo, verdict);
728 if(!
checkStoN(iSetup, detid, hit))hitresult=-5;
741 bool keepthishit=
true;
746 int subdet_cnt=
id.subdetId();
755 const std::type_info &
type =
typeid(*therechit);
759 if (hit!=0) cluster = &*(hit->
cluster());
761 edm::LogError(
"TrackerTrackHitFilter")<<
"TrackerTrackHitFilter::checkStoN : Unknown valid tracker hit in subdet " <<
id.subdetId()<<
"(detID="<<
id.rawId()<<
")\n ";
767 if (hit!=0) cluster = &*(hit->
cluster());
769 edm::LogError(
"TrackerTrackHitFilter")<<
"TrackerTrackHitFilter::checkStoN : Unknown valid tracker hit in subdet " <<
id.subdetId()<<
"(detID="<<
id.rawId()<<
")\n ";
777 throw cms::Exception(
"Unknown RecHit Type") <<
"RecHit of type " << type.name() <<
778 " not supported. (use c++filt to demangle the name)";
810 int qbin =pixelhit->
qBin();
821 else {
edm::LogInfo(
"TrackerTrackHitFilter")<<
"HIT IN PIXEL ("<<subdet_cnt <<
") but PixelRecHit is EMPTY!!!";}
837 bool corrcharge_ok=
true;
860 if(hitpointer->isValid()){
864 float clust_alpha= atan2( mom_z, mom_x );
865 float clust_beta= atan2( mom_z, mom_y );
870 float clust_charge=pixelhit->
cluster()->charge();
871 float corr_clust_charge=clust_charge *
sqrt( 1.0 / ( 1.0/
pow(
tan(clust_alpha), 2 ) +
872 1.0/
pow(
tan(clust_beta ), 2 ) +
886 edm::LogWarning(
"TrackerTrackHitFilter") <<
"TSOS not valid ! Impossible to calculate track angle.";
889 return angle_ok&&corrcharge_ok;
898 bool corrcharge_ok=
false;
901 if(!hitpointer->isValid())
return corrcharge_ok;
904 return corrcharge_ok;
912 float clust_alpha= atan2( mom_z, mom_x );
913 float clust_beta= atan2( mom_z, mom_y );
918 float clust_charge=pixelhit->
cluster()->charge();
919 float corr_clust_charge=clust_charge *
sqrt( 1.0 / ( 1.0/
pow(
tan(clust_alpha), 2 ) +
920 1.0/
pow(
tan(clust_beta ), 2 ) +
926 return corrcharge_ok;
934 return tTopo->
layer(
id);
939 return tTopo->
side(
id);
ClusterRef cluster() const
T getParameter(std::string const &) const
EventNumber_t event() const
bool hasFilledProb() const
float clusterProbability(unsigned int flags=0) const
ConstRecHitPointer const & recHit() const
friend struct const_iterator
bool getByToken(EDGetToken token, Handle< PROD > &result) const
std::vector< double > subdetStoNlowcut_
#define DEFINE_FWK_MODULE(type)
LocalVector localDirection() const
TrackerTrackHitFilter(const edm::ParameterSet &iConfig)
std::vector< TrackCandidate > TrackCandidateCollection
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
unsigned int side(const DetId &id) const
edm::EDGetTokenT< reco::TrackCollection > tokenTracks
unsigned long long EventNumber_t
bool checkStoN(const edm::EventSetup &iSetup, const DetId &id, const TrackingRecHit *therechit)
key_type key() const
Accessor for product key.
const Vector & momentum() const
track momentum vector
bool stripFrontInvalidHits_
const math::XYZPoint & outerPosition() const
position of the outermost hit
bool stripBackInvalidHits_
void produceFromTrajectory(const edm::EventSetup &iSetup, const Trajectory *itt, std::vector< TrackingRecHit * > &hits)
const math::XYZPoint & innerPosition() const
position of the innermost hit
uint32_t rawId() const
get the raw id
bool isTrackerStrip(const GeomDetEnumerators::SubDetector m)
U second(std::pair< T, U > const &p)
bool checkPXLCorrClustCharge(const TrajectoryMeasurement &meas)
std::vector< uint32_t > detsToIgnore_
DataContainer const & measurements() const
double PXLcorrClusChargeCut_
float signalOverNoise() const
std::vector< Rule > rules_
std::shared_ptr< TrackingRecHit const > ConstRecHitPointer
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Rule(const std::string &str)
const GeomDet * det() const
void produceFromTrack(const edm::EventSetup &iSetup, const Track *itt, std::vector< TrackingRecHit * > &hits)
tuple TrackerTrackHitFilter
bool replaceWithInactiveHits_
unsigned int outerDetId() const
DetId of the detector on which surface the outermost state is located.
Tan< T >::type tan(const T &t)
ClusterRef cluster() const
trackingRecHit_iterator recHitsBegin() const
Iterator to first hit on the track.
int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
std::vector< double > subdetStoNhighcut_
virtual TrackingRecHit * clone() const =0
Detector identifier class for the strip tracker.
edm::RefToBase< TrajectorySeed > seedRef() const
edm::ESHandle< TransientTrackingRecHitBuilder > theBuilder
int layerFromId(const DetId &id, const TrackerTopology *tTopo) const
int checkHit(const edm::EventSetup &iSetup, const DetId &detid, const TrackingRecHit *hit)
edm::ESHandle< TrackerGeometry > theGeometry
ClusterRef cluster() const
T const * product() const
void parseStoN(const std::string &str)
bool isTrackerPixel(const GeomDetEnumerators::SubDetector m)
unsigned int layer(const DetId &id) const
std::vector< int32_t > pxlTPLqBin_
edm::EDGetTokenT< TrajTrackAssociationCollection > tokenTrajTrack
int sideFromId(const DetId &id, const TrackerTopology *tTopo) const
bool checkHitAngle(const TrajectoryMeasurement &meas)
std::vector< bool > subdetStoN_
PropagationDirection seedDirection() const
direction of how the hits were sorted in the original seed
bool stripAllInvalidHits_
int layer(DetId detid, const TrackerTopology *tTopo) const
TrajectoryStateOnSurface const & updatedState() const
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
DetId geographicalId() const
volatile std::atomic< bool > shutdown_flag false
Detector det() const
get the detector field from this detid
TrackCandidate makeCandidate(const reco::Track &tk, std::vector< TrackingRecHit * >::iterator hitsBegin, std::vector< TrackingRecHit * >::iterator hitsEnd)
edm::ESHandle< MagneticField > theMagField
unsigned int innerDetId() const
DetId of the detector on which surface the innermost state is located.
std::string CMNSubtractionMode_
void apply(DetId detid, const TrackerTopology *tTopo, bool &verdict) const
Power< A, B >::type pow(const A &a, const B &b)
TrackingRecHitCollection::base::const_iterator trackingRecHit_iterator
iterator over a vector of reference to TrackingRecHit in the same collection
T angle(T x1, T y1, T z1, T x2, T y2, T z2)
trackingRecHit_iterator recHitsEnd() const
Iterator to last hit on the track.