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";
182 <<
"Bug found in " << __FILE__ <<
":" << __LINE__ <<
": "
183 <<
"Got a detId which is neither tagged as ECAL Barrel "
184 <<
"not ECAL endcap while looping on ECAL cell detIds\n";
187 if(phase!=prevPhase){
197 for(
int i = 0;
i < nw; ++
i){
198 w[
i] = baseWeights[
i];
204 cout << __FILE__ <<
":" << __LINE__ <<
": ";
206 cout <<
"ieta = " << setw(4) << ((
EBDetId)(*it)).ieta()
207 <<
" iphi = " << setw(4) << ((
EBDetId)(*it)).iphi() <<
" ";
209 cout <<
"ix = " << setw(3) << ((
EEDetId)(*it)).ix()
210 <<
" iy = " << setw(3) << ((
EEDetId)(*it)).iy()
211 <<
" iz = " << setw(1) << ((
EEDetId)(*it)).iy() <<
" ";
213 cout <<
"DetId " << (uint32_t) (*it);
215 cout <<
"phase: " << phase <<
"\n";
226 int nWeights,
int iSkip,
230 result.resize(nWeights);
232 int nActualWeights = 0;
236 for(
int i=0;
i<nWeights; ++
i){
237 double t_ns = tzero+(iFirst+
i)*25;
238 double s = shape(t_ns);
247 for(
int i=0;
i<nWeights; ++
i){
251 result[
i] = (result[
i]-sum/nActualWeights)/(sum2-sum*sum/nActualWeights);
268 bool decreasingOrder){
278 bool changed =
false;
280 for(
unsigned i=0;
i<a.size(); ++
i) s[
i] =
i;
281 if(a.size() == 0)
return;
284 for(
unsigned i = 0;
i < a.size()-1; ++
i){
286 const int nextj = s[
i+1];
287 if((decreasingOrder && (a[j] < a[nextj]))
288 || (!decreasingOrder && (a[
j] > a[nextj]))){
304 std::vector<int>* encodedWeights){
305 const unsigned nw = weights.size();
308 vector<double> dw(nw);
311 for(
unsigned i = 0;
i < nw; ++
i){
335 int wsumSign = wsum>0?1:-1;
336 int i = wsum>0?0:(nw-1);
338 W[iw[
i]] -= wsumSign;
341 if(i<0 || i>=(
int)nw){
343 for(
unsigned i = 0; i < nw; ++
i){
349 if(i>=(
int)nw) i = 0;
361 if(encodedWeights!=0) encodedWeights->resize(nw);
362 for(
unsigned i = 0; i < nw; ++
i){
364 if(encodedWeights) (*encodedWeights)[
i] = W[
i];
378 <<
" not found in EcalIntercalibConstantMap"<<std::endl ;
381 cout << __FILE__ <<
":" << __LINE__ <<
": ";
384 <<
" iphi = " << ((
EBDetId)detId).iphi();
387 <<
" iy = " << ((
EEDetId)detId).iy()
388 <<
" iz = " << ((
EEDetId)detId).zside();
390 cout <<
" coef = " << coef <<
"\n";
399 ofstream
file(fName.c_str());
402 <<
"Failed to open file '"
404 <<
"'for writing DCC weights\n";
409 file << comment <<
"List of weights for amplitude estimation to be used in DCC for\n"
410 << comment <<
"zero suppresssion.\n\n";
412 file << comment <<
"Note: RU: trigger tower in EB, supercrystal in EE\n"
413 << comment <<
" xtl: crystal electronic channel id in RU, from 1 to 25\n\n"
414 << comment <<
" DetId SM FED RU xtl weights[0..5]...\n";
418 file <<
"variable recid number;\n"
419 "exec select COND2CONF_INFO_SQ.NextVal into :recid from DUAL;\n"
420 "insert into weights_info (rec_id,tag,version) values (:recid,'"
422 file <<
"\n" << comment
423 <<
"index of first sample used in the weighting sum\n"
427 " insert into dcc_weightsample_dat (rec_id, logic_id, sample_id, \n"
437 file <<
"\n" << comment <<
"list of weights per crystal channel\n";
439 for(
map<
DetId, std::vector<int32_t> >::const_iterator it
443 const DetId& detId = it->first;
451 dbId(detId, fedId, smId, ruId, xtalId);
456 <<
"insert into dcc_weights_dat(rec_id,sm_id,fed_id,"
458 "weight_0,weight_1,weight_2,weight_3,weight_4,weight_5) \n"
462 const vector<int>&
weights = it->second;
464 file << delim << setw(2) << smId;
465 file << delim << setw(3) << fedId;
466 file << delim << setw(2) << ruId;
467 file << delim << setw(2) << xtalId;
469 for(
unsigned i=0;
i<weights.size(); ++
i){
470 file << delim << setw(5) << weights[
i];
476 throw cms::Exception(
"Output") <<
"Error while writing DCC weights to '"
477 << fName <<
"' file.";
484 TFile
file(fName.c_str(),
"RECREATE");
487 <<
"Failed to open file '"
489 <<
"'for writing DCC weights\n";
491 TTree
t(
"dccWeights",
"Weights for DCC ZS filter");
492 const int nWeightMax = 20;
503 t.Branch(
"weights", &buf,
510 "weights[n_weights]/I");
511 for(
map<
DetId, std::vector<int32_t> >::const_iterator it
515 buf.detId = it->first.rawId();
516 buf.n_weights = it->second.size();
519 dbId(buf.detId, buf.fedId, buf.smId, buf.ruId, buf.xtalId);
521 if(buf.n_weights>nWeightMax){
523 <<
"Number of weights (" << buf.n_weights
524 <<
") for DetId " << buf.detId
525 <<
" exceeded maximum limit (" << nWeightMax
526 <<
") of root output format. ";
528 copy(it->second.begin(), it->second.end(), buf.weights);
535 #ifndef DB_WRITE_SUPPORT
538 <<
"Code was compiled without support for writing dcc weights directly "
539 " into configuration DB. Configurable writeToDB must be set to False. "
540 "sqlMode can be used to produce an SQL*PLUS script to fill the DB\n";
542 #else //DB_WRITE_SUPPORT defined
548 cout <<
"Making connection..." << flush;
561 cout <<
"Done." << endl;
562 }
catch (runtime_error &
e) {
563 cerr << e.what() << endl;
570 cout <<
"Inserting in DB..." << endl;
574 int weight_id=weight_info.
getId();
575 cout <<
"WeightInfo inserted with ID "<< weight_id<< endl;
577 vector<ODWeightsDat> datadel;
580 vector<ODWeightsSamplesDat> dcc1stSampleConfig(
nDccs);
582 dcc1stSampleConfig[
i].setId(weight_id);
583 dcc1stSampleConfig[
i].setFedId(601+
i);
585 dcc1stSampleConfig[
i].setWeightNumber(-1);
589 for(
map<
DetId, std::vector<int32_t> >::const_iterator it
593 const DetId& detId = it->first;
594 const unsigned nWeights = 6;
597 for(
unsigned i=0;
i<weights.size(); ++
i){
600 const vector<int>&
w = it->second;
601 weights[
i] =
i<w.size()?w[
i]:0;
605 one_dat.
setId(weight_id);
613 dbId(detId, fedId, smId, ruId, xtalId);
627 datadel.push_back(one_dat);
630 std::cout<<
" .. done insertion in DB "<< endl;
632 cout<<
"closed DB connection ... done" << endl;
634 #endif //DB_WRITE_SUPPORT not defined
643 fedId = 600 + elecId.
dccId();
652 const int stripLength = 5;
656 cout << __FILE__ <<
":" << __LINE__ <<
": FED ID "
659 cout << __FILE__ <<
":" << __LINE__ <<
": SM logical ID "
662 cout << __FILE__ <<
":" << __LINE__ <<
": RU ID (TT or SC): "
665 cout << __FILE__ <<
":" << __LINE__ <<
": strip:"
668 cout << __FILE__ <<
":" << __LINE__ <<
": xtal in strip: "
669 << elecId.
xtalId() <<
"\n";
671 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)
virtual const CaloSimParameters & simParameters(const DetId &id) const
return the sim parameters relative to the right subdet
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 [...
void insertConfigSet(ICONF *iconf)
std::vector< double > inputWeights_
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)
uint32_t rawId() const
get the raw id
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 swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
EcalIntercalibConstantMap & calibMap_
void writeWeightToRootFile()
void setCrystalId(int dac)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
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
T const * product() const
void unbiasWeights(std::vector< double > &weights, std::vector< int32_t > *encodedWeigths)
EcalDccWeightBuilder(edm::ParameterSet const &ps)
int encodeWeight(double w)
void setConfigTag(std::string x)
void analyze(const edm::Event &event, const edm::EventSetup &es)
const_iterator find(uint32_t rawId) const
static const double tzero[3]
void insertConfigDataArraySet(const std::vector< DATT > &data, ICONF *iconf)
const_iterator end() const
static const int ecalDccFedIdMax
void computeAllWeights(bool withIntercalib)
virtual double timeToRise() const
const EcalElectronicsMapping * ecalElectronicsMap_
static const int ecalDccFedIdMin