CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/FastSimulation/CaloHitMakers/src/HcalHitMaker.cc

Go to the documentation of this file.
00001 #include "FastSimulation/CaloHitMakers/interface/HcalHitMaker.h"
00002 #include "FastSimulation/CaloGeometryTools/interface/CaloGeometryHelper.h"
00003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00004 #include "DataFormats/HcalDetId/interface/HcalDetId.h" // PV
00005 #include <algorithm>
00006 #include <cmath>
00007 
00008 typedef ROOT::Math::Transform3DPJ::Point Point;
00009 
00010 HcalHitMaker::HcalHitMaker(EcalHitMaker& grid,unsigned shower)
00011   :CaloHitMaker(grid.getCalorimeter(),DetId::Hcal,HcalHitMaker::getSubHcalDet(grid.getFSimTrack()),
00012                 grid.getFSimTrack()->onHcal()?grid.getFSimTrack()->onHcal():grid.getFSimTrack()->onVFcal()+1,shower),
00013    myGrid(grid),  myTrack((grid.getFSimTrack()))
00014 {
00015   // normalize the direction
00016   ecalEntrance_=myGrid.ecalEntrance();
00017   particleDirection=myTrack->ecalEntrance().Vect().Unit();
00018   radiusFactor_=(EMSHOWER)? moliereRadius:interactionLength;
00019   mapCalculated_=false;
00020   //std::cout << " Famos HCAL " << grid.getTrack()->onHcal() << " " <<  grid.getTrack()->onVFcal() << " " << showerType << std::endl;
00021   if(EMSHOWER&&(abs(grid.getFSimTrack()->type())!=11 && grid.getFSimTrack()->type()!=22))
00022     {
00023       std::cout << " FamosHcalHitMaker : Strange. The following shower has EM type" << std::endl <<* grid.getFSimTrack() << std::endl;
00024     }
00025 }
00026 
00027 bool 
00028 HcalHitMaker::addHit(double r,double phi,unsigned layer)
00029 {
00030     //  std::cout << " FamosHcalHitMaker::addHit - radiusFactor = " << radiusFactor
00031   //        << std::endl;
00032 
00033   XYZPoint point(r*radiusFactor_*std::cos(phi),r*radiusFactor_*std::sin(phi),0.);
00034 
00035   // Watch out !!!! (Point) is a real point in the MathCore terminology (not a redefined a XYZPoint which
00036   // is actually a XYZVector in the MatchCore terminology). Therefore, the Transform3D is correctly applied
00037   point = locToGlobal_((Point)point);
00038   return addHit(point,layer);
00039 }
00040 
00041 bool HcalHitMaker::addHit(const XYZPoint& point, unsigned layer)
00042 {
00043   // Temporary nasty hacks to avoid misbehaviour of not-intended-for-that
00044   //  getClosestCell in case of large (eta beyond HF ...)  and in EM showers 
00045   if(fabs(point.Z())>2000 || fabs(point.X())>2000 || fabs(point.Y())>2000) 
00046     { 
00047       if(EMSHOWER) 
00048         edm::LogWarning("HcalHitMaker") << "received a hit very far from the detector " << point << " coming from an electromagnetic shower. - Ignoring it" << std::endl;
00049       else if(HADSHOWER)
00050         edm::LogWarning("HcalHitMaker") << "received a hit very far from the detector " << point << " coming from a hadron shower. - Ignoring it" << std::endl;
00051       else if(MIP)
00052         edm::LogWarning("HcalHitMaker") << "received a hit very far from the detector " << point << " coming from a muon. - Ignoring it" << std::endl;
00053       return false; 
00054     } 
00055 
00056 
00057   double pointeta = fabs(point.eta());
00058   if(pointeta > 5.19) return false; 
00059 
00060   DetId thecellID(myCalorimeter->getClosestCell(point,false,false));
00061   
00062   HcalDetId myDetId(thecellID);
00063                                                                                                                                       
00064 //   if ( myDetId.subdetId() == HcalForward ) {
00065 //     std::cout << "HcalHitMaker : " << point.Z() << " " << myDetId.depth()    << std::endl;
00066 //   }
00067                                                                                                                                       
00068 //   std::cout << "BEFORE" << std::endl;
00069 //   std::cout << "HcalHitMaker : subdetId : " << myDetId.subdetId() << std::endl;
00070 //   std::cout << "HcalHitMaker : depth    : " << myDetId.depth()    << std::endl;
00071 //   std::cout << "HcalHitMaker : ieta     : " << myDetId.ieta()     << std::endl;
00072 //   std::cout << "HcalHitMaker : iphi     : " << myDetId.iphi()     << std::endl;
00073 //   std::cout << "HcalHitMaker : spotE    : " << spotEnergy         << std::endl;
00074 //   std::cout << "HcalHitMaker : point.X  : " << point.X()          << std::endl;
00075 //   std::cout << "HcalHitMaker : point.Y  : " << point.Y()          << std::endl;
00076 //   std::cout << "HcalHitMaker : point.Z  : " << point.Z()          << std::endl;
00077                                                                                                                                       
00078   if ( myDetId.subdetId() == HcalForward ) {
00079     int mylayer = layer;
00080     if ( myDetId.depth()==2 ) {
00081       mylayer = (int)layer;
00082     } else {
00083       mylayer = 1;
00084     }
00085     HcalDetId myDetId2((HcalSubdetector)myDetId.subdetId(),myDetId.ieta(),myDetId.iphi(),mylayer);
00086     thecellID = myDetId2;
00087   }
00088 
00089 
00090   
00091   if(!thecellID.null())
00092     {   
00093       uint32_t cell(thecellID.rawId());
00094       
00095       //      std::cout << " FamosHcalHitMaker::addHit - the cell num " << cell
00096       //                << std::endl;
00097 
00098       std::map<uint32_t,float>::iterator cellitr;
00099       cellitr = hitMap_.find(cell);
00100       if(cellitr==hitMap_.end())
00101         {
00102           hitMap_.insert(std::pair<uint32_t,float>(cell,spotEnergy));
00103         }
00104       else
00105         {
00106           cellitr->second+=spotEnergy;
00107         }
00108       return true;
00109     }
00110   return false;
00111 }
00112 
00113 bool 
00114 HcalHitMaker::setDepth(double depth,bool inCm)
00115 {
00116   currentDepth_=depth;
00117   std::vector<CaloSegment>::const_iterator segiterator;
00118   if(inCm)
00119     {
00120       segiterator = find_if(myGrid.getSegments().begin(),myGrid.getSegments().end(),CaloSegment::inSegment(currentDepth_));
00121     }
00122   else
00123     {
00124       if(EMSHOWER)
00125         segiterator = find_if(myGrid.getSegments().begin(),myGrid.getSegments().end(),CaloSegment::inX0Segment(currentDepth_));
00126       
00127       //Hadron shower 
00128       if(HADSHOWER)
00129         segiterator = find_if(myGrid.getSegments().begin(),myGrid.getSegments().end(),CaloSegment::inL0Segment(currentDepth_));
00130     }
00131   
00132   if(segiterator==myGrid.getSegments().end()) 
00133     {
00134       // Special trick  - As advised by Salavat, no leakage should be simulated
00135       if(depth > myGrid.getSegments().back().sL0Exit())
00136         {
00137           segiterator= find_if(myGrid.getSegments().begin(),myGrid.getSegments().end(),CaloSegment::inL0Segment(myGrid.getSegments().back().sL0Exit()-1.));
00138           depth=segiterator->sL0Exit()-1.;
00139           currentDepth_=depth;
00140           if(segiterator==myGrid.getSegments().end())
00141             {
00142               std::cout << " Could not go at such depth " << EMSHOWER << "  " << currentDepth_ << std::endl;
00143               std::cout << " Track " << *(myGrid.getFSimTrack()) << std::endl;
00144               return false;
00145             }
00146         }
00147       else
00148         {
00149           std::cout << " Could not go at such depth " << EMSHOWER << "  " << currentDepth_ << " " << myGrid.getSegments().back().sL0Exit() << std::endl; 
00150           std::cout << " Track " << *(myGrid.getFSimTrack()) << std::endl; 
00151           return false; 
00152         }
00153     }
00154 
00155 
00156   XYZPoint origin;
00157   if(inCm)
00158     {
00159       origin=segiterator->positionAtDepthincm(currentDepth_);
00160     }
00161   else
00162     {
00163       if(EMSHOWER)
00164         origin=segiterator->positionAtDepthinX0(currentDepth_);
00165       if(HADSHOWER)
00166         origin=segiterator->positionAtDepthinL0(currentDepth_);
00167     }
00168   XYZVector zaxis(0,0,1);
00169   XYZVector planeVec1=(zaxis.Cross(particleDirection)).Unit();
00170   locToGlobal_=Transform3D(Point(0,0,0),
00171                            Point(0,0,1),
00172                            Point(1,0,0),
00173                            (Point)origin,
00174                            (Point)(origin+particleDirection),
00175                            (Point)(origin+planeVec1));
00176   return true;
00177 }