CMS 3D CMS Logo

SiTrackerGaussianSmearingRecHitConverter.cc

Go to the documentation of this file.
00001 
00009 //PAT
00010 //FastTrackerCluster
00011 #include "FastSimDataFormats/External/interface/FastTrackerCluster.h"
00012 
00013 // SiTracker Gaussian Smearing
00014 #include "FastSimulation/TrackingRecHitProducer/interface/SiTrackerGaussianSmearingRecHitConverter.h"
00015 
00016 // SiPixel Gaussian Smearing
00017 #include "FastSimulation/TrackingRecHitProducer/interface/SiPixelGaussianSmearingRecHitConverterAlgorithm.h"
00018 
00019 // SiStripGaussianSmearing
00020 #include "FastSimulation/TrackingRecHitProducer/interface/SiStripGaussianSmearingRecHitConverterAlgorithm.h"
00021 
00022 // Geometry and magnetic field
00023 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00024 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00025 #include "Geometry/CommonDetUnit/interface/GeomDetUnit.h"
00026 #include "Geometry/TrackerGeometryBuilder/interface/GluedGeomDet.h"
00027 #include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetUnit.h"
00028 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00029 #include "MagneticField/Engine/interface/MagneticField.h"
00030 
00031 // Data Formats
00032 #include "DataFormats/Common/interface/Handle.h"
00033 #include "SimDataFormats/CrossingFrame/interface/CrossingFrame.h"        
00034 
00035 // Framework
00036 #include "FWCore/Framework/interface/ESHandle.h"
00037 #include "FWCore/Framework/interface/Event.h"
00038 #include "FWCore/Framework/interface/EventSetup.h"
00039 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00040 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00041 #include "FWCore/ServiceRegistry/interface/Service.h"
00042 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
00043 #include "FWCore/Utilities/interface/Exception.h"
00044 
00045 // Numbering scheme
00046 #include "DataFormats/SiPixelDetId/interface/PXBDetId.h"
00047 #include "DataFormats/SiPixelDetId/interface/PXFDetId.h"
00048 #include "DataFormats/SiStripDetId/interface/TIBDetId.h"
00049 #include "DataFormats/SiStripDetId/interface/TIDDetId.h"
00050 #include "DataFormats/SiStripDetId/interface/TOBDetId.h"
00051 #include "DataFormats/SiStripDetId/interface/TECDetId.h"
00052 #include "DataFormats/GeometryCommonDetAlgo/interface/ErrorFrameTransformer.h"
00053 #include "DataFormats/TrackingRecHit/interface/AlignmentPositionError.h"
00054 
00055 //For Pileup events
00056 #include "SimDataFormats/EncodedEventId/interface/EncodedEventId.h"
00057 
00058 // Random engine
00059 #include "FastSimulation/Utilities/interface/RandomEngine.h"
00060 
00061 // topology
00062 
00063 // the rec hit matcher
00064 #include "FastSimulation/TrackingRecHitProducer/interface/GSRecHitMatcher.h"
00065 
00066 // STL
00067 #include <memory>
00068 
00069 // ROOT
00070 #include <TFile.h>
00071 #include <TH1F.h>
00072 
00073 //#define FAMOS_DEBUG
00074 
00075 SiTrackerGaussianSmearingRecHitConverter::SiTrackerGaussianSmearingRecHitConverter(
00076   edm::ParameterSet const& conf) 
00077   : pset_(conf)
00078 {
00079   thePixelDataFile = 0;
00080   thePixelBarrelResolutionFile = 0;
00081   thePixelForwardResolutionFile = 0;
00082   thePixelBarrelParametrization = 0;
00083   thePixelEndcapParametrization = 0;
00084   theSiStripErrorParametrization = 0; 
00085 
00086   random = 0;
00087 
00088 
00089 #ifdef FAMOS_DEBUG
00090   std::cout << "SiTrackerGaussianSmearingRecHitConverter instantiated" << std::endl;
00091 #endif
00092 
00093   // Initialize the random number generator service
00094   edm::Service<edm::RandomNumberGenerator> rng;
00095   if ( ! rng.isAvailable() ) {
00096     throw cms::Exception("Configuration")
00097       << "SiTrackerGaussianSmearingRecHitConverter requires the RandomGeneratorService\n"
00098          "which is not present in the configuration file.\n"
00099          "You must add the service in the configuration file\n"
00100          "or remove the module that requires it";
00101   }
00102 
00103   random = new RandomEngine(&(*rng));
00104   //PAT
00105   produces<FastTrackerClusterCollection>("TrackerClusters");
00106 
00107   produces<SiTrackerGSRecHit2DCollection>("TrackerGSRecHits");
00108   produces<SiTrackerGSMatchedRecHit2DCollection>("TrackerGSMatchedRecHits");
00109 
00110   //--- PSimHit Containers
00111   trackerContainers.clear();
00112   trackerContainers = conf.getParameter<std::vector<edm::InputTag> >("ROUList");
00113   //--- delta rays p cut [GeV/c] to filter PSimHits with p>
00114   deltaRaysPCut = conf.getParameter<double>("DeltaRaysMomentumCut");
00115 
00116   //--- switch to have RecHit == PSimHit
00117   trackingPSimHits = conf.getParameter<bool>("trackingPSimHits");
00118   if(trackingPSimHits) std::cout << "### trackingPSimHits chosen " << trackingPSimHits << std::endl;
00119 
00120   // switch on/off matching
00121   doMatching = conf.getParameter<bool>("doRecHitMatching");
00122 
00123   // Switch between old (ORCA) and new (CMSSW) pixel parameterization
00124   useCMSSWPixelParameterization = conf.getParameter<bool>("UseCMSSWPixelParametrization");
00125 #ifdef FAMOS_DEBUG
00126   std::cout << (useCMSSWPixelParameterization? "CMSSW" : "ORCA") << " pixel parametrization chosen in config file." << std::endl;
00127 #endif
00128 
00129   //Clusters
00130   GevPerElectron =  conf.getParameter<double>("GevPerElectron");
00131   ElectronsPerADC =  conf.getParameter<double>("ElectronsPerADC");
00132   
00133   //
00134   // TIB
00135   localPositionResolution_TIB1x = conf.getParameter<double>("TIB1x");
00136   localPositionResolution_TIB1y = conf.getParameter<double>("TIB1y");
00137   localPositionResolution_TIB2x = conf.getParameter<double>("TIB2x");
00138   localPositionResolution_TIB2y = conf.getParameter<double>("TIB2y");
00139   localPositionResolution_TIB3x = conf.getParameter<double>("TIB3x");
00140   localPositionResolution_TIB3y = conf.getParameter<double>("TIB3y");
00141   localPositionResolution_TIB4x = conf.getParameter<double>("TIB4x");
00142   localPositionResolution_TIB4y = conf.getParameter<double>("TIB4y");
00143   //
00144   // TID
00145   localPositionResolution_TID1x = conf.getParameter<double>("TID1x");
00146   localPositionResolution_TID1y = conf.getParameter<double>("TID1y");
00147   localPositionResolution_TID2x = conf.getParameter<double>("TID2x");
00148   localPositionResolution_TID2y = conf.getParameter<double>("TID2y");
00149   localPositionResolution_TID3x = conf.getParameter<double>("TID3x");
00150   localPositionResolution_TID3y = conf.getParameter<double>("TID3y");
00151   //
00152   // TOB
00153   localPositionResolution_TOB1x = conf.getParameter<double>("TOB1x");
00154   localPositionResolution_TOB1y = conf.getParameter<double>("TOB1y");
00155   localPositionResolution_TOB2x = conf.getParameter<double>("TOB2x");
00156   localPositionResolution_TOB2y = conf.getParameter<double>("TOB2y");
00157   localPositionResolution_TOB3x = conf.getParameter<double>("TOB3x");
00158   localPositionResolution_TOB3y = conf.getParameter<double>("TOB3y");
00159   localPositionResolution_TOB4x = conf.getParameter<double>("TOB4x");
00160   localPositionResolution_TOB4y = conf.getParameter<double>("TOB4y");
00161   localPositionResolution_TOB5x = conf.getParameter<double>("TOB5x");
00162   localPositionResolution_TOB5y = conf.getParameter<double>("TOB5y");
00163   localPositionResolution_TOB6x = conf.getParameter<double>("TOB6x");
00164   localPositionResolution_TOB6y = conf.getParameter<double>("TOB6y");
00165   //
00166   // TEC
00167   localPositionResolution_TEC1x = conf.getParameter<double>("TEC1x");
00168   localPositionResolution_TEC1y = conf.getParameter<double>("TEC1y");
00169   localPositionResolution_TEC2x = conf.getParameter<double>("TEC2x");
00170   localPositionResolution_TEC2y = conf.getParameter<double>("TEC2y");
00171   localPositionResolution_TEC3x = conf.getParameter<double>("TEC3x");
00172   localPositionResolution_TEC3y = conf.getParameter<double>("TEC3y");
00173   localPositionResolution_TEC4x = conf.getParameter<double>("TEC4x");
00174   localPositionResolution_TEC4y = conf.getParameter<double>("TEC4y");
00175   localPositionResolution_TEC5x = conf.getParameter<double>("TEC5x");
00176   localPositionResolution_TEC5y = conf.getParameter<double>("TEC5y");
00177   localPositionResolution_TEC6x = conf.getParameter<double>("TEC6x");
00178   localPositionResolution_TEC6y = conf.getParameter<double>("TEC6y");
00179   localPositionResolution_TEC7x = conf.getParameter<double>("TEC7x");
00180   localPositionResolution_TEC7y = conf.getParameter<double>("TEC7y");
00181   //
00182   localPositionResolution_z = 0.0001; // not to be changed, set to minimum (1 um), Kalman Filter will crash if errors are exactly 0, setting 1 um means 0
00183   //
00184 #ifdef FAMOS_DEBUG
00185   std::cout << "RecHit local position error set to" << "\n"
00186             << "\tTIB1\tx = " << localPositionResolution_TIB1x 
00187             << " cm\ty = " << localPositionResolution_TIB1y << " cm" << "\n"
00188             << "\tTIB2\tx = " << localPositionResolution_TIB2x 
00189             << " cm\ty = " << localPositionResolution_TIB2y << " cm" << "\n"
00190             << "\tTIB3\tx = " << localPositionResolution_TIB3x 
00191             << " cm\ty = " << localPositionResolution_TIB3y << " cm" << "\n"
00192             << "\tTIB4\tx = " << localPositionResolution_TIB4x 
00193             << " cm\ty = " << localPositionResolution_TIB4y << " cm" << "\n"
00194             << "\tTID1\tx = " << localPositionResolution_TID1x 
00195             << " cm\ty = " << localPositionResolution_TID1y << " cm" << "\n"
00196             << "\tTID2\tx = " << localPositionResolution_TID2x 
00197             << " cm\ty = " << localPositionResolution_TID2y << " cm" << "\n"
00198             << "\tTID3\tx = " << localPositionResolution_TID3x 
00199             << " cm\ty = " << localPositionResolution_TID3y << " cm" << "\n"
00200             << "\tTOB1\tx = " << localPositionResolution_TOB1x 
00201             << " cm\ty = " << localPositionResolution_TOB1y << " cm" << "\n"
00202             << "\tTOB2\tx = " << localPositionResolution_TOB2x 
00203             << " cm\ty = " << localPositionResolution_TOB2y << " cm" << "\n"
00204             << "\tTOB3\tx = " << localPositionResolution_TOB3x 
00205             << " cm\ty = " << localPositionResolution_TOB3y << " cm" << "\n"
00206             << "\tTOB4\tx = " << localPositionResolution_TOB4x 
00207             << " cm\ty = " << localPositionResolution_TOB4y << " cm" << "\n"
00208             << "\tTOB5\tx = " << localPositionResolution_TOB5x 
00209             << " cm\ty = " << localPositionResolution_TOB5y << " cm" << "\n"
00210             << "\tTOB6\tx = " << localPositionResolution_TOB6x 
00211             << " cm\ty = " << localPositionResolution_TOB6y << " cm" << "\n"
00212             << "\tTEC1\tx = " << localPositionResolution_TEC1x 
00213             << " cm\ty = " << localPositionResolution_TEC1y << " cm" << "\n"
00214             << "\tTEC2\tx = " << localPositionResolution_TEC2x 
00215             << " cm\ty = " << localPositionResolution_TEC2y << " cm" << "\n"
00216             << "\tTEC3\tx = " << localPositionResolution_TEC3x 
00217             << " cm\ty = " << localPositionResolution_TEC3y << " cm" << "\n"
00218             << "\tTEC4\tx = " << localPositionResolution_TEC4x 
00219             << " cm\ty = " << localPositionResolution_TEC4y << " cm" << "\n"
00220             << "\tTEC5\tx = " << localPositionResolution_TEC5x 
00221             << " cm\ty = " << localPositionResolution_TEC5y << " cm" << "\n"
00222             << "\tTEC6\tx = " << localPositionResolution_TEC6x 
00223             << " cm\ty = " << localPositionResolution_TEC6y << " cm" << "\n"
00224             << "\tTEC7\tx = " << localPositionResolution_TEC7x 
00225             << " cm\ty = " << localPositionResolution_TEC7y << " cm" << "\n"
00226             << "\tAll:\tz = " << localPositionResolution_z     << " cm" 
00227             << std::endl;
00228 #endif
00229 
00230   //--- Number of histograms for alpha/beta barrel/forward multiplicity
00231   if(useCMSSWPixelParameterization) {
00232     nAlphaBarrel  = conf.getParameter<int>("AlphaBarrelMultiplicityNew");
00233     nBetaBarrel   = conf.getParameter<int>("BetaBarrelMultiplicityNew");
00234     nAlphaForward = conf.getParameter<int>("AlphaForwardMultiplicityNew");
00235     nBetaForward  = conf.getParameter<int>("BetaForwardMultiplicityNew");
00236   } else {
00237     nAlphaBarrel  = conf.getParameter<int>("AlphaBarrelMultiplicity");
00238     nBetaBarrel   = conf.getParameter<int>("BetaBarrelMultiplicity");
00239     nAlphaForward = conf.getParameter<int>("AlphaForwardMultiplicity");
00240     nBetaForward  = conf.getParameter<int>("BetaForwardMultiplicity");
00241   }
00242 #ifdef FAMOS_DEBUG
00243   std::cout << "Pixel maximum multiplicity set to " 
00244             << "\nBarrel"  << "\talpha " << nAlphaBarrel  
00245             << "\tbeta " << nBetaBarrel
00246             << "\nForward" << "\talpha " << nAlphaForward 
00247             << "\tbeta " << nBetaForward
00248             << std::endl;
00249 #endif
00250   
00251   // Resolution Barrel    
00252   if(useCMSSWPixelParameterization) {
00253     resAlphaBarrel_binMin   = conf.getParameter<double>("AlphaBarrel_BinMinNew"  );
00254     resAlphaBarrel_binWidth = conf.getParameter<double>("AlphaBarrel_BinWidthNew");
00255     resAlphaBarrel_binN     = conf.getParameter<int>(   "AlphaBarrel_BinNNew"    );
00256     resBetaBarrel_binMin    = conf.getParameter<double>("BetaBarrel_BinMinNew"   );
00257     resBetaBarrel_binWidth  = conf.getParameter<double>("BetaBarrel_BinWidthNew" );
00258     resBetaBarrel_binN      = conf.getParameter<int>(   "BetaBarrel_BinNNew"     );
00259   } else {
00260     resAlphaBarrel_binMin   = conf.getParameter<double>("AlphaBarrel_BinMin"  );
00261     resAlphaBarrel_binWidth = conf.getParameter<double>("AlphaBarrel_BinWidth");
00262     resAlphaBarrel_binN     = conf.getParameter<int>(   "AlphaBarrel_BinN"    );
00263     resBetaBarrel_binMin    = conf.getParameter<double>("BetaBarrel_BinMin"   );
00264     resBetaBarrel_binWidth  = conf.getParameter<double>("BetaBarrel_BinWidth" );
00265     resBetaBarrel_binN      = conf.getParameter<int>(   "BetaBarrel_BinN"     );
00266   }
00267   
00268   // Resolution Forward
00269   if(useCMSSWPixelParameterization) {
00270     resAlphaForward_binMin   = conf.getParameter<double>("AlphaForward_BinMinNew"   );
00271     resAlphaForward_binWidth = conf.getParameter<double>("AlphaForward_BinWidthNew" );
00272     resAlphaForward_binN     = conf.getParameter<int>(   "AlphaForward_BinNNew"     );
00273     resBetaForward_binMin    = conf.getParameter<double>("BetaForward_BinMinNew"    );
00274     resBetaForward_binWidth  = conf.getParameter<double>("BetaForward_BinWidthNew"  );
00275     resBetaForward_binN      = conf.getParameter<int>(   "BetaForward_BinNNew"      );
00276   } else {
00277     resAlphaForward_binMin   = conf.getParameter<double>("AlphaForward_BinMin"   );
00278     resAlphaForward_binWidth = conf.getParameter<double>("AlphaForward_BinWidth" );
00279     resAlphaForward_binN     = conf.getParameter<int>(   "AlphaForward_BinN"     );
00280     resBetaForward_binMin    = conf.getParameter<double>("BetaForward_BinMin"    );
00281     resBetaForward_binWidth  = conf.getParameter<double>("BetaForward_BinWidth"  );
00282     resBetaForward_binN      = conf.getParameter<int>(   "BetaForward_BinN"      );
00283   }
00284 
00285   // Hit Finding Probability
00286   theHitFindingProbability_PXB  = conf.getParameter<double>("HitFindingProbability_PXB" );
00287   theHitFindingProbability_PXF  = conf.getParameter<double>("HitFindingProbability_PXF" );
00288   theHitFindingProbability_TIB1 = conf.getParameter<double>("HitFindingProbability_TIB1");
00289   theHitFindingProbability_TIB2 = conf.getParameter<double>("HitFindingProbability_TIB2");
00290   theHitFindingProbability_TIB3 = conf.getParameter<double>("HitFindingProbability_TIB3");
00291   theHitFindingProbability_TIB4 = conf.getParameter<double>("HitFindingProbability_TIB4");
00292   theHitFindingProbability_TID1 = conf.getParameter<double>("HitFindingProbability_TID1");
00293   theHitFindingProbability_TID2 = conf.getParameter<double>("HitFindingProbability_TID2");
00294   theHitFindingProbability_TID3 = conf.getParameter<double>("HitFindingProbability_TID3");
00295   theHitFindingProbability_TOB1 = conf.getParameter<double>("HitFindingProbability_TOB1");
00296   theHitFindingProbability_TOB2 = conf.getParameter<double>("HitFindingProbability_TOB2");
00297   theHitFindingProbability_TOB3 = conf.getParameter<double>("HitFindingProbability_TOB3");
00298   theHitFindingProbability_TOB4 = conf.getParameter<double>("HitFindingProbability_TOB4");
00299   theHitFindingProbability_TOB5 = conf.getParameter<double>("HitFindingProbability_TOB5");
00300   theHitFindingProbability_TOB6 = conf.getParameter<double>("HitFindingProbability_TOB6");
00301   theHitFindingProbability_TEC1 = conf.getParameter<double>("HitFindingProbability_TEC1");
00302   theHitFindingProbability_TEC2 = conf.getParameter<double>("HitFindingProbability_TEC2");
00303   theHitFindingProbability_TEC3 = conf.getParameter<double>("HitFindingProbability_TEC3");
00304   theHitFindingProbability_TEC4 = conf.getParameter<double>("HitFindingProbability_TEC4");
00305   theHitFindingProbability_TEC5 = conf.getParameter<double>("HitFindingProbability_TEC5");
00306   theHitFindingProbability_TEC6 = conf.getParameter<double>("HitFindingProbability_TEC6");
00307   theHitFindingProbability_TEC7 = conf.getParameter<double>("HitFindingProbability_TEC7");
00308   //
00309 #ifdef FAMOS_DEBUG
00310   std::cout << "RecHit finding probability set to" << "\n"
00311             << "\tPXB  = " << theHitFindingProbability_PXB  << "\n"
00312             << "\tPXF  = " << theHitFindingProbability_PXF  << "\n"
00313             << "\tTIB1 = " << theHitFindingProbability_TIB1 << "\n"
00314             << "\tTIB2 = " << theHitFindingProbability_TIB2 << "\n"
00315             << "\tTIB3 = " << theHitFindingProbability_TIB3 << "\n"
00316             << "\tTIB4 = " << theHitFindingProbability_TIB4 << "\n"
00317             << "\tTID1 = " << theHitFindingProbability_TID1 << "\n"
00318             << "\tTID2 = " << theHitFindingProbability_TID2 << "\n"
00319             << "\tTID3 = " << theHitFindingProbability_TID3 << "\n"
00320             << "\tTOB1 = " << theHitFindingProbability_TOB1 << "\n"
00321             << "\tTOB2 = " << theHitFindingProbability_TOB2 << "\n"
00322             << "\tTOB3 = " << theHitFindingProbability_TOB3 << "\n"
00323             << "\tTOB4 = " << theHitFindingProbability_TOB4 << "\n"
00324             << "\tTOB5 = " << theHitFindingProbability_TOB5 << "\n"
00325             << "\tTOB6 = " << theHitFindingProbability_TOB6 << "\n"
00326             << "\tTEC1 = " << theHitFindingProbability_TEC1 << "\n"
00327             << "\tTEC2 = " << theHitFindingProbability_TEC2 << "\n"
00328             << "\tTEC3 = " << theHitFindingProbability_TEC3 << "\n"
00329             << "\tTEC4 = " << theHitFindingProbability_TEC4 << "\n"
00330             << "\tTEC5 = " << theHitFindingProbability_TEC5 << "\n"
00331             << "\tTEC6 = " << theHitFindingProbability_TEC6 << "\n"
00332             << "\tTEC7 = " << theHitFindingProbability_TEC7 << "\n"
00333             << std::endl;
00334 #endif
00335 
00336   // Initialize the si strip error parametrization
00337   theSiStripErrorParametrization = 
00338     new SiStripGaussianSmearingRecHitConverterAlgorithm(random);
00339 
00340   // Initialization of pixel parameterization posponed to beginRun(), since it depends on the magnetic field
00341 
00342 }
00343 
00344 void SiTrackerGaussianSmearingRecHitConverter::loadPixelData() {
00345   // load multiplicity cumulative probabilities
00346   // root files
00347   thePixelDataFile              = new TFile ( edm::FileInPath( thePixelMultiplicityFileName      ).fullPath().c_str() , "READ" );
00348   thePixelBarrelResolutionFile  = new TFile ( edm::FileInPath( thePixelBarrelResolutionFileName  ).fullPath().c_str() , "READ" );
00349   thePixelForwardResolutionFile = new TFile ( edm::FileInPath( thePixelForwardResolutionFileName ).fullPath().c_str() , "READ" );
00350   //
00351 
00352   // alpha barrel
00353   loadPixelData( thePixelDataFile, 
00354                  nAlphaBarrel  , 
00355                  std::string("hist_alpha_barrel")  , 
00356                  theBarrelMultiplicityAlphaCumulativeProbabilities  );
00357   // 
00358   // beta barrel
00359   loadPixelData( thePixelDataFile, 
00360                  nBetaBarrel   , 
00361                  std::string("hist_beta_barrel")   , 
00362                  theBarrelMultiplicityBetaCumulativeProbabilities   );
00363   // 
00364   // alpha forward
00365   loadPixelData( thePixelDataFile, 
00366                  nAlphaForward , 
00367                  std::string("hist_alpha_forward") , 
00368                  theForwardMultiplicityAlphaCumulativeProbabilities );
00369   // 
00370   // beta forward
00371   loadPixelData( thePixelDataFile, 
00372                  nBetaForward  , 
00373                  std::string("hist_beta_forward")  , 
00374                  theForwardMultiplicityBetaCumulativeProbabilities  );
00375 
00376   // Load also big pixel data if CMSSW parametrization is on
00377   // They are pushed back into the vectors after the normal pixels data:
00378   // [0, ..., (size/2)-1] -> Normal pixels
00379   // [size/2, ..., size-1] -> Big pixels
00380   if(useCMSSWPixelParameterization) {
00381     // alpha barrel
00382     loadPixelData( thePixelDataFile, 
00383                    nAlphaBarrel  , 
00384                    std::string("hist_alpha_barrel_big")  , 
00385                    theBarrelMultiplicityAlphaCumulativeProbabilities,
00386                    true );
00387     // 
00388     // beta barrel
00389     loadPixelData( thePixelDataFile, 
00390                    nBetaBarrel   , 
00391                    std::string("hist_beta_barrel_big")   , 
00392                    theBarrelMultiplicityBetaCumulativeProbabilities,
00393                    true );
00394     // 
00395     // alpha forward
00396     loadPixelData( thePixelDataFile, 
00397                    nAlphaForward , 
00398                    std::string("hist_alpha_forward_big") , 
00399                    theForwardMultiplicityAlphaCumulativeProbabilities, 
00400                    true );
00401     // 
00402     // beta forward
00403     loadPixelData( thePixelDataFile, 
00404                    nBetaForward  , 
00405                    std::string("hist_beta_forward_big")  , 
00406                    theForwardMultiplicityBetaCumulativeProbabilities, 
00407                    true );
00408   }
00409   // 
00410 }
00411 
00412 void SiTrackerGaussianSmearingRecHitConverter::loadPixelData( 
00413   TFile* pixelDataFile, 
00414   unsigned int nMultiplicity, 
00415   std::string histName,
00416   std::vector<TH1F*>& theMultiplicityCumulativeProbabilities,
00417   bool bigPixels) 
00418 {
00419 
00420   std::string histName_i = histName + "_%u"; // needed to open histograms with a for
00421   if(!bigPixels)
00422     theMultiplicityCumulativeProbabilities.clear();
00423   //
00424   // What's this vector? Not needed - MG
00425 //  std::vector<double> mult; // vector with fixed multiplicity
00426   for(unsigned int i = 0; i<nMultiplicity; ++i) {
00427     TH1F addHist = *((TH1F*) pixelDataFile->Get( Form( histName_i.c_str() ,i+1 )));
00428     if(i==0) {
00429       theMultiplicityCumulativeProbabilities.push_back( new TH1F(addHist) );
00430     } else {
00431       TH1F sumHist;
00432       if(bigPixels)
00433         sumHist = *(theMultiplicityCumulativeProbabilities[nMultiplicity+i-1]);
00434       else
00435         sumHist = *(theMultiplicityCumulativeProbabilities[i-1]);
00436       sumHist.Add(&addHist);
00437       theMultiplicityCumulativeProbabilities.push_back( new TH1F(sumHist) );
00438     }
00439   }
00440 
00441   // Logger
00442 #ifdef FAMOS_DEBUG
00443   const unsigned int maxMult = theMultiplicityCumulativeProbabilities.size();
00444   unsigned int iMult, multSize;
00445   if(useCMSSWPixelParameterization) {
00446     if(bigPixels) {     
00447       iMult = maxMult / 2;
00448       multSize = maxMult ;
00449     } else {                
00450       iMult = 0;
00451       multSize = maxMult;
00452     }
00453   } else {
00454     iMult = 0;
00455     multSize = maxMult ;
00456   }
00457   std::cout << " Multiplicity cumulated probability " << histName << std::endl;
00458   for(/* void */; iMult<multSize; ++iMult) {
00459     for(int iBin = 1; iBin<=theMultiplicityCumulativeProbabilities[iMult]->GetNbinsX(); ++iBin) {
00460       std::cout
00461         << " Multiplicity " << iMult+1 
00462         << " bin " << iBin 
00463         << " low edge = " 
00464         << theMultiplicityCumulativeProbabilities[iMult]->GetBinLowEdge(iBin)
00465         << " prob = " 
00466         << (theMultiplicityCumulativeProbabilities[iMult])->GetBinContent(iBin) 
00467         // remember in ROOT bin starts from 1 (0 underflow, nBin+1 overflow)
00468         << std::endl;
00469     }
00470   }
00471 #endif
00472 
00473 }
00474 
00475 // Destructor
00476 SiTrackerGaussianSmearingRecHitConverter::~SiTrackerGaussianSmearingRecHitConverter() {
00477   theBarrelMultiplicityAlphaCumulativeProbabilities.clear();
00478   theBarrelMultiplicityBetaCumulativeProbabilities.clear();
00479   theForwardMultiplicityAlphaCumulativeProbabilities.clear();
00480   theForwardMultiplicityBetaCumulativeProbabilities.clear();
00481   
00482   if(thePixelDataFile) delete thePixelDataFile;
00483   if(thePixelBarrelResolutionFile) delete thePixelBarrelResolutionFile;
00484   if(thePixelForwardResolutionFile) delete thePixelForwardResolutionFile;
00485   if(thePixelBarrelParametrization) delete thePixelBarrelParametrization;
00486   if(thePixelEndcapParametrization) delete thePixelEndcapParametrization;
00487   if(theSiStripErrorParametrization) delete theSiStripErrorParametrization;
00488 
00489   if(random) delete random;
00490 
00491 }  
00492 
00493 void 
00494 SiTrackerGaussianSmearingRecHitConverter::beginRun(edm::Run & run, const edm::EventSetup & es) 
00495 {
00496 
00497   // Initialize the Tracker Geometry
00498   edm::ESHandle<TrackerGeometry> theGeometry;
00499   es.get<TrackerDigiGeometryRecord> ().get (theGeometry);
00500   geometry = &(*theGeometry);
00501 
00502   edm::ESHandle<TrackerGeometry> theMisAlignedGeometry;
00503   es.get<TrackerDigiGeometryRecord>().get("MisAligned",theMisAlignedGeometry);
00504   misAlignedGeometry = &(*theMisAlignedGeometry);
00505 
00506   const MagneticField* magfield;
00507   edm::ESHandle<MagneticField> magField;
00508   es.get<IdealMagneticFieldRecord>().get(magField);
00509   magfield=&(*magField);
00510   GlobalPoint center(0.0, 0.0, 0.0);
00511   double magFieldAtCenter = magfield->inTesla(center).mag();
00512 
00513   // For new parameterization: select multiplicity and resolution files according to magnetic field
00514   if(useCMSSWPixelParameterization) {
00515     if(magFieldAtCenter > 3.9) {
00516       thePixelMultiplicityFileName = pset_.getParameter<std::string>( "PixelMultiplicityFile40T");
00517       thePixelBarrelResolutionFileName = pset_.getParameter<std::string>( "PixelBarrelResolutionFile40T");
00518       thePixelForwardResolutionFileName = pset_.getParameter<std::string>( "PixelForwardResolutionFile40T");
00519     } else {
00520       thePixelMultiplicityFileName = pset_.getParameter<std::string>( "PixelMultiplicityFile38T");
00521       thePixelBarrelResolutionFileName = pset_.getParameter<std::string>( "PixelBarrelResolutionFile38T");      
00522       thePixelForwardResolutionFileName = pset_.getParameter<std::string>( "PixelForwardResolutionFile38T");
00523     }
00524   } else {
00525     thePixelMultiplicityFileName = pset_.getParameter<std::string>( "PixelMultiplicityFile" );
00526     thePixelBarrelResolutionFileName = pset_.getParameter<std::string>( "PixelBarrelResolutionFile");
00527     thePixelForwardResolutionFileName = pset_.getParameter<std::string>( "PixelForwardResolutionFile");
00528   }
00529 
00530 
00531 #ifdef FAMOS_DEBUG
00532   std::cout << "Pixel multiplicity data are taken from file " << thePixelMultiplicityFileName << std::endl;
00533 
00534   std::cout << "Pixel maximum multiplicity set to " 
00535             << "\nBarrel"  << "\talpha " << nAlphaBarrel  
00536             << "\tbeta " << nBetaBarrel
00537             << "\nForward" << "\talpha " << nAlphaForward 
00538             << "\tbeta " << nBetaForward
00539             << std::endl;
00540 
00541   std::cout << "Barrel Pixel resolution data are taken from file " 
00542             << thePixelBarrelResolutionFileName << "\n"
00543             << "Alpha bin min = " << resAlphaBarrel_binMin
00544             << "\twidth = "       << resAlphaBarrel_binWidth
00545             << "\tbins = "        << resAlphaBarrel_binN
00546             << "\n"
00547             << " Beta bin min = " << resBetaBarrel_binMin
00548             << "\twidth = "       << resBetaBarrel_binWidth
00549             << "\tbins = "        << resBetaBarrel_binN
00550             << std::endl;
00551 
00552   std::cout << "Forward Pixel resolution data are taken from file " 
00553             << thePixelForwardResolutionFileName << "\n"
00554             << "Alpha bin min = " << resAlphaForward_binMin
00555             << "\twidth = "       << resAlphaForward_binWidth
00556             << "\tbins = "        << resAlphaForward_binN
00557             << "\n"
00558             << " Beta bin min = " << resBetaForward_binMin
00559             << "\twidth = "       << resBetaForward_binWidth
00560             << "\tbins = "        << resBetaForward_binN
00561             << std::endl;
00562 #endif 
00563   //
00564 
00565   //    
00566   // load pixel data
00567   loadPixelData();
00568   //
00569 
00570   // Initialize and open relevant files for the pixel barrel error parametrization
00571   thePixelBarrelParametrization = 
00572     new SiPixelGaussianSmearingRecHitConverterAlgorithm(
00573         pset_,
00574         GeomDetEnumerators::PixelBarrel,
00575         theBarrelMultiplicityAlphaCumulativeProbabilities,
00576         theBarrelMultiplicityBetaCumulativeProbabilities,
00577         thePixelBarrelResolutionFile,
00578         random);
00579   // Initialize and open relevant files for the pixel forward error parametrization 
00580   thePixelEndcapParametrization = 
00581     new SiPixelGaussianSmearingRecHitConverterAlgorithm(
00582         pset_,
00583         GeomDetEnumerators::PixelEndcap,
00584         theForwardMultiplicityAlphaCumulativeProbabilities,
00585         theForwardMultiplicityBetaCumulativeProbabilities,
00586         thePixelForwardResolutionFile,
00587         random);
00588 }
00589 
00590 void SiTrackerGaussianSmearingRecHitConverter::produce(edm::Event& e, const edm::EventSetup& es) 
00591 {
00592 
00593   // Step 0: Declare Ref and RefProd
00594   FastTrackerClusterRefProd = e.getRefBeforePut<FastTrackerClusterCollection>("TrackerClusters");
00595   
00596   // Step A: Get Inputs (PSimHit's)
00597   edm::Handle<CrossingFrame<PSimHit> > cf_simhit; 
00598   std::vector<const CrossingFrame<PSimHit> *> cf_simhitvec;
00599   for(uint32_t i=0; i<trackerContainers.size(); i++){
00600     e.getByLabel(trackerContainers[i], cf_simhit);
00601     cf_simhitvec.push_back(cf_simhit.product());
00602   }
00603   std::auto_ptr<MixCollection<PSimHit> > allTrackerHits(new MixCollection<PSimHit>(cf_simhitvec));
00604 
00605   // Step B: create temporary RecHit collection and fill it with Gaussian smeared RecHit's
00606   
00607   //NEW!!!CREATE CLUSTERS AT THE SAME TIME
00608   std::map<unsigned, edm::OwnVector<SiTrackerGSRecHit2D> > temporaryRecHits;
00609   std::map<unsigned, edm::OwnVector<FastTrackerCluster> > theClusters ;
00610   smearHits( *allTrackerHits, temporaryRecHits, theClusters);
00611 
00612  // Step C: match rechits on stereo layers
00613   std::map<unsigned, edm::OwnVector<SiTrackerGSMatchedRecHit2D> > temporaryMatchedRecHits ;
00614   if(doMatching)  matchHits(  temporaryRecHits,  temporaryMatchedRecHits, *allTrackerHits);
00615 
00616   // Step D: from the temporary RecHit collection, create the real one.
00617   std::auto_ptr<SiTrackerGSRecHit2DCollection> recHitCollection(new SiTrackerGSRecHit2DCollection);
00618   std::auto_ptr<SiTrackerGSMatchedRecHit2DCollection> recHitCollectionMatched(new SiTrackerGSMatchedRecHit2DCollection);
00619   if(doMatching){
00620     loadMatchedRecHits(temporaryMatchedRecHits, *recHitCollectionMatched);
00621     loadRecHits(temporaryRecHits, *recHitCollection);
00622   }
00623   else {
00624     //might need to have a "matched" hit collection containing the simple hits
00625     loadRecHits(temporaryRecHits, *recHitCollection);
00626   }
00627   //  std::cout << "TrackerGSRecHits hits are =\t" <<  (*recHitCollection).size()<<std::endl;
00628   //std::cout << "TrackerGSRecHitsMatched hits are =\t" <<  (*recHitCollectionMatched).size()<< std::endl;
00629 
00630   // Step E: write output to file
00631   e.put(recHitCollection,"TrackerGSRecHits");
00632   e.put(recHitCollectionMatched,"TrackerGSMatchedRecHits");
00633   
00634   //STEP F: write clusters
00635   std::auto_ptr<FastTrackerClusterCollection> clusterCollection(new FastTrackerClusterCollection);
00636   loadClusters(theClusters, *clusterCollection);
00637   e.put(clusterCollection,"TrackerClusters");
00638 }
00639 
00640 
00641 
00642 void SiTrackerGaussianSmearingRecHitConverter::smearHits(
00643                                                          MixCollection<PSimHit>& input, 
00644                                                          std::map<unsigned, edm::OwnVector<SiTrackerGSRecHit2D> >& temporaryRecHits,
00645                                                          std::map<unsigned, edm::OwnVector<FastTrackerCluster> >& theClusters)
00646 {
00647   
00648   int numberOfPSimHits = 0;
00649   
00650   //  edm::PSimHitContainer::const_iterator isim;
00651   MixCollection<PSimHit>::iterator isim = input.begin();
00652   MixCollection<PSimHit>::iterator lastSimHit = input.end();
00653   correspondingSimHit.resize(input.size());
00654   Local3DPoint position;
00655   LocalError error;
00656   LocalError inflatedError;
00657   
00658   int simHitCounter = -1;
00659   int recHitCounter = 0;
00660   
00661   // loop on PSimHits
00662   for ( ; isim != lastSimHit; ++isim ) {
00663     ++simHitCounter;
00664     DetId det((*isim).detUnitId());
00665     unsigned trackID = (*isim).trackId();
00666     uint32_t eeID = (*isim).eventId().rawId(); //get the rawId of the eeid for pileup treatment
00667 
00668     /*
00669     const GeomDet* theDet = geometry->idToDet(det);
00670     std::cout << "SimHit Track/z/r as simulated : "
00671               << trackID << " " 
00672               << theDet->surface().toGlobal((*isim).localPosition()).z() << " " 
00673               << theDet->surface().toGlobal((*isim).localPosition()).perp() << std::endl;
00674     const GeomDet* theMADet = misAlignedGeometry->idToDet(det);
00675     std::cout << "SimHit Track/z/r as reconstructed : "
00676               << trackID << " " 
00677               << theMADet->surface().toGlobal((*isim).localPosition()).z() << " " 
00678               << theMADet->surface().toGlobal((*isim).localPosition()).perp() << std::endl;
00679     */
00680 
00681     ++numberOfPSimHits; 
00682     // gaussian smearing
00683     unsigned int alphaMult = 0;
00684     unsigned int betaMult  = 0;
00685     bool isCreated = gaussianSmearing(*isim, position, error, alphaMult, betaMult);
00686     // std::cout << "Error as simulated     " << error.xx() << " " << error.xy() << " " << error.yy() << std::endl;
00687     //
00688     unsigned int subdet = det.subdetId();
00689     
00690     //
00691     if(isCreated) {
00692       //      double dist = theDet->surface().toGlobal((*isim).localPosition()).mag2();
00693       // create RecHit
00694       // Fill the temporary RecHit on the current DetId collection
00695       //      temporaryRecHits[trackID].push_back(
00696       
00697       // Fix by P.Azzi, A.Schmidt:
00698       // if this hit is on a glued detector with radial topology, 
00699       // the x-coordinate needs to be translated correctly to y=0.
00700       // this is necessary as intermediate step for the matching of hits
00701 
00702       // do it only if we do rec hit matching
00703 //       if(doMatching){
00704 //      StripSubdetector specDetId=StripSubdetector(det);
00705         
00706 //      if(specDetId.glued()) if(subdet==6 || subdet==4){         // check if on double layer in TEC or TID
00707           
00708 //        const GeomDetUnit* theDetUnit = geometry->idToDetUnit(det);
00709 //        const StripTopology& topol=(const StripTopology&)theDetUnit->topology();      
00710           
00711 //        // check if radial topology
00712 //        if(dynamic_cast <const RadialStripTopology*>(&topol)){
00713             
00714 //          const RadialStripTopology *rtopol = dynamic_cast <const RadialStripTopology*>(&topol);
00715             
00716 //          // translate to measurement coordinates
00717 //          MeasurementPoint mpoint=rtopol->measurementPosition(position);
00718 //          // set y=0
00719 //          MeasurementPoint mpoint0=MeasurementPoint(mpoint.x(),0.);
00720 //          // translate back to local coordinates with y=0
00721 //          LocalPoint lpoint0 = rtopol->localPosition(mpoint0);
00722 //          position = Local3DPoint(lpoint0.x(),0.,0.);
00723             
00724 //        }
00725 //      } // end if( specDetId.glued()...
00726 //       } // end if(doMatching)
00727       
00728       // set y=0 in single-sided strip detectors 
00729       if(doMatching && (subdet>2)){    
00730         StripSubdetector specDetId=StripSubdetector(det);
00731         if( !specDetId.glued() ){  // this is a single-sided module
00732           position = Local3DPoint(position.x(),0.,0.); // set y to 0 on single-sided modules
00733         }
00734       }
00735       else{  if(subdet>2) position = Local3DPoint(position.x(),0.,0.);    }  // no matching, set y=0 on strips
00736 
00737       // Inflate errors in case of geometry misalignment
00738       const GeomDet* theMADet = misAlignedGeometry->idToDet(det);
00739       if ( theMADet->alignmentPositionError() != 0 ) { 
00740         LocalError lape = 
00741           ErrorFrameTransformer().transform ( theMADet->alignmentPositionError()->globalError(),
00742                                               theMADet->surface() );
00743         error = LocalError ( error.xx()+lape.xx(),
00744                              error.xy()+lape.xy(),
00745                              error.yy()+lape.yy() );
00746       }
00747       
00748       float chargeADC = (*isim).energyLoss()/(GevPerElectron * ElectronsPerADC);
00749 
00750       //create cluster
00751       theClusters[trackID].push_back(
00752                                       new FastTrackerCluster(position, error, det,
00753                                                               simHitCounter, trackID,
00754                                                               eeID,
00755                                                               //(*isim).energyLoss())
00756                                                              chargeADC)
00757                                     );
00758       
00759       //       std::cout << "CLUSTER for simhit " << simHitCounter << "\t energy loss = " <<chargeADC << std::endl;
00760       
00761       // std::cout << "Error as reconstructed " << error.xx() << " " << error.xy() << " " << error.yy() << std::endl;
00762 
00763       // create rechit
00764       temporaryRecHits[trackID].push_back(
00765                  new SiTrackerGSRecHit2D(position, error, det, 
00766                                          simHitCounter, trackID, 
00767                                          eeID, 
00768                                          ClusterRef(FastTrackerClusterRefProd, simHitCounter),
00769                                          alphaMult, betaMult)
00770                  );
00771       
00772        // This a correpondence map between RecHits and SimHits 
00773       // (for later  use in matchHits)
00774       correspondingSimHit[recHitCounter++] = isim; 
00775       
00776     } // end if(isCreated)
00777 
00778   } // end loop on PSimHits
00779 
00780 }
00781 
00782 bool SiTrackerGaussianSmearingRecHitConverter::gaussianSmearing(const PSimHit& simHit, 
00783                                                                 Local3DPoint& position , 
00784                                                                 LocalError& error,
00785                                                                 unsigned& alphaMult, 
00786                                                                 unsigned& betaMult) 
00787 {
00788 
00789   // A few caracteritics of the module which the SimHit belongs to.
00790   unsigned int subdet   = DetId(simHit.detUnitId()).subdetId();
00791   unsigned int detid    = DetId(simHit.detUnitId()).rawId();
00792   const GeomDetUnit* theDetUnit = geometry->idToDetUnit((DetId)simHit.detUnitId());
00793   const BoundPlane& theDetPlane = theDetUnit->surface();
00794   const Bounds& theBounds = theDetPlane.bounds();
00795   double boundX = theBounds.width()/2.;
00796   double boundY = theBounds.length()/2.;
00797   
00798 #ifdef FAMOS_DEBUG
00799   std::cout << "\tSubdetector " << subdet 
00800             << " rawid " << detid
00801             << std::endl;
00802 #endif
00803   if(trackingPSimHits) {
00804     // z is fixed for all detectors, in case of errors resolution is fixed also for x and y to 1 um (zero)
00805     // The Matrix is the Covariance Matrix, sigma^2 on diagonal!!!
00806     error = LocalError( localPositionResolution_z * localPositionResolution_z , 
00807                         0.0 , 
00808                         localPositionResolution_z * localPositionResolution_z  );
00809     //
00810     // starting from PSimHit local position
00811     position = simHit.localPosition();
00812 #ifdef FAMOS_DEBUG
00813     std::cout << " Tracking PSimHit position set to  " << position;
00814 #endif
00815     return true; // RecHit == PSimHit with 100% hit finding efficiency
00816   }
00817   //
00818   
00819   // hit finding probability --> RecHit will be created if and only if hitFindingProbability <= theHitFindingProbability_###
00820   double hitFindingProbability = random->flatShoot();
00821 #ifdef FAMOS_DEBUG
00822   std::cout << " Hit finding probability draw: " << hitFindingProbability << std::endl;;
00823 #endif
00824   
00825   switch (subdet) {
00826     // Pixel Barrel
00827   case 1:
00828     {
00829 #ifdef FAMOS_DEBUG
00830       PXBDetId module(detid);
00831       unsigned int theLayer = module.layer();
00832       std::cout << "\tPixel Barrel Layer " << theLayer << std::endl;
00833 #endif
00834       if( hitFindingProbability > theHitFindingProbability_PXB ) return false;
00835       // Hit smearing
00836       const PixelGeomDetUnit* pixelDetUnit = dynamic_cast<const PixelGeomDetUnit*>(theDetUnit);
00837       thePixelBarrelParametrization->smearHit(simHit, pixelDetUnit, boundX, boundY);
00838       position  = thePixelBarrelParametrization->getPosition();
00839       error     = thePixelBarrelParametrization->getError();
00840       alphaMult = thePixelBarrelParametrization->getPixelMultiplicityAlpha();
00841       betaMult  = thePixelBarrelParametrization->getPixelMultiplicityBeta();
00842       return true;
00843       break;
00844     }
00845     // Pixel Forward
00846   case 2:
00847     {
00848 #ifdef FAMOS_DEBUG
00849       PXFDetId module(detid);
00850       unsigned int theDisk = module.disk();
00851       std::cout << "\tPixel Forward Disk " << theDisk << std::endl;
00852 #endif
00853       if( hitFindingProbability > theHitFindingProbability_PXF ) return false;
00854       // Hit smearing
00855       const PixelGeomDetUnit* pixelDetUnit = dynamic_cast<const PixelGeomDetUnit*>(theDetUnit);
00856       thePixelEndcapParametrization->smearHit(simHit, pixelDetUnit, boundX, boundY);
00857       position = thePixelEndcapParametrization->getPosition();
00858       error    = thePixelEndcapParametrization->getError();
00859       alphaMult = thePixelEndcapParametrization->getPixelMultiplicityAlpha();
00860       betaMult  = thePixelEndcapParametrization->getPixelMultiplicityBeta();
00861       return true;
00862       break;
00863     }
00864     // TIB
00865   case 3:
00866     {
00867       TIBDetId module(detid);
00868       unsigned int theLayer  = module.layer();
00869 #ifdef FAMOS_DEBUG
00870       std::cout << "\tTIB Layer " << theLayer << std::endl;
00871 #endif
00872       //
00873       double resolutionX, resolutionY, resolutionZ;
00874       resolutionZ = localPositionResolution_z;
00875       
00876       switch (theLayer) {
00877       case 1:
00878         {
00879           resolutionX = localPositionResolution_TIB1x;
00880           resolutionY = localPositionResolution_TIB1y;
00881           if( hitFindingProbability > theHitFindingProbability_TIB1 ) return false;
00882           break;
00883         }
00884       case 2:
00885         {
00886           resolutionX = localPositionResolution_TIB2x;
00887           resolutionY = localPositionResolution_TIB2y;
00888           if( hitFindingProbability > theHitFindingProbability_TIB2 ) return false;
00889           break;
00890         }
00891       case 3:
00892         {
00893           resolutionX = localPositionResolution_TIB3x;
00894           resolutionY = localPositionResolution_TIB3y;
00895           if( hitFindingProbability > theHitFindingProbability_TIB3 ) return false;
00896           break;
00897         }
00898       case 4:
00899         {
00900           resolutionX = localPositionResolution_TIB4x;
00901           resolutionY = localPositionResolution_TIB4y;
00902           if( hitFindingProbability > theHitFindingProbability_TIB4 ) return false;
00903           break;
00904         }
00905       default:
00906         {
00907           edm::LogError ("SiTrackerGaussianSmearingRecHits") 
00908             << "\tTIB Layer not valid " << theLayer << std::endl;
00909           return false;
00910           break;
00911         }
00912       }
00913 
00914       // Gaussian smearing
00915       theSiStripErrorParametrization->smearHit(simHit, resolutionX, resolutionY, resolutionZ, boundX, boundY);
00916       position = theSiStripErrorParametrization->getPosition();
00917       error    = theSiStripErrorParametrization->getError();
00918       alphaMult = 0;
00919       betaMult  = 0;
00920       return true;
00921       break;
00922     } // TIB
00923     
00924     // TID
00925   case 4:
00926     {
00927       TIDDetId module(detid);
00928       unsigned int theRing  = module.ring();
00929       double resolutionFactorY = 
00930         1. - simHit.localPosition().y() / theDetPlane.position().perp(); 
00931 
00932 #ifdef FAMOS_DEBUG
00933       std::cout << "\tTID Ring " << theRing << std::endl;
00934 #endif
00935       double resolutionX, resolutionY, resolutionZ;
00936       resolutionZ = localPositionResolution_z;
00937       
00938       switch (theRing) {
00939       case 1:
00940         {
00941           resolutionX = localPositionResolution_TID1x * resolutionFactorY;
00942           resolutionY = localPositionResolution_TID1y;
00943           if( hitFindingProbability > theHitFindingProbability_TID1 ) return false;
00944           break;
00945         }
00946       case 2:
00947         {
00948           resolutionX = localPositionResolution_TID2x * resolutionFactorY;
00949           resolutionY = localPositionResolution_TID2y;
00950           if( hitFindingProbability > theHitFindingProbability_TID2 ) return false;
00951           break;
00952         }
00953       case 3:
00954         {
00955           resolutionX = localPositionResolution_TID3x * resolutionFactorY;
00956           resolutionY = localPositionResolution_TID3y;
00957           if( hitFindingProbability > theHitFindingProbability_TID3 ) return false;
00958           break;
00959         }
00960       default:
00961         {
00962           edm::LogError ("SiTrackerGaussianSmearingRecHits") 
00963             << "\tTID Ring not valid " << theRing << std::endl;
00964           return false;
00965           break;
00966         }
00967       }
00968 
00969       boundX *=  resolutionFactorY;
00970 
00971       theSiStripErrorParametrization->smearHit(simHit, resolutionX, resolutionY, resolutionZ, boundX, boundY);
00972       position = theSiStripErrorParametrization->getPosition();
00973       error    = theSiStripErrorParametrization->getError();
00974       alphaMult = 0;
00975       betaMult  = 0;
00976       return true;
00977       break;
00978     } // TID
00979     
00980     // TOB
00981   case 5:
00982     {
00983       TOBDetId module(detid);
00984       unsigned int theLayer  = module.layer();
00985 #ifdef FAMOS_DEBUG
00986       std::cout << "\tTOB Layer " << theLayer << std::endl;
00987 #endif
00988       double resolutionX, resolutionY, resolutionZ;
00989       resolutionZ = localPositionResolution_z;
00990       
00991       switch (theLayer) {
00992       case 1:
00993         {
00994           resolutionX = localPositionResolution_TOB1x;
00995           resolutionY = localPositionResolution_TOB1y;
00996           if( hitFindingProbability > theHitFindingProbability_TOB1 ) return false;
00997           break;
00998         }
00999       case 2:
01000         {
01001           resolutionX = localPositionResolution_TOB2x;
01002           resolutionY = localPositionResolution_TOB2y;
01003           if( hitFindingProbability > theHitFindingProbability_TOB2 ) return false;
01004           break;
01005         }
01006       case 3:
01007         {
01008           resolutionX = localPositionResolution_TOB3x;
01009           resolutionY = localPositionResolution_TOB3y;
01010           if( hitFindingProbability > theHitFindingProbability_TOB3 ) return false;
01011           break;
01012         }
01013       case 4:
01014         {
01015           resolutionX = localPositionResolution_TOB4x;
01016           resolutionY = localPositionResolution_TOB4y;
01017           if( hitFindingProbability > theHitFindingProbability_TOB4 ) return false;
01018           break;
01019         }
01020       case 5:
01021         {
01022           resolutionX = localPositionResolution_TOB5x;
01023           resolutionY = localPositionResolution_TOB5y;
01024           if( hitFindingProbability > theHitFindingProbability_TOB5 ) return false;
01025           break;
01026         }
01027       case 6:
01028         {
01029           resolutionX = localPositionResolution_TOB6x;
01030           resolutionY = localPositionResolution_TOB6y;
01031           if( hitFindingProbability > theHitFindingProbability_TOB6 ) return false;
01032           break;
01033         }
01034       default:
01035         {
01036           edm::LogError ("SiTrackerGaussianSmearingRecHits") 
01037             << "\tTOB Layer not valid " << theLayer << std::endl;
01038           return false;
01039           break;
01040         }
01041       }
01042       theSiStripErrorParametrization->smearHit(simHit, resolutionX, resolutionY, resolutionZ, boundX, boundY);
01043       position = theSiStripErrorParametrization->getPosition();
01044       error    = theSiStripErrorParametrization->getError();
01045       alphaMult = 0;
01046       betaMult  = 0;
01047       return true;
01048       break;
01049     } // TOB
01050     
01051     // TEC
01052   case 6:
01053     {
01054       TECDetId module(detid);
01055       unsigned int theRing  = module.ring();
01056       double resolutionFactorY = 
01057         1. - simHit.localPosition().y() / theDetPlane.position().perp(); 
01058 
01059 #ifdef FAMOS_DEBUG
01060       std::cout << "\tTEC Ring " << theRing << std::endl;
01061 #endif
01062       double resolutionX, resolutionY, resolutionZ;
01063       resolutionZ = localPositionResolution_z * localPositionResolution_z;
01064       
01065       switch (theRing) {
01066       case 1:
01067         {
01068           resolutionX = localPositionResolution_TEC1x * resolutionFactorY;
01069           resolutionY = localPositionResolution_TEC1y;
01070           if( hitFindingProbability > theHitFindingProbability_TEC1 ) return false;
01071           break;
01072         }
01073       case 2:
01074         {
01075           resolutionX = localPositionResolution_TEC2x * resolutionFactorY;
01076           resolutionY = localPositionResolution_TEC2y;
01077           if( hitFindingProbability > theHitFindingProbability_TEC2 ) return false;
01078           break;
01079         }
01080       case 3:
01081         {
01082           resolutionX = localPositionResolution_TEC3x * resolutionFactorY;
01083           resolutionY = localPositionResolution_TEC3y;
01084           if( hitFindingProbability > theHitFindingProbability_TEC3 ) return false;
01085           break;
01086         }
01087       case 4:
01088         {
01089           resolutionX = localPositionResolution_TEC4x * resolutionFactorY;
01090           resolutionY = localPositionResolution_TEC4y;
01091           if( hitFindingProbability > theHitFindingProbability_TEC4 ) return false;
01092           break;
01093         }
01094       case 5:
01095         {
01096           resolutionX = localPositionResolution_TEC5x * resolutionFactorY;
01097           resolutionY = localPositionResolution_TEC5y;
01098           if( hitFindingProbability > theHitFindingProbability_TEC5 ) return false;
01099           break;
01100         }
01101       case 6:
01102         {
01103           resolutionX = localPositionResolution_TEC6x * resolutionFactorY;
01104           resolutionY = localPositionResolution_TEC6y;
01105           if( hitFindingProbability > theHitFindingProbability_TEC6 ) return false;
01106           break;
01107         }
01108       case 7:
01109         {
01110           resolutionX = localPositionResolution_TEC7x * resolutionFactorY;
01111           resolutionY = localPositionResolution_TEC7y;
01112           if( hitFindingProbability > theHitFindingProbability_TEC7 ) return false;
01113           break;
01114         }
01115       default:
01116         {
01117           edm::LogError ("SiTrackerGaussianSmearingRecHits") 
01118             << "\tTEC Ring not valid " << theRing << std::endl;
01119           return false;
01120           break;
01121         }
01122       }
01123 
01124       boundX *= resolutionFactorY;
01125       theSiStripErrorParametrization->smearHit(simHit, resolutionX, resolutionY, resolutionZ, boundX, boundY);
01126       position = theSiStripErrorParametrization->getPosition();
01127       error    = theSiStripErrorParametrization->getError();
01128       alphaMult = 0;
01129       betaMult  = 0;
01130       return true;
01131       break;
01132     } // TEC
01133     
01134   default:
01135     {
01136       edm::LogError ("SiTrackerGaussianSmearingRecHits") << "\tTracker subdetector not valid " << subdet << std::endl;
01137       return false;
01138       break;
01139     }
01140     
01141   } // subdetector case
01142     //
01143 }   
01144 
01145 
01146 
01147 void 
01148     SiTrackerGaussianSmearingRecHitConverter::loadClusters(
01149     std::map<unsigned,edm::OwnVector<FastTrackerCluster> >& theClusterMap, 
01150     FastTrackerClusterCollection& theClusterCollection) const
01151 {
01152   std::map<unsigned,edm::OwnVector<FastTrackerCluster> >::const_iterator 
01153       it = theClusterMap.begin();
01154   std::map<unsigned,edm::OwnVector<FastTrackerCluster> >::const_iterator 
01155       lastCluster = theClusterMap.end();
01156   
01157   for( ; it != lastCluster ; ++it ) { 
01158     theClusterCollection.put(it->first,(it->second).begin(),(it->second).end());
01159   }
01160 }
01161 
01162 
01163 
01164 void 
01165 SiTrackerGaussianSmearingRecHitConverter::loadRecHits(
01166      std::map<unsigned,edm::OwnVector<SiTrackerGSRecHit2D> >& theRecHits, 
01167      SiTrackerGSRecHit2DCollection& theRecHitCollection) const
01168 {
01169   std::map<unsigned,edm::OwnVector<SiTrackerGSRecHit2D> >::const_iterator 
01170     it = theRecHits.begin();
01171   std::map<unsigned,edm::OwnVector<SiTrackerGSRecHit2D> >::const_iterator 
01172     lastRecHit = theRecHits.end();
01173 
01174   for( ; it != lastRecHit ; ++it ) { 
01175     theRecHitCollection.put(it->first,(it->second).begin(),(it->second).end());
01176   }
01177 
01178 }
01179 
01180 void 
01181 SiTrackerGaussianSmearingRecHitConverter::loadMatchedRecHits(
01182      std::map<unsigned,edm::OwnVector<SiTrackerGSMatchedRecHit2D> >& theRecHits, 
01183      SiTrackerGSMatchedRecHit2DCollection& theRecHitCollection) const
01184 {
01185   std::map<unsigned,edm::OwnVector<SiTrackerGSMatchedRecHit2D> >::const_iterator 
01186     it = theRecHits.begin();
01187   std::map<unsigned,edm::OwnVector<SiTrackerGSMatchedRecHit2D> >::const_iterator 
01188     lastRecHit = theRecHits.end();
01189 
01190   for( ; it != lastRecHit ; ++it ) { 
01191     theRecHitCollection.put(it->first,(it->second).begin(),(it->second).end());
01192   }
01193 
01194 }
01195 
01196 
01197 void
01198 SiTrackerGaussianSmearingRecHitConverter::matchHits(
01199   std::map<unsigned, edm::OwnVector<SiTrackerGSRecHit2D> >& theRecHits, 
01200   std::map<unsigned, edm::OwnVector<SiTrackerGSMatchedRecHit2D> >& matchedMap, 
01201   MixCollection<PSimHit>& simhits ) {
01202 
01203   std::map<unsigned, edm::OwnVector<SiTrackerGSRecHit2D> >::iterator it = theRecHits.begin();
01204   std::map<unsigned, edm::OwnVector<SiTrackerGSRecHit2D> >::iterator lastTrack = theRecHits.end();
01205 
01206 
01207   int recHitCounter = 0;
01208 
01209   //loop over single sided tracker RecHit
01210   for(  ; it !=  lastTrack; ++it ) {
01211 
01212     edm::OwnVector<SiTrackerGSRecHit2D>::const_iterator rit = it->second.begin();
01213     edm::OwnVector<SiTrackerGSRecHit2D>::const_iterator firstRecHit = it->second.begin();
01214     edm::OwnVector<SiTrackerGSRecHit2D>::const_iterator lastRecHit = it->second.end();
01215 
01216     //loop over rechits in track
01217     for ( ; rit != lastRecHit; ++rit,++recHitCounter){
01218 
01219       DetId detid = rit->geographicalId();
01220       unsigned int subdet = detid.subdetId();
01221       // if in the strip (subdet>2)
01222       if(subdet>2){
01223 
01224         StripSubdetector specDetId=StripSubdetector(detid);
01225 
01226         // if this is on a glued, then place only one hit in vector
01227         if(specDetId.glued()){
01228 
01229           // get the track direction from the simhit
01230           LocalVector simtrackdir = correspondingSimHit[recHitCounter]->localDirection();           
01231 
01232           const GluedGeomDet* gluedDet = (const GluedGeomDet*)geometry->idToDet(DetId(specDetId.glued()));
01233           const StripGeomDetUnit* stripdet =(StripGeomDetUnit*) gluedDet->stereoDet();
01234           
01235           // global direction of track
01236           GlobalVector globaldir= stripdet->surface().toGlobal(simtrackdir);
01237           LocalVector gluedsimtrackdir=gluedDet->surface().toLocal(globaldir);
01238 
01239           // get partner layer, it is the next one or previous one in the vector
01240           edm::OwnVector<SiTrackerGSRecHit2D>::const_iterator partner = rit;
01241           edm::OwnVector<SiTrackerGSRecHit2D>::const_iterator partnerNext = rit;
01242           edm::OwnVector<SiTrackerGSRecHit2D>::const_iterator partnerPrev = rit;
01243           partnerNext++; partnerPrev--;
01244           
01245           // check if this hit is on a stereo layer (== the second layer of a double sided module)
01246           if(   specDetId.stereo()  ) {
01247         
01248             int partnersFound = 0;
01249             // check next one in vector
01250             // safety check first
01251             if(partnerNext != it->second.end() ) 
01252               if( StripSubdetector( partnerNext->geographicalId() ).partnerDetId() == detid.rawId() )   {
01253                 partner= partnerNext;
01254                 partnersFound++;
01255               }
01256             // check prevoius one in vector     
01257             if( rit !=  it->second.begin()) 
01258               if(  StripSubdetector( partnerPrev->geographicalId() ).partnerDetId() == detid.rawId() ) {
01259                 partnersFound++;
01260                 partner= partnerPrev;
01261               }
01262             
01263             
01264             // in case partner has not been found this way, need to loop over all rechits in track to be sure
01265             // (rare cases fortunately)
01266             if(partnersFound==0){
01267               for(edm::OwnVector<SiTrackerGSRecHit2D>::const_iterator iter = firstRecHit; iter != lastRecHit; ++iter  ){
01268                 if( StripSubdetector( iter->geographicalId() ).partnerDetId() == detid.rawId()){
01269                   partnersFound++;
01270                   partner = iter;
01271                 }
01272               }
01273             }
01274 
01275             if(partnersFound == 1) {
01276               SiTrackerGSMatchedRecHit2D * theMatchedHit =GSRecHitMatcher().match( &(*partner),  &(*rit),  gluedDet  , gluedsimtrackdir );
01277 
01278 
01279               //              std::cout << "Matched  hit: isMatched =\t" << theMatchedHit->isMatched() << ", "
01280               //        <<  theMatchedHit->monoHit() << ", " <<  theMatchedHit->stereoHit() << std::endl;
01281 
01282               matchedMap[it->first].push_back( theMatchedHit );
01283             } 
01284             else{
01285               // no partner to match, place projected one in map
01286               SiTrackerGSMatchedRecHit2D * theProjectedHit = GSRecHitMatcher().projectOnly( &(*rit), geometry->idToDet(detid),gluedDet, gluedsimtrackdir  );
01287               matchedMap[it->first].push_back( theProjectedHit );
01288               //there is no partner here
01289             }
01290           } // end if stereo
01291           else {   // we are on a mono layer
01292             // usually this hit is already matched, but not if stereo hit is missing (rare cases)
01293             // check if stereo hit is missing
01294             int partnersFound = 0;
01295             // check next one in vector
01296             // safety check first
01297             if(partnerNext != it->second.end() ) 
01298               if( StripSubdetector( partnerNext->geographicalId() ).partnerDetId() == detid.rawId() )   {
01299                 partnersFound++;
01300               }
01301             // check prevoius one in vector     
01302             if( rit !=  it->second.begin()) 
01303               if(  StripSubdetector( partnerPrev->geographicalId() ).partnerDetId() == detid.rawId() ) {
01304                 partnersFound++;
01305               }
01306 
01307             if(partnersFound==0){ // no partner hit found this way, need to iterate over all hits to be sure (rare cases)
01308               for(edm::OwnVector<SiTrackerGSRecHit2D>::const_iterator iter = firstRecHit; iter != lastRecHit; ++iter  ){
01309                 if( StripSubdetector( iter->geographicalId() ).partnerDetId() == detid.rawId()){
01310                   partnersFound++;
01311                 }
01312               }
01313             }       
01314             
01315             
01316             if(partnersFound==0){ // no partner hit found 
01317               // no partner to match, place projected one one in map
01318               SiTrackerGSMatchedRecHit2D * theProjectedHit = 
01319                 GSRecHitMatcher().projectOnly( &(*rit), geometry->idToDet(detid),gluedDet, gluedsimtrackdir  );
01320               
01321               //std::cout << "Projected hit: isMatched =\t" << theProjectedHit->isMatched() << ", "
01322               //        <<  theProjectedHit->monoHit() << ", " <<  theProjectedHit->stereoHit() << std::endl;
01323               
01324               matchedMap[it->first].push_back( theProjectedHit );
01325             }       
01326           } // end we are on a a mono layer
01327         } // end if glued 
01328         // else matchedMap[it->first].push_back( rit->clone() );  // if not glued place the original one in vector 
01329         else{ //need to copy the original in a "matched" type rechit
01330 
01331           SiTrackerGSMatchedRecHit2D* rit_copy = new SiTrackerGSMatchedRecHit2D(rit->localPosition(), rit->localPositionError(),
01332                                                                                 rit->geographicalId(), 
01333                                                                                 rit->simhitId(), rit->simtrackId(), rit->eeId(),
01334                                                                                 rit->cluster(),
01335                                                                                 rit->simMultX(), rit->simMultY()); 
01336           //std::cout << "Simple hit  hit: isMatched =\t" << rit_copy->isMatched() << ", "
01337           //    <<  rit_copy->monoHit() << ", " <<  rit_copy->stereoHit() << std::endl;
01338           
01339           matchedMap[it->first].push_back( rit_copy );  // if not strip place the original one in vector (making it into a matched)     
01340         }
01341         
01342       }// end if strip
01343       //      else  matchedMap[it->first].push_back( rit->clone() );  // if not strip place the original one in vector
01344       else { //need to copy the original in a "matched" type rechit
01345 
01346         SiTrackerGSMatchedRecHit2D* rit_copy = new SiTrackerGSMatchedRecHit2D(rit->localPosition(), rit->localPositionError(),
01347                                                                               rit->geographicalId(), 
01348                                                                               rit->simhitId(), rit->simtrackId(), rit->eeId(), 
01349                                                                               rit->cluster(),
01350                                                                               rit->simMultX(), rit->simMultY());        
01351         
01352         //std::cout << "Simple hit  hit: isMatched =\t" << rit_copy->isMatched() << ", "
01353         //        <<  rit_copy->monoHit() << ", " <<  rit_copy->stereoHit() << std::endl;
01354         matchedMap[it->first].push_back( rit_copy );  // if not strip place the original one in vector (makining it into a matched)
01355      }
01356       
01357     } // end loop over rechits
01358     
01359   }// end loop over tracks
01360   
01361   
01362 }

Generated on Tue Jun 9 17:35:17 2009 for CMSSW by  doxygen 1.5.4