1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
#ifndef _CSCCROSSTALKDBCONDITIONS_H
#define _CSCCROSSTALKDBCONDITIONS_H
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/ESProducer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/EventSetupRecordIntervalFinder.h"
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/Framework/interface/SourceFactory.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include <cmath>
#include <memory>
#include "CondFormats/CSCObjects/interface/CSCDBCrosstalk.h"
#include "CondFormats/DataRecord/interface/CSCDBCrosstalkRcd.h"
#include <DataFormats/MuonDetId/interface/CSCDetId.h>
class CSCCrosstalkDBConditions : public edm::ESProducer, public edm::EventSetupRecordIntervalFinder {
public:
CSCCrosstalkDBConditions(const edm::ParameterSet &);
~CSCCrosstalkDBConditions() override;
inline static CSCDBCrosstalk *prefillDBCrosstalk();
typedef std::unique_ptr<CSCDBCrosstalk> ReturnType;
ReturnType produceDBCrosstalk(const CSCDBCrosstalkRcd &);
private:
// ----------member data ---------------------------
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &,
const edm::IOVSyncValue &,
edm::ValidityInterval &) override;
};
#include <fstream>
#include <iostream>
#include <vector>
// to workaround plugin library
inline CSCDBCrosstalk *CSCCrosstalkDBConditions::prefillDBCrosstalk() {
// const int MAX_SIZE = 273024; //for ME1a unganged
const int MAX_SIZE = 252288;
const int SLOPE_FACTOR = 10000000;
const int INTERCEPT_FACTOR = 100000;
const int MAX_SHORT = 32767;
CSCDBCrosstalk *cndbcrosstalk = new CSCDBCrosstalk();
int db_index, new_index;
float db_slope_right, db_slope_left, db_intercept_right;
float db_intercept_left;
std::vector<int> db_index_id;
std::vector<float> db_slope_r;
std::vector<float> db_intercept_r;
std::vector<float> db_slope_l;
std::vector<float> db_intercept_l;
float new_slope_right, new_slope_left, new_intercept_right;
float new_intercept_left;
std::vector<int> new_index_id;
std::vector<float> new_slope_r;
std::vector<float> new_intercept_r;
std::vector<float> new_slope_l;
std::vector<float> new_intercept_l;
int counter;
std::ifstream dbdata;
dbdata.open("old_dbxtalk.dat", std::ios::in);
if (!dbdata) {
std::cerr << "Error: old_dbxtalk.dat -> no such file!" << std::endl;
exit(1);
}
while (!dbdata.eof()) {
dbdata >> db_index >> db_slope_right >> db_intercept_right >> db_slope_left >> db_intercept_left;
db_index_id.push_back(db_index);
db_slope_r.push_back(db_slope_right);
db_slope_l.push_back(db_slope_left);
db_intercept_r.push_back(db_intercept_right);
db_intercept_l.push_back(db_intercept_left);
}
dbdata.close();
std::ifstream newdata;
newdata.open("xtalk.dat", std::ios::in);
if (!newdata) {
std::cerr << "Error: xtalk.dat -> no such file!" << std::endl;
exit(1);
}
while (!newdata.eof()) {
newdata >> new_index >> new_slope_right >> new_intercept_right >> new_slope_left >> new_intercept_left;
new_index_id.push_back(new_index);
new_slope_r.push_back(new_slope_right);
new_slope_l.push_back(new_slope_left);
new_intercept_r.push_back(new_intercept_right);
new_intercept_l.push_back(new_intercept_left);
}
newdata.close();
CSCDBCrosstalk::CrosstalkContainer &itemvector = cndbcrosstalk->crosstalk;
itemvector.resize(MAX_SIZE);
cndbcrosstalk->factor_slope = int(SLOPE_FACTOR);
cndbcrosstalk->factor_intercept = int(INTERCEPT_FACTOR);
for (int i = 0; i < MAX_SIZE; ++i) {
itemvector[i].xtalk_slope_right = (short int)(db_slope_r[i] * SLOPE_FACTOR + 0.5);
itemvector[i].xtalk_intercept_right = (short int)(db_intercept_r[i] * INTERCEPT_FACTOR + 0.5);
itemvector[i].xtalk_slope_left = (short int)(db_slope_l[i] * SLOPE_FACTOR + 0.5);
itemvector[i].xtalk_intercept_left = (short int)(db_intercept_l[i] * INTERCEPT_FACTOR + 0.5);
}
for (int i = 0; i < MAX_SIZE; ++i) {
counter = db_index_id[i];
for (unsigned int k = 0; k < new_index_id.size() - 1; k++) {
if (counter == new_index_id[k]) {
if ((short int)(fabs(new_slope_r[k] * SLOPE_FACTOR + 0.5)) < MAX_SHORT)
itemvector[counter].xtalk_slope_right = int(new_slope_r[k] * SLOPE_FACTOR + 0.5);
if ((short int)(fabs(new_intercept_r[k] * INTERCEPT_FACTOR + 0.5)) < MAX_SHORT)
itemvector[counter].xtalk_intercept_right = int(new_intercept_r[k] * INTERCEPT_FACTOR + 0.5);
if ((short int)(fabs(new_slope_l[k] * SLOPE_FACTOR + 0.5)) < MAX_SHORT)
itemvector[counter].xtalk_slope_left = int(new_slope_l[k] * SLOPE_FACTOR + 0.5);
if ((short int)(fabs(new_intercept_l[k] * INTERCEPT_FACTOR + 0.5)) < MAX_SHORT)
itemvector[counter].xtalk_intercept_left = int(new_intercept_l[k] * INTERCEPT_FACTOR + 0.5);
itemvector[i] = itemvector[counter];
// std::cout<<" counter "<<counter <<" dbindex "<<new_index_id[k]<<"
// dbslope " <<db_slope_r[k]<<" new slope "<<new_slope_r[k]<<std::endl;
}
}
if (counter > 223968) {
itemvector[counter].xtalk_slope_right = int(db_slope_r[i]);
itemvector[counter].xtalk_slope_left = int(db_slope_l[i]);
itemvector[counter].xtalk_intercept_right = int(db_intercept_r[i]);
itemvector[counter].xtalk_intercept_left = int(db_intercept_l[i]);
}
}
return cndbcrosstalk;
}
#endif
|