CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Attributes | Static Private Attributes
DeviationsFromFileSensor2D Class Reference

#include <DeviationsFromFileSensor2D.h>

Public Member Functions

 DeviationsFromFileSensor2D ()
 
std::pair< ALIdouble, ALIdoublegetDevis (ALIdouble intersX, ALIdouble intersY)
 
void readFile (ALIFileIn &ifdevi)
 
void setOffset (ALIdouble offX, ALIdouble offY)
 
 ~DeviationsFromFileSensor2D ()
 

Static Public Member Functions

static const ALIbool apply ()
 
static void setApply (ALIbool val)
 

Private Attributes

bool firstScanDir
 
vvd theDeviations
 
ALIuint theNPoints
 
ALIdouble theOffsetX
 
ALIdouble theOffsetY
 
int theScanSenseX
 
int theScanSenseY
 
ALIint verbose
 

Static Private Attributes

static ALIbool theApply = true
 

Detailed Description

Definition at line 24 of file DeviationsFromFileSensor2D.h.

Constructor & Destructor Documentation

DeviationsFromFileSensor2D::DeviationsFromFileSensor2D ( )
inline

Definition at line 29 of file DeviationsFromFileSensor2D.h.

References theOffsetX, and theOffsetY.

DeviationsFromFileSensor2D::~DeviationsFromFileSensor2D ( )
inline

Definition at line 33 of file DeviationsFromFileSensor2D.h.

References getDevis(), and readFile().

33 { };

Member Function Documentation

static const ALIbool DeviationsFromFileSensor2D::apply ( )
inlinestatic

Definition at line 48 of file DeviationsFromFileSensor2D.h.

References theApply.

