53 select_ = std::make_unique<DTSegmentSelector>(
pset, collector);
56 theRecHits4DToken = (consumes<DTRecSegment4DCollection>(
pset.getParameter<
InputTag>(
"recHits4DLabel")));
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();
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;
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());
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());
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,
224 *(
chamber->superLayer(slIdAndHits->first)),
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();
283 std::unique_ptr<DTMtime> mTime;
284 std::unique_ptr<DTRecoConditions> vDrift;
286 mTime = std::make_unique<DTMtime>();
288 vDrift = std::make_unique<DTRecoConditions>();
289 vDrift->setFormulaExpr(
"[0]");
291 vDrift->setVersion(1);
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);
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!";
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
int station() const
Return the station number.
const edm::ESGetToken< DTGeometry, MuonGeometryRecord > theDTGeomToken
std::pair< const_iterator, const_iterator > range
iterator range
LocalPoint localPosition() const override
local position in SL frame
int superLayer() const
Return the superlayer number.
LocalVector localDirection() const override
the local direction in SL frame
TMaxGranularity theGranularity
std::unique_ptr< DTTTrigBaseSync > theSync
void Fill(float x, float y, float phi, float theta, float impact)
void Fill(float pos, float localAngle)
Log< level::Error, false > LogError
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
std::string theVDriftOutputFile
std::vector< const TMax * > getTMax(const DTWireId &idWire)
C::const_iterator const_iterator
constant access iterator type
std::map< DTWireId, cellInfo * > theWireIdAndCellMap
edm::ParameterSet theCalibFilePar
const CalibConsts * getConsts(DTWireId wireId) const
std::vector< float > CalibConsts
void addCell(Key wireId, const CalibConsts &calibConst)
edm::EDGetTokenT< DTRecSegment4DCollection > theRecHits4DToken
Key getKey(DTWireId wireId) const
DTSuperLayerId superLayerId() const
The id of the superlayer on which reside the segment.
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
std::unique_ptr< DTMeanTimerFitter > theFitter
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)
~DTVDriftCalibration() override
Destructor.
dtcalibration::Histograms histograms_
std::unique_ptr< DTSegmentSelector > select_
std::vector< DTRecHit1D > specificRecHits() const
Access to specific components.
void analyze(const edm::Event &event, const edm::EventSetup &eventSetup) override
void writeConsts(const std::string &outputFileName) const
std::string theCalibChamber
int wheel() const
Return the wheel number.
DTVDriftCalibration(const edm::ParameterSet &pset)
Constructor.
DTSuperLayerId superlayerId() const
Return the corresponding SuperLayerId.
void add(const std::vector< const TMax *> &tMaxes)
std::vector< dttmaxenums::TMaxCells > addedCells
DTLayerId layerId() const
Return the corresponding LayerId.
Log< level::Warning, false > LogWarning
const DTChamber * chamber(const DTChamberId &id) const
Return a DTChamber given its id.
Geom::Theta< T > theta() const