CMS 3D CMS Logo

FineDelayHistosUsingDb.cc
Go to the documentation of this file.
1 
17 #include <iostream>
18 
19 using namespace sistrip;
20 
21 // -----------------------------------------------------------------------------
24  DQMStore* bei,
25  SiStripConfigDb* const db )
26  : CommissioningHistograms( pset.getParameter<edm::ParameterSet>("FineDelayParameters"),
27  bei,
31  SamplingHistograms( pset.getParameter<edm::ParameterSet>("FineDelayParameters"),
32  bei,
34  tracker_(0)
35 {
37  << "[FineDelayHistosUsingDb::" << __func__ << "]"
38  << " Constructing object...";
39  delays_.clear();
40 }
41 
42 // -----------------------------------------------------------------------------
46  << "[FineDelayHistosUsingDb::" << __func__ << "]"
47  << " Destructing object...";
48 }
49 
50 // -----------------------------------------------------------------------------
53  const edm::EventSetup& setup ) {
54  // get geometry
56  setup.get<TrackerDigiGeometryRecord>().get(estracker);
57  tracker_=&(* estracker);
59  cosmic_ = this->pset().getParameter<bool>("cosmic");
60 }
61 
62 // -----------------------------------------------------------------------------
65 
66  if ( !db() ) {
68  << "[FineDelayHistosUsingDb::" << __func__ << "]"
69  << " NULL pointer to SiStripConfigDb interface!"
70  << " Aborting upload...";
71  return;
72  }
73 
74  // Retrieve and update PLL device descriptions
77  bool upload = update( devices );
78 
79  // Check if new PLL settings are valid
80  if ( !upload ) {
82  << "[FineDelayHistosUsingDb::" << __func__ << "]"
83  << " Found invalid PLL settings (coarse > 15)"
84  << " Aborting update to database...";
85  return;
86  }
87 
88  // Upload PLL device descriptions
89  if ( doUploadConf() ) {
91  << "[FineDelayHistosUsingDb::" << __func__ << "]"
92  << " Uploading PLL settings to DB...";
95  << "[FineDelayHistosUsingDb::" << __func__ << "]"
96  << " Upload of PLL settings to DB finished!";
97  } else {
99  << "[FineDelayHistosUsingDb::" << __func__ << "]"
100  << " TEST only! No PLL settings will be uploaded to DB...";
101  }
102 
103  // Update FED descriptions with new ticker thresholds
104  db()->clearFedDescriptions();
106  update( feds );
107 
108  // Update FED descriptions with new ticker thresholds
109  if ( doUploadConf() ) {
111  << "[FineDelayHistosUsingDb::" << __func__ << "]"
112  << " Uploading FED ticker thresholds to DB...";
115  << "[FineDelayHistosUsingDb::" << __func__ << "]"
116  << " Upload of FED ticker thresholds to DB finished!";
117  } else {
119  << "[FineDelayHistosUsingDb::" << __func__ << "]"
120  << " TEST only! No FED ticker thresholds will be uploaded to DB...";
121  }
122 
123 }
124 
126  // do nothing if delays_ map is already filled
127  if(delays_.size()>0) return;
128 
129  // the point from which track should originate
130  float x = 0.; float y = 0.; float z = 0.;
131  if(cosmic_) { y = 385.; z=20.; } // mean entry point of cosmics
132  GlobalPoint referenceP_ = GlobalPoint(x,y,z);
133  const double c = 30; // cm/ns
134 
135  // the reference parameters (best delay in ns, initial Latency)
136  float bestDelay_ = 0.;
137  if(data().size()) {
138  Analyses::const_iterator iter = data().begin();
139  bestDelay_ = dynamic_cast<SamplingAnalysis*>(iter->second)->maximum();
140  }
141 
142  // Retrieve FED ids from cabling
143  auto ids = cabling()->fedIds() ;
144 
145  // loop over the FED ids
146  for (auto ifed = ids.begin(); ifed != ids.end(); ++ifed) {
147  auto conns = cabling()->fedConnections(*ifed);
148  // loop over the connections for that FED
149  for ( auto iconn = conns.begin(); iconn != conns.end(); ++iconn ) {
150  // check that this is a tracker module
151  if(DetId(iconn->detId()).det()!=DetId::Tracker) continue;
152  // retrieve the position of that module in the tracker using the geometry
153  // and use it to compute the distance to the reference point set in the configuration
154  if(tracker_) {
155  float dist = tracker_->idToDetUnit(DetId(iconn->detId()))->toLocal(referenceP_).mag();
156  float tof = dist/c ;
157  // compute the PLL delay shift for the module as delay + tof
158  float delay = bestDelay_+tof;
159  // store that in the map
160  delays_[SiStripFecKey( iconn->fecCrate(),
161  iconn->fecSlot(),
162  iconn->fecRing(),
163  iconn->ccuAddr(),
164  iconn->ccuChan(), 0 ).key()] = delay;
166  << "[FineDelayHistosUsingDb::" << __func__ << "] Computed Delay to be added to PLL: "
167  << bestDelay_ << " " << tof << " " << delay << std::endl;
168  } else {
170  << "[FineDelayHistosUsingDb::" << __func__ << "]"
171  << " Tracker geometry not initialized. Impossible to compute the delays.";
172  }
173  }
174  }
175 }
176 
177 // -----------------------------------------------------------------------------
180 
181  // do the core computation of delays per FED connection
182  computeDelays();
183 
184  // Iterate through devices and update device descriptions
185  uint16_t updated = 0;
186  std::vector<SiStripFecKey> invalid;
187  SiStripConfigDb::DeviceDescriptionsV::const_iterator idevice;
188  for ( idevice = devices.begin(); idevice != devices.end(); idevice++ ) {
189 
190  // Check device type
191  if ( (*idevice)->getDeviceType() != PLL ) { continue; }
192 
193  // Cast to retrieve appropriate description object
194  pllDescription* desc = dynamic_cast<pllDescription*>( *idevice );
195  if ( !desc ) { continue; }
196 
197  // Retrieve device addresses from device description
198  const SiStripConfigDb::DeviceAddress& addr = db()->deviceAddress(*desc);
199 
200  // Construct key from device description
201  uint32_t fec_key = SiStripFecKey( addr.fecCrate_,
202  addr.fecSlot_,
203  addr.fecRing_,
204  addr.ccuAddr_,
205  addr.ccuChan_,
206  0 ).key();
207  SiStripFecKey fec_path = SiStripFecKey( fec_key );
208 
209  // extract the delay from the map
210  float delay = desc->getDelayCoarse()*25+desc->getDelayFine()*25./24. + delays_[fec_key];
211  int delayCoarse = int(delay/25);
212  int delayFine = int(round((delay-25*delayCoarse)*24./25.));
213  if(delayFine==24) { delayFine=0; ++delayCoarse; }
214  // maximum coarse setting
215  if ( delayCoarse > 15 ) { invalid.push_back(fec_key); delayCoarse = sistrip::invalid_; }
216 
217  // Update PLL settings
218  if ( delayCoarse != sistrip::invalid_ &&
219  delayFine != sistrip::invalid_ ) {
220 
221  std::stringstream ss;
222  ss << "[FineDelayHistosUsingDb::" << __func__ << "]"
223  << " Updating coarse/fine PLL settings"
224  << " for Crate/FEC/slot/ring/CCU "
225  << fec_path.fecCrate() << "/"
226  << fec_path.fecSlot() << "/"
227  << fec_path.fecRing() << "/"
228  << fec_path.ccuAddr() << "/"
229  << fec_path.ccuChan()
230  << " from "
231  << static_cast<uint16_t>( desc->getDelayCoarse() ) << "/"
232  << static_cast<uint16_t>( desc->getDelayFine() );
233  desc->setDelayCoarse(delayCoarse);
234  desc->setDelayFine(delayFine);
235  updated++;
236  ss << " to "
237  << static_cast<uint16_t>( desc->getDelayCoarse() ) << "/"
238  << static_cast<uint16_t>( desc->getDelayFine() );
239  LogTrace(mlDqmClient_) << ss.str();
240 
241  } else {
243  << "[FineDelayHistosUsingDb::" << __func__ << "]"
244  << " Unexpected PLL delay settings for Crate/FEC/slot/ring/CCU "
245  << fec_path.fecCrate() << "/"
246  << fec_path.fecSlot() << "/"
247  << fec_path.fecRing() << "/"
248  << fec_path.ccuAddr() << "/"
249  << fec_path.ccuChan();
250  }
251 
252  }
253 
254  // Check if invalid settings were found
255  if ( !invalid.empty() ) {
256  std::stringstream ss;
257  ss << "[FineDelayHistosUsingDb::" << __func__ << "]"
258  << " Found PLL coarse setting of 15"
259  << " (not allowed!) for following channels"
260  << " (Crate/FEC/slot/ring/CCU/LLD): ";
261  std::vector<SiStripFecKey>::iterator ikey = invalid.begin();
262  std::vector<SiStripFecKey>::iterator jkey = invalid.end();
263  for ( ; ikey != jkey; ++ikey ) {
264  ss << ikey->fecCrate() << "/"
265  << ikey->fecSlot() << "/"
266  << ikey->fecRing() << "/"
267  << ikey->ccuAddr() << "/"
268  << ikey->ccuChan() << ", ";
269  }
270  edm::LogWarning(mlDqmClient_) << ss.str();
271  return false;
272  }
273 
275  << "[FineDelayHistosUsingDb::" << __func__ << "]"
276  << " Updated PLL settings for "
277  << updated << " modules";
278  return true;
279 }
280 
281 // -----------------------------------------------------------------------------
284 
285  // do the core computation of delays per FED connection
286  computeDelays();
287 
288  // Retrieve FED ids from cabling
289  auto ids = cabling()->fedIds() ;
290 
291  // loop over the FED ids
292  for ( SiStripConfigDb::FedDescriptionsV::const_iterator ifed = feds.begin(); ifed != feds.end(); ifed++ ) {
293  // If FED id not found in list (from cabling), then continue
294  if ( find( ids.begin(), ids.end(), (*ifed)->getFedId() ) == ids.end() ) { continue; }
295  auto conns = cabling()->fedConnections((*ifed)->getFedId());
296  // loop over the connections for that FED
297  for ( auto iconn = conns.begin(); iconn != conns.end(); iconn++ ) {
298  // check that this is a tracker module
299  if(DetId(iconn->detId()).det()!=DetId::Tracker) continue;
300  // build the Fed9UAddress for that channel. Used to update the description.
301  Fed9U::Fed9UAddress fedChannel = Fed9U::Fed9UAddress(iconn->fedCh());
302  // retreive the current value for the delays
303  int fedDelayCoarse = (*ifed)->getCoarseDelay(fedChannel);
304  int fedDelayFine = (*ifed)->getFineDelay(fedChannel);
305  int fedDelay = int(fedDelayCoarse*25. - fedDelayFine*24./25.);
306  // extract the delay from the map
307  int delay = int(round( delays_[SiStripFecKey( iconn->fecCrate(),
308  iconn->fecSlot(),
309  iconn->fecRing(),
310  iconn->ccuAddr(),
311  iconn->ccuChan(), 0 ).key()]));
312  // compute the FED delay
313  // this is done by substracting the best (PLL) delay to the present value (from the db)
314  fedDelay -= delay;
315  fedDelayCoarse = (fedDelay/25)+1;
316  fedDelayFine = fedDelayCoarse*25-fedDelay;
317  if(fedDelayFine==25) { fedDelayFine = 0; --fedDelayCoarse; }
318  // update the FED delay
319  std::stringstream ss;
320  ss << "[FineDelayHistosUsingDb::" << __func__ << "]"
321  << " Updating the FED delay"
322  << " for loop FED id/ch "
323  << (*ifed)->getFedId() << "/" << iconn->fedCh()
324  << " from "
325  << (*ifed)->getCoarseDelay( fedChannel) << "/" << (*ifed)->getFineDelay( fedChannel)
326  << " to ";
327  (*ifed)->setDelay(fedChannel, fedDelayCoarse, fedDelayFine);
328  ss << (*ifed)->getCoarseDelay(fedChannel) << "/" << (*ifed)->getFineDelay( fedChannel) << std::endl;
329  LogTrace(mlDqmClient_) << ss.str();
330  }
331  }
332 
334  << "[FineDelayHistosUsingDb::" << __func__ << "]"
335  << " Updated FED delay for " << ids.size() << " FEDs!";
336 
337 }
338 
339 // -----------------------------------------------------------------------------
342  Analysis analysis ) {
343 
344  SamplingAnalysis* anal = dynamic_cast<SamplingAnalysis*>( analysis->second );
345  if ( !anal ) { return; }
346 
347  SiStripFecKey fec_key( anal->fecKey() ); //@@ analysis->first
348  SiStripFedKey fed_key( anal->fedKey() );
349 
350  FineDelayAnalysisDescription* tmp;
351  tmp = new FineDelayAnalysisDescription( anal->maximum(),
352  anal->error(),
353  0,
354  0,
355  0,
356  0,
357  0,
358  0,
359  db()->dbParams().partitions().begin()->second.partitionName(),
360  db()->dbParams().partitions().begin()->second.runNumber(),
361  anal->isValid(),
362  "",
363  fed_key.fedId(),
364  fed_key.feUnit(),
365  fed_key.feChan(),
366  fed_key.fedApv() );
367 
368  // Add comments
369  typedef std::vector<std::string> Strings;
370  Strings errors = anal->getErrorCodes();
371  Strings::const_iterator istr = errors.begin();
372  Strings::const_iterator jstr = errors.end();
373  for ( ; istr != jstr; ++istr ) { tmp->addComments( *istr ); }
374 
375  // Store description
376  desc.push_back( tmp );
377 
378 }
def upload(url, args, files)
size
Write out results.
T getParameter(std::string const &) const
static const char tracker_[]
Analysis for latency run.
const uint32_t & fedKey() const
const uint16_t & fecRing() const
A container class for generic run and event-related info, information required by the commissioning a...
Definition: SiStripFedKey.h:56
const edm::ParameterSet & pset() const
virtual bool isValid() const
FedDescriptionsRange getFedDescriptions(std::string partition="")
std::vector< std::string > Strings
Definition: MsgTools.h:18
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
FedDescriptions::range FedDescriptionsRange
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:1
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
Definition: GeomDet.h:69
static const char mlDqmClient_[]
virtual void configure(const edm::ParameterSet &, const edm::EventSetup &)
const uint16_t & fecSlot() const
void clearDeviceDescriptions(std::string partition="")
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
sistrip classes
const uint32_t & key() const
Definition: SiStripKey.h:125
Utility class that identifies a position within the strip tracker control structure, down to the level of an APV25.
Definition: SiStripFecKey.h:45
const_iterator_range partitions() const
const TrackerGeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
T mag() const
Definition: PV3DBase.h:67
const float & error() const
FedsConstIterRange fedIds() const
DeviceDescriptions::range DeviceDescriptionsRange
An interface class to the DeviceFactory.
const uint32_t & fecKey() const
FineDelayHistosUsingDb(const edm::ParameterSet &pset, DQMStore *, SiStripConfigDb *const )
DeviceAddress deviceAddress(const deviceDescription &)
std::map< unsigned int, float > delays_
#define LogTrace(id)
const uint16_t & fecCrate() const
Definition: DetId.h:18
const SiStripDbParams & dbParams() const
bool update(SiStripConfigDb::DeviceDescriptionsRange)
void uploadFedDescriptions(std::string partition="")
const T & get() const
Definition: EventSetup.h:55
const uint16_t & ccuAddr() const
static const uint16_t invalid_
Definition: Constants.h:16
ConnsConstIterRange fedConnections(uint16_t fed_id) const
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
void create(SiStripConfigDb::AnalysisDescriptionsV &, Analysis)
const TrackerGeometry * tracker_
HLT enums.
virtual void configure(const edm::ParameterSet &, const edm::EventSetup &)
std::vector< AnalysisDescription * > AnalysisDescriptionsV
const uint16_t & ccuChan() const
const float & maximum() const
Definition: errors.py:1
SiStripConfigDb *const db() const
void clearFedDescriptions(std::string partition="")
DeviceDescriptionsRange getDeviceDescriptions(std::string partition="")
void uploadDeviceDescriptions(std::string partition="")
SiStripFedCabling *const cabling() const
const VString & getErrorCodes() const