53 select_ = std::make_unique<DTSegmentSelector>(
pset, collector);
59 string rootFileName = pset.getUntrackedParameter<
string>(
"rootFileName");
60 theFile =
new TFile(rootFileName.c_str(),
"RECREATE");
63 debug = pset.getUntrackedParameter<
bool>(
"debug",
false);
67 theFitter->setVerbosity(1);
69 hChi2 =
new TH1F(
"hChi2",
"Chi squared tracks", 100, 0, 100);
75 findVDriftAndT0 = pset.getUntrackedParameter<
bool>(
"fitAndWrite",
false);
78 theCalibChamber = pset.getUntrackedParameter<
string>(
"calibChamber",
"All");
90 if (tMaxGranularity !=
"bySL") {
91 LogError(
"Calibration") <<
"[DTVDriftCalibration] tMaxGranularity will be fixed to bySL.";
92 tMaxGranularity =
"bySL";
95 if (tMaxGranularity ==
"bySL") {
97 }
else if (tMaxGranularity ==
"byChamber") {
99 }
else if (tMaxGranularity ==
"byPartition") {
103 <<
"[DTVDriftCalibration] Check parameter tMaxGranularity: " << tMaxGranularity <<
" option not available";
105 LogVerbatim(
"Calibration") <<
"[DTVDriftCalibration]Constructor called!";
110 LogVerbatim(
"Calibration") <<
"[DTVDriftCalibration]Destructor called!";
114 LogTrace(
"Calibration") <<
"--- [DTVDriftCalibration] Event analysed #Run: " <<
event.id().run()
115 <<
" #Event: " <<
event.id().event();
120 stringstream linestr;
121 int selWheel, selStation, selSector;
123 linestr >> selWheel >> selStation >> selSector;
124 chosenChamberId =
DTChamberId(selWheel, selStation, selSector);
125 LogTrace(
"Calibration") <<
"chosen chamber " << chosenChamberId;
147 for (chamberIdIt = all4DSegments->id_begin(); chamberIdIt != all4DSegments->id_end(); ++chamberIdIt) {
150 LogTrace(
"Calibration") <<
"Chamber Id: " << *chamberIdIt;
161 if (!(*segment).hasZed() && !(*segment).hasPhi()) {
162 LogError(
"Calibration") <<
"4D segment without Z and Phi segments";
166 LogTrace(
"Calibration") <<
"Segment local pos (in chamber RF): " << (*segment).localPosition()
167 <<
"\nSegment global pos: " << chamber->
toGlobal((*segment).localPosition());
169 if (!((*
select_)(*segment, event, eventSetup)))
174 map<DTSuperLayerId, vector<DTRecHit1D> > hitsBySLMap;
175 if ((*segment).hasPhi()) {
180 for (vector<DTRecHit1D>::const_iterator
hit = phiHits.begin();
hit != phiHits.end(); ++
hit) {
183 hitsBySLMap[slId].push_back(*
hit);
189 if ((*segment).hasZed()) {
192 zSeg2DPosInCham = chamber->
toLocal(sl->
toGlobal((*zSeg).localPosition()));
193 zSeg2DDirInCham = chamber->
toLocal(sl->
toGlobal((*zSeg).localDirection()));
197 LocalPoint segment4DLocalPos = (*segment).localPosition();
198 LocalVector segment4DLocalDir = (*segment).localDirection();
199 double chiSquare = ((*segment).chi2() / (*segment).degreesOfFreedom());
201 hChi2->Fill(chiSquare);
202 if ((*segment).hasPhi())
203 h2DSegmRPhi->
Fill(phiSeg2DPosInCham.
x(), phiSeg2DDirInCham.
x() / phiSeg2DDirInCham.
z());
204 if ((*segment).hasZed())
205 h2DSegmRZ->
Fill(zSeg2DPosInCham.
y(), zSeg2DDirInCham.
y() / zSeg2DDirInCham.
z());
207 if ((*segment).hasZed() && (*segment).hasPhi())
209 segment4DLocalPos.
y(),
210 atan(segment4DLocalDir.
x() / segment4DLocalDir.
z()) * 180. /
Geom::pi(),
211 atan(segment4DLocalDir.
y() / segment4DLocalDir.
z()) * 180. /
Geom::pi(),
213 else if ((*segment).hasPhi())
215 atan(segment4DLocalDir.
x() / segment4DLocalDir.
z()) * 180. /
Geom::pi());
216 else if ((*segment).hasZed())
217 LogWarning(
"Calibration") <<
"4d segment with only Z";
220 for (
map<
DTSuperLayerId, vector<DTRecHit1D> >::const_iterator slIdAndHits = hitsBySLMap.begin();
221 slIdAndHits != hitsBySLMap.end();
223 if (slIdAndHits->second.size() < 3)
228 DTTMax slSeg(slIdAndHits->second,
230 chamber->
toGlobal((*segment).localDirection()),
231 chamber->
toGlobal((*segment).localPosition()),
235 vector<const TMax*> tMaxes = slSeg.
getTMax(slId);
239 if (cell ==
nullptr) {
240 TString
name = (((((TString)
"TMax" + (
long)slId.
wheel()) + (
long)slId.
station()) + (
long)slId.
sector()) +
248 LogWarning(
"Calibration") <<
"[DTVDriftCalibration] ###Warning: the chosen granularity is not implemented " 249 "yet, only bySL available!";
279 gROOT->GetList()->Write();
300 DTWireId wireId = (*wireCell).first;
301 vector<float> newConstants;
302 TString
N = (((((TString)
"TMax" + (
long)wireId.
wheel()) + (
long)wireId.
station()) + (
long)wireId.
sector()) +
304 vector<float> vDriftAndReso =
theFitter->evaluateVDriftAndReso(N);
307 if (vDriftAndReso.front() == -1)
310 if (oldConstants !=
nullptr) {
311 newConstants.push_back((*oldConstants)[0]);
312 newConstants.push_back((*oldConstants)[1]);
313 newConstants.push_back((*oldConstants)[2]);
315 newConstants.push_back(-1);
316 newConstants.push_back(-1);
317 newConstants.push_back(-1);
319 for (
int ivd = 0; ivd <= 5; ivd++) {
322 newConstants.push_back(vDriftAndReso[ivd]);
325 calibValuesFile.
addCell(calibValuesFile.
getKey(wireId), newConstants);
329 LogTrace(
"Calibration") <<
" SL: " << (wireId.
layerId()).superlayerId() <<
" vDrift = " << vDriftAndReso[0]
330 <<
" reso = " << vDriftAndReso[1];
369 LogVerbatim(
"Calibration") <<
"[DTVDriftCalibration]Writing vdrift object to DB!";
372 string record =
"DTMtimeRcd";
373 DTCalibDBUtils::writeToDB<DTMtime>(
record, mTime);
396 vector<const TMax*> tMaxes = _tMaxes;
407 unsigned hSubGroup = 0;
408 for (vector<const TMax*>::const_iterator it = tMaxes.begin(); it != tMaxes.end(); ++it) {
409 if (*it ==
nullptr) {
413 if (addedCells.size() == 4 ||
find(addedCells.begin(), addedCells.end(), (*it)->cells) != addedCells.end()) {
416 addedCells.push_back((*it)->cells);
420 unsigned t0Factor = (*it)->t0Factor;
421 hSubGroup = (*it)->hSubGroup;
426 cout <<
"Error: no cell type assigned to TMax" << endl;
450 histos->Fill(tmax123, tmax124, tmax134, tmax234, s124, s134, t0_123, t0_124, t0_134, t0_234, hSubGroup);
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
const DTSuperLayer * superLayer(const DTSuperLayerId &id) const
Return the superlayer corresponding to the given id.
Key getKey(DTWireId wireId) const
void writeConsts(const std::string &outputFileName) const
std::pair< const_iterator, const_iterator > range
iterator range
TMaxGranularity theGranularity
const DTChamber * chamber(const DTChamberId &id) const
Return a DTChamber given its id.
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)
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::string theVDriftOutputFile
std::vector< const TMax * > getTMax(const DTWireId &idWire)
Geom::Theta< T > theta() const
C::const_iterator const_iterator
constant access iterator type
std::map< DTWireId, cellInfo * > theWireIdAndCellMap
edm::ParameterSet theCalibFilePar
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
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.
std::unique_ptr< DTMeanTimerFitter > theFitter
LocalPoint localPosition() const override
local position in SL frame
~DTVDriftCalibration() override
Destructor.
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.
LocalVector localDirection() const override
the local direction in SL frame
DTVDriftCalibration(const edm::ParameterSet &pset)
Constructor.
int station() const
Return the station number.
int wheel() const
Return the wheel number.