test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
BuildElasticCorrectionsFile Class Reference
Inheritance diagram for BuildElasticCorrectionsFile:
edm::one::EDAnalyzer<> edm::one::EDAnalyzerBase edm::EDConsumerBase

Public Member Functions

 BuildElasticCorrectionsFile (const edm::ParameterSet &ps)
 
 ~BuildElasticCorrectionsFile ()
 
- Public Member Functions inherited from edm::one::EDAnalyzer<>
 EDAnalyzer ()=default
 
- Public Member Functions inherited from edm::one::EDAnalyzerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzerBase ()
 
ModuleDescription const & moduleDescription () const
 
virtual ~EDAnalyzerBase ()
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesDependentUpon (std::string const &iProcessName, std::string const &iModuleLabel, bool iPrint, std::vector< char const * > &oModuleLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Private Member Functions

virtual void analyze (const edm::Event &e, const edm::EventSetup &es)
 
virtual void beginRun (edm::Run const &, edm::EventSetup const &)
 
virtual void endJob ()
 
void ProcessOnePot (unsigned int id, double a, double b, double c, RPAlignmentCorrectionsData &corr, TotemRPGeometry const &geom)
 
void ProcessOneStation (unsigned int id, double N_a, double N_b, double N_c, double F_a, double F_b, double F_c, RPAlignmentCorrectionsData &corr, const TotemRPGeometry &geom)
 

Private Attributes

std::string inputFileName
 
std::string outputFileName
 

Additional Inherited Members

- Public Types inherited from edm::one::EDAnalyzerBase
typedef EDAnalyzerBase ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::one::EDAnalyzerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Definition at line 23 of file BuildElasticCorrectionsFile.cc.

Constructor & Destructor Documentation

BuildElasticCorrectionsFile::BuildElasticCorrectionsFile ( const edm::ParameterSet ps)

Definition at line 48 of file BuildElasticCorrectionsFile.cc.

48  :
49  inputFileName(ps.getParameter<string>("inputFileName")),
50  outputFileName(ps.getParameter<string>("outputFileName"))
51 {
52 }
T getParameter(std::string const &) const
BuildElasticCorrectionsFile::~BuildElasticCorrectionsFile ( )
inline

Definition at line 27 of file BuildElasticCorrectionsFile.cc.

27 {}

Member Function Documentation

virtual void BuildElasticCorrectionsFile::analyze ( const edm::Event e,
const edm::EventSetup es 
)
inlineprivatevirtual

Implements edm::one::EDAnalyzerBase.

Definition at line 33 of file BuildElasticCorrectionsFile.cc.

33 {}
void BuildElasticCorrectionsFile::beginRun ( edm::Run const &  ,
edm::EventSetup const &  es 
)
privatevirtual

Definition at line 56 of file BuildElasticCorrectionsFile.cc.

References funct::A, Clusterizer1DCommons::add(), create_public_lumi_plots::ax, EnergyCorrector::c, corr, KineDebug3::count(), ztail::d, TotemRPDetId::decToRawId(), Exception, relativeConstraints::geom, edm::EventSetup::get(), edm::ParameterSet::getParameterSet(), RPAlignmentCorrectionsData::GetSensorCorrection(), RPAlignmentCorrectionsData::GetSensorMap(), edm::ParameterSet::getUntrackedParameter(), customizeTrackingMonitorSeedNumber::idx, input, inputFileName, RPAlignmentCorrectionsDataSequence::Insert(), convertSQLitetoXML_cfg::output, outputFileName, ProcessOneStation(), edm::ESHandle< class >::product(), lumiContext::sequence, RPAlignmentCorrectionsData::SetSensorCorrection(), RPAlignmentCorrectionData::sh_r(), findQualityFiles::size, RPAlignmentCorrectionsMethods::WriteXMLFile(), RPAlignmentCorrectionsDataSequence::WriteXMLFile(), and z.

57 {
58  // get geometry (including pre-elastic alignments)
60  es.get<VeryForwardRealGeometryRecord>().get(geom);
61 
62  // open input file
63  FILE *inF = fopen(inputFileName.c_str(), "r");
64  if (!inF)
65  throw cms::Exception("BuildElasticCorrectionsFile") << "Can't open file `" << inputFileName << "'." << endl;
66 
67  // prepare output
69 
70  // process input data
71  while (!feof(inF)) {
72  unsigned long from, to;
73  float L_F_a, L_F_b, L_F_c;
74  float L_N_a, L_N_b, L_N_c;
75  float R_N_a, R_N_b, R_N_c;
76  float R_F_a, R_F_b, R_F_c;
77 
78  int count = fscanf(inF, "%lu,%lu,%E,%E,%E,%E,%E,%E,%E,%E,%E,%E,%E,%E", &from, &to,
79  &L_F_a, &L_F_b, &L_F_c, &L_N_a, &L_N_b, &L_N_c,
80  &R_N_a, &R_N_b, &R_N_c, &R_F_a, &R_F_b, &R_F_c);
81 
82  if (count >=0 && count != 14)
83  throw cms::Exception("BuildElasticCorrectionsFile") << "Only " << count << " numbers in a row." << endl;
84 
85  if (count != 14)
86  continue;
87 
89 
90  ProcessOneStation( 2, L_N_a*1E-3, L_N_b*1E-3, L_N_c*1E-3, L_F_a*1E-3, L_F_b*1E-3, L_F_c*1E-3, corr, *geom);
91  ProcessOneStation(12, R_N_a*1E-3, R_N_b*1E-3, R_N_c*1E-3, R_F_a*1E-3, R_F_b*1E-3, R_F_c*1E-3, corr, *geom);
92 
93  sequence.Insert(from, to, corr);
94  }
95 
96  fclose(inF);
97 
98  // save output
99  sequence.WriteXMLFile(outputFileName, false, false, false, true, false, true);
100 
101 #if 0
102  // get parameters
103  double z1 = ps.getUntrackedParameter<double>("z1");
104  double z2 = ps.getUntrackedParameter<double>("z2");
105  double de_x1 = ps.getUntrackedParameter<double>("de_x1");
106  double de_x2 = ps.getUntrackedParameter<double>("de_x2");
107  double de_y1 = ps.getUntrackedParameter<double>("de_y1");
108  double de_y2 = ps.getUntrackedParameter<double>("de_y2");
109  double de_rho1 = ps.getUntrackedParameter<double>("de_rho1");
110  double de_rho2 = ps.getUntrackedParameter<double>("de_rho2");
111 
112  // calculate slopes and intercepts
113  double a_x = (de_x2 - de_x1) / (z2 - z1), b_x = de_x1 - a_x * z1;
114  double a_y = (de_y2 - de_y1) / (z2 - z1), b_y = de_y1 - a_y * z1;
115  double a_rho = (de_rho2 - de_rho1) / (z2 - z1), b_rho = de_rho1 - a_rho * z1;
116 
117  if (z1 == z2)
118  throw cms::Exception("z1 equals z2");
119 
120  // prepare output - expand input to sensor level
122  for (RPAlignmentCorrectionsData::mapType::const_iterator it = input.GetSensorMap().begin();
123  it != input.GetSensorMap().end(); ++it) {
124  unsigned int rawId = TotemRPDetId::decToRawId(it->first);
125  CLHEP::Hep3Vector d = geom->LocalToGlobalDirection(rawId, CLHEP::Hep3Vector(0., 1., 0.));
126 
127  RPAlignmentCorrectionsData ac = input.GetFullSensorCorrection(it->first);
128  ac.XYTranslationToReadout(d.x(), d.y());
129  output.SetSensorCorrection(it->first, ac);
130  }
131 
132  // apply singular-mode change
133  printf("\tID shift in x shift in y rotation about z\n");
134  for (RPAlignmentCorrectionsData::mapType::const_iterator it = output.GetSensorMap().begin();
135  it != output.GetSensorMap().end(); ++it) {
136  unsigned int rawId = TotemRPDetId::decToRawId(it->first);
137  CLHEP::Hep3Vector d = geom->LocalToGlobalDirection(rawId, CLHEP::Hep3Vector(0., 1., 0.));
138  double dx = d.x(), dy = d.y();
139  CLHEP::Hep3Vector c = geom->GetDetTranslation(rawId);
140  double cx = c.x(), cy = c.y(), z = c.z();
141 
142  double de_x = a_x * z + b_x;
143  double de_y = a_y * z + b_y;
144  double de_rho = a_rho * z + b_rho;
145 
146  printf("\t%u %+10.1f um %+10.1f um %+10.1f mrad\n", it->first, de_x*1E3, de_y*1E3, de_rho*1E3);
147  //printf("\t\tcx=%e, cy=%E | dx=%E, dy=%E\n", cx, cy, dx, dy);
148 
149  double inc_s = +(dx*de_x + dy*de_y) - de_rho * (-dy*(cx + de_x) + dx*(cy + de_y));
150  double inc_rho = de_rho;
151  //printf("\t\t %E, %E\n", inc_s, inc_rho);
152 
153  RPAlignmentCorrectionsData &ac = output.GetSensorCorrection(it->first);
154  ac.SetTranslationR(ac.sh_r() + inc_s, ac.sh_r_e());
155  ac.SetRotationZ(ac.rot_z() + inc_rho, ac.rot_z_e());
156  ac.ReadoutTranslationToXY(dx, dy);
157  }
158 
159  // factorize alignments and write output
160  vector<unsigned int> rps;
161  unsigned int last_rp = 123456;
162  for (RPAlignmentCorrectionsData::mapType::const_iterator it = input.GetSensorMap().begin();
163  it != input.GetSensorMap().end(); ++it) {
164  unsigned int rp = it->first/10;
165  if (last_rp != rp) {
166  rps.push_back(rp);
167  last_rp = rp;
168  }
169  }
170  AlignmentGeometry alGeom;
171  AlignmentTask::BuildGeometry(rps, geom.product(), 0., alGeom);
172  RPAlignmentCorrectionsData expanded, factored;
173  output.FactorRPFromSensorCorrections(expanded, factored, alGeom);
174  RPAlignmentCorrectionsMethods.WriteXMLFile(factored, ps.getUntrackedParameter<string>("outputFile"));
175 
176 
177  // constants
178  double z0 = ps.getUntrackedParameter("z0", 0.);
179 
180 
181  // transverse shifts
182  const ParameterSet &ps_shift_xy = ps.getParameterSet("shift_xy");
183  bool perform = ps_shift_xy.getUntrackedParameter<bool>("perform");
184  if (perform) {
185  // process user input
186  bool add = ps_shift_xy.getUntrackedParameter<bool>("add");
187 
188  double z_x1 = ps_shift_xy.getUntrackedParameter<double>("z_x1");
189  double z_x2 = ps_shift_xy.getUntrackedParameter<double>("z_x2");
190  double z_y1 = ps_shift_xy.getUntrackedParameter<double>("z_y1");
191  double z_y2 = ps_shift_xy.getUntrackedParameter<double>("z_y2");
192  double v_x1 = ps_shift_xy.getUntrackedParameter<double>("v_x1");
193  double v_x2 = ps_shift_xy.getUntrackedParameter<double>("v_x2");
194  double v_y1 = ps_shift_xy.getUntrackedParameter<double>("v_y1");
195  double v_y2 = ps_shift_xy.getUntrackedParameter<double>("v_y2");
196 
197  double ax = (v_x2 - v_x1) / (z_x2 - z_x1);
198  double ay = (v_y2 - v_y1) / (z_y2 - z_y1);
199  double bx = v_x1 - ax*z_x1;
200  double by = v_y1 - ay*z_y1;
201 
202  // determine the current coefficients to the singular modes
203  unsigned int size = output.GetSensorMap().size();
204  TMatrixD A(size, 4);
205  TVectorD M(size);
206  unsigned idx = 0;
207  for (RPAlignmentCorrectionsData::mapType::const_iterator it = output.GetSensorMap().begin();
208  it != output.GetSensorMap().end(); ++it) {
209  unsigned int rawId = TotemRPDetId::decToRawId(it->first);
210 
211  CLHEP::Hep3Vector d = geom->LocalToGlobalDirection(rawId, CLHEP::Hep3Vector(0., 1., 0.));
212  DDTranslation c = geom->GetDetector(rawId)->translation();
213  double z = c.z() - z0;
214 
215  RPAlignmentCorrectionData &ac = output.GetSensorCorrection(it->first);
216  double sh_r = ac.sh_r();
217 
218  A(idx, 0) = d.x()*z;
219  A(idx, 1) = d.x();
220  A(idx, 2) = d.y()*z;
221  A(idx, 3) = d.y();
222  M(idx) = sh_r;
223  idx++;
224  }
225 
226 
227 #endif
228 }
T getUntrackedParameter(std::string const &, T const &) const
Time sequence of alignment corrections.
void Insert(edm::TimeValue_t first, edm::TimeValue_t last, const RPAlignmentCorrectionsData &corr)
inserts a set of corrections with validity interval [first, last]
const mapType & GetSensorMap() const
returns the map of sensor alignment corrections
void add(const std::vector< const T * > &source, std::vector< const T * > &dest)
void ProcessOneStation(unsigned int id, double N_a, double N_b, double N_c, double F_a, double F_b, double F_c, RPAlignmentCorrectionsData &corr, const TotemRPGeometry &geom)
Event setup record containing the real (actual) geometry information.
static std::string const input
Definition: EdmProvDump.cc:44
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
tuple d
Definition: ztail.py:151
void SetSensorCorrection(unsigned int id, const RPAlignmentCorrectionData &ac)
sets the alignment correction for the given sensor
Alignment correction or result of alignment procedure for a single RP sensor. Within the geometry des...
RPAlignmentCorrectionData & GetSensorCorrection(unsigned int id)
returns the correction value from the sensor map
void WriteXMLFile(const std::string &fileName, bool precise=false, bool wrErrors=true, bool wrSh_r=true, bool wrSh_xy=true, bool wrSh_z=true, bool wrRot_z=true) const
saves data to an alignment file
JetCorrectorParameters corr
Definition: classes.h:5
static void WriteXMLFile(const RPAlignmentCorrectionsData &, const std::string &fileName, bool precise=false, bool wrErrors=true, bool wrSh_r=true, bool wrSh_xy=true, bool wrSh_z=true, bool wrRot_z=true)
writes corrections into a single XML file
ParameterSet const & getParameterSet(std::string const &) const
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
T const * product() const
Definition: ESHandle.h:86
Container for RP alignment corrections. The corrections are stored on two levels - RP and sensor...
tuple size
Write out results.
static unsigned int decToRawId(unsigned int dec)
fast conversion Decimal to Raw ID
Definition: TotemRPDetId.h:129
virtual void BuildElasticCorrectionsFile::endJob ( void  )
inlineprivatevirtual

Reimplemented from edm::one::EDAnalyzerBase.

Definition at line 34 of file BuildElasticCorrectionsFile.cc.

34 {}
void BuildElasticCorrectionsFile::ProcessOnePot ( unsigned int  id,
double  a,
double  b,
double  c,
RPAlignmentCorrectionsData corr,
TotemRPGeometry const &  geom 
)
private

Definition at line 247 of file BuildElasticCorrectionsFile.cc.

References a, b, EnergyCorrector::c, funct::cos(), TotemRPDetId::decToRawId(), TotemRPGeometry::GetDetTranslation(), i, RPAlignmentCorrectionsData::SetSensorCorrection(), and funct::sin().

Referenced by ProcessOneStation().

249 {
250  // distances in mm, angles in rad
251 
252  for (unsigned int i = 0; i < 10; i++) {
253  unsigned int symId = rpId*10 + i;
254  unsigned int rawId = TotemRPDetId::decToRawId(symId);
255  CLHEP::Hep3Vector dc = geom.GetDetTranslation(rawId);
256 
257  double de_x = (cos(a) - 1.) * dc.x() - sin(a) * dc.y();
258  double de_y = sin(a) * dc.x() + (cos(a) - 1.) * dc.y();
259 
260  double sh_x = de_x - b;
261  double sh_y = de_y - c;
262  double rot_z = a;
263 
264  corr.SetSensorCorrection(symId, RPAlignmentCorrectionData(sh_x, sh_y, 0., rot_z));
265  }
266 }
int i
Definition: DBlmapReader.cc:9
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
void SetSensorCorrection(unsigned int id, const RPAlignmentCorrectionData &ac)
sets the alignment correction for the given sensor
Alignment correction or result of alignment procedure for a single RP sensor. Within the geometry des...
double b
Definition: hdecay.h:120
double a
Definition: hdecay.h:121
static unsigned int decToRawId(unsigned int dec)
fast conversion Decimal to Raw ID
Definition: TotemRPDetId.h:129
void BuildElasticCorrectionsFile::ProcessOneStation ( unsigned int  id,
double  N_a,
double  N_b,
double  N_c,
double  F_a,
double  F_b,
double  F_c,
RPAlignmentCorrectionsData corr,
const TotemRPGeometry geom 
)
private

Definition at line 232 of file BuildElasticCorrectionsFile.cc.

References ProcessOnePot().

Referenced by beginRun().

234 {
235 
236  ProcessOnePot(id*10 + 0, N_a, N_b, N_c, corr, geom);
237  ProcessOnePot(id*10 + 1, N_a, N_b, N_c, corr, geom);
238 
239  // TODO: horizontals
240 
241  ProcessOnePot(id*10 + 4, F_a, F_b, F_c, corr, geom);
242  ProcessOnePot(id*10 + 5, F_a, F_b, F_c, corr, geom);
243 }
void ProcessOnePot(unsigned int id, double a, double b, double c, RPAlignmentCorrectionsData &corr, TotemRPGeometry const &geom)

Member Data Documentation

std::string BuildElasticCorrectionsFile::inputFileName
private

Definition at line 30 of file BuildElasticCorrectionsFile.cc.

Referenced by beginRun().

std::string BuildElasticCorrectionsFile::outputFileName
private

Definition at line 30 of file BuildElasticCorrectionsFile.cc.

Referenced by beginRun().