42 using namespace dttmaxenums;
53 select_ = std::make_unique<DTSegmentSelector>(
pset, collector);
56 theRecHits4DToken = (consumes<DTRecSegment4DCollection>(pset.getParameter<
InputTag>(
"recHits4DLabel")));
60 theFile =
new TFile(rootFileName.c_str(),
"RECREATE");
63 debug =
pset.getUntrackedParameter<
bool>(
"debug",
false);
65 theFitter = std::make_unique<DTMeanTimerFitter>(
theFile);
67 theFitter->setVerbosity(1);
69 hChi2 =
new TH1F(
"hChi2",
"Chi squared tracks", 100, 0, 100);
70 h2DSegmRPhi =
new h2DSegm(
"SLRPhi");
71 h2DSegmRZ =
new h2DSegm(
"SLRZ");
72 h4DSegmAllCh =
new h4DSegm(
"AllCh");
73 histograms_.bookHistos();
75 findVDriftAndT0 =
pset.getUntrackedParameter<
bool>(
"fitAndWrite",
false);
78 theCalibChamber =
pset.getUntrackedParameter<
string>(
"calibChamber",
"All");
81 theVDriftOutputFile =
pset.getUntrackedParameter<
string>(
"vDriftFileName");
84 theCalibFilePar =
pset.getUntrackedParameter<
ParameterSet>(
"calibFileConfig");
87 string tMaxGranularity =
pset.getUntrackedParameter<
string>(
"tMaxGranularity",
"bySL");
89 writeLegacyVDriftDB =
pset.getParameter<
bool>(
"writeLegacyVDriftDB");
92 if (tMaxGranularity !=
"bySL") {
93 LogError(
"Calibration") <<
"[DTVDriftCalibration] tMaxGranularity will be fixed to bySL.";
94 tMaxGranularity =
"bySL";
97 if (tMaxGranularity ==
"bySL") {
98 theGranularity = bySL;
99 }
else if (tMaxGranularity ==
"byChamber") {
100 theGranularity = byChamber;
101 }
else if (tMaxGranularity ==
"byPartition") {
102 theGranularity = byPartition;
105 <<
"[DTVDriftCalibration] Check parameter tMaxGranularity: " << tMaxGranularity <<
" option not available";
107 LogVerbatim(
"Calibration") <<
"[DTVDriftCalibration]Constructor called!";
112 LogVerbatim(
"Calibration") <<
"[DTVDriftCalibration]Destructor called!";
116 LogTrace(
"Calibration") <<
"--- [DTVDriftCalibration] Event analysed #Run: " <<
event.id().run()
117 <<
" #Event: " <<
event.id().event();
121 if (theCalibChamber !=
"All") {
122 stringstream linestr;
123 int selWheel, selStation, selSector;
125 linestr >> selWheel >> selStation >> selSector;
126 chosenChamberId =
DTChamberId(selWheel, selStation, selSector);
127 LogTrace(
"Calibration") <<
"chosen chamber " << chosenChamberId;
142 for (chamberIdIt = all4DSegments->id_begin(); chamberIdIt != all4DSegments->id_end(); ++chamberIdIt) {
145 LogTrace(
"Calibration") <<
"Chamber Id: " << *chamberIdIt;
148 if ((theCalibChamber !=
"All") && ((*chamberIdIt) != chosenChamberId))
156 if (!(*segment).hasZed() && !(*segment).hasPhi()) {
157 LogError(
"Calibration") <<
"4D segment without Z and Phi segments";
161 LogTrace(
"Calibration") <<
"Segment local pos (in chamber RF): " << (*segment).localPosition()
162 <<
"\nSegment global pos: " << chamber->
toGlobal((*segment).localPosition());
164 if (!((*
select_)(*segment, event, eventSetup)))
169 map<DTSuperLayerId, vector<DTRecHit1D> > hitsBySLMap;
170 if ((*segment).hasPhi()) {
175 for (vector<DTRecHit1D>::const_iterator
hit = phiHits.begin();
hit != phiHits.end(); ++
hit) {
178 hitsBySLMap[slId].push_back(*
hit);
184 if ((*segment).hasZed()) {
187 zSeg2DPosInCham = chamber->
toLocal(sl->
toGlobal((*zSeg).localPosition()));
188 zSeg2DDirInCham = chamber->
toLocal(sl->
toGlobal((*zSeg).localDirection()));
192 LocalPoint segment4DLocalPos = (*segment).localPosition();
193 LocalVector segment4DLocalDir = (*segment).localDirection();
194 double chiSquare = ((*segment).chi2() / (*segment).degreesOfFreedom());
196 hChi2->Fill(chiSquare);
197 if ((*segment).hasPhi())
198 h2DSegmRPhi->
Fill(phiSeg2DPosInCham.
x(), phiSeg2DDirInCham.
x() / phiSeg2DDirInCham.
z());
199 if ((*segment).hasZed())
200 h2DSegmRZ->
Fill(zSeg2DPosInCham.
y(), zSeg2DDirInCham.
y() / zSeg2DDirInCham.
z());
202 if ((*segment).hasZed() && (*segment).hasPhi())
204 segment4DLocalPos.
y(),
205 atan(segment4DLocalDir.
x() / segment4DLocalDir.
z()) * 180. /
Geom::pi(),
206 atan(segment4DLocalDir.
y() / segment4DLocalDir.
z()) * 180. /
Geom::pi(),
208 else if ((*segment).hasPhi())
210 atan(segment4DLocalDir.
x() / segment4DLocalDir.
z()) * 180. /
Geom::pi());
211 else if ((*segment).hasZed())
212 LogWarning(
"Calibration") <<
"4d segment with only Z";
215 for (map<
DTSuperLayerId, vector<DTRecHit1D> >::const_iterator slIdAndHits = hitsBySLMap.begin();
216 slIdAndHits != hitsBySLMap.end();
218 if (slIdAndHits->second.size() < 3)
223 DTTMax slSeg(slIdAndHits->second,
225 chamber->
toGlobal((*segment).localDirection()),
226 chamber->
toGlobal((*segment).localPosition()),
231 vector<const TMax*> tMaxes = slSeg.
getTMax(slId);
235 if (cell ==
nullptr) {
236 TString
name = (((((TString)
"TMax" + (
long)slId.
wheel()) + (
long)slId.
station()) + (
long)slId.
sector()) +
244 LogWarning(
"Calibration") <<
"[DTVDriftCalibration] ###Warning: the chosen granularity is not implemented "
245 "yet, only bySL available!";
275 gROOT->GetList()->Write();
285 if (writeLegacyVDriftDB) {
305 DTWireId wireId = (*wireCell).first;
306 vector<float> newConstants;
307 TString
N = (((((TString)
"TMax" + (
long)wireId.
wheel()) + (
long)wireId.
station()) + (
long)wireId.
sector()) +
309 vector<float> vDriftAndReso = theFitter->evaluateVDriftAndReso(N);
312 if (vDriftAndReso.front() == -1)
315 if (oldConstants !=
nullptr) {
316 newConstants.push_back((*oldConstants)[0]);
317 newConstants.push_back((*oldConstants)[1]);
318 newConstants.push_back((*oldConstants)[2]);
320 newConstants.push_back(-1);
321 newConstants.push_back(-1);
322 newConstants.push_back(-1);
324 for (
int ivd = 0; ivd <= 5; ivd++) {
327 newConstants.push_back(vDriftAndReso[ivd]);
330 calibValuesFile.
addCell(calibValuesFile.
getKey(wireId), newConstants);
333 if (writeLegacyVDriftDB) {
336 vector<double>
params = {vDriftAndReso[0]};
337 vDrift->
set(wireId, params);
339 LogTrace(
"Calibration") <<
" SL: " << (wireId.
layerId()).superlayerId() <<
" vDrift = " << vDriftAndReso[0]
340 <<
" reso = " << vDriftAndReso[1];
379 LogVerbatim(
"Calibration") <<
"[DTVDriftCalibration]Writing vdrift object to DB!";
382 if (writeLegacyVDriftDB) {
383 string record =
"DTMtimeRcd";
384 DTCalibDBUtils::writeToDB<DTMtime>(
record, mTime);
386 DTCalibDBUtils::writeToDB<DTRecoConditions>(
"DTRecoConditionsVdriftRcd", vDrift);
410 vector<const TMax*> tMaxes = _tMaxes;
421 unsigned hSubGroup = 0;
422 for (vector<const TMax*>::const_iterator it = tMaxes.begin(); it != tMaxes.end(); ++it) {
423 if (*it ==
nullptr) {
434 unsigned t0Factor = (*it)->t0Factor;
435 hSubGroup = (*it)->hSubGroup;
440 cout <<
"Error: no cell type assigned to TMax" << endl;
464 histos->
Fill(tmax123, tmax124, tmax134, tmax234, s124, s134, t0_123, t0_124, t0_134, t0_234, hSubGroup);
Log< level::Info, true > LogVerbatim
const DTSuperLayer * superLayer(const DTSuperLayerId &id) const
Return the superlayer corresponding to the given id.
Key getKey(DTWireId wireId) const
const edm::ESGetToken< DTGeometry, MuonGeometryRecord > theDTGeomToken
void writeConsts(const std::string &outputFileName) const
std::pair< const_iterator, const_iterator > range
iterator range
LocalPoint localPosition() const override
local position in SL frame
LocalVector localDirection() const override
the local direction in SL frame
TMaxGranularity theGranularity
const DTChamber * chamber(const DTChamberId &id) const
Return a DTChamber given its id.
void setVersion(int version)
void set(const DTWireId &wireid, const std::vector< double > &values)
Fill the payload.
int set(int wheelId, int stationId, int sectorId, int slId, float mTime, float mTrms, DTTimeUnits::type unit)
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
std::unique_ptr< DTTTrigBaseSync > theSync
void Fill(float x, float y, float phi, float theta, float impact)
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
void Fill(float pos, float localAngle)
Log< level::Error, false > LogError
DTSuperLayerId superlayerId() const
Return the corresponding SuperLayerId.
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
std::vector< const TMax * > getTMax(const DTWireId &idWire)
const uint16_t range(const Frame &aFrame)
Geom::Theta< T > theta() const
bool getData(T &iHolder) const
C::const_iterator const_iterator
constant access iterator type
std::map< DTWireId, cellInfo * > theWireIdAndCellMap
std::vector< float > CalibConsts
int superLayer() const
Return the superlayer number.
void addCell(Key wireId, const CalibConsts &calibConst)
edm::EDGetTokenT< DTRecSegment4DCollection > theRecHits4DToken
void add(const std::vector< const TMax * > &tMaxes)
std::vector< DTRecHit1D > specificRecHits() const
Access to specific components.
DTSuperLayerId superLayerId() const
The id of the superlayer on which reside the segment.
void Fill(float tmax123, float tmax124, float tmax134, float tmax234, dttmaxenums::SigmaFactor s124, dttmaxenums::SigmaFactor s134, unsigned t0_123, unsigned t0_124, unsigned t0_134, unsigned t0_234, unsigned hSubGroup)
caConstants::TupleMultiplicity const CAHitNtupletGeneratorKernelsGPU::HitToTuple const cms::cuda::AtomicPairCounter GPUCACell const *__restrict__ cells
~DTVDriftCalibration() override
Destructor.
dtcalibration::Histograms histograms_
std::unique_ptr< DTSegmentSelector > select_
void analyze(const edm::Event &event, const edm::EventSetup &eventSetup) override
const CalibConsts * getConsts(DTWireId wireId) const
std::string theCalibChamber
DTLayerId layerId() const
Return the corresponding LayerId.
DTVDriftCalibration(const edm::ParameterSet &pset)
Constructor.
void setFormulaExpr(const std::string &expr)
Set the expression representing the formula used for parametrization.
std::vector< dttmaxenums::TMaxCells > addedCells
Log< level::Warning, false > LogWarning
int station() const
Return the station number.
int wheel() const
Return the wheel number.