9 #include "FPCCDPixelHit.h"
10 #include "FPCCDData.h"
14 #include <EVENT/MCParticle.h>
15 #include <IMPL/TrackerHitImpl.h>
16 #include <IMPL/TrackerHitPlaneImpl.h>
17 #include <gear/ZPlanarParameters.h>
18 #include <gear/ZPlanarLayerLayout.h>
19 #include <UTIL/CellIDEncoder.h>
20 #include "UTIL/LCTOOLS.h"
22 #include <ILDCellIDEncoding.h>
23 #include "UTIL/LCTrackerConf.h"
24 #include <UTIL/ILDConf.h>
26 #include <gsl/gsl_randist.h>
43 #include "CLHEP/Vector/LorentzVector.h"
44 #include <marlin/Global.h>
45 #include <EVENT/Track.h>
46 #include <gear/GEAR.h>
47 #include <gear/BField.h>
50 using namespace lcio ;
51 using namespace marlin ;
60 _description =
"FPCCDClustering icteats TrackerHits from FPCCDPixelHits" ;
64 registerProcessorParameter(
"Debug",
69 registerProcessorParameter(
"EnergyDigitizatoin",
70 "switch for digitization of energy deposit",
74 registerProcessorParameter(
"RandomNoise",
75 "Random noise option",
79 registerProcessorParameter(
"FPCCD_PixelSize" ,
80 "Pixel size of FPCCD (unit:mm) (default: 0.005)",
88 FloatVec PixelSizeVec;
89 PixelSizeVec.push_back(0.005);
90 PixelSizeVec.push_back(0.005);
91 PixelSizeVec.push_back(0.010);
92 PixelSizeVec.push_back(0.010);
93 PixelSizeVec.push_back(0.010);
94 PixelSizeVec.push_back(0.010);
96 registerProcessorParameter(
"Each_FPCCD_pixelSize(mm)",
97 "Each ladder's Pixel size of FPCCD (unit:mm) (default:0.005)",
103 registerProcessorParameter(
"PixelHeight" ,
108 registerProcessorParameter(
"PointResolutionRPhi" ,
109 "R-Phi Resolution in VTX" ,
113 registerProcessorParameter(
"PointResolutionZ" ,
114 "Z Resolution in VTX" ,
118 registerProcessorParameter(
"positionReso_ReadingFile_ON",
119 "true: reading file for allocation of position reso. false: rough allocation of position reso. ",
123 registerProcessorParameter(
"positionReso_ReadingFile",
124 "On: reading file for allocation of position reso.",
126 std::string(
"MarlinReco/v01-05/TrackDigi/FPCCDDigi/src/FPCCDClustering_ResoMap_MS_EL_ON_ver0.dat"));
128 registerProcessorParameter(
"noiseElectronSigma",
129 "gaussian sigma of number of electron of noise",
133 registerProcessorParameter(
"NumberOfBitsForEnergyDeposit",
134 "Number of Bits used for energy depsit",
138 registerProcessorParameter(
"NumberOfElectronForStep",
139 "Number of electron for 1 step",
143 registerProcessorParameter(
"Threshold",
144 "Cell Threshold in electrons",
148 registerProcessorParameter(
"ElectronsPerKeV",
161 registerProcessorParameter(
"ClusterRejection_1stCut_isActive",
162 "If true, 1stCut is active. false makes this inactive. minus value makes cut on the layer inactive ",
173 registerProcessorParameter(
"ClusterRejection_1stCut_ZWidth",
174 "Clusters with ZWidth >= this value are discarded. minus value makes cut on the layer inactive",
178 IntVec RPhiWidthVec(6);
179 RPhiWidthVec[0] = 10;
180 RPhiWidthVec[1] = 10;
185 registerProcessorParameter(
"ClusterRejection_1stCut_RPhiWidth",
186 "Clusters with RPhiWidth >= this value are discarded. minus value makes cut on the layer inactive ",
197 registerProcessorParameter(
"ClusterRejection_1stCut_nPix",
198 "Clusters with nPix >= this value are discarded. minus value makes cut on the layer inactive",
202 registerProcessorParameter(
"ClusterRejection_Mori2ndCut_isActive",
203 "true: active, false: inactive",
214 registerProcessorParameter(
"ClusterRejection_Mori2ndCut_areaZ_parameter",
215 "You can choose float[0,~900]. 0 discards most of bad clusters, although some clusters are sacrified. minus value makes cut on the layer inactive",
220 registerProcessorParameter(
"ClusterRejection_Kamai2ndCut_isActive",
221 "true: active, false: inactive",
232 registerProcessorParameter(
"ClusterRejection_Kamai2ndCut_b_parameter",
233 "You can choose float[0,10]. less than 2 discards most of bad clusters, although some clusters are sacrified. minus value makes cut on the layer inactive",
237 IntVec MinZWidthVec(6);
244 registerProcessorParameter(
"ClusterRejection_Kamai2ndCut_Save_minimum_Cluster_Z_Width_parameter",
245 "You can choose int[0,~7]. If a cluster with ZWidth <= this value, this is not discarded.",
249 registerProcessorParameter(
"MakeRelationOftrkhitsAndsimthits",
250 "If false, Clustering doesn't make LCRelation.",
255 registerProcessorParameter(
"RemovePixelHitsCollection",
256 "Remove VTX Pixel Hits collection after processing",
261 registerInputCollection( LCIO::SIMTRACKERHIT,
262 "VTXCollectionName" ,
263 "Name of the VTX SimTrackerHit collection" ,
265 std::string(
"VXDCollection") ) ;
267 registerInputCollection( LCIO::LCGENERICOBJECT,
268 "VTXPixelHitCollection" ,
269 "Name of the VTX PixelHit collection" ,
271 std::string(
"VTXPixelHits") ) ;
274 registerOutputCollection( LCIO::TRACKERHIT,
276 "Name of the vxd TrackerHit output collection" ,
278 std::string(
"VXDTrackerHits") ) ;
280 registerOutputCollection( LCIO::LCRELATION,
281 "SimTrackerHitRelCollection" ,
282 "Name of TrackerHit SimTrackerHit relation collection" ,
284 std::string(
"VXDTrackerHitRelations") ) ;
286 registerProcessorParameter(
"outputRootFileName",
287 "output root file name & path (default: ./positionReso.root)",
289 std::string(
"./positionReso.root"));
291 registerProcessorParameter(
"treeName",
292 "tree name which belongs to the above output root file name & path(default: tree)",
312 _rng = gsl_rng_alloc(gsl_rng_ranlxs2);
320 _tree->Branch(
"nEvt",&
_nEvt,
"nEvt/I");
321 _tree->Branch(
"nlinks",&
_link.nlink,
"nlinks/I");
322 _tree->Branch(
"weight",
_link.weight,
"weight[nlinks]/F");
323 _tree->Branch(
"simthits_x",
_simthits.x,
"simthits_x[nlinks]/D");
324 _tree->Branch(
"simthits_y",
_simthits.y,
"simthits_y[nlinks]/D");
325 _tree->Branch(
"simthits_z",
_simthits.z,
"simthits_z[nlinks]/D");
326 _tree->Branch(
"simthits_R",
_simthits.R,
"simthits_R[nlinks]/D");
327 _tree->Branch(
"simthits_pdg",
_simthits.pdg,
"simthits_pdg[nlinks]/I");
328 _tree->Branch(
"simthits_mass",
_simthits.mass,
"simthits_mass[nlinks]/D");
329 _tree->Branch(
"simthits_vx",
_simthits.vx,
"simthits_vx[nlinks]/D");
330 _tree->Branch(
"simthits_vy",
_simthits.vy,
"simthits_vy[nlinks]/D");
331 _tree->Branch(
"simthits_vz",
_simthits.vz,
"simthits_vz[nlinks]/D");
332 _tree->Branch(
"simthits_px",
_simthits.px,
"simthits_px[nlinks]/F");
333 _tree->Branch(
"simthits_py",
_simthits.py,
"simthits_py[nlinks]/F");
334 _tree->Branch(
"simthits_pz",
_simthits.pz,
"simthits_pz[nlinks]/F");
335 _tree->Branch(
"simthits_pAbs",
_simthits.pAbs,
"simthits_pAbs[nlinks]/D");
336 _tree->Branch(
"simthits_theta",
_simthits.theta,
"simthits_theta[nlinks]/D");
337 _tree->Branch(
"simthits_phi",
_simthits.phi,
"simthits_phi[nlinks]/D");
338 _tree->Branch(
"simthits_area_theta",
_simthits.area_theta,
"simthits_area_theta[nlinks]/D");
339 _tree->Branch(
"simthits_area_phi",
_simthits.area_phi,
"simthits_area_phi[nlinks]/D");
340 _tree->Branch(
"simthits_layer",
_simthits.layer,
"simthits_layer[nlinks]/I");
341 _tree->Branch(
"simthits_ladder",
_simthits.ladder,
"simthits_ladder[nlinks]/I");
342 _tree->Branch(
"simthits_mcp_px",
_simthits.mcp_px,
"simthits_mcp_px[nlinks]/D");
343 _tree->Branch(
"simthits_mcp_py",
_simthits.mcp_py,
"simthits_mcp_py[nlinks]/D");
344 _tree->Branch(
"simthits_mcp_pz",
_simthits.mcp_pz,
"simthits_mcp_pz[nlinks]/D");
345 _tree->Branch(
"simthits_mcp_energy",
_simthits.mcp_energy,
"simthits_mcp_energy[nlinks]/D");
346 _tree->Branch(
"simthits_mcp_time",
_simthits.mcp_time,
"simthits_mcp_time[nlinks]/F");
347 _tree->Branch(
"simthits_mcp_Pt",
_simthits.mcp_Pt,
"simthits_mcp_Pt[nlinks]/D");
348 _tree->Branch(
"simthits_mcp_isCreatedInSimulation",
_simthits.mcp_isCreatedInSimulation,
"simthits_mcp_isCreatedInSimulation[nlinks]/I");
349 _tree->Branch(
"simthits_mcp_isBackscatter",
_simthits.mcp_isBackscatter,
"simthits_mcp_isBackscatter[nlinks]/I");
350 _tree->Branch(
"simthits_mcp_vertexIsNotEndpointOfParent",
_simthits.mcp_vertexIsNotEndpointOfParent,
"simthits_mcp_vertexIsNotEndpointOfParent[nlinks]/I");
351 _tree->Branch(
"simthits_mcp_isDecayedInTracker",
_simthits.mcp_isDecayedInTracker,
"simthits_mcp_isDecayedInTracker[nlinks]/I");
352 _tree->Branch(
"simthits_mcp_isDecayedInCalorimeter",
_simthits.mcp_isDecayedInCalorimeter,
"simthits_mcp_isDecayedInCalorimeter[nlinks]/I");
353 _tree->Branch(
"simthits_mcp_hasLeftDetector",
_simthits.mcp_hasLeftDetector,
"simthits_mcp_hasLeftDetector[nlinks]/I");
354 _tree->Branch(
"simthits_mcp_isStopped",
_simthits.mcp_isStopped,
"simthits_mcp_isStopped[nlinks]/I");
355 _tree->Branch(
"simthits_mcp_d0",
_simthits.mcp_d0,
"simthits_mcp_d0[nlinks]/F");
356 _tree->Branch(
"simthits_mcp_z0",
_simthits.mcp_z0,
"simthits_mcp_z0[nlinks]/F");
357 _tree->Branch(
"simthits_mcp_phi0",
_simthits.mcp_phi0,
"simthits_mcp_phi0[nlinks]/F");
358 _tree->Branch(
"simthits_mcp_omega",
_simthits.mcp_omega,
"simthits_mcp_omega[nlinks]/F");
359 _tree->Branch(
"simthits_mcp_tanL",
_simthits.mcp_tanL,
"simthits_mcp_tanL[nlinks]/F");
360 _tree->Branch(
"simthits_xi",
_simthits.xi,
"simthits_xi[nlinks]/D");
361 _tree->Branch(
"simthits_zeta",
_simthits.zeta,
"simthits_zeta[nlinks]/D");
362 _tree->Branch(
"simthits_edep",
_simthits.edep,
"simthits_edep[nlinks]/F");
368 _tree->Branch(
"trkhits_x",
_trkhits.x,
"trkhits_x[nlinks]/D");
369 _tree->Branch(
"trkhits_y",
_trkhits.y,
"trkhits_y[nlinks]/D");
370 _tree->Branch(
"trkhits_z",
_trkhits.z,
"trkhits_z[nlinks]/D");
371 _tree->Branch(
"trkhits_R",
_trkhits.R,
"trkhits_R[nlinks]/D");
372 _tree->Branch(
"trkhits_area_theta",
_trkhits.area_theta,
"trkhits_area_theta[nlinks]/D");
373 _tree->Branch(
"trkhits_area_phi",
_trkhits.area_phi,
"trkhits_area_phi[nlinks]/D");
374 _tree->Branch(
"trkhits_CWidth_RPhi",
_trkhits.CWidth_RPhi,
"trkhits_CWidth_RPhi[nlinks]/i");
375 _tree->Branch(
"trkhits_CWidth_Z",
_trkhits.CWidth_Z,
"trkhits_CWidth_Z[nlinks]/i");
376 _tree->Branch(
"trkhits_tilt",
_trkhits.tilt,
"trkhits_tilt[nlinks]/i");
377 _tree->Branch(
"trkhits_nPix",
_trkhits.nPix,
"trkhits_nPix[nlinks]/i");
378 _tree->Branch(
"trkhits_layer",
_trkhits.layer,
"trkhits_layer[nlinks]/I");
379 _tree->Branch(
"trkhits_ladder",
_trkhits.ladder,
"trkhits_ladder[nlinks]/I");
380 _tree->Branch(
"trkhits_xi",
_trkhits.xi,
"trkhits_xi[nlinks]/D");
381 _tree->Branch(
"trkhits_zeta",
_trkhits.zeta,
"trkhits_zeta[nlinks]/D");
382 _tree->Branch(
"trkhits_edep",
_trkhits.edep,
"trkhits_edep[nlinks]/F");
384 _tree->Branch(
"trkhits_tposX",
_trkhits.tposX,
"trkhits_tposX[nlinks]/D");
385 _tree->Branch(
"trkhits_tposY",
_trkhits.tposY,
"trkhits_tposY[nlinks]/D");
386 _tree->Branch(
"trkhits_tposZ",
_trkhits.tposZ,
"trkhits_tposZ[nlinks]/D");
387 _tree->Branch(
"trkhits_cx",
_trkhits.cx,
"trkhits_cx[nlinks]/D");
388 _tree->Branch(
"trkhits_cy",
_trkhits.cy,
"trkhits_cy[nlinks]/D");
389 _tree->Branch(
"trkhits_cz",
_trkhits.cz,
"trkhits_cz[nlinks]/D");
390 _tree->Branch(
"trkhits_dot",
_trkhits.dot,
"trkhits_dot[nlinks]/D");
392 _tree->Branch(
"diff_RPhi",
_diff.RPhi,
"diff_RPhi[nlinks]/D");
393 _tree->Branch(
"diff_Z",
_diff.Z,
"diff_Z[nlinks]/D");
404 std::cout <<
"========FATAL ERROR============================" << std::endl;
405 std::cout <<
"positionReso_ReadingFile is not opened!! exit!!" << std::endl;
407 std::cout <<
"The above path seems to be wrong. " << std::endl;
408 std::cout <<
"FPCCDClustering exits! " << std::endl;
409 std::cout <<
"===============================================" << std::endl;
414 for(
int i = 0 ; i < 6 ; i++){
415 for(
int j = 1 ; j <= 49 ; j++){
417 short int code = i * 100 + j;
421 for(
int i = 0 ; i < 6 ; i++){
422 for(
int j = 1 ; j <= 49 ; j++){
424 short int code = i * 100 + j;
436 const gear::ZPlanarParameters &gearVXD = Global::GEAR->getVXDParameters();
437 const gear::ZPlanarLayerLayout &layerVXD=gearVXD.getVXDLayerLayout();
439 _nLayer = layerVXD.getNLayers() ;
444 _geodata[ly].nladder = layerVXD.getNLadders(ly);
446 _geodata[ly].rmin = layerVXD.getSensitiveDistance(ly);
448 _geodata[ly].phi0 = layerVXD.getPhi0(ly);
449 _geodata[ly].sthick = layerVXD.getSensitiveThickness(ly);
450 _geodata[ly].sximin = -layerVXD.getSensitiveOffset(ly)
451 -layerVXD.getSensitiveWidth(ly)/2.0;
452 _geodata[ly].sximax = -layerVXD.getSensitiveOffset(ly)
453 +layerVXD.getSensitiveWidth(ly)/2.0;
454 _geodata[ly].hlength = layerVXD.getSensitiveLength(ly);
460 for(
int ld=0;ld<
_geodata[ly].nladder;ld++) {
464 double incline = phi - (M_PI/2.0);
465 while( incline > 1.0*M_PI || incline < -1.0*M_PI ){ incline > 1.0*M_PI ? incline -= 2.0*M_PI : incline += 2.0*M_PI ;}
466 _geodata[ly].ladder_incline[ld] = incline;
482 LCCollection* STHcol=0;
485 catch(DataNotAvailableException &
e){
486 if (
_debug >= 1) { std::cout <<
"Collection " <<
_colNameVTX.c_str() <<
" is unavailable in event "
487 <<
_nEvt << std::endl; }
490 try { STHcol = evt->getCollection(
_colNameSTH ) ; }
491 catch(DataNotAvailableException &e){
492 if (
_debug >= 1) { std::cout <<
"Collection " <<
_colNameSTH.c_str() <<
" is unavailable in event "
493 <<
_nEvt << std::endl; }
498 std::cout <<
" Collection =" <<
_colNameVTX <<
" nevt=" <<
_nEvt << std::endl;
499 std::cout <<
" Collection =" <<
_colNameSTH <<
" nevt=" <<
_nEvt << std::endl;
500 if( pHitCol != 0 ) { std::cout <<
" number of elements is " << pHitCol->getNumberOfElements() << std::endl; }
501 if( STHcol != 0 ) { std::cout <<
" number of elements is " << STHcol->getNumberOfElements() << std::endl; }
504 if( pHitCol != 0 && STHcol != 0){
506 int nhit=theData.unpackPixelHits(*pHitCol);
508 if(
_debug >= 2 ) { LCTOOLS::dumpEvent( evt ) ;}
510 if(
_debug >=2 ) { std::cout <<
" nhit=" << nhit << std::endl; }
517 LCFlagImpl lcFlag(0);
518 lcFlag.setBit( LCIO::LCREL_WEIGHTED );
519 relCol->setFlag( lcFlag.getFlag() );
527 std::cout <<
"dumpEvent FPCCDClustering" << std::endl;
528 LCTOOLS::dumpEvent( evt ) ;
531 for(
int i = pHitCol->getNumberOfElements(); i>0; i--){
532 pHitCol->removeElementAt(i-1);
546 if( pHitCol != 0 && STHcol != 0){
550 catch(DataNotAvailableException &e){
552 std::cout <<
"miss getCollection!! at _nEvt = " <<
_nEvt << std::endl;
554 <<
_nEvt << std::endl; }
572 LCFlagImpl forRootlcFlag(0);
573 forRootlcFlag.setBit( LCIO::LCREL_WEIGHTED );
575 rootRelCol->setFlag( forRootlcFlag.getFlag() );
578 _link.nlink = rootRelCol->getNumberOfElements();
579 for(
unsigned int ri = 0; ri <
_link.nlink; ri++ ){
580 LCRelation* link_p =
dynamic_cast<LCRelation*
>( rootRelCol->getElementAt(ri) );
581 _link.weight[ri] = link_p->getWeight();
582 TrackerHit* trkhit_p =
dynamic_cast<TrackerHit*
>( link_p->getFrom() );
583 SimTrackerHit* simthit_p =
dynamic_cast<SimTrackerHit*
>( link_p->getTo() );
585 _simthits.x[ri] = simthit_p->getPosition()[0];
586 _simthits.y[ri] = simthit_p->getPosition()[1];
587 _simthits.z[ri] = simthit_p->getPosition()[2];
590 _simthits.pdg[ri] = simthit_p->getMCParticle()->getPDG();
591 _simthits.mass[ri] = simthit_p->getMCParticle()->getMass();
592 _simthits.px[ri] = simthit_p->getMomentum()[0];
593 _simthits.py[ri] = simthit_p->getMomentum()[1];
594 _simthits.pz[ri] = simthit_p->getMomentum()[2];
595 _simthits.mcp_px[ri] = simthit_p->getMCParticle()->getMomentum()[0];
596 _simthits.mcp_py[ri] = simthit_p->getMCParticle()->getMomentum()[1];
597 _simthits.mcp_pz[ri] = simthit_p->getMCParticle()->getMomentum()[2];
599 _simthits.vx[ri] = simthit_p->getMCParticle()->getVertex()[0];
600 _simthits.vy[ri] = simthit_p->getMCParticle()->getVertex()[1];
601 _simthits.vz[ri] = simthit_p->getMCParticle()->getVertex()[2];
602 _simthits.mcp_energy[ri] = simthit_p->getMCParticle()->getEnergy();
603 _simthits.mcp_time[ri] = simthit_p->getMCParticle()->getTime();
604 _simthits.mcp_isCreatedInSimulation[ri] = simthit_p->getMCParticle()->isCreatedInSimulation();
605 _simthits.mcp_isBackscatter[ri] = simthit_p->getMCParticle()->isBackscatter();
606 _simthits.mcp_vertexIsNotEndpointOfParent[ri] = simthit_p->getMCParticle()->vertexIsNotEndpointOfParent();
607 _simthits.mcp_isDecayedInTracker[ri] = simthit_p->getMCParticle()->isDecayedInTracker();
608 _simthits.mcp_isDecayedInCalorimeter[ri] = simthit_p->getMCParticle()->isDecayedInCalorimeter();
609 _simthits.mcp_hasLeftDetector[ri] = simthit_p->getMCParticle()->hasLeftDetector();
610 _simthits.mcp_isStopped[ri] = simthit_p->getMCParticle()->isStopped();
624 _trkhits.x[ri] = trkhit_p->getPosition()[0];
625 _trkhits.y[ri] = trkhit_p->getPosition()[1];
626 _trkhits.z[ri] = trkhit_p->getPosition()[2];
640 int cellid1 = trkhit_p->getCellID1();
641 unsigned int xiwidth = cellid1 & 0x000001ff ;
642 unsigned int zetawidth = ( cellid1 >> 9 ) & 0x000001ff;
643 unsigned int nPix = ( cellid1 >> 18) & 0x000003ff;
644 unsigned int tilt = ( cellid1 >> 28) & 0x00000003;
671 const int cellId_sim = simthit_p->getCellID0();
672 UTIL::BitField64 encoder_sim( lcio::LCTrackerCellID::encoding_string() ) ;
673 encoder_sim.setValue(cellId_sim) ;
674 _simthits.layer[ri] = encoder_sim[lcio::LCTrackerCellID::layer()] ;
675 _simthits.ladder[ri] = encoder_sim[lcio::LCTrackerCellID::module()] ;
677 const int cellId_trk = trkhit_p->getCellID0();
678 UTIL::BitField64 encoder_trk( lcio::LCTrackerCellID::encoding_string() ) ;
679 encoder_trk.setValue(cellId_trk) ;
680 _trkhits.layer[ri] = encoder_trk[lcio::LCTrackerCellID::layer()] ;
681 _trkhits.ladder[ri] = encoder_trk[lcio::LCTrackerCellID::module()] ;
690 double sinphi =
_geodata[tlayer].sinphi[tladder];
691 double cosphi =
_geodata[tlayer].cosphi[tladder];
692 lpos[0] = gpos[0] * sinphi - gpos[1] * cosphi + gpos[2] * 0;
693 lpos[1] = gpos[0] * cosphi + gpos[1] * sinphi + gpos[2] * 0;
694 lpos[2] = gpos[0] * 0 + gpos[1] * 0 + gpos[2] * 1;
703 sinphi =
_geodata[tlayer].sinphi[tladder];
704 cosphi =
_geodata[tlayer].cosphi[tladder];
705 lpos[0] = gpos[0] * sinphi - gpos[1] * cosphi + gpos[2] * 0;
706 lpos[1] = gpos[0] * cosphi + gpos[1] * sinphi + gpos[2] * 0;
707 lpos[2] = gpos[0] * 0 + gpos[1] * 0 + gpos[2] * 1;
723 const double xioffset[6] = {-5.5+1.575320104,
730 const double layerdistance[6] = { 15.9575,
736 const double hlength[6] = {62.5,62.5,125,125,125,125};
738 std::cout <<
"xioffset : " << std::endl;
739 for(
int jj = 0; jj < 6; jj++) std::cout << xioffset[jj] <<
" " << std::endl;
740 std::cout <<
"layerdistance : " << std::endl;
741 for(
int jj = 0; jj < 6; jj++) std::cout << layerdistance[jj] <<
" " << std::endl;
742 std::cout <<
"hlength : " << std::endl;
743 for(
int jj = 0; jj < 6; jj++) std::cout << hlength[jj] <<
" " << std::endl;
745 std::cout <<
" _geodata[ly].sximin : " << std::endl;
746 for(
int jj = 0; jj < 6; jj++) std::cout <<
_geodata[jj].sximin <<
" " << std::endl;
747 std::cout <<
" _geodata[ly].rmin : " << std::endl;
748 for(
int jj = 0; jj < 6; jj++) std::cout <<
_geodata[jj].rmin <<
" " << std::endl;
749 std::cout <<
" _geodata[ly].hlength : " << std::endl;
750 for(
int jj = 0; jj < 6; jj++) std::cout <<
_geodata[jj].hlength <<
" " << std::endl;
755 gear::Vector3D tpos(trkhit_p->getPosition()[0],trkhit_p->getPosition()[1],trkhit_p->getPosition()[2]);
762 double tposR = tpos.rho();
763 double tposphi = tpos.phi();
765 double TrkXi = tposR*(cos(tposphi)*
_geodata[mly].sinphi[mld]-sin(tposphi)*
_geodata[mly].cosphi[mld]) -
_geodata[mly].sximin;
766 double TrkZeta = tpos.z()+
_geodata[mly].hlength;
768 _trkhits.edep[ri] = trkhit_p->getEDep();
769 _simthits.edep[ri] = simthit_p->getEDep();
776 if(tilt>1) sign = -1;
779 TVector3 ClusterDir(pixelsize*(xiwidth-1),sign*pixelsize*(zetawidth-1),
_pixelheight);
780 TVector3 revClusterDir(-ClusterDir.X(),-ClusterDir.Y(),ClusterDir.Z());
782 if( revClusterDir.Unit().Dot( tposDir.Unit() ) > ClusterDir.Unit().Dot( tposDir.Unit() )){
783 ClusterDir.SetX(revClusterDir.X());
784 ClusterDir.SetY(revClusterDir.Y());
786 _trkhits.cx[ri] = ClusterDir.Unit().X();
787 _trkhits.cy[ri] = ClusterDir.Unit().Y();
788 _trkhits.cz[ri] = ClusterDir.Unit().Z();
790 _trkhits.dot[ri] = ClusterDir.Unit().Dot( tposDir.Unit() );
811 typedef std::multimap< std::pair<int,int>, SimTrackerHit*> RelMap_t;
824 double sxiwidth = sximax-sximin;
840 PixelHitMap_t::iterator it=pHitData->itBegin(
layer,
ladder);
850 FPCCDPixelHit *aHit=(*it).second;
858 int xiID=aHit->getXiID();
859 int zetaID=aHit->getZetaID();
861 ladderHit.insert(map<FPCCDHitLoc_t, FPCCDPixelHit*>::value_type(hitloc, aHit));
867 unsigned int noiseXi = 0;
868 unsigned int noiseZeta = 0;
869 double noiseEdep = 0;
874 noiseZeta = (
unsigned int)gsl_ran_flat(
_rng, 0, 2*hlength/
_pixelSizeVec[layer] );
876 FPCCDLadderHit_t::iterator noiseIt=ladderHit.find( noiseHitLoc );
878 if( noiseIt == ladderHit.end() ){
880 FPCCDPixelHit* noiseHit =
new FPCCDPixelHit(layer,
ladder, noiseXi, noiseZeta, noiseEdep, FPCCDPixelHit::kBKG, 0);
882 ladderHit.insert( map<FPCCDHitLoc_t, FPCCDPixelHit*>::value_type( noiseHitLoc, noiseHit) );
887 if( ladderHit.size() > 0 ) {
895 std::cout <<
"Layer:" <<
layer <<
" ladder:" <<
ladder <<
" # of clusters=" << clusterVec.size() << std::endl;
896 std::cout <<
" # pixels in each clusters are ";
897 for(
unsigned int i=0;i<clusterVec.size();i++) {
898 std::cout << clusterVec[i]->size() <<
" " ;
899 if ( i > 1000 ) { std::cout <<
" ... omitting the rest. " ;
break; }
908 for(
int i=clusterVec.size()-1;i>=0;i--){
delete clusterVec[i]; }
929 CellIDEncoder<TrackerHitPlaneImpl> cellid_encoder( lcio::LCTrackerCellID::encoding_string() , trkHitVec ) ;
930 for(
unsigned int ic=0;ic<clusterVec.size();ic++) {
933 double xiene = 0.0;
double zetaene = 0.0;
double enesum = 0.0;
934 int maxxi = 0;
int minxi = 0;
int maxzeta = 0;
int minzeta = 0;
935 FPCCDPixelHit::HitQuality_t trackquality = FPCCDPixelHit::kSingle;
940 FPCCDPixelHit *maxXiHit=(*cluster)[0]; FPCCDPixelHit *minXiHit=(*cluster)[0];
941 FPCCDPixelHit *maxZetaHit=(*cluster)[0]; FPCCDPixelHit *minZetaHit=(*cluster)[0];
943 unsigned int nPix=cluster->size();
944 std::list<int> orderVecOfCluster(0);
945 for(
unsigned int i=0;i<
nPix;i++) {
947 int overlaidSize = (*cluster)[i]->getSizeOfOrderID();
949 for(
int ios = 0; ios < overlaidSize; ios++){
950 orderVecOfCluster.push_back( (*cluster)[i]->getOrderID(ios) );
954 FPCCDPixelHit *aHit=(*cluster)[i]; trackquality = aHit->getQuality(); enesum+=aHit->getEdep();
955 xiene+=((double)(aHit->getXiID()+0.5))*
_pixelSizeVec[layer]*aHit->getEdep();
956 zetaene+=((double)(aHit->getZetaID()+0.5))*
_pixelSizeVec[layer]*aHit->getEdep();
959 maxxi = aHit->getXiID(); minxi = maxxi;
960 maxzeta = aHit->getZetaID(); minzeta = maxzeta;
963 if( aHit->getXiID() > maxxi){ maxxi = aHit->getXiID(); maxXiHit=aHit;}
964 if( aHit->getXiID() < minxi){ minxi = aHit->getXiID(); minXiHit=aHit;}
965 if(aHit->getZetaID() > maxzeta){ maxzeta = aHit->getZetaID();maxZetaHit=aHit;}
966 if(aHit->getZetaID() < minzeta){ minzeta = aHit->getZetaID();minZetaHit=aHit;}
968 FPCCDPixelHit::HitQuality_t addedQuality = aHit->getQuality();
969 if( trackquality != FPCCDPixelHit::kBKGOverlap){
970 if(trackquality == FPCCDPixelHit::kBKG){
971 addedQuality=FPCCDPixelHit::kBKG ? trackquality=FPCCDPixelHit::kBKG : trackquality=FPCCDPixelHit::kBKGOverlap;
974 else if(addedQuality==FPCCDPixelHit::kSignalOverlap){trackquality=FPCCDPixelHit::kSignalOverlap; }
977 unsigned int xiWidth = maxxi-minxi + 1;
978 unsigned int zetaWidth = maxzeta-minzeta + 1;
984 unsigned short int tilt=0;
985 if( xiWidth==1 || zetaWidth==1 ) tilt=0;
987 if(maxXiHit->getZetaID()-minXiHit->getZetaID()>0 && maxZetaHit->getXiID()-minZetaHit->getXiID()>0) tilt=1;
988 else if(maxXiHit->getZetaID()-minXiHit->getZetaID()<=0 && maxZetaHit->getXiID()-minZetaHit->getXiID()<=0) tilt=2;
992 double xiave = xiene/enesum;
993 double zetaave = zetaene/enesum;
1004 + eta0*
_geodata[layer].cosphi[ladder];
1006 + eta0*
_geodata[layer].sinphi[ladder];
1017 std::vector<int> typesOfOrderID;
1018 orderVecOfCluster.sort();
1019 std::list<int>::iterator itlist;
1021 for(itlist = orderVecOfCluster.begin(); itlist != orderVecOfCluster.end(); itlist++){
1022 if(*itlist != tmpV){
1023 typesOfOrderID.push_back(*itlist);
1029 float pointResoRPhi = 0.0;
1030 float pointResoZ = 0.0;
1033 short int codeRPhi = layer * 100 + xiWidth;
1036 if(pointResoRPhi < 0.00001){ pointResoRPhi = (sqrt((
float)(xiWidth + 1.5)) - 1)*1
e-3; }
1038 else{ pointResoRPhi = (sqrt((
float)(xiWidth + 1.5)) - 1)*1
e-3; }
1040 short int codeZ = layer * 100 + zetaWidth;
1041 if(zetaWidth <= 49){
1043 if(pointResoZ < 0.00001){ pointResoZ = (sqrt((
float)(zetaWidth + 1.5)) - 1)*1
e-3; }
1045 else{ pointResoZ = (sqrt((
float)(zetaWidth + 1.5)) - 1)*1
e-3; }
1054 TrackerHitPlaneImpl* trkHit =
new TrackerHitPlaneImpl ;
1056 trkHit->setType( 100 + layer);
1058 cellid_encoder[ lcio::LCTrackerCellID::subdet() ] = lcio::ILDDetID::VXD ;
1059 cellid_encoder[ lcio::LCTrackerCellID::side() ] = 0 ;
1060 cellid_encoder[ lcio::LCTrackerCellID::layer() ] =
layer ;
1061 cellid_encoder[ lcio::LCTrackerCellID::module() ] =
ladder ;
1062 cellid_encoder[ lcio::LCTrackerCellID::sensor() ] = 0 ;
1064 cellid_encoder.setCellID( trkHit );
1066 unsigned int cellid1=0;
1067 cellid1 = ((trackquality << 30) & 0xc0000000) |
1068 ((tilt << 28) & 0x30000000) |
1069 ((nPix << 18) & 0x0ffc0000) |
1070 ((zetaWidth << 9) & 0x0003fe00) |
1071 ((xiWidth) & 0x000001ff) ;
1073 trkHit->setCellID1(cellid1);
1074 float u_direction[2] ;
1075 u_direction[0] = M_PI/2.0;
1078 float v_direction[2] ;
1079 v_direction[0] = 0.0 ;
1080 v_direction[1] = 0.0 ;
1082 trkHit->setU( u_direction ) ;
1083 trkHit->setV( v_direction ) ;
1087 trkHit->setdU( pointResoRPhi ) ;
1088 trkHit->setdV( pointResoZ ) ;
1090 trkHit->setPosition( newpos ) ;
1091 trkHit->setEDep( enesum );
1095 SimTrackerHit* p_simthit;
1096 int ntypes = typesOfOrderID.size();
1097 for(
int i = 0; i < ntypes; i++){
1098 LCRelationImpl* rel =
new LCRelationImpl ;
1099 if(typesOfOrderID[i] >= 0){
1100 p_simthit =
dynamic_cast<SimTrackerHit*
>( STHcol->getElementAt( typesOfOrderID[i] ) ) ;
1101 float nTo =
static_cast<float>( ntypes );
1102 rel->setTo( p_simthit );
1103 rel->setFrom( trkHit );
1104 rel->setWeight( nTo );
1105 relCol->addElement( rel );
1109 trkHitVec->addElement( trkHit );
1144 FPCCDLadderHit_t::iterator ih = ladderHit.begin();
1145 while( ih != ladderHit.end() ) {
1146 FPCCDPixelHit *h=(*ih).second;
1149 if( h==0 ) {
continue; }
1154 cluster->push_back(h);
1155 int xi0=h->getXiID();
1156 int zeta0=h->getZetaID();
1157 typedef std::pair<int, int> Direction_t;
1158 std::stack<Direction_t> direction;
1159 for(
int i=-1;i<=1;i++) {
1160 for(
int j=-1;j<=1;j++) {
1161 if( i!=0 || j!= 0 ) { direction.push(Direction_t(i,j)); }
1165 while( ! direction.empty() ) {
1166 Direction_t newdir=direction.top();
1167 int xi=xi0+newdir.first;
1168 int zeta=zeta0+newdir.second;
1170 if( xi < 0 || xi > maxxi || zeta < 0 || zeta > maxzeta ) {
1171 direction.pop();
continue;
1174 FPCCDLadderHit_t::iterator look=ladderHit.find(newloc);
1175 if( look == ladderHit.end() ) {
1176 direction.pop();
continue;
1178 FPCCDPixelHit *aHit=(*look).second;
1180 direction.pop();
continue;
1182 cluster->push_back( aHit );
1185 for (
int ix=-1;ix<=1;ix++) {
1186 for(
int iz=-1;iz<=1;iz++) {
1187 if( ix != 0 || iz != 0 ) {
1188 direction.push(Direction_t(newdir.first+ix, newdir.second+iz));
1193 if( cluster->size() > 0 ) {
1196 clusterVec.push_back(cluster);
1216 streamlog_out(MESSAGE) <<
" end() " <<
name()
1217 <<
" processed " <<
_nEvt <<
" events in " <<
_nRun <<
" runs "
1231 if(count > nStep ) count = nStep ;
1253 double bz = Global::GEAR->getBField().at(
gear::Vector3D( 0.,0.,0.) ).z() ;
1255 p = pmcp->getMomentum();
1256 const double pi = 3.14159265359;
1257 const double pt = sqrt(p[0]*p[0]+p[1]*p[1]) ;
1258 double radius = pt / (2.99792458E-4*bz) ;
1259 double omega = pmcp->getCharge()/radius ;
1260 double tanL = p[2]/pt ;
1261 double oldphi0 = atan2(p[1],p[0]);
1262 while( oldphi0 <= -pi ){ oldphi0 += 2. *
pi ; }
1263 while( oldphi0 > pi ){ oldphi0 -= 2. *
pi ; }
1265 double oldsinphi0 = std::sin(oldphi0);
1266 double oldcosphi0 = std::cos(oldphi0);
1267 double centx = pmcp->getVertex()[0] + 1/omega * oldcosphi0;
1268 double centy = pmcp->getVertex()[1] + 1/omega * oldsinphi0;
1270 if(omega > 0){ newphi0 = std::atan2(centy,centx); }
1271 else{ newphi0 = std::atan2(-centy,-centx); }
1272 double sinphi0 = std::sin(newphi0);
1273 double cosphi0 = std::cos(newphi0);
1274 double d0 = centx * cosphi0 + centy * sinphi0 - 1.0/omega ;
1275 double z0 = pmcp->getVertex()[2] - 1.0/omega *(newphi0 - oldphi0)*tanL;
struct FPCCDClustering::firstCut _firstCut
virtual void init()
Called at the begin of the job before anything is read.
unsigned int nPix[MAX_LINK]
ResoMap _resolutionMapRPhi
double _electronNoiseRate
std::pair< unsigned int, unsigned int > FPCCDHitLoc_t
std::vector< GeoData_t > _geodata
std::string _rootFileName
bool _positionReso_ReadingFile_ON
struct FPCCDClustering::Kamai2ndCut _k2Cut
std::map< FPCCDHitLoc_t, FPCCDPixelHit * > FPCCDLadderHit_t
CLHEP::Hep3Vector Vector3D
unsigned int tilt[MAX_LINK]
struct FPCCDClustering::@11 _simthits
std::string _outRelColNameVTX
std::string _positionReso_ReadingFile
void makeClustersInALadder(int layer, FPCCDLadderHit_t &ladderHit, FPCCDClusterVec_t &cvec)
FPCCDClustering aFPCCDClustering
virtual void processRunHeader(LCRunHeader *run)
Called for every run.
std::string _outColNameVTX
void calcTrackParameterOfMCP(MCParticle *pmcp, double *par)
std::vector< FPCCDCluster_t * > FPCCDClusterVec_t
struct FPCCDClustering::Mori2ndCut _m2Cut
std::vector< LCCollection * > LCCollectionVec
std::vector< FPCCDPixelHit * > FPCCDCluster_t
virtual void end()
Called after data processing for clean up.
virtual void check(LCEvent *evt)
Called for every event - the working horse.
void EnergyDigitizer(FPCCDPixelHit *aHit)
struct FPCCDClustering::@13 _diff
struct FPCCDClustering::@12 _trkhits
bool _remove_pixelhits_collection
struct FPCCDClustering::@10 _link
virtual const std::string & name() const
virtual void modifyEvent(LCEvent *evt)
void makeTrackerHit(LCCollection *STHcol, int layer, int ladder, FPCCDClusterVec_t &cvec, std::multimap< std::pair< int, int >, SimTrackerHit * > relMap, LCCollectionVec *relCol, LCCollectionVec *trkHitVec)
void makeTrackerHitVec(FPCCDData *pxHits, LCCollection *STHcol, LCCollectionVec *relCol, LCCollectionVec *trkHitvec)