Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.3.X] Introduce a special AlCaReco for Strip Small Bias Scans #24383

Merged
merged 5 commits into from Sep 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions Calibration/TkAlCaRecoProducers/plugins/BuildFile.xml
Expand Up @@ -8,6 +8,7 @@
<use name="CondFormats/BeamSpotObjects"/>
<use name="CondFormats/DataRecord"/>
<use name="CondCore/DBOutputService"/>
<use name="CommonTools/UtilAlgos"/>
<use name="RecoVertex/BeamSpotProducer"/>
<use name="Calibration/TkAlCaRecoProducers"/>

Expand All @@ -30,3 +31,6 @@
<library file="PCLMetadataWriter.cc" name="PCLMetadataWriter">
<flags EDM_PLUGIN="1"/>
</library>
<library file="CalibrationTrackSelectorFromDetIdList.cc" name="CalibrationTrackSelectorFromDetIdList">
<flags EDM_PLUGIN="1"/>
</library>
@@ -0,0 +1,172 @@
// -*- C++ -*-
//
// Package: CalibrationTrackSelectorFromDetIdList
// Class: CalibrationTrackSelectorFromDetIdList
//
/**\class CalibrationTrackSelectorFromDetIdList CalibrationTrackSelectorFromDetIdList.cc Calibration/TkAlCaRecoProducers/plugins/CalibrationTrackSelectorFromDetIdList.cc
Description: Selects tracks that have at leaast one valid hit on a given set of Tracker DetIds
*/
//
// Original Author: Marco Musich
// Created: Wed Aug 22 09:17:01 CEST 2018
//
//

// system include files
#include <memory>

// user include files
#include "CommonTools/UtilAlgos/interface/DetIdSelector.h"
#include "DataFormats/TrackCandidate/interface/TrackCandidateCollection.h"
#include "DataFormats/TrackReco/interface/Track.h"
#include "DataFormats/TrackReco/interface/TrackFwd.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/Framework/interface/stream/EDProducer.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
#include "TrackingTools/Records/interface/TransientRecHitRecord.h"
#include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
#include "TrackingTools/TrajectoryState/interface/TrajectoryStateTransform.h"
#include "TrackingTools/TransientTrackingRecHit/interface/TransientTrackingRecHitBuilder.h"

//
// class decleration
//

class dso_hidden CalibrationTrackSelectorFromDetIdList final : public edm::stream::EDProducer<> {
public:
explicit CalibrationTrackSelectorFromDetIdList(const edm::ParameterSet&);
~CalibrationTrackSelectorFromDetIdList() override;

private:
void beginRun(edm::Run const& run, const edm::EventSetup&) override;
void produce(edm::Event&, const edm::EventSetup&) override;
edm::EDGetTokenT<reco::TrackCollection> m_label;
TrackCandidate makeCandidate(const reco::Track &tk, std::vector<TrackingRecHit *>::iterator hitsBegin, std::vector<TrackingRecHit *>::iterator hitsEnd);

std::vector<DetIdSelector> detidsels_;
bool m_verbose;

edm::ESHandle<TrackerGeometry> theGeometry;
edm::ESHandle<MagneticField> theMagField;

};

CalibrationTrackSelectorFromDetIdList::CalibrationTrackSelectorFromDetIdList(const edm::ParameterSet& iConfig): detidsels_() {

std::vector<edm::ParameterSet> selconfigs = iConfig.getParameter<std::vector<edm::ParameterSet> >("selections");

for(std::vector<edm::ParameterSet>::const_iterator selconfig=selconfigs.begin();selconfig!=selconfigs.end();++selconfig) {
DetIdSelector selection(*selconfig);
detidsels_.push_back(selection);
}

m_verbose = iConfig.getUntrackedParameter<bool>("verbose");
m_label = consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("Input"));
produces<TrackCandidateCollection>();
}


CalibrationTrackSelectorFromDetIdList::~CalibrationTrackSelectorFromDetIdList() {}

//
// member functions
//

