CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/SLHCUpgradeSimulations/L1TrackTrigger/plugins/HitDump.cc

Go to the documentation of this file.
00001 
00002 //  Analyzer by Nicola  //
00003 //    july 2010 @ PD    //
00005 
00007 //       HEADERS       //
00009 
00011 // CLASS HEADER
00012 // No more necessary in the current "no *.h file" implementation
00013 
00015 // FRAMEWORK HEADERS
00016 #include "FWCore/PluginManager/interface/ModuleDef.h"
00017 #include "FWCore/Framework/interface/MakerMacros.h"
00018 //
00019 #include "FWCore/Framework/interface/EDAnalyzer.h"
00020 #include "FWCore/Framework/interface/Event.h"
00021 #include "FWCore/Framework/interface/ESHandle.h"
00022 #include "FWCore/Framework/interface/EventSetup.h"
00023 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00024 //
00025 #include "FWCore/Utilities/interface/InputTag.h"
00026 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00027 #include "FWCore/ServiceRegistry/interface/Service.h"
00028 
00030 // DATA FORMATS HEADERS
00031 #include "DataFormats/Common/interface/Handle.h"
00032 #include "DataFormats/Common/interface/EDProduct.h"
00033 #include "DataFormats/Common/interface/Ref.h"
00034 //
00035 #include "DataFormats/DetId/interface/DetId.h"
00036 #include "DataFormats/SiPixelDetId/interface/PXBDetId.h" 
00037 #include "DataFormats/SiPixelDetId/interface/PXFDetId.h" 
00038 #include "DataFormats/Common/interface/DetSetVector.h"
00039 //
00040 #include "SimDataFormats/SLHC/interface/StackedTrackerTypes.h"
00041 #include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
00042 #include "SimDataFormats/TrackingHit/interface/PSimHit.h"
00043 #include "SimDataFormats/Track/interface/SimTrack.h"
00044 #include "SimDataFormats/Track/interface/SimTrackContainer.h"
00045 #include "SimDataFormats/Vertex/interface/SimVertex.h"
00046 #include "SimDataFormats/Vertex/interface/SimVertexContainer.h"
00047 //
00048 #include "DataFormats/Math/interface/LorentzVector.h"
00049 #include "DataFormats/Math/interface/Vector3D.h"
00050 //
00051 //#include "SimDataFormats/SLHC/interface/L1CaloCluster.h"
00052 //
00053 #include "DataFormats/L1Trigger/interface/L1EmParticle.h"
00054 #include "DataFormats/L1Trigger/interface/L1EmParticleFwd.h"
00055 #include "DataFormats/L1Trigger/interface/L1JetParticle.h"
00056 #include "DataFormats/L1Trigger/interface/L1JetParticleFwd.h"
00057 //
00058 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
00059 #include "DataFormats/Candidate/interface/Candidate.h"
00060 //
00061 #include "DataFormats/GeometryCommonDetAlgo/interface/MeasurementPoint.h"
00062 #include "DataFormats/SiPixelDetId/interface/PixelChannelIdentifier.h"
00063 #include "TrackingTools/GeomPropagators/interface/HelixArbitraryPlaneCrossing.h"
00065 // FAST SIMULATION STUFF
00066 #include "FastSimulation/Particle/interface/RawParticle.h"
00067 #include "FastSimulation/BaseParticlePropagator/interface/BaseParticlePropagator.h"
00068 
00070 // DETECTOR GEOMETRY HEADERS
00071 #include "MagneticField/Engine/interface/MagneticField.h"
00072 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00073 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00074 #include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetUnit.h"
00075 #include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetType.h"
00076 #include "Geometry/TrackerGeometryBuilder/interface/PixelTopologyBuilder.h"
00077 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00078 #include "Geometry/TrackerGeometryBuilder/interface/RectangularPixelTopology.h"
00079 #include "Geometry/CommonDetUnit/interface/GeomDetType.h"
00080 #include "Geometry/CommonDetUnit/interface/GeomDetUnit.h"
00081 //
00082 #include "Geometry/Records/interface/StackedTrackerGeometryRecord.h"
00083 #include "Geometry/TrackerGeometryBuilder/interface/StackedTrackerGeometry.h"
00084 #include "Geometry/TrackerGeometryBuilder/interface/StackedTrackerDetUnit.h"
00085 #include "DataFormats/SiPixelDetId/interface/StackedTrackerDetId.h"
00086 
00087 
00089 // PHYSICS TOOLS
00090 #include "CommonTools/UtilAlgos/interface/TFileService.h"
00091 #include "RecoTracker/TkSeedGenerator/interface/FastHelix.h"
00092 #include "TrackingTools/TrajectoryState/interface/FreeTrajectoryState.h"
00093 #include "RecoTauTag/TauTagTools/interface/GeneratorTau.h"
00094 //
00095 #include "DataFormats/GeometryCommonDetAlgo/interface/MeasurementVector.h"
00096 #include "DataFormats/GeometrySurface/interface/BoundPlane.h"
00097 //#include "SLHCUpgradeSimulations/Utilities/interface/constants.h"
00098 
00100 // ROOT HEADERS
00101 #include <TROOT.h>
00102 #include <TTree.h>
00103 #include <TFile.h>
00104 #include <TF1.h>
00105 #include <TH2F.h>
00106 #include <TH1F.h>
00107 #include <TH2D.h>
00108 #include <TH1D.h>
00109 #include <TH2.h>
00110 #include <TH1.h>
00111 
00113 // STD HEADERS
00114 #include <memory>
00115 #include <string>
00116 #include <iostream>
00117 #include <fstream>
00118 
00120 // NAMESPACES
00121 // I hate them to be used this way because
00122 // I lose the feel of 'what is from where'
00123 // but I need them, unfortunately...
00124 using namespace std;
00125 using namespace edm;
00126 using namespace reco;
00127 //using namespace cmsUpgrades;
00128 //using namespace l1slhc;
00129 using namespace l1extra;
00130 
00132 //                          //
00133 //     CLASS DEFINITION     //
00134 //                          //
00136 
00137 class TTree;
00138 class TFile;
00139 class TH1D;
00140 class TH2D;
00141 class TGraph;
00142 class RectangularPixelTopology;
00143 class TransientInitialStateEstimator;
00144 class MagneticField;
00145 class TrackerGeometry;
00146 class TrajectoryStateOnSurface;
00147 class PTrajectoryStateOnDet;
00148 //
00149 class HitDump : public edm::EDAnalyzer
00150 {
00152   public:
00154     explicit HitDump(const edm::ParameterSet& iConfig);
00155     virtual ~HitDump();
00156     // Typical methods used on Loops over events
00157     virtual void beginJob();
00158     virtual void endJob();
00159     virtual void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup);
00160 
00162 
00164   protected:
00165                      
00167   private:
00168 
00169     edm::InputTag L1TkTrackletCollInputTag;
00170     
00171     bool testedGeometry;
00172     bool debugPrintouts;
00173 
00174     int eventnum;
00175 
00177     TH1D* h_EvtCnt;
00178 
00180     TH2D* hDigi_XY;
00181     TH2D* hDigi_RZ;
00182     
00183     TH2D* hDet_LayMod;
00184     TH2D* hDet_LayLad;
00185     TH2D* hDet_LadMod;
00186 
00188     TH2D* hGeom_Layer_R;
00189     TH2D* hGeom_iPhi_Phi;
00190     TH2D* hGeom_iZ_Z;
00191 
00192 
00195     edm::ParameterSet config;
00196 
00197   string fileString_ ;
00198   std::ofstream myfile;
00199 };
00200 
00201 
00203 //                              //
00204 //     CLASS IMPLEMENTATION     //
00205 //                              //
00207 
00209 // CONSTRUCTOR
00210 HitDump::HitDump(edm::ParameterSet const& iConfig) : 
00211   config(iConfig)
00212 {
00214   L1TkTrackletCollInputTag = iConfig.getParameter< edm::InputTag >("L1TkTrackletCollType");
00215   fileString_ = iConfig.getUntrackedParameter<string>("fileString","ForUlrich.txt");
00216 }
00217 
00219 // DESTRUCTOR
00220 HitDump::~HitDump()
00221 {
00224   myfile.close();
00225 }  
00226 
00228 // END JOB
00229 void HitDump::endJob()//edm::Run& run, const edm::EventSetup& iSetup
00230 {
00232   std::cerr << " HitDump::endJob" << std::endl;
00234 }
00235 
00237 // BEGIN JOB
00238 void HitDump::beginJob()
00239 {
00240 
00243   //double trkMPt = 99999.9;
00244 
00245   eventnum=0;
00246 
00247   cout<<"HitDump::beginJob opening file:"<<fileString_<<endl;
00248   myfile.open(fileString_.c_str());
00249 
00250 
00251   testedGeometry = false;
00252   debugPrintouts = false;
00253 
00254   std::ostringstream histoName;
00255   std::ostringstream histoTitle;
00256 
00257 
00259 }
00260 
00262 // ANALYZE
00263 void HitDump::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00264 {
00265 
00266 
00267   eventnum++;
00268 
00270   edm::ESHandle<TrackerGeometry>                               geometryHandle;
00271   const TrackerGeometry*                                       theGeometry;
00272 
00273   edm::ESHandle<StackedTrackerGeometry>           stackedGeometryHandle;
00274   const StackedTrackerGeometry*                   theStackedGeometry;
00275   StackedTrackerGeometry::StackContainerIterator  StackedTrackerIterator;
00276 
00279   iSetup.get<TrackerDigiGeometryRecord>().get(geometryHandle);
00280   theGeometry = &(*geometryHandle);
00282   iSetup.get<StackedTrackerGeometryRecord>().get(stackedGeometryHandle);
00283   theStackedGeometry = stackedGeometryHandle.product(); 
00284 
00285 
00287   // GET MAGNETIC FIELD //
00289   edm::ESHandle<MagneticField> magneticFieldHandle;
00290   iSetup.get<IdealMagneticFieldRecord>().get(magneticFieldHandle);
00291   const MagneticField* theMagneticField = magneticFieldHandle.product();
00292   double mMagneticFieldStrength = theMagneticField->inTesla(GlobalPoint(0,0,0)).z();
00293 
00295   // GET BS //
00297   //edm::Handle< std::vector< cmsUpgrades::L1TkBeam > > beamHandle;
00298   //iEvent.getByLabel( "L1TkBeams", beamHandle );
00299   GlobalPoint beamPos(0.0,0.0,0.0);
00300 
00302   // GET SIMTRACKS //
00304   edm::Handle<edm::SimTrackContainer>   simTrackHandle;
00305   edm::Handle<edm::SimVertexContainer>  simVtxHandle;
00306   //iEvent.getByLabel( "famosSimHits", simTrackHandle );
00307   //iEvent.getByLabel( "famosSimHits", simVtxHandle );
00308   iEvent.getByLabel( "g4SimHits", simTrackHandle );
00309   iEvent.getByLabel( "g4SimHits", simVtxHandle );
00310 
00312   // GET MC PARTICLES //
00314   edm::Handle<reco::GenParticleCollection> genpHandle;
00315   iEvent.getByLabel( "genParticles", genpHandle );
00316 
00317 
00319   // GET PIXEL DIGIS //
00321   edm::Handle<edm::DetSetVector<PixelDigi> >         pixelDigiHandle;
00322   edm::Handle<edm::DetSetVector<PixelDigiSimLink> >  pixelDigiSimLinkHandle;
00323   iEvent.getByLabel("simSiPixelDigis", pixelDigiHandle);
00324   iEvent.getByLabel("simSiPixelDigis", pixelDigiSimLinkHandle);
00325 
00326 
00328   // GET THE PRIMITIVES //
00330   edm::Handle<L1TkCluster_PixelDigi_Collection>  pixelDigiL1TkClusterHandle;
00331   edm::Handle<L1TkStub_PixelDigi_Collection>     pixelDigiL1TkStubHandle;
00332   //edm::Handle<L1TkTracklet_PixelDigi_Collection> pixelDigiL1TkTrackletHandle;
00333   edm::Handle<L1TkTrack_PixelDigi_Collection>    pixelDigiL1TkTrackHandle;
00334   iEvent.getByLabel("L1TkClustersFromPixelDigis", pixelDigiL1TkClusterHandle);
00335   iEvent.getByLabel("L1TkStubsFromPixelDigis","StubsPass",    pixelDigiL1TkStubHandle);
00336   //iEvent.getByLabel("L1TkTrackletsFromPixelDigis", "ShortTrackletsVtx00HelFit", pixelDigiL1TkTrackletHandle);
00337   //iEvent.getByLabel( L1TkTrackletCollInputTag, pixelDigiL1TkTrackletHandle);
00338   //iEvent.getByLabel("L1TkTracksFromPixelDigis",    "Level1TracksHelFitVtxYes", pixelDigiL1TkTrackHandle);
00339 
00340   // dump map between inner and outer modules
00341 
00342   static bool first=true;
00343 
00344   if (first) {
00345     
00346     first=false;
00347     
00348     //edm::ESHandle<cmsUpgrades::StackedTrackerGeometry> stackedGeometryHandle;
00349     //const cmsUpgrades::StackedTrackerGeometry* theStackedGeometry;
00350     //cmsUpgrades::StackedTrackerGeometry::StackContainerIterator
00351     //  StackedTrackerIterator;
00352     
00355     //iSetup.get<TrackerDigiGeometryRecord>().get(geometryHandle);
00356     //theGeometry = &(*geometryHandle);
00358     // iSetup.get<StackedTrackerGeometryRecord>().get(stackedGeometryHandle);
00359     //theStackedGeometry = stackedGeometryHandle.product(); /// Note this
00360     //is different
00362       
00363 
00364     std::map< uint32_t, bool > detIdToInnerMap; 
00365 
00366 
00367 
00369     for ( StackedTrackerIterator = theStackedGeometry->stacks().begin();
00370           StackedTrackerIterator != theStackedGeometry->stacks().end();
00371           ++StackedTrackerIterator ) {
00372         
00373       StackedTrackerDetUnit* stackDetUnit = *StackedTrackerIterator;
00374       StackedTrackerDetId stackDetId = stackDetUnit->Id();
00375       assert(stackDetUnit == theStackedGeometry->idToStack(stackDetId));
00376         
00377       const GeomDet* det0 = theStackedGeometry->idToDet(stackDetId, 0);
00378       const GeomDet* det1 = theStackedGeometry->idToDet(stackDetId, 1);
00379 
00380       uint32_t detId0 = det0->geographicalId().rawId();
00381       uint32_t detId1 = det1->geographicalId().rawId();
00382 
00383       DetId tkId0(detId0);
00384       DetId tkId1(detId1);
00385 
00386       const GeomDetUnit* gDetUnit = theGeometry->idToDetUnit( tkId0 );
00387       MeasurementPoint mp0( 0.5, 0.5 );
00388       MeasurementPoint mp1( 1024 + 0.5, 0.5 );
00389       MeasurementPoint mp2( 0.5, 80 + 0.5 );
00390       GlobalPoint pdPos0 = gDetUnit->surface().toGlobal( gDetUnit->topology().localPosition( mp0 ) ) ;      
00391       GlobalPoint pdPos1 = gDetUnit->surface().toGlobal( gDetUnit->topology().localPosition( mp1 ) ) ;      
00392       GlobalPoint pdPos2 = gDetUnit->surface().toGlobal( gDetUnit->topology().localPosition( mp2 ) ) ;      
00393 
00394       PXBDetId pxbId0(tkId0);
00395 
00396       PXBDetId pxbId1(tkId1);
00397 
00398       int iStack=stackDetId.iLayer()+1;
00399 
00400       if (iStack==1000000){
00401         iStack=stackDetId.iRing()+1000;
00402       }
00403 
00404       if (myfile.is_open()) {      
00405         myfile << "Map: " 
00406                << iStack << "\t" 
00407                << stackDetId.iPhi()+1 << "\t" 
00408                << stackDetId.iZ() << "\t" 
00409                << iStack << "\t" 
00410                << stackDetId.iPhi()+1 << "\t" 
00411                << stackDetId.iZ() << "\t"
00412                << pdPos0.x() << "\t"<< pdPos0.y() << "\t"<< pdPos0.z() << "\t"
00413                << pdPos1.x() << "\t"<< pdPos1.y() << "\t"<< pdPos1.z() << "\t"
00414                << pdPos2.x() << "\t"<< pdPos2.y() << "\t"<< pdPos2.z() << "\t"
00415                << endl; 
00416       } 
00417 
00418       detIdToInnerMap.insert( make_pair(detId0, true) );
00419       detIdToInnerMap.insert( make_pair(detId1, false) );
00420     }
00421     myfile << "EndMap" <<endl;
00422 
00423   }
00424 
00425 
00426   if (myfile.is_open()) {
00427     myfile << "Event: "<<eventnum<<std::endl;
00428   }
00429 
00430 
00432   SimTrackContainer::const_iterator iterSimTracks;
00433   for ( iterSimTracks = simTrackHandle->begin();
00434         iterSimTracks != simTrackHandle->end();
00435         ++iterSimTracks ) {
00436     
00438     int vertexIndex = iterSimTracks->vertIndex();
00439     const SimVertex& theSimVertex = (*simVtxHandle)[vertexIndex];
00440     math::XYZTLorentzVectorD trkVtxPos = theSimVertex.position();
00441     GlobalPoint trkVtxCorr = GlobalPoint( trkVtxPos.x() - beamPos.x(), 
00442                                           trkVtxPos.y() - beamPos.y(), 
00443                                           trkVtxPos.z() - beamPos.z() );
00444     
00445     if (myfile.is_open()) {
00446       double pt=iterSimTracks->momentum().pt();
00447       if (pt!=pt) pt=9999.999;
00448       myfile << "SimTrack: " 
00449              << iterSimTracks->trackId() << "\t" 
00450              << iterSimTracks->type() << "\t" 
00451              << pt << "\t" 
00452              << iterSimTracks->momentum().eta() << "\t" 
00453              << iterSimTracks->momentum().phi() << "\t" 
00454              << trkVtxCorr.x() << "\t" 
00455              << trkVtxCorr.y() << "\t" 
00456              << trkVtxCorr.z() << "\t" 
00457              << std::endl;
00458     }
00459     
00460   } 
00461 
00462   if (myfile.is_open()) {
00463     myfile << "SimTrackEnd"<<endl;
00464   }
00465  
00466 
00467   /*
00469   for ( clusterHitsIter = clusterHits.begin();
00470         clusterHitsIter != clusterHits.end();
00471         clusterHitsIter++ ) {
00472 
00473   }
00474   */
00475 
00476   // End loop over L1TkClusters
00477 
00479   DetSetVector<PixelDigi>::const_iterator iterDet;
00480   for ( iterDet = pixelDigiHandle->begin();
00481         iterDet != pixelDigiHandle->end();
00482         iterDet++ ) {
00483 
00485     DetId tkId( iterDet->id );
00486     StackedTrackerDetId stdetid(tkId);
00488     if ( tkId.subdetId() == 2 ) {
00489 
00490       //cout << "Will create pxfId"<<endl;
00491       PXFDetId pxfId(tkId);
00492       DetSetVector<PixelDigiSimLink>::const_iterator itDigiSimLink1=pixelDigiSimLinkHandle->find(pxfId.rawId());
00493       if (itDigiSimLink1!=pixelDigiSimLinkHandle->end()){
00494         //cout << "Found forward digisim link"<<endl;
00495         DetSet<PixelDigiSimLink> digiSimLink = *itDigiSimLink1;
00496         //DetSet<PixelDigiSimLink> digiSimLink = (*pixelDigiSimLinkHandle)[ pxfId.rawId() ];
00497         DetSet<PixelDigiSimLink>::const_iterator iterSimLink;
00499 
00500         int disk = pxfId.disk();
00501         
00502         if (disk<4) {
00503           continue;
00504         }
00505 
00506         disk-=3;
00507         
00508         // Layer 0-20
00509         //DetId digiDetId = iterDet->id;
00510         //int sensorLayer = 0.5*(2*PXFDetId(digiDetId).layer() + (PXFDetId(digiDetId).ladder() + 1)%2 - 8);
00511         
00513         DetSet<PixelDigi>::const_iterator iterDigi;
00514         for ( iterDigi = iterDet->data.begin();
00515               iterDigi != iterDet->data.end();
00516               iterDigi++ ) {
00517       
00519           if ( iterDigi->adc() <= 30 ) continue;
00520           
00522           const GeomDetUnit* gDetUnit = theGeometry->idToDetUnit( tkId );
00523           MeasurementPoint mp( iterDigi->row() + 0.5, iterDigi->column() + 0.5 );
00524           GlobalPoint pdPos = gDetUnit->surface().toGlobal( gDetUnit->topology().localPosition( mp ) ) ;
00525           
00526           int offset=1000;
00527 
00528           if (pxfId.side()==1) {
00529             offset=2000;
00530           }
00531 
00532           assert(pxfId.panel()==1);
00533 
00534           if (myfile.is_open()) {
00535             myfile << "Digi: " 
00536                    << offset+disk << "\t" 
00537                    << iterDigi->row() << "\t" 
00538                    << iterDigi->column() << "\t" 
00539                    << pxfId.blade() << "\t" 
00540                    << pxfId.panel() << "\t" 
00541               //     << stdetid.iPhi() << "\t" 
00542                    << pxfId.module() << "\t" 
00543                    << pdPos.x() << "\t"
00544                    << pdPos.y() << "\t"
00545                    << pdPos.z() << "\t"
00546                    << std::endl;
00547           }
00548           
00551           for ( iterSimLink = digiSimLink.data.begin();
00552                 iterSimLink != digiSimLink.data.end();
00553                 iterSimLink++) {
00554             
00556             if ( (int)iterSimLink->channel() == iterDigi->channel() ) {
00557               
00559               unsigned int simTrackId = iterSimLink->SimTrackId();
00560               if (myfile.is_open()) {
00561                 myfile << "SimTrackId: "<<simTrackId<<std::endl;
00562               }
00563             }
00564           }
00565         }
00566       }
00567     }
00568 
00569     if ( tkId.subdetId() == 1 ) {
00571       PXBDetId pxbId(tkId);
00572       DetSetVector<PixelDigiSimLink>::const_iterator itDigiSimLink=pixelDigiSimLinkHandle->find(pxbId.rawId());
00573       if (itDigiSimLink==pixelDigiSimLinkHandle->end()){
00574         continue;
00575       }
00576       DetSet<PixelDigiSimLink> digiSimLink = *itDigiSimLink;
00577       //DetSet<PixelDigiSimLink> digiSimLink = (*pixelDigiSimLinkHandle)[ pxbId.rawId() ];
00578       DetSet<PixelDigiSimLink>::const_iterator iterSimLink;
00580       if ( pxbId.layer() < 5 ) {
00581         continue;
00582         
00583       }
00584 
00585       // Layer 0-20
00586       DetId digiDetId = iterDet->id;
00587       int sensorLayer = 0.5*(2*PXBDetId(digiDetId).layer() + (PXBDetId(digiDetId).ladder() + 1)%2 - 8);
00588       
00590       DetSet<PixelDigi>::const_iterator iterDigi;
00591       for ( iterDigi = iterDet->data.begin();
00592             iterDigi != iterDet->data.end();
00593             iterDigi++ ) {
00594         
00596         if ( iterDigi->adc() <= 30 ) continue;
00597         
00599         const GeomDetUnit* gDetUnit = theGeometry->idToDetUnit( tkId );
00600         MeasurementPoint mp( iterDigi->row() + 0.5, iterDigi->column() + 0.5 );
00601         GlobalPoint pdPos = gDetUnit->surface().toGlobal( gDetUnit->topology().localPosition( mp ) ) ;
00602         
00603         
00604         if (myfile.is_open()) {
00605           myfile << "Digi: " 
00606                  << sensorLayer << "\t" 
00607                  << iterDigi->row() << "\t" 
00608                  << iterDigi->column() << "\t" 
00609                  << pxbId.layer() << "\t" 
00610                  << pxbId.ladder() << "\t" 
00611             //     << stdetid.iPhi() << "\t" 
00612                  << pxbId.module() << "\t" 
00613                  << pdPos.x() << "\t"
00614                  << pdPos.y() << "\t"
00615                  << pdPos.z() << "\t"
00616                  << std::endl;
00617         }
00618         
00621         for ( iterSimLink = digiSimLink.data.begin();
00622               iterSimLink != digiSimLink.data.end();
00623               iterSimLink++) {
00624           
00626           if ( (int)iterSimLink->channel() == iterDigi->channel() ) {
00627             
00629             unsigned int simTrackId = iterSimLink->SimTrackId();
00630             if (myfile.is_open()) {
00631               myfile << "SimTrackId: "<<simTrackId<<std::endl;
00632             }
00633           }
00634         }
00635       }
00636     }
00637   }    
00638 
00639   if (myfile.is_open()) {
00640     myfile << "DigiEnd"<<endl;
00641   }
00642 
00643   
00644 
00645 
00647   L1TkStub_PixelDigi_Collection::const_iterator iterL1TkStub;
00648   for ( iterL1TkStub = pixelDigiL1TkStubHandle->begin();
00649         iterL1TkStub != pixelDigiL1TkStubHandle->end();
00650         ++iterL1TkStub ) {
00651 
00652     double stubPt = theStackedGeometry->findRoughPt(mMagneticFieldStrength,&(*iterL1TkStub));
00653                                                     
00654     if (stubPt>10000.0) stubPt=9999.99;
00655     GlobalPoint stubPosition = theStackedGeometry->findGlobalPosition(&(*iterL1TkStub));
00656 
00657     StackedTrackerDetId stubDetId = iterL1TkStub->getDetId();
00658     unsigned int iStack = stubDetId.iLayer();
00659     unsigned int iRing = stubDetId.iRing();
00660     unsigned int iPhi = stubDetId.iPhi();
00661     unsigned int iZ = stubDetId.iZ();
00662 
00663     //const StackedTrackerDetUnit* aDetUnit = theStackedGeometry->idToStack(stubDetId);
00664     //DetId id0 = aDetUnit->stackMember(0);
00665     //DetId id1 = aDetUnit->stackMember(1);
00666 
00667     //PXBDetId pxb0 = PXBDetId(id0);
00668     //PXBDetId pxb1 = PXBDetId(id1);
00669 
00670     if (iStack==999999) {
00671       iStack=1000+iRing;
00672     }
00673 
00674     if (myfile.is_open()) {
00675       myfile << "Stub: "<<
00676         iStack<<"\t"<<
00677         iPhi<<"\t"<<
00678         iZ<<"\t"<<
00679         stubPt<<"\t"<<
00680         stubPosition.x()<<"\t"<<
00681         stubPosition.y()<<"\t"<<
00682         stubPosition.z()<<"\t"<<
00683         std::endl;
00684     }
00685 
00687     edm::Ptr<L1TkCluster_PixelDigi_> innerCluster = iterL1TkStub->getClusterPtr(0);
00688 
00689     const DetId innerDetId = theStackedGeometry->idToDet( innerCluster->getDetId(), 0 )->geographicalId();
00690 
00691     for (unsigned int ihit=0;ihit<innerCluster->getHits().size();ihit++){
00692 
00693       std::pair<int,int> rowcol=PixelChannelIdentifier::channelToPixel(innerCluster->getHits().at(ihit)->channel());
00694     
00695       if (myfile.is_open()) {
00696         if (iStack<1000) {
00697           myfile << "InnerStackDigi: " 
00698                  << rowcol.first << "\t" 
00699                  << rowcol.second << "\t" 
00700                  << PXBDetId(innerDetId).ladder() << "\t" 
00701                  << PXBDetId(innerDetId).module() << "\t" 
00702                  << std::endl;
00703         }
00704         else {
00705           myfile << "InnerStackDigi: " 
00706                  << rowcol.first << "\t" 
00707                  << rowcol.second << "\t" 
00708                  << PXFDetId(innerDetId).disk() << "\t" 
00709                  << PXFDetId(innerDetId).module() << "\t" 
00710                  << std::endl;
00711         }
00712       }    
00713     }
00714 
00715 
00716     edm::Ptr<L1TkCluster_PixelDigi_> outerCluster = iterL1TkStub->getClusterPtr(1);
00717       
00718     const DetId outerDetId = theStackedGeometry->idToDet( outerCluster->getDetId(), 1 )->geographicalId();
00719 
00720     for (unsigned int ihit=0;ihit<outerCluster->getHits().size();ihit++){
00721 
00722       std::pair<int,int> rowcol=PixelChannelIdentifier::channelToPixel(outerCluster->getHits().at(ihit)->channel());
00723     
00724       if (myfile.is_open()) {
00725         if (iStack<1000) {
00726           myfile << "OuterStackDigi: " 
00727                  << rowcol.first << "\t" 
00728                  << rowcol.second << "\t" 
00729                  << PXBDetId(outerDetId).ladder() << "\t" 
00730                  << PXBDetId(outerDetId).module() << "\t" 
00731                  << std::endl;
00732         }
00733         else {
00734           myfile << "OuterStackDigi: " 
00735                  << rowcol.first << "\t" 
00736                  << rowcol.second << "\t" 
00737                  << PXFDetId(outerDetId).disk() << "\t" 
00738                  << PXFDetId(outerDetId).module() << "\t" 
00739                  << std::endl;
00740         }
00741       }
00742     }    
00743     
00744     
00745     /*      
00746           
00748     DetSetVector<PixelDigi>::const_iterator iterDet;
00749     for ( iterDet = pixelDigiHandle->begin();
00750           iterDet != pixelDigiHandle->end();
00751           iterDet++ ) {
00752       
00754       DetId tkId( iterDet->id );
00755       
00756       
00757       if (innerDetId.rawId()==outerDetId.rawId()) {
00758         std::cerr<<"STUB DEBUGGING INNER LAYER == OUTER LAYER RAW ID"<<std::endl;
00759       }
00760     
00761       if (innerDetId.rawId()==tkId.rawId()) {
00762         // Layer 1-10.5
00763         //int sensorLayer = (2*PXBDetId(tkId).layer() + (PXBDetId(tkId).ladder() + 1)%2 - 8);
00764 
00766         DetSet<PixelDigi>::const_iterator iterDigi;
00767         for ( iterDigi = iterDet->data.begin();
00768               iterDigi != iterDet->data.end();
00769               iterDigi++ ) {
00770 
00772           if ( iterDigi->adc() <= 30 ) continue;
00773           for (unsigned int ihit=0;ihit<innerCluster->getHits().size();ihit++){
00774             if (iterDigi->channel() == innerCluster->getHits().at(ihit)->channel()) {
00775               if (myfile.is_open()) {
00776                 if (iStack<1000) {
00777                   myfile << "InnerStackDigi: " 
00778                          << iterDigi->row() << "\t" 
00779                          << iterDigi->column() << "\t" 
00780                          << PXBDetId(tkId).ladder() << "\t" 
00781                          << PXBDetId(tkId).module() << "\t" 
00782                          << std::endl;
00783                 }
00784                 else {
00785                   myfile << "InnerStackDigi: " 
00786                          << iterDigi->row() << "\t" 
00787                          << iterDigi->column() << "\t" 
00788                          << PXFDetId(tkId).disk() << "\t" 
00789                          << PXFDetId(tkId).module() << "\t" 
00790                          << std::endl;
00791                 }
00792               }
00793             }
00794           }
00795         }
00796       }
00797     
00798       if (outerDetId.rawId()==tkId.rawId()) {
00799         // Layer 0-20
00800         //int sensorLayer = (2*PXBDetId(tkId).layer() + (PXBDetId(tkId).ladder() + 1)%2 - 8);
00801 
00803         DetSet<PixelDigi>::const_iterator iterDigi;
00804         for ( iterDigi = iterDet->data.begin();
00805               iterDigi != iterDet->data.end();
00806               iterDigi++ ) {
00807 
00809           if ( iterDigi->adc() <= 30 ) continue;
00810           for (unsigned int ihit=0;ihit<outerCluster->getHits().size();ihit++){
00811             if (iterDigi->channel() == outerCluster->getHits().at(ihit)->channel()) {
00812               if (myfile.is_open()) {
00813                 if (iStack<1000) {
00814                   myfile << "OuterStackDigi: " 
00815                          << iterDigi->row() << "\t" 
00816                          << iterDigi->column() << "\t" 
00817                          << PXBDetId(tkId).ladder() << "\t" 
00818                          << PXBDetId(tkId).module() << "\t" 
00819                          << std::endl;
00820                 }
00821                 else{
00822                   myfile << "OuterStackDigi: " 
00823                          << iterDigi->row() << "\t" 
00824                          << iterDigi->column() << "\t" 
00825                          << PXFDetId(tkId).disk() << "\t" 
00826                          << PXFDetId(tkId).module() << "\t" 
00827                          << std::endl;
00828                 }
00829               }
00830             }
00831           }     
00832         }
00833     */  
00834   }
00835 
00836       /*
00838      PXBDetId pxbId(tkId);
00840      if ( pxbId.layer() < 5 ) continue;
00841      //std::cerr<<std::endl;
00842      
00843      unsigned int whichStack = pxbId.layer() - 5;
00844      //std::cerr<<iStack<<"\t"<<whichStack<<"\t"<<innerCluster.getStack()<<"\t"<<outerCluster.getStack()<<std::endl;
00845      if (whichStack != innerCluster.getStack()) continue;
00846      if (whichStack != outerCluster.getStack()) continue;
00847 
00848      unsigned int whichPhi = floor(pxbId.ladder() / 2);
00849      //std::cerr<<iPhi<<"\t"<<whichPhi<<"\t"<<innerCluster.getLadderPhi()<<"\t"<<outerCluster.getLadderPhi()<<std::endl;
00850      if (whichPhi != innerCluster.getLadderPhi()) continue;
00851      if (whichPhi != outerCluster.getLadderPhi()) continue;
00852      
00853      unsigned int whichZ = pxbId.module();
00854      //std::cerr<<iZ<<"\t"<<whichZ<<"\t"<<innerCluster.getLadderZ()<<"\t"<<outerCluster.getLadderZ()<<std::endl;
00855      if (whichZ != innerCluster.getLadderZ()) continue;
00856      if (whichZ != outerCluster.getLadderZ()) continue;
00857       */
00858 
00859   if (myfile.is_open()) {
00860     myfile << "StubEnd"<<endl;
00861   }
00862 
00863 
00865   //h_EvtCnt->Fill(iEvent.id().event()); /// The +0.2 is to be sure of being in the correct bin
00866 
00867 
00873   std::vector<StackedTrackerDetUnit*> stackContainer = theStackedGeometry->stacks();
00874   if (testedGeometry==false) {
00876     for ( unsigned int k=0; k<stackContainer.size(); k++ ) {
00877       //StackedTrackerDetUnit* detUnitIt = stackContainer.at(k);
00878       //StackedTrackerDetId stackDetId = detUnitIt->Id();
00879       //int layer = stackDetId.layer();
00880       //int iPhi  = stackDetId.iPhi();
00881       //int iZ    = stackDetId.iZ();
00882       //int doublestack;
00883       //if (layer%2==0) doublestack = layer/2;
00884       //else doublestack = (layer-1)/2;
00885       /*
00886         DetId testDet(stackDetId.rawId());
00887         PXBDetId testDetId(stackDetId.rawId());
00888         std::cerr<<"layer "<<layer<<" "<<testDetId.layer()<<std::endl;
00889         
00890         uint32_t uPhi = testDetId.ladder();
00891         if ( uPhi > 768 ) uPhi -= 768;
00892         else if ( uPhi > 512 ) uPhi -= 512;
00893         else if ( uPhi > 256 ) uPhi -= 256;
00894 
00895         uint32_t uZ = testDetId.module();
00896         if ( uZ%2 == 0 ) uZ = uZ/2;
00897         else uZ = (uZ-1)/2;
00898 
00899         std::cerr<<"ORIGINAL:"<<std::endl;
00900         std::cerr<<stackDetId<<std::endl;
00901 
00902         StackedTrackerDetId pippo( 1, testDetId.layer(), uPhi, uZ );
00903         std::cerr<<"TEST:"<<std::endl;
00904         std::cerr<<pippo<<std::endl;
00905       */
00906       //const GeomDetUnit* detUnit = theStackedGeometry->idToDetUnit( stackDetId, layer%2 );
00907       //GlobalPoint zeroZeroPoint = detUnit->toGlobal( detUnit->topology().localPosition( MeasurementPoint( 0, 0) ) );
00908       //hGeom_Layer_R->Fill( zeroZeroPoint.perp(), layer );
00909       //hGeom_iPhi_Phi->Fill( zeroZeroPoint.phi(), iPhi );
00910       //hGeom_iZ_Z->Fill( zeroZeroPoint.z(), iZ );
00911 
00912     } 
00913 
00914     testedGeometry = true;
00915   }
00916 
00917 
00918 } 
00919 
00921 //                             //
00922 // SOME OTHER CUSTOM FUNCTIONS //
00923 //                             //
00925 
00926 
00927 
00928 
00929 
00930 
00932 // DEFINE THIS AS A PLUG-IN
00933 DEFINE_FWK_MODULE(HitDump);
00934 
00935 
00936 
00937