CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/FastSimulation/CaloHitMakers/src/PreshowerHitMaker.cc

Go to the documentation of this file.
00001 #include "FastSimulation/CaloHitMakers/interface/PreshowerHitMaker.h"
00002 #
00003 #include "FastSimulation/CaloGeometryTools/interface/CaloGeometryHelper.h"
00004 #include "FastSimulation/Utilities/interface/LandauFluctuationGenerator.h"
00005 #include "DataFormats/DetId/interface/DetId.h"
00006 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
00007 #include "Geometry/EcalAlgo/interface/EcalPreshowerGeometry.h"
00008 
00009 #include "Math/GenVector/Plane3D.h"
00010 
00011 #include <cmath>
00012 
00013 typedef ROOT::Math::Plane3D Plane3D;
00014 typedef ROOT::Math::Transform3DPJ::Point Point;
00015 
00016 // LandauFluctuationGenerator PreshowerHitMaker::theGenerator=LandauFluctuationGenerator();
00017 
00018 PreshowerHitMaker::PreshowerHitMaker(
00019     CaloGeometryHelper * calo,
00020     const XYZPoint& layer1entrance, 
00021     const XYZVector& layer1dir, 
00022     const XYZPoint& layer2entrance, 
00023     const XYZVector& layer2dir,
00024     const LandauFluctuationGenerator* aGenerator):
00025   CaloHitMaker(calo,DetId::Ecal,EcalPreshower,2),
00026   psLayer1Entrance_(layer1entrance),
00027   psLayer1Dir_(layer1dir),
00028   psLayer2Entrance_(layer2entrance),
00029   psLayer2Dir_(layer2dir),
00030   totalLayer1_(0.),totalLayer2_(0.),
00031   theGenerator(aGenerator)
00032 {
00033   double dummyt;
00034   anglecorrection1_ = 0.;
00035   anglecorrection2_ = 0.;
00036    // Check if the entrance points are really on the wafers
00037   // Layer 1 
00038   layer1valid_ = (layer1entrance.Mag2()>0.);
00039   if(layer1valid_)
00040     {
00041       int z=(psLayer1Entrance_.z()>0)? 1:-1;
00042       Plane3D plan1(0.,0.,1.,-z*myCalorimeter->preshowerZPosition(1));
00043 
00044       psLayer1Entrance_ = intersect(plan1,layer1entrance,layer1entrance+layer1dir,dummyt,false);
00045 
00046       XYZVector zaxis(0,0,1);
00047       XYZVector planeVec1=(zaxis.Cross(layer1dir)).Unit();
00048       locToGlobal1_=Transform3D(Point(0,0,0),
00049                                 Point(0,0,1),
00050                                 Point(1,0,0),
00051                                 (Point)psLayer1Entrance_,
00052                                 (Point)(psLayer1Entrance_+layer1dir),
00053                                 (Point)(psLayer1Entrance_+planeVec1));
00054 
00055       anglecorrection1_ = fabs(zaxis.Dot(layer1dir));
00056       if(anglecorrection1_!=0.) anglecorrection1_ = 1./anglecorrection1_;
00057       //      std::cout << " Layer 1 entrance " << psLayer1Entrance_ << std::endl;
00058       //      std::cout << " Layer 1 corr " << anglecorrection1_ << std::endl;
00059     }
00060 
00061   // Layer 2
00062   layer2valid_ = (layer2entrance.Mag2()>0.);
00063   if(layer2valid_)
00064     {
00065       int z=(psLayer2Entrance_.z()>0) ? 1:-1;
00066       Plane3D plan2(0.,0.,1.,-z*myCalorimeter->preshowerZPosition(2));
00067       
00068       psLayer2Entrance_ = intersect(plan2,layer2entrance,layer2entrance+layer2dir,dummyt,false);
00069 
00070       XYZVector zaxis(0,0,1);
00071       XYZVector planeVec2=(zaxis.Cross(layer2dir)).Unit();
00072       locToGlobal2_=Transform3D(Point(0,0,0),
00073                                 Point(0,0,1),
00074                                 Point(1,0,0),
00075                                (Point)psLayer2Entrance_,
00076                                (Point)(psLayer2Entrance_+layer2dir),
00077                                (Point)(psLayer2Entrance_+planeVec2));
00078       
00079       anglecorrection2_ = fabs(zaxis.Dot(layer2dir));
00080       if(anglecorrection2_!=0.) anglecorrection2_ = 1./anglecorrection2_;
00081       //      std::cout << " Layer 2 entrance " << psLayer2Entrance_ << std::endl;
00082       //      std::cout << " Layer 2 corr " << anglecorrection2_ << std::endl;
00083     }
00084   //  theGenerator=LandauFluctuationGenerator();
00085 }
00086 
00087 
00088 bool
00089 PreshowerHitMaker::addHit(double r,double phi,unsigned layer)
00090 {
00091   if((layer==1&&!layer1valid_)||((layer==2&&!layer2valid_))) return false;
00092 
00093   r*=moliereRadius;
00094   XYZPoint point (r*std::cos(phi),r*std::sin(phi),0.);
00095   point =  (layer==1) ? locToGlobal1_((Point)point) : locToGlobal2_((Point)point);
00096   //  std::cout << "  Point " << point  << std::endl;
00097   int z=(point.z()>0) ? 1: -1;
00098   point = XYZPoint(point.x(),point.y(),z*myCalorimeter->preshowerZPosition(layer));
00099   //  std::cout << "r " << r << "  Point after " << point  << std::endl;
00100   //  std::cout << " Layer " << layer << " " << point << std::endl;
00101   DetId strip = myCalorimeter->getEcalPreshowerGeometry()->getClosestCellInPlane(GlobalPoint(point.x(),point.y(),point.z()),layer);
00102 
00103   float meanspot=(layer==1) ? mip1_ : mip2_; 
00104   float spote = meanspot + 0.000021*theGenerator->landau();
00105   spote *= ( (layer==1) ? anglecorrection1_ : anglecorrection2_ );
00106 
00107   if(!strip.null())
00108     {
00109       uint32_t stripNumber=strip.rawId();
00110       std::map<uint32_t,float>::iterator cellitr;
00111       cellitr = hitMap_.find(stripNumber);
00112       if( cellitr==hitMap_.end())
00113         {
00114           hitMap_.insert(std::pair<uint32_t,float>(stripNumber,spote));
00115         }
00116       else
00117         {
00118           cellitr->second+=spote;
00119         }  
00120       //      std::cout << " found " << stripNumber << " " << spote <<std::endl;
00121       if(layer==1){
00122         totalLayer1_+=spote;
00123       }
00124       else if (layer==2) {
00125         totalLayer2_+=spote;
00126       }
00127       return true;
00128     }
00129   //  std::cout << "  Could not find a cell " << point << std::endl;
00130   return false;
00131 }