// ------------ method called to produce the data ------------
void CalibrationTrackSelectorFromDetIdList::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
using namespace edm;
using namespace std;

edm::Handle<std::vector<reco::Track> > tracks;
iEvent.getByToken(m_label, tracks);
auto output = std::make_unique<TrackCandidateCollection>();

// loop on tracks
for (std::vector<reco::Track>::const_iterator ittrk = tracks->begin(), edtrk = tracks->end(); ittrk != edtrk; ++ittrk) {
const reco::Track *trk = &(*ittrk);

std::vector<TrackingRecHit *> hits;
hits.clear();

bool saveTrack(false);

for (trackingRecHit_iterator ith = trk->recHitsBegin(), edh = trk->recHitsEnd(); ith != edh; ++ith) {
const TrackingRecHit * hit = (*ith); // ith is an iterator on edm::Ref to rechit
DetId detid = hit->geographicalId();

for (const auto &detidsel : detidsels_){
if(detidsel.isSelected(detid)) {
LogDebug("CalibrationTrackSelectorFromDetIdList") << "Selected by selection " << detid;
saveTrack=true;
break;
}
}

// here there will be the selection
hits.push_back(hit->clone());

}

std::vector<TrackingRecHit *>::iterator begin = hits.begin(), end = hits.end();

if(saveTrack){
output->push_back( makeCandidate ( *ittrk, begin, end ) );
}

}
iEvent.put(std::move(output));
}

TrackCandidate
CalibrationTrackSelectorFromDetIdList::makeCandidate(const reco::Track &tk, std::vector<TrackingRecHit *>::iterator hitsBegin, std::vector<TrackingRecHit *>::iterator hitsEnd) {

PropagationDirection pdir = tk.seedDirection();
PTrajectoryStateOnDet state;
if ( pdir == anyDirection ) throw cms::Exception("UnimplementedFeature") << "Cannot work with tracks that have 'anyDirecton' \n";

if ( (pdir == alongMomentum) == ( (tk.outerPosition()-tk.innerPosition()).Dot(tk.momentum()) >= 0 ) ) {
// use inner state
TrajectoryStateOnSurface originalTsosIn(trajectoryStateTransform::innerStateOnSurface(tk, *theGeometry, &*theMagField));
state = trajectoryStateTransform::persistentState( originalTsosIn, DetId(tk.innerDetId()) );
} else {
// use outer state
TrajectoryStateOnSurface originalTsosOut(trajectoryStateTransform::outerStateOnSurface(tk, *theGeometry, &*theMagField));
state = trajectoryStateTransform::persistentState( originalTsosOut, DetId(tk.outerDetId()) );
}
TrajectorySeed seed(state, TrackCandidate::RecHitContainer(), pdir);
TrackCandidate::RecHitContainer ownHits;
ownHits.reserve(hitsEnd - hitsBegin);
for ( ; hitsBegin != hitsEnd; ++hitsBegin) {
ownHits.push_back( *hitsBegin );
}

TrackCandidate cand(ownHits, seed, state, tk.seedRef());

return cand;
}

void CalibrationTrackSelectorFromDetIdList::beginRun(edm::Run const& run, const edm::EventSetup& iSetup) {
iSetup.get<TrackerDigiGeometryRecord>().get(theGeometry);
iSetup.get<IdealMagneticFieldRecord>().get(theMagField);

if(m_verbose){
for (const auto &detidsel : detidsels_){
auto theDetIds = theGeometry.product()->detIds();
for(const auto &theDet : theDetIds){
if(detidsel.isSelected(theDet)) {
LogDebug("CalibrationTrackSelectorFromDetIdList") << "detid: " << theDet.rawId() << " is taken" << std::endl;
}
}
}
}

}


//define this as a plug-in
DEFINE_FWK_MODULE(CalibrationTrackSelectorFromDetIdList);
@@ -0,0 +1,23 @@
import FWCore.ParameterSet.Config as cms

