6 #define AIDATT_USE_DD4HEP 1
17 #include "IO/LCWriter.h"
18 #include "EVENT/LCEvent.h"
19 #include "EVENT/LCCollection.h"
20 #include "EVENT/SimTrackerHit.h"
21 #include "UTIL/LCTrackerConf.h"
23 #include <IMPL/LCCollectionVec.h>
24 #include "IMPL/TrackImpl.h"
27 #include "DD4hep/Detector.h"
28 #include "DD4hep/DD4hepUnits.h"
29 #include "DDRec/SurfaceHelper.h"
30 #include "DDRec/SurfaceManager.h"
31 #include "DDRec/Surface.h"
32 #include "DDRec/CellIDPositionConverter.h"
37 #include "aidaTT/DD4hepGeometry.hh"
38 #include "aidaTT/AidaTT.hh"
39 #include "aidaTT/ConstantSolenoidBField.hh"
40 #include "aidaTT/analyticalPropagation.hh"
41 #include "aidaTT/simplifiedPropagation.hh"
42 #include "aidaTT/GBLInterface.hh"
43 #include "aidaTT/fitResults.hh"
49 int main(
int argc,
char** argv)
53 std::cout <<
" usage: ./gbl_example ILDEx.xml ILDExSimu.slcio" << std::endl ;
58 std::string inFile = argv[1] ;
62 theDet.fromCompact(inFile);
64 dd4hep::DetElement world = theDet.world() ;
66 aidaTT::DD4hepGeometry geom(theDet);
68 const auto& surfaces = geom.getSurfaces() ;
70 dd4hep::rec::CellIDPositionConverter cellid_converter(theDet);
72 dd4hep::rec::SurfaceManager& surfMan = *theDet.extension<dd4hep::rec::SurfaceManager>() ;
76 std::map< long64, const aidaTT::ISurface* > surfMap ;
77 for(
const auto& surf : surfaces)
79 surfMap[surf->id() ] = (surf) ;
86 std::string lcioFileName = argv[2] ;
88 LCReader* rdr = LCFactory::getInstance()->createLCReader() ;
89 rdr->open(lcioFileName) ;
91 std::string outFileName =
"trackTest.slcio";
93 LCWriter* wrt = LCFactory::getInstance()->createLCWriter() ;
94 wrt->open(outFileName) ;
98 std::vector< std::string > colNames ;
99 colNames.push_back(
"SiTrackerBarrelHits") ;
104 UTIL::BitField64 idDecoder(LCTrackerCellID::encoding_string()) ;
113 aidaTT::trackParameters bogusTP;
119 const double initialOmega = 1.5 * 1e-4;
120 const double initialTanLambda = 1.;
121 const double initialPhi = M_PI_2;
123 bogusTP.setTrackParameters(aidaTT::Vector5(initialOmega, initialTanLambda, initialPhi, 0., 0.));
127 aidaTT::ConstantSolenoidBField* bfield =
new aidaTT::ConstantSolenoidBField(3.5);
130 aidaTT::analyticalPropagation* propagation =
new aidaTT::analyticalPropagation();
134 aidaTT::GBLInterface* fitter =
new aidaTT::GBLInterface();
137 while((evt = rdr->readNextEvent()) != 0)
140 IMPL::LCCollectionVec* outputTrackCollection =
new IMPL::LCCollectionVec(EVENT::LCIO::TRACK);
141 std::string outName =
"trytracks";
143 std::cout <<
" reading an event " << std::endl;
145 aidaTT::trajectory theMaster(bogusTP, fitter, propagation, &geom);
147 for(
unsigned icol = 0, ncol = colNames.size() ; icol < ncol ; ++icol)
149 LCCollection* col = NULL;
152 col = evt->getCollection(colNames[ icol ]) ;
154 catch(DataNotAvailableException &e)
159 int nHit = col->getNumberOfElements() ;
161 for(
int i = 0 ; i < nHit ; ++i)
163 SimTrackerHit* sHit = (SimTrackerHit*) col->getElementAt(i) ;
164 long64
id = sHit->getCellID0() ;
172 const aidaTT::ISurface* surf = surfMap[ id ] ;
174 dd4hep::rec::Vector3D pos1;
175 pos1 = surf->origin();
176 double recalcPos[3] = {pos1.x(), pos1.y(), pos1.z()};
177 if(surf->type().isSensitive()) {
179 std::vector<double> precisionDummy;
180 precisionDummy.push_back(1. / 0.0001);
181 precisionDummy.push_back(1. / 0.00012);
185 theMaster.addMeasurement(recalcPos, precisionDummy, *surf, sHit);
189 theMaster.prepareForFitting();
192 const aidaTT::fitResults& result = *(theMaster.getFitResults());
194 TrackImpl* theTrack =
new TrackImpl();
195 theTrack->setOmega(result.estimatedParameters()(0)) ;
196 theTrack->setTanLambda(result.estimatedParameters()(1));
197 theTrack->setPhi(result.estimatedParameters()(2));
198 theTrack->setD0(result.estimatedParameters()(3));
199 theTrack->setZ0(result.estimatedParameters()(4));
201 TrackImpl* theInitialTrack =
new TrackImpl();
202 theInitialTrack->setOmega(initialOmega) ;
203 theInitialTrack->setTanLambda(initialTanLambda);
204 theInitialTrack->setPhi(initialPhi);
205 theInitialTrack->setD0(0.);
206 theInitialTrack->setZ0(0.);
209 outputTrackCollection->addElement(theTrack);
210 outputTrackCollection->addElement(theInitialTrack);
213 evt->addCollection(outputTrackCollection , outName);
215 wrt->writeEvent(evt);