49 select_ = std::make_unique<DTSegmentSelector>(
pset, collector);
52 theRecHits4DToken = (consumes<DTRecSegment4DCollection>(
pset.getParameter<
InputTag>(
"recHits4DLabel")));
59 debug =
pset.getUntrackedParameter<
bool>(
"debug",
false);
61 theFitter = std::make_unique<DTMeanTimerFitter>(
theFile);
63 theFitter->setVerbosity(1);
65 hChi2 =
new TH1F(
"hChi2",
"Chi squared tracks", 100, 0, 100);
66 h2DSegmRPhi =
new h2DSegm(
"SLRPhi");
67 h2DSegmRZ =
new h2DSegm(
"SLRZ");
68 h4DSegmAllCh =
new h4DSegm(
"AllCh");
69 histograms_.bookHistos();
71 findVDriftAndT0 =
pset.getUntrackedParameter<
bool>(
"fitAndWrite",
false);
74 theCalibChamber =
pset.getUntrackedParameter<
string>(
"calibChamber",
"All");
77 theVDriftOutputFile =
pset.getUntrackedParameter<
string>(
"vDriftFileName");
80 theCalibFilePar =
pset.getUntrackedParameter<
ParameterSet>(
"calibFileConfig");
83 string tMaxGranularity =
pset.getUntrackedParameter<
string>(
"tMaxGranularity",
"bySL");
86 if (tMaxGranularity !=
"bySL") {
87 LogError(
"Calibration") <<
"[DTVDriftCalibration] tMaxGranularity will be fixed to bySL.";
88 tMaxGranularity =
"bySL";
91 if (tMaxGranularity ==
"bySL") {
92 theGranularity = bySL;
93 }
else if (tMaxGranularity ==
"byChamber") {
94 theGranularity = byChamber;
95 }
else if (tMaxGranularity ==
"byPartition") {
96 theGranularity = byPartition;
99 <<
"[DTVDriftCalibration] Check parameter tMaxGranularity: " << tMaxGranularity <<
" option not available";
101 LogVerbatim(
"Calibration") <<
"[DTVDriftCalibration]Constructor called!";
106 LogVerbatim(
"Calibration") <<
"[DTVDriftCalibration]Destructor called!";
110 LogTrace(
"Calibration") <<
"--- [DTVDriftCalibration] Event analysed #Run: " <<
event.id().run()
111 <<
" #Event: " <<
event.id().event();
116 stringstream linestr;
117 int selWheel, selStation, selSector;
119 linestr >> selWheel >> selStation >> selSector;
120 chosenChamberId =
DTChamberId(selWheel, selStation, selSector);
121 LogTrace(
"Calibration") <<
"chosen chamber " << chosenChamberId;
143 for (chamberIdIt = all4DSegments->id_begin(); chamberIdIt != all4DSegments->id_end(); ++chamberIdIt) {
146 LogTrace(
"Calibration") <<
"Chamber Id: " << *chamberIdIt;
157 if (!(*segment).hasZed() && !(*segment).hasPhi()) {
158 LogError(
"Calibration") <<
"4D segment without Z and Phi segments";
162 LogTrace(
"Calibration") <<
"Segment local pos (in chamber RF): " << (*segment).localPosition()
163 <<
"\nSegment global pos: " <<
chamber->toGlobal((*segment).localPosition());
170 map<DTSuperLayerId, vector<DTRecHit1D> > hitsBySLMap;
171 if ((*segment).hasPhi()) {
176 for (vector<DTRecHit1D>::const_iterator
hit = phiHits.begin();
hit != phiHits.end(); ++
hit) {
179 hitsBySLMap[slId].push_back(*
hit);
185 if ((*segment).hasZed()) {
188 zSeg2DPosInCham =
chamber->toLocal(sl->
toGlobal((*zSeg).localPosition()));
189 zSeg2DDirInCham =
chamber->toLocal(sl->
toGlobal((*zSeg).localDirection()));
193 LocalPoint segment4DLocalPos = (*segment).localPosition();
194 LocalVector segment4DLocalDir = (*segment).localDirection();
195 double chiSquare = ((*segment).chi2() / (*segment).degreesOfFreedom());
198 if ((*segment).hasPhi())
199 h2DSegmRPhi->
Fill(phiSeg2DPosInCham.
x(), phiSeg2DDirInCham.
x() / phiSeg2DDirInCham.
z());
200 if ((*segment).hasZed())
201 h2DSegmRZ->
Fill(zSeg2DPosInCham.
y(), zSeg2DDirInCham.
y() / zSeg2DDirInCham.
z());
203 if ((*segment).hasZed() && (*segment).hasPhi())
205 segment4DLocalPos.
y(),
206 atan(segment4DLocalDir.
x() / segment4DLocalDir.
z()) * 180. /
Geom::pi(),
207 atan(segment4DLocalDir.
y() / segment4DLocalDir.
z()) * 180. /
Geom::pi(),
209 else if ((*segment).hasPhi())
211 atan(segment4DLocalDir.
x() / segment4DLocalDir.
z()) * 180. /
Geom::pi());
212 else if ((*segment).hasZed())
213 LogWarning(
"Calibration") <<
"4d segment with only Z";
216 for (
map<
DTSuperLayerId, vector<DTRecHit1D> >::const_iterator slIdAndHits = hitsBySLMap.begin();
217 slIdAndHits != hitsBySLMap.end();
219 if (slIdAndHits->second.size() < 3)
224 DTTMax slSeg(slIdAndHits->second,
225 *(
chamber->superLayer(slIdAndHits->first)),
226 chamber->toGlobal((*segment).localDirection()),
227 chamber->toGlobal((*segment).localPosition()),
232 vector<const TMax*> tMaxes = slSeg.
getTMax(slId);
236 if (cell ==
nullptr) {
237 TString
name = (((((TString)
"TMax" + (
long)slId.
wheel()) + (
long)slId.
station()) + (
long)slId.
sector()) +
245 LogWarning(
"Calibration") <<
"[DTVDriftCalibration] ###Warning: the chosen granularity is not implemented "
246 "yet, only bySL available!";
276 gROOT->GetList()->Write();
297 DTWireId wireId = (*wireCell).first;
298 vector<float> newConstants;
299 TString
N = (((((TString)
"TMax" + (
long)wireId.
wheel()) + (
long)wireId.
station()) + (
long)wireId.
sector()) +
301 vector<float> vDriftAndReso =
theFitter->evaluateVDriftAndReso(
N);
304 if (vDriftAndReso.front() == -1)
307 if (oldConstants !=
nullptr) {
308 newConstants.push_back((*oldConstants)[0]);
309 newConstants.push_back((*oldConstants)[1]);
310 newConstants.push_back((*oldConstants)[2]);
312 newConstants.push_back(-1);
313 newConstants.push_back(-1);
314 newConstants.push_back(-1);
316 for (
int ivd = 0; ivd <= 5; ivd++) {
319 newConstants.push_back(vDriftAndReso[ivd]);
322 calibValuesFile.
addCell(calibValuesFile.
getKey(wireId), newConstants);
326 LogTrace(
"Calibration") <<
" SL: " << (wireId.
layerId()).superlayerId() <<
" vDrift = " << vDriftAndReso[0]
327 <<
" reso = " << vDriftAndReso[1];
366 LogVerbatim(
"Calibration") <<
"[DTVDriftCalibration]Writing vdrift object to DB!";
369 string record =
"DTMtimeRcd";
370 DTCalibDBUtils::writeToDB<DTMtime>(
record, mTime);
393 vector<const TMax*> tMaxes = _tMaxes;
404 unsigned hSubGroup = 0;
405 for (vector<const TMax*>::const_iterator it = tMaxes.begin(); it != tMaxes.end(); ++it) {
406 if (*it ==
nullptr) {
417 unsigned t0Factor = (*it)->t0Factor;
418 hSubGroup = (*it)->hSubGroup;
423 cout <<
"Error: no cell type assigned to TMax" << endl;
447 histos->
Fill(tmax123, tmax124, tmax134, tmax234, s124, s134, t0_123, t0_124, t0_134, t0_234, hSubGroup);