CMS 3D CMS Logo

DigitizerFP420.cc

Go to the documentation of this file.
00001 
00002 // File: DigitizerFP420.cc
00003 // Date: 12.2006
00004 // Description: DigitizerFP420 for FP420
00005 // Modifications: 
00007 //
00008 // system include files
00009 #include <memory>
00010 
00011 #include "DataFormats/Common/interface/DetSetVector.h"
00012 //#include "DataFormats/SiStripDigi/interface/SiStripDigi.h"
00013 //#include "DataFormats/SiStripDigi/interface/SiStripRawDigi.h"
00014 //#include "SimDataFormats/TrackerDigiSimLink/interface/StripDigiSimLink.h"
00015 
00016 // user include files
00017 #include "FWCore/Framework/interface/Frameworkfwd.h"
00018 #include "FWCore/Framework/interface/EDProducer.h"
00019 
00020 #include "FWCore/Framework/interface/Event.h"
00021 #include "FWCore/Framework/interface/MakerMacros.h"
00022 
00023 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00024 #include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
00025 #include "SimDataFormats/TrackingHit/interface/PSimHit.h"
00026 #include "SimDataFormats/CrossingFrame/interface/CrossingFrame.h"
00027 #include "SimDataFormats/CrossingFrame/interface/MixCollection.h"
00029 #include "SimRomanPot/SimFP420/interface/DigitizerFP420.h"
00030 #include "DataFormats/FP420Digi/interface/DigiCollectionFP420.h"
00031 #include "DataFormats/FP420Digi/interface/HDigiFP420.h"
00032 //#include "SimRomanPot/SimFP420/interface/DigiCollectionFP420.h"
00033 //#include "SimG4CMS/FP420/interface/FP420G4HitCollection.h"
00034 //#include "SimG4CMS/FP420/interface/FP420G4Hit.h"
00035 
00036 //needed for the geometry:
00037 #include "FWCore/Framework/interface/EventSetup.h"
00038 #include "FWCore/Framework/interface/ESHandle.h"
00039 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00040 #include "Geometry/CommonDetUnit/interface/GeomDetType.h"
00041 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00042 #include "Geometry/TrackerNumberingBuilder/interface/GeometricDet.h"
00043 //#include "Geometry/CommonTopologies/interface/StripTopology.h"
00044 //#include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetType.h"
00045 //#include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetUnit.h"
00046 //needed for the magnetic field:
00047 //#include "MagneticField/Engine/interface/MagneticField.h"
00048 //#include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00049 //#include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
00050 #include "SimGeneral/HepPDTRecord/interface/ParticleDataTable.h"
00051 
00052 //Data Base infromations
00053 //#include "CondFormats/DataRecord/interface/SiStripLorentzAngleRcd.h"
00054 //#include "CalibTracker/Records/interface/SiStripGainRcd.h"
00055 //#include "CondFormats/DataRecord/interface/SiStripNoisesRcd.h"
00056 //#include "CondFormats/DataRecord/interface/SiStripPedestalsRcd.h"
00057 //#include "CondFormats/SiStripObjects/interface/SiStripLorentzAngle.h"
00058 //#include "CondFormats/SiStripObjects/interface/SiStripNoises.h"
00059 //#include "CondFormats/SiStripObjects/interface/SiStripPedestals.h"
00060 //#include "CalibFormats/SiStripObjects/interface/SiStripGain.h"
00061 //#include "CalibTracker/Records/interface/SiStripDetCablingRcd.h"
00062 //#include "CalibFormats/SiStripObjects/interface/SiStripDetCabling.h"
00063 
00064 //Random Number
00065 #include "FWCore/ServiceRegistry/interface/Service.h"
00066 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
00067 #include "FWCore/Utilities/interface/Exception.h"
00068 #include "CLHEP/Random/RandomEngine.h"
00069 
00070 // G4 stuff
00071 #include "G4SDManager.hh"
00072 #include "G4Step.hh"
00073 #include "G4Track.hh"
00074 #include "G4VProcess.hh"
00075 #include "G4HCofThisEvent.hh"
00076 #include "G4UserEventAction.hh"
00077 #include "G4TransportationManager.hh"
00078 #include "G4ProcessManager.hh"
00079 
00080 #include <cstdlib> 
00081 #include <vector>
00082 
00083 using namespace std;
00084 
00085 //#include <iostream>
00086 
00087 
00088 
00089 
00090 namespace cms
00091 {
00092 DigitizerFP420::DigitizerFP420(const edm::ParameterSet& conf):conf_(conf),stripDigitizer_(new FP420DigiMain(conf)) {
00093 
00094 
00095     std::string alias ( conf.getParameter<std::string>("@module_label") );
00096 
00097   //  produces<edm::DetSetVector<HDigiFP420> >().setBranchAlias( alias );
00098   //  produces<edm::DetSetVector<HDigiFP420SimLink> >().setBranchAlias ( alias + "hDigiFP420SimLink");
00099     produces<DigiCollectionFP420>().setBranchAlias( alias );
00100 
00101     trackerContainers.clear();
00102     trackerContainers = conf.getParameter<std::vector<std::string> >("ROUList");
00103 
00104     verbosity = conf_.getUntrackedParameter<int>("VerbosityLevel");
00105     dn0   = conf_.getParameter<int>("NumberFP420Detectors");
00106     sn0   = conf_.getParameter<int>("NumberFP420Stations");
00107     pn0 = conf_.getParameter<int>("NumberFP420SPlanes");
00108 
00109  //  produces<DigiCollectionFP420>();
00110 
00111   //  produces<StripDigiCollection>();
00112   //   produces<HDigiFP420>();
00113   //  produces<edm::DetSetVector<HDigiFP420> >().setBranchAlias( alias );  
00114 
00115  //  produces<DigiCollectionFP420>();
00116   // produces<DigiCollectionFP420>("HDigiFP420");
00117 
00118  //  produces<edm::DigiCollectionFP420>();
00119 
00120   //   produces<edm::DetSetVector<DigiCollectionFP420> >();
00121 
00122     if(verbosity>0) {
00123       std::cout << "Creating a DigitizerFP420" << std::endl;
00124       std::cout << "DigitizerFP420: dn0=" << dn0 << " sn0=" << sn0 << " pn0=" << pn0 << std::endl;
00125       std::cout << "DigitizerFP420:trackerContainers.size()=" << trackerContainers.size() << std::endl;
00126 
00127     }
00128 }
00129 
00130 // Virtual destructor needed.
00131   DigitizerFP420::~DigitizerFP420() { 
00132     if(verbosity>0) {
00133       std::cout << "Destroying a DigitizerFP420" << std::endl;
00134     }
00135     delete stripDigitizer_;
00136     
00137   }  
00138   
00139 
00140 
00141   //  void DigitizerFP420::produce(PSimHitCollection *   theCAFI, DigiCollectionFP420 & output) {
00142   void DigitizerFP420::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)  {
00143   // be lazy and include the appropriate namespaces
00144    using namespace edm; 
00145    using namespace std;   
00146     
00147     if(verbosity>0) {
00148               std::cout <<" ===" << std::endl;
00149               std::cout <<" ============== DigitizerFP420: start   produce= " << std::endl;
00150               std::cout <<" ===" << std::endl;
00151     }
00152   // Get input
00153 //    std::cout << "DigitizerFP420 start produce" << std::endl;
00154 //  edm::ESHandle < ParticleDataTable > pdt;
00155 //  iSetup.getData( pdt );
00156     
00157     // Step A: Get Inputs for allTrackerHits
00158     edm::Handle<CrossingFrame<PSimHit> > cf_simhit;
00159     std::vector<const CrossingFrame<PSimHit> *> cf_simhitvec;
00160     for(uint32_t i = 0; i< trackerContainers.size();i++){
00161       iEvent.getByLabel("mix",trackerContainers[i],cf_simhit);
00162       cf_simhitvec.push_back(cf_simhit.product());   }
00163     std::auto_ptr<MixCollection<PSimHit> > allTrackerHits(new MixCollection<PSimHit>(cf_simhitvec));
00164 
00165   // use instead of the previous
00166     /*
00167     Handle<CrossingFrame<PSimHit> > xFrame;
00168     iEvent.getByLabel("mix","FP420SI",xFrame);
00169     auto_ptr<MixCollection<PSimHit> > allTrackerHits( new MixCollection<PSimHit>(xFrame.product()) );
00170 */
00171 
00172   // use instead of the previous
00173     /*
00174     edm::Handle<CrossingFrame<PSimHit> > crossingFrame;
00175       const std::string FP420HitsName("FP420SI");
00176     bool isHit = true;
00177     iEvent.getByLabel("mix",FP420HitsName,crossingFrame);
00178       MixCollection<PSimHit> * FP420Hits = 0 ;
00179     //    std::auto_ptr<MixCollection<PSimHit> > allTrackerHits(new MixCollection<PSimHit>(crossingFrame.product()));
00180        FP420Hits = new MixCollection<PSimHit>(crossingFrame.product());
00181     //  if ( ! FP420Hits->inRegistry()  ) isHit = false;
00182     //  if ( isHit ) {
00183      std::auto_ptr<MixCollection<PSimHit> >  allTrackerHits( FP420Hits );
00184     //  }  
00185 */
00186 
00187 //    std::cout << "DigitizerFP420 Step A done" << std::endl;
00188     
00189     //Loop on PSimHit
00190     
00191 
00193     // Step C: create empty output collection
00194       std::auto_ptr<DigiCollectionFP420> output(new DigiCollectionFP420);
00195   //  std::auto_ptr<edm::DetSetVector<HDigiFP420> > outputfinal(new edm::DetSetVector<HDigiFP420>(output) );
00196   //  std::auto_ptr<edm::DetSetVector<HDigiFP420> > outputfinal(new edm::DetSetVector<HDigiFP420>(output) );
00197   //  std::auto_ptr<edm::DetSetVector<HDigiFP420SimLink> > outputlink(new edm::DetSetVector<HDigiFP420SimLink>(output) );
00198 
00199         SimHitMap.clear();
00200 
00201   // ==================================
00202     if(verbosity>0) {
00203               std::cout <<" ===" << std::endl;
00204               std::cout <<" ============== DigitizerFP420: MixCollection treatment= " << std::endl;
00205               std::cout <<" ===" << std::endl;
00206     }
00207   
00208         MixCollection<PSimHit>::iterator isim;
00209         for (isim=allTrackerHits->begin(); isim!= allTrackerHits->end();isim++) {
00210           unsigned int unitID = (*isim).detUnitId();
00211           int det, zside, sector, zmodule, sScale = 2*(pn0-1), dScale = 2*(pn0-1)*(sn0-1);
00212           FP420NumberingScheme::unpackFP420Index(unitID, det, zside, sector, zmodule);
00213           int zScale=2;  unsigned int intindex = dScale*(det - 1)+sScale*(sector - 1)+zScale*(zmodule - 1)+zside;
00214     if(verbosity>0) {
00215           double  losenergy = (*isim).energyLoss();
00216               std::cout <<" ===" << std::endl;
00217               std::cout <<" ============== DigitizerFP420:  losenergy= " << losenergy << std::endl;
00218               std::cout <<" === for intindex = " << intindex << std::endl;
00219     }
00220 
00221           SimHitMap[intindex].push_back((*isim));
00222           // SimHitMap[unitID].push_back((*isim));
00223         }
00224         //============================================================================================================================
00225 
00226     if(verbosity>0) {
00227               std::cout <<" ===" << std::endl;
00228               std::cout <<" ============== DigitizerFP420: put zero to container " << std::endl;
00229               std::cout <<" ===" << std::endl;
00230     }
00231         //    put zero to container info from the beginning (important! because not any detID is updated with coming of new event     !!!!!!   
00232         // clean info of container from previous event
00233         for (int det=1; det<dn0; det++) {
00234           for (int sector=1; sector<sn0; sector++) {
00235             for (int zmodule=1; zmodule<pn0; zmodule++) {
00236               for (int zside=1; zside<3; zside++) {
00237                 int sScale = 2*(pn0-1), dScale = 2*(pn0-1)*(sn0-1);
00238                 //      int index = FP420NumberingScheme::packFP420Index(det, zside, sector, zmodule);
00239                 // intindex is a continues numbering of FP420
00240                 int zScale=2;  unsigned int detID = dScale*(det - 1)+sScale*(sector - 1)+zScale*(zmodule - 1)+zside;
00241                 std::vector<HDigiFP420> collector;
00242                 collector.clear();
00243                 DigiCollectionFP420::Range inputRange;
00244                 inputRange.first = collector.begin();
00245                 inputRange.second = collector.end();
00246                 output->putclear(inputRange,detID);
00247               }//for
00248             }//for
00249           }//for
00250         }//for
00251         //                                                                                                                      !!!!!!   
00252         // if we want to keep Digi container/Collection for one event uncomment the line below and vice versa
00253         output->clear();   //container_.clear() --> start from the beginning of the container
00254         
00255         //============================================================================================================================================
00256         
00257         
00258     if(verbosity>0) {
00259               std::cout <<" ===" << std::endl;
00260               std::cout <<" ============== DigitizerFP420: start loop over det iu " << std::endl;
00261               std::cout <<" ===" << std::endl;
00262     }
00263         bool first = true;
00264         for (int det=1; det<dn0; det++) {
00265           for (int sector=1; sector<sn0; sector++) {
00266             for (int zmodule=1; zmodule<pn0; zmodule++) {
00267               for (int zside=1; zside<3; zside++) {
00268                 
00269                 int sScale = 2*(pn0-1), dScale = 2*(pn0-1)*(sn0-1);
00270                 //      int index = CaloNumberingPacker::packCastorIndex(det,zside, sector, zmodule);
00271                 
00272                 // intindex is a continues numbering of FP420
00273                 int zScale=2;  unsigned int iu = dScale*(det - 1)+sScale*(sector - 1)+zScale*(zmodule - 1)+zside;
00274                 // int zScale=10;       unsigned int intindex = sScale*(sector - 1)+zScale*(zside - 1)+zmodule;
00275                 if(verbosity>0) {
00276                   int index = FP420NumberingScheme::packFP420Index(det, zside, sector, zmodule);
00277                   std::cout << " DigitizerFP420:2 run loop   index = " <<  index <<  " iu = " << iu  << std::endl;
00278                 }
00279                 
00280                 //    GlobalVector bfield=pSetup->inTesla((*iu)->surface().position());
00281                 //      CLHEP::Hep3Vector Bfieldloc=bfield();
00282                 G4ThreeVector bfield(  0.,  0.,  0.0  );
00283                 //      G4ThreeVector bfield(  0.5,  0.5,  1.0  );
00284                 
00285                 
00286                 if(verbosity>0) {
00287                   std::cout <<" ===" << std::endl;
00288                   std::cout <<" ============== DigitizerFP420:  call run for iu= " << iu << std::endl;
00289                   std::cout <<" ===" << std::endl;
00290                 }
00291                 collector.clear();
00292                 
00293                 collector= stripDigitizer_->run( SimHitMap[iu],
00294                                                  bfield,
00295                                                  iu
00296                                                  ); // stripDigitizer_.run...  return 
00297                 //                                               ,sScale
00298                 
00299                 
00300                 
00301                 if(verbosity>0) {
00302                   std::cout <<" ===" << std::endl;
00303                   std::cout <<" ===" << std::endl;
00304                   std::cout <<"=======  DigitizerFP420:  collector size = " << collector.size() << std::endl;
00305                   std::cout <<" ===" << std::endl;
00306                   std::cout <<" ===" << std::endl;
00307                 }             
00308                 /*              
00309                 
00310                 std::vector<HDigiFP420> collector;
00311                 collector.clear();
00312                 DigiCollectionFP420::Range inputRange;
00313                 inputRange.first = collector.begin();
00314                 inputRange.second = collector.end();
00315                 output->putclear(inputRange,detID);
00316 */
00317                 if (collector.size()>0){
00318                   if(verbosity>0) {
00319                     std::cout <<"         ============= DigitizerFP420:collector start!!!!!!!!!!!!!!" << std::endl;
00320                   }
00321                   DigiCollectionFP420::Range outputRange;
00322                   outputRange.first = collector.begin();
00323                   outputRange.second = collector.end();
00324                   
00325                   if ( first ) {
00326                     // use it only if ClusterCollectionFP420 is the ClusterCollection of one event, otherwise, do not use (loose 1st cl. of 1st event only)
00327                     first = false;
00328                     unsigned int  detID0= 0;
00329                     output->put(outputRange,detID0); // !!! put into adress 0 for detID which will not be used never
00330                   } //if ( first ) 
00331                   
00332                   // put !!!
00333                   output->put(outputRange,iu);
00334                   
00335                 } // if(collector.size()>0
00336                 
00337               }   // for
00338             }   // for
00339           }   // for
00340         }   // for
00341         
00342         
00343         // END
00344         
00345         
00346         
00347         
00348         
00349         
00350         if(verbosity>0) {
00351           //     check of access to the collector:
00352           for (int det=1; det<dn0; det++) {
00353             for (int sector=1; sector<sn0; sector++) {
00354               for (int zmodule=1; zmodule<pn0; zmodule++) {
00355                 for (int zside=1; zside<3; zside++) {
00356                   int sScale = 2*(pn0-1), dScale = 2*(pn0-1)*(sn0-1);
00357                   int zScale=2;  unsigned int iu = dScale*(det - 1)+sScale*(sector - 1)+zScale*(zmodule - 1)+zside;
00358                   collector.clear();
00359                   DigiCollectionFP420::Range outputRange;
00360                   //    outputRange = output->get(iu);
00361                   outputRange = output->get(iu);
00362                   
00363                   // fill output in collector vector (for may be sorting? or other checks)
00364                   std::vector<HDigiFP420> collector;
00365                   //  collector.clear();
00366                   DigiCollectionFP420::ContainerIterator sort_begin = outputRange.first;
00367                   DigiCollectionFP420::ContainerIterator sort_end = outputRange.second;
00368                   for ( ;sort_begin != sort_end; ++sort_begin ) {
00369                     collector.push_back(*sort_begin);
00370                   } // for
00371                   //  std::sort(collector.begin(),collector.end());
00372                   std::cout <<" ===" << std::endl;
00373                   std::cout <<" ===" << std::endl;
00374                   std::cout <<"=======DigitizerFP420:check of re-new collector size = " << collector.size() << std::endl;
00375                   std::cout <<" iu = " << iu << std::endl;
00376                   std::cout <<" ===" << std::endl;
00377                   vector<HDigiFP420>::const_iterator simHitIter = collector.begin();
00378                   vector<HDigiFP420>::const_iterator simHitIterEnd = collector.end();
00379                   for (;simHitIter != simHitIterEnd; ++simHitIter) {
00380                     const HDigiFP420 istrip = *simHitIter;
00381                     
00382                     std::cout << "DigitizerFP420:check: HDigiFP420:: zside = " << zside << "  det=" << det << std::endl;
00383                     std::cout << " strip number=" << istrip.strip() << "  adc=" << istrip.adc() << std::endl;
00384                     std::cout <<" ===" << std::endl;
00385                     std::cout <<" ===" << std::endl;
00386                     std::cout <<" ===" << std::endl;
00387                     std::cout <<" =======================" << std::endl;
00388                   }
00389                   
00390                   //==================================
00391                   
00392                 }   // for
00393               }   // for
00394             }   // for
00395           }   // for
00396           
00397           //     end of check of access to the strip collection
00398           
00399         }       
00400         //     
00401         
00402         
00403         // Step D: write output to file
00404         //    iEvent.put(output);
00405         
00406         if(verbosity>0) {
00407           std::cout << "DigitizerFP420 recoutput" << std::endl;
00408         }
00409         // Step D: write output to file
00410         iEvent.put(output);
00411         // iEvent.put(outputlink);
00412         //        iEvent.put(pDigis);
00413         
00414         // Step D: write output to file 
00415         //  iEvent.put(output);
00416         //  iEvent.put(outputlink);
00417         //-------------------------------------------------------------------
00418         //    std::cout << "DigitizerFP420 recoutput" << std::endl;
00419         //        iEvent.put(pDigis);
00420         
00421         
00422         
00423         
00424   }//produce
00425   
00426 } // namespace cms
00427 
00428 //}
00429 //define this as a plug-in
00430 
00431 //DEFINE_FWK_MODULE(DigitizerFP420);

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