8 #define DB_WRITE_SUPPORT 30 #ifdef DB_WRITE_SUPPORT 33 #endif //DB_WRITE_SUPPORT defined 46 dcc1stSample_(ps.getParameter<
int>(
"dcc1stSample")),
47 sampleToSkip_(ps.getParameter<
int>(
"sampleToSkip")),
48 nDccWeights_(ps.getParameter<
int>(
"nDccWeights")),
49 inputWeights_(ps.getParameter<vector<double> >(
"inputWeights")),
50 mode_(ps.getParameter<
string>(
"mode")),
51 dccWeightsWithIntercalib_(ps.getParameter<
bool>(
"dccWeightsWithIntercalib")),
52 writeToDB_(ps.getParameter<
bool>(
"writeToDB")),
53 writeToAsciiFile_(ps.getParameter<
bool>(
"writeToAsciiFile")),
54 writeToRootFile_(ps.getParameter<
bool>(
"writeToRootFile")),
55 asciiOutputFileName_(ps.getParameter<
string>(
"asciiOutputFileName")),
56 rootOutputFileName_(ps.getParameter<
string>(
"rootOutputFileName")),
57 dbSid_(ps.getParameter<
string>(
"dbSid")),
58 dbUser_(ps.getParameter<
string>(
"dbUser")),
59 dbPassword_(ps.getUntrackedParameter<
string>(
"dbPassword",
"")),
60 dbTag_(ps.getParameter<
string>(
"dbTag")),
61 dbVersion_(ps.getParameter<
int>(
"dbVersion")),
62 sqlMode_(ps.getParameter<
bool>(
"sqlMode")),
63 calibMap_(emptyCalibMap_)
65 if(
mode_==
"weightsFromConfig"){
69 <<
"Inconsistent configuration. 'nDccWeights' parameters indicated " 70 <<
nDccWeights_ <<
" weights while parameter 'inputWeights_' contains " 73 }
else if(
mode_==
"computeWeights"){
77 <<
"Invalid value ('" <<
mode_ <<
"') for parameter mode. " 78 <<
"Valid values are: 'weightsFromConfig' and 'computeWeights'\n";
117 const vector<DetId>& ebDetIds
123 const vector<DetId>& eeDetIds
130 vector<DetId> detIds(ebDetIds.size()+eeDetIds.size());
131 copy(ebDetIds.begin(), ebDetIds.end(), detIds.begin());
132 copy(eeDetIds.begin(), eeDetIds.end(), detIds.begin()+ebDetIds.size());
134 vector<double> baseWeights(nw);
135 vector<double>
w(nw);
145 for(vector<DetId>::const_iterator it = detIds.begin();
146 it != detIds.end(); ++it){
153 cout << __FILE__ <<
":" << __LINE__ <<
": ";
155 cout <<
"ieta = " << setw(4) << ((
EBDetId)(*it)).ieta()
156 <<
" iphi = " << setw(4) << ((
EBDetId)(*it)).iphi() <<
" ";
158 cout <<
"ix = " << setw(3) << ((
EEDetId)(*it)).ix()
159 <<
" iy = " << setw(3) << ((
EEDetId)(*it)).iy()
160 <<
" iz = " << setw(1) << ((
EEDetId)(*it)).iy() <<
" ";
163 <<
"Bug found in " << __FILE__ <<
":" << __LINE__ <<
": " 164 <<
"Got a detId which is neither tagged as ECAL Barrel " 165 <<
"not ECAL endcap while looping on ECAL cell detIds\n";
167 cout <<
" -> phase: " << phase <<
"\n";
168 cout <<
" -> binOfMax: " << binOfMax <<
"\n";
172 bool useDBShape =
true;
183 <<
"Bug found in " << __FILE__ <<
":" << __LINE__ <<
": " 184 <<
"Got a detId which is neither tagged as ECAL Barrel " 185 <<
"not ECAL endcap while looping on ECAL cell detIds\n";
188 if(phase!=prevPhase){
198 for(
int i = 0;
i < nw; ++
i){
199 w[
i] = baseWeights[
i];
205 cout << __FILE__ <<
":" << __LINE__ <<
": ";
207 cout <<
"ieta = " << setw(4) << ((
EBDetId)(*it)).ieta()
208 <<
" iphi = " << setw(4) << ((
EBDetId)(*it)).iphi() <<
" ";
210 cout <<
"ix = " << setw(3) << ((
EEDetId)(*it)).ix()
211 <<
" iy = " << setw(3) << ((
EEDetId)(*it)).iy()
212 <<
" iz = " << setw(1) << ((
EEDetId)(*it)).iy() <<
" ";
214 cout <<
"DetId " << (uint32_t) (*it);
216 cout <<
"phase: " << phase <<
"\n";
227 int nWeights,
int iSkip,
231 result.resize(nWeights);
233 int nActualWeights = 0;
237 for(
int i=0;
i<nWeights; ++
i){
238 double t_ns = tzero+(iFirst+
i)*25;
239 double s = shape(t_ns);
248 for(
int i=0;
i<nWeights; ++
i){
252 result[
i] = (result[
i]-sum/nActualWeights)/(sum2-sum*sum/nActualWeights);
269 bool decreasingOrder){
279 bool changed =
false;
281 for(
unsigned i=0;
i<a.size(); ++
i) s[
i] =
i;
282 if(a.empty())
return;
285 for(
unsigned i = 0;
i < a.size()-1; ++
i){
287 const int nextj = s[
i+1];
288 if((decreasingOrder && (a[j] < a[nextj]))
289 || (!decreasingOrder && (a[j] > a[nextj]))){
305 std::vector<int>* encodedWeights){
306 const unsigned nw = weights.size();
309 vector<double> dw(nw);
312 for(
unsigned i = 0;
i < nw; ++
i){
336 int wsumSign = wsum>0?1:-1;
337 int i = wsum>0?0:(nw-1);
339 W[iw[
i]] -= wsumSign;
342 if(i<0 || i>=(
int)nw){
344 for(
unsigned i = 0; i < nw; ++
i){
350 if(i>=(
int)nw) i = 0;
362 if(encodedWeights!=
nullptr) encodedWeights->resize(nw);
363 for(
unsigned i = 0; i < nw; ++
i){
365 if(encodedWeights) (*encodedWeights)[
i] = W[
i];
379 <<
" not found in EcalIntercalibConstantMap"<<std::endl ;
382 cout << __FILE__ <<
":" << __LINE__ <<
": ";
385 <<
" iphi = " << ((
EBDetId)detId).iphi();
388 <<
" iy = " << ((
EEDetId)detId).iy()
389 <<
" iz = " << ((
EEDetId)detId).zside();
391 cout <<
" coef = " << coef <<
"\n";
400 ofstream
file(fName.c_str());
403 <<
"Failed to open file '" 405 <<
"'for writing DCC weights\n";
410 file << comment <<
"List of weights for amplitude estimation to be used in DCC for\n" 411 << comment <<
"zero suppresssion.\n\n";
413 file << comment <<
"Note: RU: trigger tower in EB, supercrystal in EE\n" 414 << comment <<
" xtl: crystal electronic channel id in RU, from 1 to 25\n\n" 415 << comment <<
" DetId SM FED RU xtl weights[0..5]...\n";
419 file <<
"variable recid number;\n" 420 "exec select COND2CONF_INFO_SQ.NextVal into :recid from DUAL;\n" 421 "insert into weights_info (rec_id,tag,version) values (:recid,'" 423 file <<
"\n" << comment
424 <<
"index of first sample used in the weighting sum\n" 428 " insert into dcc_weightsample_dat (rec_id, logic_id, sample_id, \n" 438 file <<
"\n" << comment <<
"list of weights per crystal channel\n";
440 for(
map<
DetId, std::vector<int32_t> >::const_iterator it
444 const DetId& detId = it->first;
452 dbId(detId, fedId, smId, ruId, xtalId);
457 <<
"insert into dcc_weights_dat(rec_id,sm_id,fed_id," 459 "weight_0,weight_1,weight_2,weight_3,weight_4,weight_5) \n" 463 const vector<int>&
weights = it->second;
465 file << delim << setw(2) << smId;
467 file << delim << setw(2) << ruId;
468 file << delim << setw(2) << xtalId;
470 for(
unsigned i=0;
i<weights.size(); ++
i){
471 file << delim << setw(5) << weights[
i];
477 throw cms::Exception(
"Output") <<
"Error while writing DCC weights to '" 478 << fName <<
"' file.";
485 TFile
file(fName.c_str(),
"RECREATE");
488 <<
"Failed to open file '" 490 <<
"'for writing DCC weights\n";
492 TTree
t(
"dccWeights",
"Weights for DCC ZS filter");
493 const int nWeightMax = 20;
504 t.Branch(
"weights", &buf,
511 "weights[n_weights]/I");
512 for(
map<
DetId, std::vector<int32_t> >::const_iterator it
516 buf.detId = it->first.rawId();
517 buf.n_weights = it->second.size();
520 dbId(buf.detId, buf.fedId, buf.smId, buf.ruId, buf.xtalId);
522 if(buf.n_weights>nWeightMax){
524 <<
"Number of weights (" << buf.n_weights
525 <<
") for DetId " << buf.detId
526 <<
" exceeded maximum limit (" << nWeightMax
527 <<
") of root output format. ";
529 copy(it->second.begin(), it->second.end(), buf.weights);
536 #ifndef DB_WRITE_SUPPORT 539 <<
"Code was compiled without support for writing dcc weights directly " 540 " into configuration DB. Configurable writeToDB must be set to False. " 541 "sqlMode can be used to produce an SQL*PLUS script to fill the DB\n";
543 #else //DB_WRITE_SUPPORT defined 549 cout <<
"Making connection..." << flush;
550 const string& filePrefix =
string(
"file:");
562 cout <<
"Done." << endl;
563 }
catch (runtime_error &
e) {
564 cerr << e.what() << endl;
571 cout <<
"Inserting in DB..." << endl;
575 int weight_id=weight_info.
getId();
576 cout <<
"WeightInfo inserted with ID "<< weight_id<< endl;
578 vector<ODWeightsDat> datadel;
581 vector<ODWeightsSamplesDat> dcc1stSampleConfig(
nDccs);
583 dcc1stSampleConfig[
i].setId(weight_id);
584 dcc1stSampleConfig[
i].setFedId(601+
i);
586 dcc1stSampleConfig[
i].setWeightNumber(-1);
590 for(
map<
DetId, std::vector<int32_t> >::const_iterator it
594 const DetId& detId = it->first;
595 const unsigned nWeights = 6;
598 for(
unsigned i=0;
i<weights.size(); ++
i){
601 const vector<int>&
w = it->second;
602 weights[
i] =
i<w.size()?w[
i]:0;
606 one_dat.
setId(weight_id);
614 dbId(detId, fedId, smId, ruId, xtalId);
628 datadel.push_back(one_dat);
631 std::cout<<
" .. done insertion in DB "<< endl;
633 cout<<
"closed DB connection ... done" << endl;
635 #endif //DB_WRITE_SUPPORT not defined 644 fedId = 600 + elecId.
dccId();
653 const int stripLength = 5;
657 cout << __FILE__ <<
":" << __LINE__ <<
": FED ID " 660 cout << __FILE__ <<
":" << __LINE__ <<
": SM logical ID " 663 cout << __FILE__ <<
":" << __LINE__ <<
": RU ID (TT or SC): " 666 cout << __FILE__ <<
":" << __LINE__ <<
": strip:" 669 cout << __FILE__ <<
":" << __LINE__ <<
": xtal in strip: " 670 << elecId.
xtalId() <<
"\n";
672 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