00001 #include "FastSimulation/CaloGeometryTools/interface/CrystalPad.h"
00002
00003 #include <iostream>
00004
00005 std::vector<CLHEP::Hep2Vector> CrystalPad::aVector(4);
00006
00007
00008 CrystalPad::CrystalPad(const CrystalPad& right)
00009 {
00010 corners_ = right.corners_;
00011 dir_ = right.dir_;
00012 number_ = right.number_;
00013 survivalProbability_ = right.survivalProbability_;
00014 center_ = right.center_;
00015 epsilon_ = right.epsilon_;
00016 dummy_ = right.dummy_;
00017 }
00018
00019 CrystalPad&
00020 CrystalPad::operator = (const CrystalPad& right ) {
00021 if (this != &right) {
00022 corners_ = right.corners_;
00023 dir_ = right.dir_;
00024 number_ = right.number_;
00025 survivalProbability_ = right.survivalProbability_;
00026 center_ = right.center_;
00027 epsilon_ = right.epsilon_;
00028 dummy_ = right.dummy_;
00029 }
00030 return *this;
00031 }
00032
00033 CrystalPad::CrystalPad(unsigned number,
00034 const std::vector<CLHEP::Hep2Vector>& corners)
00035 :
00036 corners_(corners),
00037 dir_(aVector),
00038 number_(number),
00039 survivalProbability_(1.),
00040 center_(0.,0.),
00041 epsilon_(0.001)
00042 {
00043
00044
00045 if(corners.size()!=4)
00046 {
00047 std::cout << " Try to construct a quadrilateral with " << corners.size() << " points ! " << std::endl;
00048 dummy_=true;
00049 }
00050 else
00051 {
00052 dummy_=false;
00053
00054 for(unsigned ic=0; ic<4;++ic)
00055 {
00056 dir_[ic] = (corners[(ic+1)%4]-corners[ic]).unit();
00057 center_+=corners_[ic];
00058 }
00059 center_*=0.25;
00060 }
00061
00062
00063
00064 }
00065
00066 CrystalPad::CrystalPad(unsigned number, int onEcal,
00067 const std::vector<XYZPoint>& corners,
00068 const XYZPoint& origin,
00069 const XYZVector& vec1,
00070 const XYZVector& vec2)
00071 :
00072 corners_(aVector),
00073 dir_(aVector),
00074 number_(number),
00075 survivalProbability_(1.),
00076 center_(0.,0.),
00077 epsilon_(0.001)
00078 {
00079
00080
00081 if(corners.size()!=4)
00082 {
00083 std::cout << " Try to construct a quadrilateral with " << corners.size() << " points ! " << std::endl;
00084 dummy_=true;
00085 }
00086 else
00087 {
00088 dummy_=false;
00089 double sign=(onEcal==1) ? -1.: 1.;
00090
00091
00092 trans_=Transform3D((Point)origin,
00093 (Point)(origin+vec1),
00094 (Point)(origin+vec2),
00095 Point(0.,0.,0.),
00096 Point(0.,0.,sign),
00097 Point(0.,1.,0.));
00098 trans_.GetDecomposition(rotation_,translation_);
00099
00100 for(unsigned ic=0;ic<4;++ic)
00101 {
00102
00103 XYZPoint corner = rotation_(corners[ic])+translation_;
00104
00105 corners_[ic] = CLHEP::Hep2Vector(corner.X(),corner.Y());
00106 center_+=corners_[ic];
00107 }
00108 for(unsigned ic=0;ic<4;++ic)
00109 {
00110 dir_[ic] = (corners_[(ic+1)%4]-corners_[ic]).unit();
00111 }
00112 center_*=0.25;
00113 }
00114
00115
00116
00117
00118
00119
00120 }
00121 CrystalPad::CrystalPad(unsigned number,
00122 const std::vector<XYZPoint>& corners,
00123 const Transform3D & trans,double scaf)
00124 :
00125 corners_(aVector),
00126 dir_(aVector),
00127 number_(number),
00128 survivalProbability_(1.),
00129 center_(0.,0.),
00130 epsilon_(0.001),
00131 yscalefactor_(scaf)
00132 {
00133
00134
00135 if(corners.size()!=4)
00136 {
00137 std::cout << " Try to construct a quadrilateral with " << corners.size() << " points ! " << std::endl;
00138 dummy_=true;
00139 }
00140 else
00141 {
00142 dummy_=false;
00143
00144
00145 trans_=trans;
00146
00147 trans_.GetDecomposition(rotation_,translation_);
00148 for(unsigned ic=0;ic<4;++ic)
00149 {
00150
00151 XYZPoint corner=rotation_(corners[ic])+translation_;
00152
00153 corners_[ic] = CLHEP::Hep2Vector(corner.X(),corner.Y()*yscalefactor_);
00154 center_+=corners_[ic];
00155 }
00156 for(unsigned ic=0;ic<4;++ic)
00157 {
00158 dir_[ic] = (corners_[(ic+1)%4]-corners_[ic]).unit();
00159 }
00160 center_*=0.25;
00161 }
00162 }
00163
00164 bool
00165 CrystalPad::inside(const CLHEP::Hep2Vector & ppoint,bool debug) const
00166 {
00167
00168
00169
00170
00171
00172
00173
00174 CLHEP::Hep2Vector pv0(ppoint-corners_[0]);
00175 CLHEP::Hep2Vector pv2(ppoint-corners_[2]);
00176 CLHEP::Hep2Vector n1(pv0-(pv0*dir_[0])*dir_[0]);
00177 CLHEP::Hep2Vector n2(pv2-(pv2*dir_[2])*dir_[2]);
00178
00179
00180
00181 double r1(n1*n2);
00182 bool inside1(r1<=0.);
00183
00184 if (!inside1) return false;
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198 CLHEP::Hep2Vector pv1(ppoint-corners_[1]);
00199 CLHEP::Hep2Vector pv3(ppoint-corners_[3]);
00200 CLHEP::Hep2Vector n3(pv1-(pv1*dir_[1])*dir_[1]);
00201 CLHEP::Hep2Vector n4(pv3-(pv3*dir_[3])*dir_[3]);
00202
00203
00204
00205 double r2(n3*n4);
00206 bool inside2(r2<=0.);
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222 return inside2;
00223 }
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244 void CrystalPad::print() const
00245 {
00246 std::cout << " Corners " << std::endl;
00247 std::cout << corners_[0] << std::endl;
00248 std::cout << corners_[1] << std::endl;
00249 std::cout << corners_[2] << std::endl;
00250 std::cout << corners_[3] << std::endl;
00251 }
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262 CLHEP::Hep2Vector& CrystalPad::edge(unsigned iside,int n)
00263 {
00264 return corners_[(iside+n)%4];
00265 }
00266
00267 CLHEP::Hep2Vector & CrystalPad::edge(CaloDirection dir)
00268 {
00269 switch(dir)
00270 {
00271 case NORTHWEST:
00272 return corners_[0];
00273 break;
00274 case NORTHEAST:
00275 return corners_[1];
00276 break;
00277 case SOUTHEAST:
00278 return corners_[2];
00279 break;
00280 case SOUTHWEST:
00281 return corners_[3];
00282 break;
00283 default:
00284 {
00285 std::cout << " Serious problem in CrystalPad ! " << dir << std::endl;
00286 return corners_[0];
00287 }
00288 }
00289 return corners_[0];
00290 }
00291
00292
00293 void
00294 CrystalPad::extrems(double &xmin,double& xmax,double &ymin, double& ymax) const
00295 {
00296 xmin=ymin=999;
00297 xmax=ymax=-999;
00298 for(unsigned ic=0;ic<4;++ic)
00299 {
00300 if(corners_[ic].x()<xmin) xmin=corners_[ic].x();
00301 if(corners_[ic].x()>xmax) xmax=corners_[ic].x();
00302 if(corners_[ic].y()<ymin) ymin=corners_[ic].y();
00303 if(corners_[ic].y()>ymax) ymax=corners_[ic].y();
00304 }
00305 }
00306
00307 void
00308 CrystalPad::resetCorners() {
00309
00310
00311 center_ = CLHEP::Hep2Vector(0.,0.);
00312 for(unsigned ic=0;ic<4;++ic) center_ += corners_[ic];
00313 center_ *= 0.25;
00314
00315
00316
00317 for(unsigned ic=0;ic<4;++ic)
00318 corners_[ic] += 0.001 * (corners_[ic] - center_) ;
00319
00320 }
00321
00322 std::ostream & operator << (std::ostream& ost, CrystalPad & quad)
00323 {
00324 ost << " Number " << quad.getNumber() << std::endl ;
00325 ost << NORTHWEST << quad.edge(NORTHWEST) << std::endl;
00326 ost << NORTHEAST << quad.edge(NORTHEAST) << std::endl;
00327 ost << SOUTHEAST << quad.edge(SOUTHEAST) << std::endl;
00328 ost << SOUTHWEST << quad.edge(SOUTHWEST) << std::endl;
00329
00330 return ost;
00331 }
00332
00333 void
00334 CrystalPad::getDrawingCoordinates(std::vector<float> &x, std::vector<float>&y) const
00335 {
00336 x.clear();
00337 y.clear();
00338 x.push_back(corners_[0].x());
00339 x.push_back(corners_[1].x());
00340 x.push_back(corners_[2].x());
00341 x.push_back(corners_[3].x());
00342 x.push_back(corners_[0].x());
00343 y.push_back(corners_[0].y());
00344 y.push_back(corners_[1].y());
00345 y.push_back(corners_[2].y());
00346 y.push_back(corners_[3].y());
00347 y.push_back(corners_[0].y());
00348 }