CMS 3D CMS Logo

FP420DigiMain.cc

Go to the documentation of this file.
00001 
00002 // File: FP420DigiMain.cc
00003 // Date: 12.2006
00004 // Description: FP420DigiMain for FP420
00005 // Modifications: 
00007 #include "SimDataFormats/TrackingHit/interface/PSimHit.h"
00008 #include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
00009 
00010 //#include "SimG4CMS/FP420/interface/FP420G4HitCollection.h"
00011 //#include "SimG4CMS/FP420/interface/FP420G4Hit.h"
00012 #include "SimRomanPot/SimFP420/interface/FP420DigiMain.h"
00013 
00014 #include "SimRomanPot/SimFP420/interface/ChargeDrifterFP420.h"
00015 #include "SimRomanPot/SimFP420/interface/ChargeDividerFP420.h"
00016 
00017 //#include "SimRomanPot/SimFP420/interface/HDigiFP420.h"
00018 #include "DataFormats/FP420Digi/interface/HDigiFP420.h"
00019 //#include "DataFormats/SiStripDigi/interface/SiStripDigi.h"
00020 //#include "DataFormats/Common/interface/DetSetVector.h"
00021 //#include "SimDataFormats/TrackerDigiSimLink/interface/StripDigiSimLink.h"
00022 
00023 
00024 
00025 
00026 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00027 #include <gsl/gsl_sf_erf.h>
00028 #include "CLHEP/Random/RandGauss.h"
00029 #include "CLHEP/Random/RandFlat.h"
00030 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00031 
00032 // Here zside = xytype - type of plate
00033 
00034 #include <vector>
00035 #include <iostream>
00036 using namespace std;
00037 
00038 //#define CBOLTZ (1.38E-23)
00039 //#define e_SI (1.6E-19)
00040 
00041 
00042 
00043 FP420DigiMain::FP420DigiMain(const edm::ParameterSet& conf):conf_(conf){
00044   std::cout << "Creating a FP420DigiMain" << std::endl;
00045   ndigis=0;
00046   verbosity        = conf_.getUntrackedParameter<int>("VerbosityLevel");
00047   theElectronPerADC= conf_.getParameter<double>("ElectronFP420PerAdc");
00048   theThreshold     = conf_.getParameter<double>("AdcFP420Threshold");
00049   noNoise          = conf_.getParameter<bool>("NoFP420Noise");
00050   addNoisyPixels   = conf_.getParameter<bool>("AddNoisyPixels");
00051   thez420          = conf_.getParameter<double>("z420");
00052   thezD2           = conf_.getParameter<double>("zD2");
00053   thezD3           = conf_.getParameter<double>("zD3");
00054   theApplyTofCut   = conf_.getParameter<bool>("ApplyTofCut");
00055   tofCut           = conf_.getParameter<double>("LowtofCutAndTo200ns");
00056   xytype=2;
00057   
00058   if(verbosity>0) {
00059     std::cout << "theApplyTofCut=" << theApplyTofCut << " tofCut=" << tofCut << std::endl;
00060     std::cout << "FP420DigiMain theElectronPerADC=" << theElectronPerADC << " theThreshold=" << theThreshold << " noNoise=" << noNoise << std::endl;
00061   }
00062   // X (or Y)define type of sensor (zside=1 or 2 used to derive it: 1-Y, 2-X)
00063   // for every type there is normal pixel size=0.05 and Wide 0.400 mm
00064   Thick300 = 0.300;       // = 0.300 mm  normalized to 300micron Silicon
00065   //ENC= 2160.;             //          EquivalentNoiseCharge300um = 2160. + other sources of noise
00066   ENC= 960.;             //          EquivalentNoiseCharge300um = 2160. + other sources of noise
00067   
00068   ldriftX = 0.050;        // in mm(zside=1)
00069   ldriftY = 0.050;        // in mm(zside=2)
00070   moduleThickness = 0.250; // mm(zside=1)(zside=2)
00071   
00072   pitchY= 0.050;          // in mm(zside=1)
00073   pitchX= 0.050;          // in mm(zside=2)
00074   numStripsY = 201;        // Y plate number of strips:200*0.050=10mm (zside=1)
00075   numStripsX = 401;        // X plate number of strips:400*0.050=20mm (zside=2)
00076   
00077   pitchYW= 0.400;          // in mm(zside=1)
00078   pitchXW= 0.400;          // in mm(zside=2)
00079   numStripsYW = 51;        // Y plate number of W strips:50 *0.400=20mm (zside=1) - W have ortogonal projection
00080   numStripsXW = 26;        // X plate number of W strips:25 *0.400=10mm (zside=2) - W have ortogonal projection
00081   
00082   //  tofCut = 1350.;           // Cut on the particle TOF range  = 1380 - 1500
00083   elossCut = 0.00003;           // Cut on the particle TOF   = 100 or 50
00084   
00085   
00086   if(verbosity>0) {
00087     std::cout << "FP420DigiMain moduleThickness=" << moduleThickness << std::endl;
00088   }
00089   
00090   
00091   
00092   theFP420NumberingScheme = new FP420NumberingScheme();
00093   
00094   float noiseRMS = ENC*moduleThickness/Thick300;
00095   
00096   theZSuppressFP420 = new ZeroSuppressFP420(conf_,noiseRMS/theElectronPerADC); 
00097   thePileUpFP420 = new PileUpFP420();
00098   theDConverterFP420 = new DigiConverterFP420(theElectronPerADC);
00099   
00100   if(verbosity>0) {
00101     std::cout << "FP420DigiMain end of constructor" << std::endl;
00102   }
00103 }
00104 FP420DigiMain::~FP420DigiMain(){
00105   if(verbosity>0) {
00106     std::cout << "Destroying a FP420DigiMain" << std::endl;
00107   }
00108   delete theGNoiseFP420;
00109   delete theZSuppressFP420;
00110   delete theHitDigitizerFP420;
00111   delete thePileUpFP420;
00112   delete theDConverterFP420;
00113   
00114 }
00115 
00116 
00117 
00118 //  Run the algorithm
00119 //  ------------------
00120 
00121 vector <HDigiFP420> FP420DigiMain::run(const std::vector<PSimHit> &input,
00122                                        G4ThreeVector bfield, unsigned int iu )  {
00123   //                                   G4ThreeVector bfield, unsigned int iu, int sScale)  {
00124   
00125   //  // unpack from iu:
00126   //  //  int  sScale = 20, zScale=2;
00127   //  int  zScale=2;
00128   //  int  sector = (iu-1)/sScale + 1 ;
00129   //  int  zmodule = (iu - (sector - 1)*sScale - 1) /zScale + 1 ;
00130   //  int  zside = iu - (sector - 1)*sScale - (zmodule - 1)*zScale ;
00131   //  if(verbosity>10) {
00132   //    std::cout << "FP420DigiMain xytype=" << xytype << " zside=" << zside << " zmodule=" << zmodule << " sector=" << sector << std::endl;
00133   //  }
00134   
00135   // Y:
00136   if (xytype ==1) {
00137     numStrips = numStripsY;  // Y plate number of strips:200*0.050=10mm --> 100*0.100=10mm
00138     pitch= pitchY;
00139     ldrift = ldriftX; // because drift is in local coordinates which 90 degree rotated ( for correct timeNormalization & noiseRMS calculations)
00140     numStripsW = numStripsYW;  // Y plate number of strips:200*0.050=10mm --> 100*0.100=10mm
00141     pitchW= pitchYW;
00142   }
00143   // X:
00144   if (xytype ==2) {
00145     numStrips = numStripsX;  // X plate number of strips:400*0.050=20mm --> 200*0.100=20mm
00146     pitch= pitchX;
00147     ldrift = ldriftY; // because drift is in local coordinates which 90 degree rotated ( for correct timeNormalization & noiseRMS calculations)
00148     numStripsW = numStripsXW;  // X plate number of strips:400*0.050=20mm --> 200*0.100=20mm
00149     pitchW= pitchXW;
00150   }
00151   
00152   float noiseRMS = ENC*moduleThickness/Thick300;
00153   
00154   
00155   theHitDigitizerFP420 = new HitDigitizerFP420(moduleThickness,ldrift,ldriftY,ldriftX,thez420,thezD2,thezD3);
00156   int numPixels = numStrips*numStripsW;
00157   theGNoiseFP420 = new GaussNoiseFP420(numPixels,noiseRMS,theThreshold,addNoisyPixels);
00158   //  theGNoiseFP420 = new GaussNoiseFP420(numStrips,noiseRMS,theThreshold,addNoisyPixels);
00159   
00160   
00161   
00162   
00163   thePileUpFP420->reset();
00164   //  unsigned int detID = det->globalId().rawId();
00165   //  unsigned int detID = 1;
00166   bool first = true; // AG
00167   
00168   // main loop (AZ) 
00169   //
00170   // First: loop on the SimHits
00171   //
00172   vector<PSimHit>::const_iterator simHitIter = input.begin();
00173   vector<PSimHit>::const_iterator simHitIterEnd = input.end();
00174   for (;simHitIter != simHitIterEnd; ++simHitIter) {
00175     
00176     const PSimHit ihit = *simHitIter;
00177     // detID (AG)
00178     if ( first ) {
00179       //       detID = ihit.detUnitId();    // AZ
00180       first = false;
00181     }
00182     // main part here (AZ):
00183     double  losenergy = ihit.energyLoss();
00184     float   tof = ihit.tof();
00185     //ouble  losenergy = ihit.getEnergyLoss();
00186     //float   tof = ihit.getTof();
00187     if(verbosity>0) {
00188       unsigned int unitID = ihit.detUnitId();
00189       //    //      int det, zside, sector, zmodule;
00190       //    //      FP420NumberingScheme::unpackFP420Index(unitID, det, zside, sector, zmodule);
00191       //    //        int  sScale = 20;
00192       //    // intindex is a continues numbering of FP420
00193       //    //    int zScale=2;  unsigned int intindex = sScale*(sector - 1)+zScale*(zmodule - 1)+zside; 
00194       //    // int zScale=10;   unsigned int intindex = sScale*(sector - 1)+zScale*(zside - 1)+zmodule;
00195       std::cout << " *******FP420DigiMain:                           intindex= " << iu << std::endl;
00196       std::cout << " tof= " << tof << "  EnergyLoss= " << losenergy  << "  pabs= " <<  ihit.pabs() << std::endl;
00197       std::cout << " EntryLocalP x= " << ihit.entryPoint().x() << " EntryLocalP y= " << ihit.entryPoint().y() << std::endl;
00198       std::cout << " ExitLocalP x= " << ihit.exitPoint().x() << " ExitLocalP y= " << ihit.exitPoint().y() << std::endl;
00199       std::cout << " EntryLocalP z= " << ihit.entryPoint().z() << " ExitLocalP z= " << ihit.exitPoint().z() << std::endl;
00200       std::cout << " unitID= " << unitID << "  xytype= " << xytype << " particleType= " << ihit.particleType() << " trackId= " << ihit.trackId() << std::endl;
00201       //    std::cout << " sector= " << sector << "  zmodule= " << zmodule << std::endl;
00202       std::cout << "  bfield= " << bfield << std::endl;
00203     }
00204 
00205   if(verbosity>0) {
00206       std::cout << " *******FP420DigiMain:                           theApplyTofCut= " << theApplyTofCut << std::endl;
00207       std::cout << " tof= " << tof << "  EnergyLoss= " << losenergy  << "  pabs= " <<  ihit.pabs() << std::endl;
00208       std::cout << " particleType= " << ihit.particleType() << std::endl;
00209   }
00210     if ( ( !(theApplyTofCut)  ||  (theApplyTofCut &&   tofCut < abs(tof) < (tofCut+200.)) ) && losenergy > elossCut) {
00211       //    if ( abs(tof) < tofCut && losenergy > elossCut) {
00212       // if ( losenergy>0) {
00213       if(verbosity>0) std::cout << " inside tof: OK " << std::endl;
00214       
00215       //   zside = 1 - Y strips;   =2 - X strips;
00216       //          HitDigitizerFP420::hit_map_type _temp = theHitDigitizerFP420->processHit(ihit,bfield,zside,numStrips,pitch);
00217       HitDigitizerFP420::hit_map_type _temp = theHitDigitizerFP420->processHit(ihit,bfield,xytype,numStrips,pitch,numStripsW,pitchW,moduleThickness); 
00218       
00219       
00220       
00221       thePileUpFP420->add(_temp,ihit);
00222       
00223     }// if
00224     else {
00225       //    std::cout << " *******FP420DigiMain: ERROR???  losenergy =  " <<  losenergy  << std::endl;
00226     }
00227     // main part end (AZ) 
00228   } //for
00229   // main loop end (AZ) 
00230   
00231   PileUpFP420::signal_map_type theSignal = thePileUpFP420->dumpSignal();
00232   PileUpFP420::HitToDigisMapType theLink = thePileUpFP420->dumpLink();  
00233   
00234   
00235   PileUpFP420::signal_map_type afterNoise;
00236   
00237   if (noNoise) {
00238     afterNoise = theSignal;
00239   } else {
00240     afterNoise = theGNoiseFP420->addNoise(theSignal);
00241     //    add_noise();
00242   }
00243   
00244   //  if((pixelInefficiency>0) && (_signal.size()>0)) 
00245   //  pixel_inefficiency(); // Kill some pixels
00246   
00247   
00248   
00249   digis.clear();
00250   
00251   
00252   
00253   //                                                                                                                !!!!!
00254   push_digis(theZSuppressFP420->zeroSuppress(theDConverterFP420->convert(afterNoise)),
00255              theLink,afterNoise);
00256   
00257   
00258   
00259   return digis; // to HDigiFP420
00260 }
00261 
00262 
00263 
00264 
00265 
00266 void FP420DigiMain::push_digis(const DigitalMapType& dm,
00267                                const HitToDigisMapType& htd,
00268                                const PileUpFP420::signal_map_type& afterNoise
00269                                )        {
00270   //  
00271   if(verbosity>0) {
00272     std::cout << " ****FP420DigiMain: push_digis start: do for loop dm.size()=" <<  dm.size() << std::endl;
00273   }
00274   
00275   
00276   digis.reserve(50); 
00277   digis.clear();
00278   //   link_coll.clear();
00279   for ( DigitalMapType::const_iterator i=dm.begin(); i!=dm.end(); i++) {
00280     
00281     // Load digis
00282     // push to digis the content of first and second words of HDigiFP420 vector for every strip pointer (*i)
00283     digis.push_back( HDigiFP420( (*i).first, (*i).second));
00284     ndigis++; 
00285     // very useful check:
00286     if(verbosity>0) {
00287       std::cout << " ****FP420DigiMain:push_digis:  ndigis = " << ndigis << std::endl;
00288       std::cout << "push_digis: strip  = " << (*i).first << "  adc = " << (*i).second << std::endl;
00289     }    
00290     
00291   }
00292   
00294   /*       
00295   //
00296   // reworked to access the fraction of amplitude per simhit PSimHit
00297   //
00298   for ( HitToDigisMapType::const_iterator mi=htd.begin(); mi!=htd.end(); mi++) {
00299   #ifdef mydigidebug1
00300   std::cout << " ****push_digis:first for:  (*mi).first = " << (*mi).first << std::endl;
00301   std::cout << " if condition   = " << (*((const_cast<DigitalMapType * >(&dm))))[(*mi).first] << std::endl;
00302   #endif
00303   //    if ((*((const_cast<DigitalMapType * >(&dm))))[(*mi).first] != 0){
00304   if ((*((const_cast<DigitalMapType * >(&dm)))).find((*mi).first) != (*((const_cast<DigitalMapType * >(&dm)))).end() ){
00305   //
00306   // For each channel, sum up the signals from a simtrack
00307   //
00308   map<const PSimHit *, Amplitude> totalAmplitudePerSimHit;
00309   for (vector < pair < const PSimHit*, Amplitude > >::const_iterator simul = 
00310   (*mi).second.begin() ; simul != (*mi).second.end(); simul ++){
00311   #ifdef mydigidebug1
00312   std::cout << " ****push_digis:inside last for: (*simul).second= " << (*simul).second << std::endl;
00313   #endif
00314   totalAmplitudePerSimHit[(*simul).first] += (*simul).second;
00315   } // for
00316   }  // if
00317   } // for
00318   */
00319   
00321     
00322     // reworked to access the fraction of amplitude per simhit
00323     
00324     for ( HitToDigisMapType::const_iterator mi=htd.begin(); mi!=htd.end(); mi++) {
00325       //      
00326       if ((*((const_cast<DigitalMapType * >(&dm)))).find((*mi).first) != (*((const_cast<DigitalMapType * >(&dm)))).end() ){
00327         // --- For each channel, sum up the signals from a simtrack
00328         //
00329         map<const PSimHit *, Amplitude> totalAmplitudePerSimHit;
00330         for (vector < pair < const PSimHit*, Amplitude > >::const_iterator simul =
00331                (*mi).second.begin() ; simul != (*mi).second.end(); simul ++){
00332           totalAmplitudePerSimHit[(*simul).first] += (*simul).second;
00333         }
00334         /*      
00335         //--- include the noise as well
00336         
00337         PileUpFP420::signal_map_type& temp1 = const_cast<PileUpFP420::signal_map_type&>(afterNoise);
00338         float totalAmplitude1 = temp1[(*mi).first];
00339         
00340         //--- digisimlink
00341         for (map<const PSimHit *, Amplitude>::const_iterator iter = totalAmplitudePerSimHit.begin();
00342         iter != totalAmplitudePerSimHit.end(); iter++){
00343         
00344         float threshold = 0.;
00345         if (totalAmplitudePerSimHit[(*iter).first]/totalAmplitude1 >= threshold) {
00346         float fraction = totalAmplitudePerSimHit[(*iter).first]/totalAmplitude1;
00347         
00348         //Noise fluctuation could make fraction>1. Unphysical, set it by hand.
00349         if(fraction >1.) fraction = 1.;
00350         
00351         link_coll.push_back(StripDigiSimLink( (*mi).first,   //channel
00352         ((*iter).first)->trackId(), //simhit
00353         fraction));    //fraction
00354         }//if
00355         }//for
00356         */
00357         //
00358       }//if
00359     }//for
00360     //
00361     //
00363       //      
00364       //      
00365       //      
00366       }

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