# AlCaReco for track based calibration using MinBias events
OutALCARECOSiStripCalSmallBiasScan_noDrop = cms.PSet(
SelectEvents = cms.untracked.PSet(
SelectEvents = cms.vstring('pathALCARECOSiStripCalSmallBiasScan')
),
outputCommands = cms.untracked.vstring(
'keep *_ALCARECOSiStripCalSmallBiasScan_*_*',
'keep *_siStripClusters_*_*',
'keep *_siPixelClusters_*_*',
'keep DetIdedmEDCollection_siStripDigis_*_*',
'keep L1AcceptBunchCrossings_*_*_*',
'keep L1GlobalTriggerReadoutRecord_gtDigis_*_*',
'keep LumiScalerss_scalersRawToDigi_*_*',
'keep DcsStatuss_scalersRawToDigi_*_*',
'keep *_TriggerResults_*_*')
)


import copy
OutALCARECOSiStripCalSmallBiasScan=copy.deepcopy(OutALCARECOSiStripCalSmallBiasScan_noDrop)
OutALCARECOSiStripCalSmallBiasScan.outputCommands.insert(0,"drop *")
@@ -0,0 +1,124 @@
import FWCore.ParameterSet.Config as cms

# Set the HLT paths
import HLTrigger.HLTfilters.hltHighLevel_cfi
ALCARECOSiStripCalSmallBiasScanHLT = HLTrigger.HLTfilters.hltHighLevel_cfi.hltHighLevel.clone(
andOr = True, ## choose logical OR between Triggerbits
eventSetupPathsKey = 'SiStripCalSmallBiasScan',
throw = False # tolerate triggers stated above, but not available
)

# Select only events where tracker had HV on (according to DCS bit information)
# AND respective partition is in the run (according to FED information)
import CalibTracker.SiStripCommon.SiStripDCSFilter_cfi
DCSStatusForSiStripCalSmallBiasScan = CalibTracker.SiStripCommon.SiStripDCSFilter_cfi.siStripDCSFilter.clone()

from RecoVertex.BeamSpotProducer.BeamSpot_cff import *
from RecoTracker.IterativeTracking.InitialStep_cff import *
from RecoTracker.Configuration.RecoTrackerP5_cff import *
from RecoTracker.TrackProducer.TrackRefitter_cfi import *

################################################################################################
#TRACK REFITTER
################################################################################################
ALCARECOSiStripCalSmallBiasScanTracksRefit = TrackRefitter.clone(src = cms.InputTag("generalTracks"),
NavigationSchool = cms.string("")
)

