8 #define DB_WRITE_SUPPORT 30 #ifdef DB_WRITE_SUPPORT 33 #endif //DB_WRITE_SUPPORT defined 45 : dcc1stSample_(ps.getParameter<
int>(
"dcc1stSample")),
46 sampleToSkip_(ps.getParameter<
int>(
"sampleToSkip")),
47 nDccWeights_(ps.getParameter<
int>(
"nDccWeights")),
48 inputWeights_(ps.getParameter<vector<double> >(
"inputWeights")),
49 mode_(ps.getParameter<
string>(
"mode")),
50 dccWeightsWithIntercalib_(ps.getParameter<
bool>(
"dccWeightsWithIntercalib")),
51 writeToDB_(ps.getParameter<
bool>(
"writeToDB")),
52 writeToAsciiFile_(ps.getParameter<
bool>(
"writeToAsciiFile")),
53 writeToRootFile_(ps.getParameter<
bool>(
"writeToRootFile")),
54 asciiOutputFileName_(ps.getParameter<
string>(
"asciiOutputFileName")),
55 rootOutputFileName_(ps.getParameter<
string>(
"rootOutputFileName")),
56 dbSid_(ps.getParameter<
string>(
"dbSid")),
57 dbUser_(ps.getParameter<
string>(
"dbUser")),
58 dbPassword_(ps.getUntrackedParameter<
string>(
"dbPassword",
"")),
59 dbTag_(ps.getParameter<
string>(
"dbTag")),
60 dbVersion_(ps.getParameter<
int>(
"dbVersion")),
61 sqlMode_(ps.getParameter<
bool>(
"sqlMode")),
62 calibMap_(emptyCalibMap_) {
63 if (
mode_ ==
"weightsFromConfig") {
66 throw cms::Exception(
"Config") <<
"Inconsistent configuration. 'nDccWeights' parameters indicated " 67 <<
nDccWeights_ <<
" weights while parameter 'inputWeights_' contains " 70 }
else if (
mode_ ==
"computeWeights") {
74 <<
"Valid values are: 'weightsFromConfig' and 'computeWeights'\n";
121 vector<DetId> detIds(ebDetIds.size() + eeDetIds.size());
122 copy(ebDetIds.begin(), ebDetIds.end(), detIds.begin());
123 copy(eeDetIds.begin(), eeDetIds.end(), detIds.begin() + ebDetIds.size());
125 vector<double> baseWeights(nw);
126 vector<double>
w(nw);
135 for (vector<DetId>::const_iterator it = detIds.begin(); it != detIds.end(); ++it) {
141 cout << __FILE__ <<
":" << __LINE__ <<
": ";
143 cout <<
"ieta = " << setw(4) << ((
EBDetId)(*it)).ieta()
144 <<
" iphi = " << setw(4) << ((
EBDetId)(*it)).iphi() <<
" ";
146 cout <<
"ix = " << setw(3) << ((
EEDetId)(*it)).ix()
147 <<
" iy = " << setw(3) << ((
EEDetId)(*it)).iy()
148 <<
" iz = " << setw(1) << ((
EEDetId)(*it)).iy() <<
" ";
151 <<
"Bug found in " << __FILE__ <<
":" << __LINE__ <<
": " 152 <<
"Got a detId which is neither tagged as ECAL Barrel " 153 <<
"not ECAL endcap while looping on ECAL cell detIds\n";
155 cout <<
" -> phase: " << phase <<
"\n";
156 cout <<
" -> binOfMax: " << binOfMax <<
"\n";
160 bool useDBShape =
true;
170 throw cms::Exception(
"EcalDccWeightBuilder") <<
"Bug found in " << __FILE__ <<
":" << __LINE__ <<
": " 171 <<
"Got a detId which is neither tagged as ECAL Barrel " 172 <<
"not ECAL endcap while looping on ECAL cell detIds\n";
175 if (phase != prevPhase) {
183 for (
int i = 0;
i < nw; ++
i) {
184 w[
i] = baseWeights[
i];
191 cout << __FILE__ <<
":" << __LINE__ <<
": ";
193 cout <<
"ieta = " << setw(4) << ((
EBDetId)(*it)).ieta() <<
" iphi = " << setw(4) << ((
EBDetId)(*it)).iphi()
196 cout <<
"ix = " << setw(3) << ((
EEDetId)(*it)).ix() <<
" iy = " << setw(3) << ((
EEDetId)(*it)).iy()
197 <<
" iz = " << setw(1) << ((
EEDetId)(*it)).iy() <<
" ";
199 cout <<
"DetId " << (uint32_t)(*it);
201 cout <<
"phase: " << phase <<
"\n";
216 result.resize(nWeights);
218 int nActualWeights = 0;
220 const double tzero = -(binOfMax - 1) * 25 + timePhase + shape.
timeToRise();
222 for (
int i = 0;
i < nWeights; ++
i) {
223 double t_ns = tzero + (iFirst +
i) * 25;
224 double s = shape(t_ns);
233 for (
int i = 0;
i < nWeights; ++
i) {
237 result[
i] = (result[
i] - sum / nActualWeights) / (sum2 - sum * sum / nActualWeights);
257 bool changed =
false;
259 for (
unsigned i = 0;
i < a.size(); ++
i)
265 for (
unsigned i = 0;
i < a.size() - 1; ++
i) {
267 const int nextj = s[
i + 1];
268 if ((decreasingOrder && (a[j] < a[nextj])) || (!decreasingOrder && (a[j] > a[nextj]))) {
284 const unsigned nw = weights.size();
287 vector<double> dw(nw);
290 for (
unsigned i = 0;
i < nw; ++
i) {
314 int wsumSign = wsum > 0 ? 1 : -1;
315 int i = wsum > 0 ? 0 : (nw - 1);
317 W[iw[
i]] -= wsumSign;
320 if (i < 0 || i >= (
int)nw) {
322 for (
unsigned i = 0; i < nw; ++
i) {
342 if (encodedWeights !=
nullptr)
343 encodedWeights->resize(nw);
344 for (
unsigned i = 0; i < nw; ++
i) {
347 (*encodedWeights)[
i] = W[
i];
359 std::cout << (uint32_t)detId <<
" not found in EcalIntercalibConstantMap" << std::endl;
362 cout << __FILE__ <<
":" << __LINE__ <<
": ";
365 <<
" iphi = " << ((
EBDetId)detId).iphi();
368 <<
" iy = " << ((
EEDetId)detId).iy()
369 <<
" iz = " << ((
EEDetId)detId).zside();
371 cout <<
" coef = " << coef <<
"\n";
378 ofstream
file(fName.c_str());
380 throw cms::Exception(
"Output") <<
"Failed to open file '" << fName <<
"'for writing DCC weights\n";
385 file << comment <<
"List of weights for amplitude estimation to be used in DCC for\n" 386 << comment <<
"zero suppresssion.\n\n";
388 file << comment <<
"Note: RU: trigger tower in EB, supercrystal in EE\n" 389 << comment <<
" xtl: crystal electronic channel id in RU, from 1 to 25\n\n" 390 << comment <<
" DetId SM FED RU xtl weights[0..5]...\n";
394 file <<
"variable recid number;\n" 395 "exec select COND2CONF_INFO_SQ.NextVal into :recid from DUAL;\n" 396 "insert into weights_info (rec_id,tag,version) values (:recid,'" 400 <<
"index of first sample used in the weighting sum\n" 405 " insert into dcc_weightsample_dat (rec_id, logic_id, sample_id, \n" 407 " values(:recid,fedid," 417 file <<
"\n" << comment <<
"list of weights per crystal channel\n";
421 const DetId& detId = it->first;
429 dbId(detId, fedId, smId, ruId, xtalId);
434 file <<
"-- detId " << detId.
rawId() <<
"\n" 435 <<
"insert into dcc_weights_dat(rec_id,sm_id,fed_id," 437 "weight_0,weight_1,weight_2,weight_3,weight_4,weight_5) \n" 441 const vector<int>&
weights = it->second;
444 file << delim << setw(2) << smId;
446 file << delim << setw(2) << ruId;
447 file << delim << setw(2) << xtalId;
449 for (
unsigned i = 0;
i < weights.size(); ++
i) {
450 file << delim << setw(5) << weights[
i];
457 throw cms::Exception(
"Output") <<
"Error while writing DCC weights to '" << fName <<
"' file.";
462 TFile
file(fName.c_str(),
"RECREATE");
463 if (
file.IsZombie()) {
464 throw cms::Exception(
"Output") <<
"Failed to open file '" << fName <<
"'for writing DCC weights\n";
466 TTree
t(
"dccWeights",
"Weights for DCC ZS filter");
467 const int nWeightMax = 20;
486 "weights[n_weights]/I");
489 buf.detId = it->first.rawId();
490 buf.n_weights = it->second.size();
493 dbId(buf.detId, buf.fedId, buf.smId, buf.ruId, buf.xtalId);
495 if (buf.n_weights > nWeightMax) {
496 throw cms::Exception(
"EcalDccWeight") <<
"Number of weights (" << buf.n_weights <<
") for DetId " << buf.detId
497 <<
" exceeded maximum limit (" << nWeightMax <<
") of root output format. ";
499 copy(it->second.begin(), it->second.end(), buf.weights);
506 #ifndef DB_WRITE_SUPPORT 508 throw cms::Exception(
"DccWeight") <<
"Code was compiled without support for writing dcc weights directly " 509 " into configuration DB. Configurable writeToDB must be set to False. " 510 "sqlMode can be used to produce an SQL*PLUS script to fill the DB\n";
512 #else //DB_WRITE_SUPPORT defined 514 cout <<
"going to write to the online DB " <<
dbSid_ <<
" user " <<
dbUser_ << endl;
519 cout <<
"Making connection..." << flush;
520 const string& filePrefix =
string(
"file:");
532 cout <<
"Done." << endl;
533 }
catch (runtime_error&
e) {
534 cerr << e.what() << endl;
541 cout <<
"Inserting in DB..." << endl;
545 int weight_id = weight_info.
getId();
546 cout <<
"WeightInfo inserted with ID " << weight_id << endl;
548 vector<ODWeightsDat> datadel;
551 vector<ODWeightsSamplesDat> dcc1stSampleConfig(
nDccs);
553 dcc1stSampleConfig[
i].setId(weight_id);
554 dcc1stSampleConfig[
i].setFedId(601 +
i);
556 dcc1stSampleConfig[
i].setWeightNumber(-1);
562 const DetId& detId = it->first;
563 const unsigned nWeights = 6;
566 for (
unsigned i = 0;
i < weights.size(); ++
i) {
569 const vector<int>&
w = it->second;
570 weights[
i] =
i < w.size() ? w[
i] : 0;
574 one_dat.
setId(weight_id);
582 dbId(detId, fedId, smId, ruId, xtalId);
596 datadel.push_back(one_dat);
599 std::cout <<
" .. done insertion in DB " << endl;
601 cout <<
"closed DB connection ... done" << endl;
603 #endif //DB_WRITE_SUPPORT not defined 608 fedId = 600 + elecId.
dccId();
614 smId = 10000 -
fedId;
617 const int stripLength = 5;
618 xtalId = (elecId.
stripId() - 1) * stripLength + elecId.
xtalId();
621 cout << __FILE__ <<
":" << __LINE__ <<
": FED ID " 624 cout << __FILE__ <<
":" << __LINE__ <<
": SM logical ID " 627 cout << __FILE__ <<
":" << __LINE__ <<
": RU ID (TT or SC): " 630 cout << __FILE__ <<
":" << __LINE__ <<
": strip:" 633 cout << __FILE__ <<
":" << __LINE__ <<
": xtal in strip: " 634 << elecId.
xtalId() <<
"\n";
636 cout << __FILE__ <<
":" << __LINE__ <<
": xtalId in RU: "
void writeWeightToAsciiFile()
int xtalId() const
get the channel id
std::map< DetId, std::vector< int > > encodedWeights_
double decodeWeight(int W)
void analyze(const edm::Event &event, const edm::EventSetup &es) override
int stripId() const
get the tower id
const self & getMap() const
double intercalib(const DetId &detId)
Ecal readout channel identification [32:20] Unused (so far) [19:13] DCC id [12:6] tower [5:3] strip [...
std::vector< double > inputWeights_
constexpr uint32_t rawId() const
get the raw id
edm::ESHandle< CaloGeometry > geom_
static const double weightScale_
void dbId(const DetId &detId, int &fedId, int &smId, int &ruId, int &xtalId) const
int towerId() const
get the tower id
bool dccWeightsWithIntercalib_
void computeWeights(const EcalShapeBase &shape, int binOfMax, double timePhase, int iFirst0, int nWeights, int iSkip0, std::vector< double > &result)
double timePhase() const
the adjustment you need to apply to get the signal where you want it
void sort(const std::vector< T > &a, std::vector< int > &s, bool decreasingOrder=false)
EcalElectronicsId getElectronicsId(const DetId &id) const
Get the electronics id for this det id.
std::string asciiOutputFileName_
void insertConfigDataArraySet(const std::vector< DATT > &data, ICONF *iconf) noexcept(false)
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
EcalIntercalibConstantMap & calibMap_
void writeWeightToRootFile()
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
void insertConfigSet(ICONF *iconf) noexcept(false)
const CaloSimParameters & simParameters(const DetId &id) const override
return the sim parameters relative to the right subdet
void setCrystalId(int dac)
int dccId() const
get the DCC (Ecal Local DCC value not global one) id
std::string rootOutputFileName_
void readPassword(const std::string &fileName, const std::string &user, std::string &password)
std::vector< Item >::const_iterator const_iterator
void unbiasWeights(std::vector< double > &weights, std::vector< int32_t > *encodedWeigths)
EcalDccWeightBuilder(edm::ParameterSet const &ps)
std::vector< DetId > getValidDetIds() const
Get the list of all valid detector ids.
int encodeWeight(double w)
void setConfigTag(std::string x)
void computeAllWeights(bool withIntercalib, const edm::EventSetup &es)
const_iterator find(uint32_t rawId) const
static const double tzero[3]
const_iterator end() const
static const int ecalDccFedIdMax
T const * product() const
const EcalElectronicsMapping * ecalElectronicsMap_
static const int ecalDccFedIdMin
double timeToRise() const override