8 #define DB_WRITE_SUPPORT 24 #ifdef DB_WRITE_SUPPORT 27 #endif //DB_WRITE_SUPPORT defined 39 : dcc1stSample_(ps.getParameter<
int>(
"dcc1stSample")),
40 sampleToSkip_(ps.getParameter<
int>(
"sampleToSkip")),
41 nDccWeights_(ps.getParameter<
int>(
"nDccWeights")),
42 inputWeights_(ps.getParameter<
vector<double> >(
"inputWeights")),
43 mode_(ps.getParameter<
string>(
"mode")),
44 dccWeightsWithIntercalib_(ps.getParameter<
bool>(
"dccWeightsWithIntercalib")),
45 writeToDB_(ps.getParameter<
bool>(
"writeToDB")),
46 writeToAsciiFile_(ps.getParameter<
bool>(
"writeToAsciiFile")),
47 writeToRootFile_(ps.getParameter<
bool>(
"writeToRootFile")),
48 asciiOutputFileName_(ps.getParameter<
string>(
"asciiOutputFileName")),
49 rootOutputFileName_(ps.getParameter<
string>(
"rootOutputFileName")),
50 dbSid_(ps.getParameter<
string>(
"dbSid")),
51 dbUser_(ps.getParameter<
string>(
"dbUser")),
52 dbPassword_(ps.getUntrackedParameter<
string>(
"dbPassword",
"")),
53 dbTag_(ps.getParameter<
string>(
"dbTag")),
54 dbVersion_(ps.getParameter<
int>(
"dbVersion")),
55 sqlMode_(ps.getParameter<
bool>(
"sqlMode")),
59 calibMap_(emptyCalibMap_),
60 ebShape_(consumesCollector()),
61 eeShape_(consumesCollector()) {
62 if (
mode_ ==
"weightsFromConfig") {
65 throw cms::Exception(
"Config") <<
"Inconsistent configuration. 'nDccWeights' parameters indicated " 66 <<
nDccWeights_ <<
" weights while parameter 'inputWeights_' contains " 69 }
else if (
mode_ ==
"computeWeights") {
73 <<
"Valid values are: 'weightsFromConfig' and 'computeWeights'\n";
110 vector<DetId> detIds(ebDetIds.size() + eeDetIds.size());
111 copy(ebDetIds.begin(), ebDetIds.end(), detIds.begin());
112 copy(eeDetIds.begin(), eeDetIds.end(), detIds.begin() + ebDetIds.size());
114 vector<double> baseWeights(nw);
115 vector<double>
w(nw);
124 for (vector<DetId>::const_iterator
it = detIds.begin();
it != detIds.end(); ++
it) {
130 edm::LogVerbatim(
"EcalDccWeightBuilder") << __FILE__ <<
":" << __LINE__ <<
": ";
137 <<
" iz = " << setw(1) << ((
EEDetId)(*
it)).
iy() <<
" ";
140 <<
"Bug found in " << __FILE__ <<
":" << __LINE__ <<
": " 141 <<
"Got a detId which is neither tagged as ECAL Barrel " 142 <<
"not ECAL endcap while looping on ECAL cell detIds\n";
145 edm::LogVerbatim(
"EcalDccWeightBuilder") <<
" -> binOfMax: " << binOfMax <<
"\n";
156 throw cms::Exception(
"EcalDccWeightBuilder") <<
"Bug found in " << __FILE__ <<
":" << __LINE__ <<
": " 157 <<
"Got a detId which is neither tagged as ECAL Barrel " 158 <<
"not ECAL endcap while looping on ECAL cell detIds\n";
161 if (
phase != prevPhase) {
169 for (
int i = 0;
i < nw; ++
i) {
170 w[
i] = baseWeights[
i];
177 edm::LogVerbatim(
"EcalDccWeightBuilder") << __FILE__ <<
":" << __LINE__ <<
": ";
184 <<
" iz = " << setw(1) << ((
EEDetId)(*
it)).
iy() <<
" ";
205 int nActualWeights = 0;
209 for (
int i = 0;
i < nWeights; ++
i) {
210 double t_ns =
tzero + (iFirst +
i) * 25;
220 for (
int i = 0;
i < nWeights; ++
i) {
224 result[
i] = (
result[
i] - sum / nActualWeights) / (sum2 - sum * sum / nActualWeights);
237 bool changed =
false;
239 for (
unsigned i = 0;
i <
a.size(); ++
i)
245 for (
unsigned i = 0;
i <
a.size() - 1; ++
i) {
247 const int nextj =
s[
i + 1];
248 if ((decreasingOrder && (
a[
j] <
a[nextj])) || (!decreasingOrder && (
a[
j] >
a[nextj]))) {
257 const unsigned nw =
weights.size();
260 vector<double> dw(nw);
263 for (
unsigned i = 0;
i < nw; ++
i) {
279 int wsumSign = wsum > 0 ? 1 : -1;
280 int i = wsum > 0 ? 0 : (nw - 1);
282 W[iw[
i]] -= wsumSign;
285 if (i < 0 || i >= (
int)nw) {
287 for (
unsigned i = 0;
i < nw; ++
i) {
299 if (encodedWeights !=
nullptr)
300 encodedWeights->resize(nw);
301 for (
unsigned i = 0;
i < nw; ++
i) {
304 (*encodedWeights)[
i] = W[
i];
316 edm::LogVerbatim(
"EcalDccWeightBuilder") << (uint32_t)
detId <<
" not found in EcalIntercalibConstantMap";
319 edm::LogVerbatim(
"EcalDccWeightBuilder") << __FILE__ <<
":" << __LINE__ <<
": ";
337 throw cms::Exception(
"Output") <<
"Failed to open file '" <<
fName <<
"'for writing DCC weights\n";
340 const char* comment =
sqlMode_ ?
"-- " :
"# ";
342 file << comment <<
"List of weights for amplitude estimation to be used in DCC for\n" 343 << comment <<
"zero suppresssion.\n\n";
345 file << comment <<
"Note: RU: trigger tower in EB, supercrystal in EE\n" 346 << comment <<
" xtl: crystal electronic channel id in RU, from 1 to 25\n\n" 347 << comment <<
" DetId SM FED RU xtl weights[0..5]...\n";
351 file <<
"variable recid number;\n" 352 "exec select COND2CONF_INFO_SQ.NextVal into :recid from DUAL;\n" 353 "insert into weights_info (rec_id,tag,version) values (:recid,'" 357 <<
"index of first sample used in the weighting sum\n" 362 " insert into dcc_weightsample_dat (rec_id, logic_id, sample_id, \n" 364 " values(:recid,fedid," 374 file <<
"\n" << comment <<
"list of weights per crystal channel\n";
391 file <<
"-- detId " <<
detId.rawId() <<
"\n" 392 <<
"insert into dcc_weights_dat(rec_id,sm_id,fed_id," 394 "weight_0,weight_1,weight_2,weight_3,weight_4,weight_5) \n" 401 file << delim << setw(2) << smId;
403 file << delim << setw(2) << ruId;
404 file << delim << setw(2) << xtalId;
406 for (
unsigned i = 0;
i <
weights.size(); ++
i) {
414 throw cms::Exception(
"Output") <<
"Error while writing DCC weights to '" <<
fName <<
"' file.";
420 if (
file.IsZombie()) {
421 throw cms::Exception(
"Output") <<
"Failed to open file '" <<
fName <<
"'for writing DCC weights\n";
423 TTree
t(
"dccWeights",
"Weights for DCC ZS filter");
424 const int nWeightMax = 20;
443 "weights[n_weights]/I");
446 buf.detId =
it->first.rawId();
447 buf.n_weights =
it->second.size();
452 if (
buf.n_weights > nWeightMax) {
453 throw cms::Exception(
"EcalDccWeight") <<
"Number of weights (" <<
buf.n_weights <<
") for DetId " <<
buf.detId
454 <<
" exceeded maximum limit (" << nWeightMax <<
") of root output format. ";
456 copy(
it->second.begin(),
it->second.end(),
buf.weights);
463 #ifndef DB_WRITE_SUPPORT 465 throw cms::Exception(
"DccWeight") <<
"Code was compiled without support for writing dcc weights directly " 466 " into configuration DB. Configurable writeToDB must be set to False. " 467 "sqlMode can be used to produce an SQL*PLUS script to fill the DB\n";
469 #else //DB_WRITE_SUPPORT defined 476 edm::LogVerbatim(
"EcalDccWeightBuilder") <<
"Making connection..." << flush;
487 }
catch (runtime_error&
e) {
497 econn->insertConfigSet(&weight_info);
499 int weight_id = weight_info.
getId();
500 edm::LogVerbatim(
"EcalDccWeightBuilder") <<
"WeightInfo inserted with ID " << weight_id;
502 vector<ODWeightsDat> datadel;
505 vector<ODWeightsSamplesDat> dcc1stSampleConfig(
nDccs);
507 dcc1stSampleConfig[
i].setId(weight_id);
508 dcc1stSampleConfig[
i].setFedId(601 +
i);
510 dcc1stSampleConfig[
i].setWeightNumber(-1);
512 econn->insertConfigDataArraySet(dcc1stSampleConfig, &weight_info);
517 const unsigned nWeights = 6;
520 for (
unsigned i = 0;
i <
weights.size(); ++
i) {
523 const vector<int>&
w =
it->second;
528 one_dat.
setId(weight_id);
550 datadel.push_back(one_dat);
552 econn->insertConfigDataArraySet(datadel, &weight_info);
555 edm::LogVerbatim(
"EcalDccWeightBuilder") <<
"closed DB connection ... done";
557 #endif //DB_WRITE_SUPPORT not defined 568 smId = 10000 -
fedId;
571 const int stripLength = 5;
572 xtalId = (elecId.
stripId() - 1) * stripLength + elecId.
xtalId();
575 edm::LogVerbatim(
"EcalDccWeightBuilder") << __FILE__ <<
":" << __LINE__ <<
": FED ID " 578 edm::LogVerbatim(
"EcalDccWeightBuilder") << __FILE__ <<
":" << __LINE__ <<
": SM logical ID " 581 edm::LogVerbatim(
"EcalDccWeightBuilder") << __FILE__ <<
":" << __LINE__ <<
": RU ID (TT or SC): " 584 edm::LogVerbatim(
"EcalDccWeightBuilder") << __FILE__ <<
":" << __LINE__ <<
": strip:" 587 edm::LogVerbatim(
"EcalDccWeightBuilder") << __FILE__ <<
":" << __LINE__ <<
": xtal in strip: " 588 << elecId.
xtalId() <<
"\n";
590 edm::LogVerbatim(
"EcalDccWeightBuilder") << __FILE__ <<
":" << __LINE__ <<
": xtalId in RU: "
Log< level::Info, true > LogVerbatim
void writeWeightToAsciiFile()
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
std::map< DetId, std::vector< int > > encodedWeights_
double decodeWeight(int W)
void analyze(const edm::Event &event, const edm::EventSetup &es) override
const edm::ESGetToken< EcalElectronicsMapping, EcalMappingRcd > mappingToken_
double intercalib(const DetId &detId)
void dbId(const DetId &detId, int &fedId, int &smId, int &ruId, int &xtalId) const
Ecal readout channel identification [32:20] Unused (so far) [19:13] DCC id [12:6] tower [5:3] strip [...
std::vector< double > inputWeights_
const CaloSimParameters & simParameters(const DetId &id) const override
return the sim parameters relative to the right subdet
int dccId() const
get the DCC (Ecal Local DCC value not global one) id
edm::ESHandle< CaloGeometry > geom_
static const double weightScale_
Log< level::Error, false > LogError
const edm::ESGetToken< EcalIntercalibConstants, EcalIntercalibConstantsRcd > intercalibConstToken_
void swap(Association< C > &lhs, Association< C > &rhs)
bool dccWeightsWithIntercalib_
void computeWeights(const EcalShapeBase &shape, int binOfMax, double timePhase, int iFirst0, int nWeights, int iSkip0, std::vector< double > &result)
void sort(const std::vector< T > &a, std::vector< int > &s, bool decreasingOrder=false)
std::string asciiOutputFileName_
double timePhase() const
the adjustment you need to apply to get the signal where you want it
int towerId() const
get the tower id
EcalIntercalibConstantMap & calibMap_
void writeWeightToRootFile()
void setCrystalId(int dac)
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
const_iterator find(uint32_t rawId) const
std::string rootOutputFileName_
const edm::ESGetToken< CaloGeometry, CaloGeometryRecord > geometryToken_
ALPAKA_FN_ACC ALPAKA_FN_INLINE uint32_t ix(uint32_t id)
std::vector< DetId > getValidDetIds() const
Get the list of all valid detector ids.
std::vector< Item >::const_iterator const_iterator
int stripId() const
get the tower id
void unbiasWeights(std::vector< double > &weights, std::vector< int32_t > *encodedWeigths)
EcalDccWeightBuilder(edm::ParameterSet const &ps)
int encodeWeight(double w)
int xtalId() const
get the channel id
void setConfigTag(std::string x)
EcalElectronicsId getElectronicsId(const DetId &id) const
Get the electronics id for this det id.
void computeAllWeights(bool withIntercalib, const edm::EventSetup &es)
static const double tzero[3]
ALPAKA_FN_ACC ALPAKA_FN_INLINE uint32_t iy(uint32_t id)
const self & getMap() const
const_iterator end() const
static const int ecalDccFedIdMax
const EcalElectronicsMapping * ecalElectronicsMap_
static const int ecalDccFedIdMin