################################################################################################
#TRACK FILTER
################################################################################################
import Calibration.TkAlCaRecoProducers.CalibrationTrackSelectorFromDetIdList_cfi as TrackSelectorFromDetIdList
ALCARECOSiStripCalSmallBiasScanSelectedTracks = TrackSelectorFromDetIdList.CalibrationTrackSelectorFromDetIdList.clone(Input= cms.InputTag("ALCARECOSiStripCalSmallBiasScanTracksRefit"),
selections=cms.VPSet(
cms.PSet(detSelection = cms.uint32(1), detLabel = cms.string("TIB - 1.2.2.1") ,selection=cms.untracked.vstring("0x1FFFFFFF-0x16005865")),
cms.PSet(detSelection = cms.uint32(2), detLabel = cms.string("TIB - 1.2.2.1") ,selection=cms.untracked.vstring("0x1FFFFFFF-0x16005866")),
cms.PSet(detSelection = cms.uint32(3), detLabel = cms.string("TIB - 1.2.2.1") ,selection=cms.untracked.vstring("0x1FFFFFFF-0x16005869")),
cms.PSet(detSelection = cms.uint32(4), detLabel = cms.string("TIB - 1.2.2.1") ,selection=cms.untracked.vstring("0x1FFFFFFF-0x1600586a")),
cms.PSet(detSelection = cms.uint32(5), detLabel = cms.string("TIB - 1.2.2.1") ,selection=cms.untracked.vstring("0x1FFFFFFF-0x1600586d")),
cms.PSet(detSelection = cms.uint32(6), detLabel = cms.string("TIB - 1.2.2.1") ,selection=cms.untracked.vstring("0x1FFFFFFF-0x1600586e")),
cms.PSet(detSelection = cms.uint32(7), detLabel = cms.string("TIB + 1.6.2.5") ,selection=cms.untracked.vstring("0x1FFFFFFF-0x160069e5")),
cms.PSet(detSelection = cms.uint32(8), detLabel = cms.string("TIB + 1.6.2.5") ,selection=cms.untracked.vstring("0x1FFFFFFF-0x160069e6")),
cms.PSet(detSelection = cms.uint32(9), detLabel = cms.string("TIB + 1.6.2.5") ,selection=cms.untracked.vstring("0x1FFFFFFF-0x160069e9")),
cms.PSet(detSelection = cms.uint32(10),detLabel = cms.string("TIB + 1.6.2.5") ,selection=cms.untracked.vstring("0x1FFFFFFF-0x160069ea")),
cms.PSet(detSelection = cms.uint32(11),detLabel = cms.string("TIB + 1.6.2.5") ,selection=cms.untracked.vstring("0x1FFFFFFF-0x160069ed")),
cms.PSet(detSelection = cms.uint32(12),detLabel = cms.string("TIB + 1.6.2.5") ,selection=cms.untracked.vstring("0x1FFFFFFF-0x160069ee")),
cms.PSet(detSelection = cms.uint32(13),detLabel = cms.string("TOB + 1.3.1.6") ,selection=cms.untracked.vstring("0x1FFFFFFF-0x1a0062c5")),
cms.PSet(detSelection = cms.uint32(14),detLabel = cms.string("TOB + 1.3.1.6") ,selection=cms.untracked.vstring("0x1FFFFFFF-0x1a0062c6")),
cms.PSet(detSelection = cms.uint32(15),detLabel = cms.string("TOB + 1.3.1.6") ,selection=cms.untracked.vstring("0x1FFFFFFF-0x1a0062c9")),
cms.PSet(detSelection = cms.uint32(16),detLabel = cms.string("TOB + 1.3.1.6") ,selection=cms.untracked.vstring("0x1FFFFFFF-0x1a0062ca")),
cms.PSet(detSelection = cms.uint32(17),detLabel = cms.string("TOB + 1.3.1.6") ,selection=cms.untracked.vstring("0x1FFFFFFF-0x1a0062cd")),
cms.PSet(detSelection = cms.uint32(18),detLabel = cms.string("TOB + 1.3.1.6") ,selection=cms.untracked.vstring("0x1FFFFFFF-0x1a0062ce")),
cms.PSet(detSelection = cms.uint32(19),detLabel = cms.string("TOB + 1.3.1.6") ,selection=cms.untracked.vstring("0x1FFFFFFF-0x1a0062d1")),
cms.PSet(detSelection = cms.uint32(20),detLabel = cms.string("TOB + 1.3.1.6") ,selection=cms.untracked.vstring("0x1FFFFFFF-0x1a0062d2")),
cms.PSet(detSelection = cms.uint32(21),detLabel = cms.string("TOB + 1.3.1.6") ,selection=cms.untracked.vstring("0x1FFFFFFF-0x1a0062d5")),
cms.PSet(detSelection = cms.uint32(22),detLabel = cms.string("TOB + 1.3.1.6") ,selection=cms.untracked.vstring("0x1FFFFFFF-0x1a0062d6")),
cms.PSet(detSelection = cms.uint32(23),detLabel = cms.string("TOB + 1.3.1.6") ,selection=cms.untracked.vstring("0x1FFFFFFF-0x1a0062d9")),
cms.PSet(detSelection = cms.uint32(24),detLabel = cms.string("TOB + 1.3.1.6") ,selection=cms.untracked.vstring("0x1FFFFFFF-0x1a0062da")),
cms.PSet(detSelection = cms.uint32(25),detLabel = cms.string("TOB + 4.3.3.8") ,selection=cms.untracked.vstring("0x1FFFFFFF-0x1a0120a4")),
cms.PSet(detSelection = cms.uint32(26),detLabel = cms.string("TOB + 4.3.3.8") ,selection=cms.untracked.vstring("0x1FFFFFFF-0x1a0120a8")),
cms.PSet(detSelection = cms.uint32(27),detLabel = cms.string("TOB + 4.3.3.8") ,selection=cms.untracked.vstring("0x1FFFFFFF-0x1a0120ac")),
cms.PSet(detSelection = cms.uint32(28),detLabel = cms.string("TOB + 4.3.3.8") ,selection=cms.untracked.vstring("0x1FFFFFFF-0x1a0120b0")),
cms.PSet(detSelection = cms.uint32(29),detLabel = cms.string("TOB + 4.3.3.8") ,selection=cms.untracked.vstring("0x1FFFFFFF-0x1a0120b4")),
cms.PSet(detSelection = cms.uint32(30),detLabel = cms.string("TOB + 4.3.3.8") ,selection=cms.untracked.vstring("0x1FFFFFFF-0x1a0120b8")),
cms.PSet(detSelection = cms.uint32(31),detLabel = cms.string("TEC - 3.7.1.1.2"),selection=cms.untracked.vstring("0x1FFFFFFF-0x1c05e464")),
cms.PSet(detSelection = cms.uint32(32),detLabel = cms.string("TEC - 3.7.1.1.2"),selection=cms.untracked.vstring("0x1FFFFFFF-0x1c05e468")),
cms.PSet(detSelection = cms.uint32(33),detLabel = cms.string("TEC - 3.7.1.1.2"),selection=cms.untracked.vstring("0x1FFFFFFF-0x1c05e46c")),
cms.PSet(detSelection = cms.uint32(34),detLabel = cms.string("TEC - 3.7.1.1.2"),selection=cms.untracked.vstring("0x1FFFFFFF-0x1c05e484")),
cms.PSet(detSelection = cms.uint32(35),detLabel = cms.string("TEC - 3.7.1.1.2"),selection=cms.untracked.vstring("0x1FFFFFFF-0x1c05e488")),
cms.PSet(detSelection = cms.uint32(36),detLabel = cms.string("TEC - 3.7.1.1.2"),selection=cms.untracked.vstring("0x1FFFFFFF-0x1c05e48c")),
cms.PSet(detSelection = cms.uint32(37),detLabel = cms.string("TEC - 3.7.1.1.2"),selection=cms.untracked.vstring("0x1FFFFFFF-0x1c05e490")),
cms.PSet(detSelection = cms.uint32(38),detLabel = cms.string("TEC - 3.7.1.1.2"),selection=cms.untracked.vstring("0x1FFFFFFF-0x1c05e4c4")),
cms.PSet(detSelection = cms.uint32(39),detLabel = cms.string("TEC - 3.7.1.1.2"),selection=cms.untracked.vstring("0x1FFFFFFF-0x1c05e4c8")),
cms.PSet(detSelection = cms.uint32(40),detLabel = cms.string("TEC - 3.7.1.1.2"),selection=cms.untracked.vstring("0x1FFFFFFF-0x1c05e4cc")),
cms.PSet(detSelection = cms.uint32(41),detLabel = cms.string("TEC - 3.7.1.1.2"),selection=cms.untracked.vstring("0x1FFFFFFF-0x1c05e4d0")),
cms.PSet(detSelection = cms.uint32(42),detLabel = cms.string("TEC - 3.7.1.1.3"),selection=cms.untracked.vstring("0x1FFFFFFF-0x1c05e4a5")),
cms.PSet(detSelection = cms.uint32(43),detLabel = cms.string("TEC - 3.7.1.1.3"),selection=cms.untracked.vstring("0x1FFFFFFF-0x1c05e4a6")),
cms.PSet(detSelection = cms.uint32(44),detLabel = cms.string("TEC - 3.7.1.1.3"),selection=cms.untracked.vstring("0x1FFFFFFF-0x1c05e4a9")),
cms.PSet(detSelection = cms.uint32(45),detLabel = cms.string("TEC - 3.7.1.1.3"),selection=cms.untracked.vstring("0x1FFFFFFF-0x1c05e4aa")),
cms.PSet(detSelection = cms.uint32(46),detLabel = cms.string("TEC - 3.7.1.1.3"),selection=cms.untracked.vstring("0x1FFFFFFF-0x1c05e4e4")),
cms.PSet(detSelection = cms.uint32(47),detLabel = cms.string("TEC - 3.7.1.1.3"),selection=cms.untracked.vstring("0x1FFFFFFF-0x1c05e4e8")),
cms.PSet(detSelection = cms.uint32(48),detLabel = cms.string("TEC - 3.7.1.1.3"),selection=cms.untracked.vstring("0x1FFFFFFF-0x1c05e4ec")),
cms.PSet(detSelection = cms.uint32(49),detLabel = cms.string("TEC - 3.7.1.1.3"),selection=cms.untracked.vstring("0x1FFFFFFF-0x1c05e4f0")),
cms.PSet(detSelection = cms.uint32(50),detLabel = cms.string("TEC - 3.7.1.1.3"),selection=cms.untracked.vstring("0x1FFFFFFF-0x1c05e4f4"))
)
)