Referenced by heavyIonTools.ConfigureHeavyIons::__call__(), editorTools.UserCodeTool::__call__(), HiCoreTools.RestrictInputToAOD::__call__(), coreTools.RunOnData::__call__(), trackTools.MakeAODTrackCandidates::__call__(), runJetUncertainties.RunJetUncertainties::__call__(), metTools.AddMETCollection::__call__(), heavyIonTools.ProductionDefaults::__call__(), editorTools.ChangeSource::__call__(), HiCoreTools.RemoveMCMatching::__call__(), cmsswVersionTools.PickRelValInputFiles::__call__(), coreTools.RemoveMCMatching::__call__(), trackTools.MakePATTrackCandidates::__call__(), trigTools.SwitchOnTrigger::__call__(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties::__call__(), heavyIonTools.SelectionDefaults::__call__(), HiCoreTools.RemoveAllPATObjectsBut::__call__(), heavyIonTools.DisbaleMonteCarloDeps::__call__(), HiCoreTools.RemoveSpecificPATObjects::__call__(), trigTools.SwitchOnTriggerStandAlone::__call__(), trackTools.MakeTrackCandidates::__call__(), tauTools.AddTauCollection::__call__(), trigTools.SwitchOnTriggerMatching::__call__(), HiCoreTools.RemoveCleaning::__call__(), HiCoreTools.AddCleaning::__call__(), trigTools.SwitchOnTriggerMatchingStandAlone::__call__(), trigTools.SwitchOnTriggerMatchEmbedding::__call__(), jetTools.AddJetCollection::__call__(), jetTools.SwitchJetCollection::__call__(), jetTools.UpdateJetCollection::__call__(), jetTools.AddJetID::__call__(), jetTools.SetTagInfos::__call__(), OptOSensor2D::detailedTraversesLightRay(), and OptOSensor2D::fastTraversesLightRay().

48  {
49  return theApply;
50  }
std::pair< ALIdouble, ALIdouble > DeviationsFromFileSensor2D::getDevis ( ALIdouble  intersX,
ALIdouble  intersY 
)

Definition at line 140 of file DeviationsFromFileSensor2D.cc.

References MessageLogger_cfi::cerr, gather_cfg::cout, MillePedeFileConverter_cfg::e, cmsRelvalreport::exit, cuy::ii, DeviationSensor2D::posX(), RecoTauValidation_cfi::posX, RecoTauValidation_cfi::posY, funct::pow(), mathSSE::sqrt(), theDeviations, theNPoints, theOffsetX, theOffsetY, theScanSenseX, and theScanSenseY.

Referenced by ~DeviationsFromFileSensor2D().

141 {
142  //intersX += 10000;
143  //intersY += 10000;
144  if(verbose >= 4) std::cout << " entering getdevis " << intersX << " " <<intersY << " " << this << std::endl;
145  vvd::iterator vvdite;
146  vd::iterator vdite;
147 
148  // assume scan is in Y first, else revers intersection coordinates
149 /* if( !firstScanDirY ) {
150  ALIdouble tt = intersY;
151  intersY = intersX;
152  intersX = tt;
153  }
154 */
155 
156  //---------- look which point in the deviation matrices correspond to intersX,Y
157  //----- Look for each column, between which rows intersY is
158  //assume first dir is Y
159  auto yrows = std::make_unique<unsigned int[]>(theNPoints);
160 
161  unsigned int ii = 0;
162  ALIbool insideMatrix = false;
163  for( vvdite = theDeviations.begin(); vvdite != (theDeviations.end()-1); ++vvdite ){
164  for( vdite = (*vvdite).begin(); vdite != ((*vvdite).end()-1); ++vdite ){
165  if( verbose >= 5 ) std::cout << " check posy " << (*(vdite))->posY() << " " << (*(vdite+1))->posY() << " " << (*(vdite)) << std::endl;
166  // if posy is between this point and previous one
167 
168  //- std::cout << "intersy" << intersY << " " << (*(vdite))->posY() << std::endl;
169 
170  if( (intersY - (*(vdite))->posY() )*theScanSenseY > 0
171  && (intersY - (*(vdite+1))->posY() )*theScanSenseY < 0 ) {
172  //-std::cout << " ii " << ii << std::endl;
173  yrows[ii] = vdite - (*vvdite).begin();
174  if( verbose >= 3 ) std::cout << intersY << " DeviationsFromFileSensor2D yrows " << ii << " " << yrows[ii] << " : " << (*(vdite))->posY() << std::endl;
175  insideMatrix = true;
176  break;
177  }
178  }
179  ii++;
180  }
181  if(insideMatrix == 0) {
182  std::cerr << "!!EXITING intersection in Y outside matrix of deviations from file " << intersY << std::endl;
183  exit(1);
184  }
185  insideMatrix = false;
186 
187  vd thePoints;
188  thePoints.clear();
189  //----- For each row in 'yrows' look between which columns intersX is
190  unsigned int rn;
191  DeviationSensor2D *dev1,*dev2;
192  for( ii = 0; ii < theNPoints-1; ii++) {
193  rn = yrows[ii];
194  //- std::cout << ii << " rn " << rn << std::endl;
195  dev1 = (*(theDeviations.begin()+ii))[ rn ]; // column ii, row yrows[ii]
196  rn = yrows[ii+1];
197  dev2 = (*(theDeviations.begin()+ii+1))[ rn ]; // column ii+1, row yrows[ii+1]
198  if( (intersX - dev1->posX() )*theScanSenseX > 0
199  && (intersX - dev2->posX() )*theScanSenseX < 0) {
200  thePoints.push_back( dev1 );
201  thePoints.push_back( dev2 );
202  insideMatrix = true;
203  if( verbose >= 3 ) std::cout << " column up " << ii << " " << dev1->posX() << " " << dev2->posX() << " : " << intersX << std::endl;
204  }
205 
206  rn = yrows[ii] + 1;
207  if(rn == theNPoints) rn = theNPoints-1;
208  dev1 = (*(theDeviations.begin()+ii))[ rn ]; // column ii, row yrows[ii]+1
209  rn = yrows[ii+1] + 1;
210  if(rn == theNPoints) rn = theNPoints-1;
211  dev2 = (*(theDeviations.begin()+ii+1))[ rn ]; // column ii+1, row yrows[ii+1]+1
212  if( (intersX - dev1->posX() )*theScanSenseX > 0
213  && (intersX - dev2->posX() )*theScanSenseX < 0) {
214  thePoints.push_back( dev1 );
215  thePoints.push_back( dev2 );
216  if( verbose >= 3 ) std::cout << " column down " << ii << " " << dev1->posX() << " " << dev2->posX() << " : " << intersX << std::endl;
217  }
218 
219  if( thePoints.size() == 4 ) break;
220 
221  }
222 
223  if(insideMatrix == 0) {
224  std::cerr << "!!EXITING intersection in X outside matrix of deviations from file " << intersX << std::endl;
225  exit(1);
226  }
227 
228  //----------- If loop finished and not 4 points, point is outside scan bounds
229 
230  //----- calculate deviation in x and y interpolating between four points
231  ALIdouble dist, disttot=0, deviX=0, deviY=0;
232 
233  if( verbose >= 4) std::cout << " thepoints size " << thePoints.size() << std::endl;
234 
235  for( ii = 0; ii < 4; ii++) {
236  dist = sqrt( pow(thePoints[ii]->posX() - intersX, 2 ) + pow(thePoints[ii]->posY() - intersY, 2 ) );
237  disttot += 1./dist;
238  deviX += thePoints[ii]->devX()/dist;
239  deviY += thePoints[ii]->devY()/dist;
240  if( verbose >= 4 ) {
241  //t std::cout << ii << " point " << *thePoints[ii] << std::endl;
242  std::cout << ii << " distances: " << dist << " " << deviX << " " << deviY << " devX " << thePoints[ii]->devX() << " devY " << thePoints[ii]->devY() << std::endl;
243  }
244  }
245  deviX /= disttot;
246  deviY /= disttot;
247 
248  // add offset
249  deviX += theOffsetX;
250  deviY += theOffsetY;
251  if( verbose >= 4 ) {
252  std::cout << " devisX/Y: " << deviX << " " << deviY
253  << " intersX/Y " << intersX << " " << intersY << std::endl;
254  }
255 
256  //change sign!!!!!?!?!?!?!?!
257  deviX *= -1;
258  deviY *= -1;
259  return std::pair< ALIdouble, ALIdouble>( deviX*1.e-6, deviY*1e-6 ); // matrix is in microrad
260 
261 }
long double ALIdouble
Definition: CocoaGlobals.h:11
bool ALIbool
Definition: CocoaGlobals.h:19
std::vector< DeviationSensor2D * > vd
T sqrt(T t)
Definition: SSEVec.h:18
ii
Definition: cuy.py:590
const ALIdouble & posX()
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
void DeviationsFromFileSensor2D::readFile ( ALIFileIn ifdevi)

Definition at line 21 of file DeviationsFromFileSensor2D.cc.

References funct::abs(), MessageLogger_cfi::cerr, gather_cfg::cout, ALIUtils::debug, ALIUtils::dumpVS(), ALIFileIn::eof(), cmsRelvalreport::exit, DeviationSensor2D::fillData(), firstScanDir, ALIFileIn::getWordsInLine(), ALIFileIn::name(), DeviationSensor2D::posX(), DeviationSensor2D::posY(), mathSSE::sqrt(), theDeviations, theNPoints, theScanSenseX, theScanSenseY, xdir, and ydir.

Referenced by Vispa.Plugins.EventBrowser.EventBrowserTabController.EventBrowserTabController::navigate(), Vispa.Main.TabController.TabController::open(), Vispa.Main.TabController.TabController::refresh(), and ~DeviationsFromFileSensor2D().

22 {
24  // verbose = 4;
25  if( verbose >= 3) std::cout << "DeviationsFromFileSensor2D::readFile " << this << ifdevi.name() << std::endl;
26 
27  theScanSenseX = 0;
28  theScanSenseY = 0;
29 
30  ALIuint nl = 1;
31 
32  ALIdouble oldposX=0, oldposY=0;
33  vd vcol;
34  std::vector<ALIstring> wl;
35  /* //------ first line with dimension factors //now with global option
36  ifdevi.getWordsInLine( wl );
37  if( wl[0] != "DIMFACTOR:" || wl.size() != 3) {
38  std::cerr << "Error reading sensor2D deviation file " << ifdevi.name() << std::endl
39  << " first line has to be DIMFACTOR: 'posDimFactor' 'angDimFactor' " << std::endl;
40  ALIUtils::dumpVS( wl, " ");
41  exit(1);
42  }
43  ALIdouble posDimFactor = atof(wl[1].c_str());
44  ALIdouble angDimFactor = atof(wl[2].c_str());
45  */
46 
47  for(;;) {
48  ifdevi.getWordsInLine( wl );
49  if(ifdevi.eof() ) break;
50 
52  dev->fillData( wl );
53 
54  if(verbose >= 5) {
55  ALIUtils::dumpVS( wl, "deviation sensor2D", std::cout );
56  }
57 
58  //--- line 2 of data
59  if(nl == 2) {
60  //--------- get if scan is first in Y or X
62  if(verbose >= 3) std::cout << "firstScanDir " << firstScanDir << " " << dev->posX() << " " << oldposX << " " << dev->posY() << " " << oldposY << std::endl;
63  if( std::abs( dev->posX() - oldposX ) > std::abs( dev->posY() - oldposY ) ) {
64  std::cerr << "!!!EXITING first scan direction has to be Y for the moment " << ifdevi.name() << std::endl;
66  exit(1);
67  }
68  //-------- get sense of first scan direction
69  if(firstScanDir == ydir ){
70  if( dev->posY() > oldposY ) {
71  theScanSenseY = +1;
72  } else {
73  theScanSenseY = -1;
74  }
75  if( verbose >= 3 ) std::cout << " theScanSenseY " << theScanSenseY << std::endl;
76  }else {
77  if( dev->posX() > oldposX ) {
78  theScanSenseX = +1;
79  } else {
80  theScanSenseX = -1;
81  }
82  if( verbose >= 3 ) std::cout << " theScanSenseX " << theScanSenseX << std::endl;
83  }
84  }
85 
86  //- std::cout << "firstScanDir " << firstScanDir << " " << dev->posX() << " " << oldposX << " " << dev->posY() << " " << oldposY << std::endl;
87 
88  //------- check if change of row: clear current std::vector of column values
89  if( ( firstScanDir == ydir && ( dev->posY() - oldposY)*theScanSenseY < 0 )
90  || ( firstScanDir == xdir && ( dev->posX() - oldposX)*theScanSenseX < 0 )) {
91  theDeviations.push_back( vcol );
92  vcol.clear();
93 
94  //- std::cout << " theDevi size " << theDeviations.size() << " " << ifdevi.name() << std::endl;
95  //-------- get sense of second scan direction
96  if( theScanSenseY == 0 ) {
97  if( dev->posY() > oldposY ) {
98  theScanSenseY = +1;
99  } else {
100  theScanSenseY = -1;
101  }
102  }
103  if( theScanSenseX == 0 ) {
104  if( dev->posX() > oldposX ) {
105  theScanSenseX = +1;
106  } else {
107  theScanSenseX = -1;
108  }
109  }
110  if( verbose >= 3 ) std::cout << " theScanSenseX " << theScanSenseX << " theScanSenseY " << theScanSenseY << std::endl;
111  }
112 
113  oldposX = dev->posX();
114  oldposY = dev->posY();
115 
116  //--- fill deviation std::vectors
117  vcol.push_back( dev );
118  nl++;
119  }
120  theDeviations.push_back( vcol );
121 
122  //----- Calculate std::vector size
123  ALIdouble dvsiz = ( sqrt( ALIdouble(nl-1) ) );
124  //----- Check that it is a square of points (<=> vsiz is integer)
125  ALIuint vsiz = ALIuint(dvsiz);
126  if( vsiz != dvsiz ) {
127  if( ALIUtils::debug >= 0) std::cerr << "!!WARNING: error reading deviation file: number of X points <> number of Y points : Number of points in X " << dvsiz << " nl " << nl-1 << " file " << ifdevi.name() << std::endl;
128  // exit(1);
129  }
130  theNPoints = vsiz;
131 
132  if(verbose >= 4 ) {
133  std::cout << " Filling deviation from file: " << ifdevi.name() << " theNPoints " << theNPoints << std::endl;
134  }
135 
136 }
long double ALIdouble
Definition: CocoaGlobals.h:11
ALIbool eof()
Definition: ALIFileIn.cc:211
const ALIstring & name()
Definition: ALIFileIn.h:44
static ALIint debug
Definition: ALIUtils.h:36
std::vector< DeviationSensor2D * > vd
T sqrt(T t)
Definition: SSEVec.h:18
const ALIdouble & posY()
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ALIint getWordsInLine(std::vector< ALIstring > &wl)
Definition: ALIFileIn.cc:83
const ALIdouble & posX()
void fillData(const std::vector< ALIstring > &wl)
static void dumpVS(const std::vector< ALIstring > &wl, const std::string &msg, std::ostream &outs=std::cout)
dumps a vector of strings with a message to outs
Definition: ALIUtils.cc:501
unsigned int ALIuint
Definition: CocoaGlobals.h:17
static void DeviationsFromFileSensor2D::setApply ( ALIbool  val)
inlinestatic
void DeviationsFromFileSensor2D::setOffset ( ALIdouble  offX,
ALIdouble  offY 
)
inline

Definition at line 42 of file DeviationsFromFileSensor2D.h.

References theOffsetX, and theOffsetY.

42  {
43  theOffsetX = offX;
44  theOffsetY = offY;
45  }

Member Data Documentation

bool DeviationsFromFileSensor2D::firstScanDir
private

Definition at line 59 of file DeviationsFromFileSensor2D.h.

Referenced by readFile().

ALIbool DeviationsFromFileSensor2D::theApply = true
staticprivate

Definition at line 64 of file DeviationsFromFileSensor2D.h.

Referenced by apply(), and setApply().

vvd DeviationsFromFileSensor2D::theDeviations
private

Definition at line 63 of file DeviationsFromFileSensor2D.h.

Referenced by getDevis(), and readFile().

ALIuint DeviationsFromFileSensor2D::theNPoints
private

Definition at line 62 of file DeviationsFromFileSensor2D.h.

Referenced by getDevis(), and readFile().

ALIdouble DeviationsFromFileSensor2D::theOffsetX
private

Definition at line 68 of file DeviationsFromFileSensor2D.h.

Referenced by DeviationsFromFileSensor2D(), getDevis(), and setOffset().

ALIdouble DeviationsFromFileSensor2D::theOffsetY
private

Definition at line 68 of file DeviationsFromFileSensor2D.h.

Referenced by DeviationsFromFileSensor2D(), getDevis(), and setOffset().

int DeviationsFromFileSensor2D::theScanSenseX
private

Definition at line 60 of file DeviationsFromFileSensor2D.h.

Referenced by getDevis(), and readFile().

int DeviationsFromFileSensor2D::theScanSenseY
private

Definition at line 60 of file DeviationsFromFileSensor2D.h.

Referenced by getDevis(), and readFile().

ALIint DeviationsFromFileSensor2D::verbose
private