CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
UETableProducer.cc
Go to the documentation of this file.
1 // system include files
2 #include <iostream>
3 #include <fstream>
4 #include <vector>
5 #include <string>
6 #include <algorithm>
7 
8 // user include files
11 
17 
19 
23 
24 // For DB entry using JetCorrector to store the vector of float
26 
28 
29 
30 using namespace std;
31 //
32 // class decleration
33 //
34 
36 public:
37  explicit UETableProducer(const edm::ParameterSet&);
38  ~UETableProducer();
39 
40 private:
41  virtual void beginRun(const edm::EventSetup&) ;
42  virtual void analyze(const edm::Event&, const edm::EventSetup&);
43  virtual void endJob() ;
44 
45  // ----------member data ---------------------------
46 
47  bool debug_;
49 
51  unsigned int runnum_;
52 
53  unsigned int index = 0,
54  np[5],
55  ni0[2],
56  ni1[2],
57  ni2[2];
58 
59  // ue_interpolation_pf0[15][344],
60  // ue_interpolation_pf1[15][344],
61  // ue_interpolation_pf2[15][82];
62 
63 };
64 
65 //
66 // constants, enums and typedefs
67 //
68 
69 //
70 // static data member definitions
71 //
72 
73 //
74 // constructors and destructor
75 //
77  runnum_(0)
78 {
79  //now do what ever initialization is needed
80  calibrationFile_ = iConfig.getParameter<std::string>("txtFile");
81  //calibrationFile_ = "RecoHI/HiJetAlgos/data/ue_calibrations_pf_data.txt";
82 
83  debug_ = iConfig.getUntrackedParameter<bool>("debug",false);
84  jetCorrectorFormat_ = iConfig.getUntrackedParameter<bool>("jetCorrectorFormat",false);
85 
86  np[0] = 3;// Number of reduced PF ID (track, ECAL, HCAL)
87  np[1] = 15;// Number of pseudorapidity block
88  np[2] = 5;// Fourier series order
89  np[3] = 2;// Re or Im
90  np[4] = 82;// Number of feature parameter
91 
92  ni0[0] = np[1];
93  ni0[1] = 344;// Number of track binning (kept = ECAL)
94 
95  ni1[0] = np[1];
96  ni1[1] = 344;// Number of ECAL binning
97 
98  ni2[0] = np[1];
99  ni2[1] = 82;// Number of HCAL binning
100 
101 }
102 
104 {
105  // do anything here that needs to be done at desctruction time
106  // (e.g. close files, deallocate resources etc.)
107 }
108 
109 //
110 // member functions
111 //
112 
113 // ------------ method called to for each event ------------
114 void
116 {
117  // nothing
118 
119 }
120 
121 // ------------ method called once each job just before starting event loop ------------
122 void
124 {
125 }
126 
127 // ------------ method called once each job just after ending the event loop ------------
128 void
130  std::string qpDataName = calibrationFile_.c_str();
131  std::ifstream textTable_(qpDataName.c_str());
132 
133  std::vector<float> ue_vec;
134  UETable *ue_predictor_pf = NULL;
135 
136  if (!jetCorrectorFormat_) {
137  ue_predictor_pf = new UETable();
138  }
139  // unsigned int Nnp_full = np[0] * np[1] * np[2] * np[3] * np[4];
140  unsigned int Nnp = np[0] * np[1] * (1 + (np[2] - 1) * np[3]) * np[4];
141  unsigned int Nni0 = ni0[0]*ni0[1];
142  unsigned int Nni1 = ni1[0]*ni1[1];
143  unsigned int Nni2 = ni2[0]*ni2[1];
144 
145  if (!jetCorrectorFormat_) {
146  ue_predictor_pf->np.resize(5);
147  ue_predictor_pf->ni0.resize(2);
148  ue_predictor_pf->ni1.resize(2);
149  ue_predictor_pf->ni2.resize(2);
150 
151  std::copy(np, np + 5, ue_predictor_pf->np.begin());
152  std::copy(ni0, ni0 + 2, ue_predictor_pf->ni0.begin());
153  std::copy(ni1, ni1 + 2, ue_predictor_pf->ni1.begin());
154  std::copy(ni2, ni2 + 2, ue_predictor_pf->ni2.begin());
155 
156  static const float edge_pseudorapidity[16] = {
157  -5.191, -2.650, -2.043, -1.740, -1.479, -1.131, -0.783, -0.522, 0.522, 0.783, 1.131, 1.479, 1.740, 2.043, 2.650, 5.191
158  };
159 
160  ue_predictor_pf->edgeEta.resize(16);
161 
162  std::copy(edge_pseudorapidity, edge_pseudorapidity + 16, ue_predictor_pf->edgeEta.begin());
163 
164  }
165 
167 
168  while( std::getline( textTable_, line)){
169  if(!line.size() || line[0]=='#') {
170  std::cout<<" continue "<<std::endl;
171  continue;
172  }
173  std::istringstream linestream(line);
174  float val;
175  int bin0, bin1, bin2, bin3, bin4;
176  if(index < Nnp){
177  linestream>>bin0>>bin1>>bin2>>bin3>>bin4>>val;
178  ue_vec.push_back(val);
179  }else if(index < Nnp + Nni0){
180  linestream>>bin0>>bin1>>val;
181  ue_vec.push_back(val);
182  }else if(index < Nnp + Nni0 + Nni1){
183  linestream>>bin0>>bin1>>val;
184  ue_vec.push_back(val);
185  }else if(index < Nnp + Nni0 + Nni1 + Nni2){
186  linestream>>bin0>>bin1>>val;
187  ue_vec.push_back(val);
188  }
189  ++index;
190 
191  }
192 
194 
195  if( pool.isAvailable() ){
196 
197  if (jetCorrectorFormat_) {
198  // A minimal dummy line that satisfies the JME # token >= 6 requirement, and has the correct key type
199  JetCorrectorParameters::Definitions definition("1 0 0 0 Correction L1Offset");
200  std::vector<JetCorrectorParameters::Record> record(1, JetCorrectorParameters::Record(ue_vec.size(), std::vector<float>(ue_vec.size(), 0), std::vector<float>(ue_vec.size(), 0), ue_vec));
202 
204 
205  jme_payload->push_back(JetCorrectorParametersCollection::L1Offset, parameter);
206 
207  if( pool->isNewTagRequest( "JetCorrectionsRecord" ) ){
208  pool->createNewIOV<JetCorrectorParametersCollection>( jme_payload, pool->beginOfTime(), pool->endOfTime(), "JetCorrectionsRecord" );
209  }else{
210  pool->appendSinceTime<JetCorrectorParametersCollection>( jme_payload, pool->currentTime(), "JetCorrectionsRecord" );
211  }
212  }
213  else {
214  ue_predictor_pf->values = ue_vec;
215 
216  if( pool->isNewTagRequest( "HeavyIonUERcd" ) ){
217  pool->createNewIOV<UETable>( ue_predictor_pf, pool->beginOfTime(), pool->endOfTime(), "HeavyIonUERcd" );
218  }else{
219  pool->appendSinceTime<UETable>( ue_predictor_pf, pool->currentTime(), "HeavyIonUERcd" );
220  }
221  }
222  }
223 }
224 
225 
226 //define this as a plug-in
virtual void endJob()
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
virtual void analyze(const edm::Event &, const edm::EventSetup &)
JetCorrectorParameters::Record record
Definition: classes.h:7
void push_back(key_type i, value_type const &j, label_type const &flav="")
std::vector< unsigned int > ni2
Definition: UETable.h:29
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< unsigned int > np
Definition: UETable.h:26
#define NULL
Definition: scimark2.h:8
unsigned int ni2[2]
UETableProducer(const edm::ParameterSet &)
void appendSinceTime(T *payloadObj, cond::Time_t sinceTime, const std::string &recordName, bool withlogging=false)
int iEvent
Definition: GenABIO.cc:230
int np
Definition: AMPTWrapper.h:33
bool isNewTagRequest(const std::string &recordName)
std::vector< unsigned int > ni1
Definition: UETable.h:28
virtual void beginRun(const edm::EventSetup &)
unsigned int np[5]
bool isAvailable() const
Definition: Service.h:46
unsigned int ni1[2]
unsigned int runnum_
void createNewIOV(T *firstPayloadObj, cond::Time_t firstSinceTime, cond::Time_t firstTillTime, const std::string &recordName, bool withlogging=false)
std::vector< unsigned int > ni0
Definition: UETable.h:27
std::vector< float > values
Definition: UETable.h:25
std::vector< float > edgeEta
Definition: UETable.h:30
unsigned int index
tuple cout
Definition: gather_cfg.py:121
Definition: UETable.h:7
unsigned int ni0[2]