################################################################################################
#TRACK PRODUCER
#now we give the TrackCandidate coming out of the CalibrationTrackSelectorFromDetIdList to the track producer
################################################################################################
import RecoTracker.TrackProducer.CTFFinalFitWithMaterial_cff
HitFilteredTracks = RecoTracker.TrackProducer.CTFFinalFitWithMaterial_cff.ctfWithMaterialTracks.clone(
src = 'ALCARECOSiStripCalSmallBiasScanSelectedTracks',
#TrajectoryInEvent = True
TTRHBuilder = "WithAngleAndTemplate"
)

ALCARECOTrackFilterRefit = cms.Sequence(offlineBeamSpot +
ALCARECOSiStripCalSmallBiasScanTracksRefit +
ALCARECOSiStripCalSmallBiasScanSelectedTracks +
HitFilteredTracks
)
# Select only good tracks
import Alignment.CommonAlignmentProducer.AlignmentTrackSelector_cfi
ALCARECOSiStripCalSmallBiasScan = Alignment.CommonAlignmentProducer.AlignmentTrackSelector_cfi.AlignmentTrackSelector.clone()

ALCARECOSiStripCalSmallBiasScan.filter = True ##do not store empty events
ALCARECOSiStripCalSmallBiasScan.src = 'HitFilteredTracks'
ALCARECOSiStripCalSmallBiasScan.applyBasicCuts = True
ALCARECOSiStripCalSmallBiasScan.ptMin = 0.8 ##GeV
ALCARECOSiStripCalSmallBiasScan.nHitMin = 6 ## at least 6 hits required
ALCARECOSiStripCalSmallBiasScan.chi2nMax = 10.

ALCARECOSiStripCalSmallBiasScan.GlobalSelector.applyIsolationtest = False
ALCARECOSiStripCalSmallBiasScan.GlobalSelector.applyGlobalMuonFilter = False
ALCARECOSiStripCalSmallBiasScan.GlobalSelector.applyJetCountFilter = False

ALCARECOSiStripCalSmallBiasScan.TwoBodyDecaySelector.applyMassrangeFilter = False
ALCARECOSiStripCalSmallBiasScan.TwoBodyDecaySelector.applyChargeFilter = False
ALCARECOSiStripCalSmallBiasScan.TwoBodyDecaySelector.applyAcoplanarityFilter = False
ALCARECOSiStripCalSmallBiasScan.TwoBodyDecaySelector.applyMissingETFilter = False

# Final Sequence #
seqALCARECOSiStripCalSmallBiasScan = cms.Sequence(ALCARECOSiStripCalSmallBiasScanHLT*DCSStatusForSiStripCalSmallBiasScan*ALCARECOTrackFilterRefit*ALCARECOSiStripCalSmallBiasScan)