void EUTelProcessorTrackAnalysis::processEvent(LCEvent * evt){ EUTelEventImpl * event = static_cast<EUTelEventImpl*> (evt); ///We change the class so we can use EUTelescope functions if (event->getEventType() == kEORE) { streamlog_out(DEBUG4) << "EORE found: nothing else to do." << endl; return; }else if (event->getEventType() == kUNKNOWN) { streamlog_out(WARNING2) << "Event number " << event->getEventNumber() << " in run " << event->getRunNumber() << " is of unknown type. Continue considering it as a normal Data Event." << endl; } LCCollection* eventCollection = NULL; try { eventCollection = evt->getCollection(_trackInputCollectionName); streamlog_out(DEBUG1) << "collection : " << _trackInputCollectionName << " retrieved" << std::endl; }catch (DataNotAvailableException e) { streamlog_out(MESSAGE0) << _trackInputCollectionName << " collection not available" << std::endl; throw marlin::SkipEventException(this); } if (eventCollection != NULL) { streamlog_out(DEBUG2) << "Collection contains data! Continue!" << endl; for (int iTrack = 0; iTrack < eventCollection->getNumberOfElements(); ++iTrack){ EUTelTrack track = *(static_cast<EUTelTrack*> (eventCollection->getElementAt(iTrack))); _analysis->plotResidualVsPosition(track); _analysis->plotIncidenceAngles(track); } } }
/// Loop over collection and extract particle data size_t LCIOEventHandler::collectionLoop(const std::string& collection, DDEveParticleActor& actor) { Branches::const_iterator ibr = m_branches.find(collection); if ( ibr != m_branches.end() ) { LCCollection* c = (*ibr).second; if ( c ) { DDEveParticle part; int n = c->getNumberOfElements(); actor.setSize(n); for(int i=0; i<n; ++i) { LCObject* ptr = c->getElementAt(i); if ( _convertParticleFunc(ptr,&part) ) { actor(part); } } return n; } } return 0; }
/// Load the next event bool LCIOEventHandler::NextEvent() { m_data.clear(); m_hasEvent = false; m_branches.clear(); m_data.clear(); if ( hasFile() ) { m_event = m_lcReader->readNextEvent(); if ( m_event ) { typedef std::vector<std::string> _S; const _S* collnames = m_event->getCollectionNames(); for( _S::const_iterator i = collnames->begin(); i != collnames->end(); ++i) { LCCollection* c = m_event->getCollection(*i); m_data[c->getTypeName()].push_back(make_pair((*i).c_str(),c->getNumberOfElements())); m_branches[*i] = c; } m_hasEvent = true; return 1; } throw runtime_error("+++ EventHandler::readEvent: Failed to read event"); } throw runtime_error("+++ EventHandler::readEvent: No file open!"); }
void EUTelProcessorCoordinateTransformHits::processEvent(LCEvent* event) { //Check the event type and if it is the last event. EUTelEventImpl* evt = static_cast<EUTelEventImpl*>(event); if( evt->getEventType() == kEORE ) { streamlog_out( MESSAGE5 ) << "EORE found: nothing else to do." << std::endl; return; } else if( evt->getEventType() == kUNKNOWN ) { streamlog_out( WARNING2 ) << "Event number " << evt->getEventNumber() << " in run " << evt->getRunNumber() << " is of unknown type. Continue considering it as a normal Data Event." << std::endl; } //Opens collection for input. LCCollection* inputCollection = nullptr; try { inputCollection = evt->getCollection(_hitCollectionNameInput); } catch (DataNotAvailableException& e) { streamlog_out( WARNING2 ) << _hitCollectionNameInput << " collection not available" << std::endl; return; } LCCollectionVec* outputCollection = nullptr; try { outputCollection = static_cast<LCCollectionVec*> (event->getCollection( _hitCollectionNameOutput )); } catch(...) { outputCollection = new LCCollectionVec(LCIO::TRACKERHIT); } std::string encoding = inputCollection->getParameters().getStringVal( LCIO::CellIDEncoding ); if(encoding.empty()) { encoding = EUTELESCOPE::HITENCODING; } lcio::CellIDDecoder<TrackerHitImpl> hitDecoder ( encoding ); lcio::UTIL::CellIDReencoder<TrackerHitImpl> cellReencoder( encoding, outputCollection ); //Now get each individual hit LOOP OVER! for(int iHit = 0; iHit < inputCollection->getNumberOfElements(); ++iHit) { TrackerHitImpl* inputHit = static_cast<TrackerHitImpl*>(inputCollection->getElementAt(iHit)); TrackerHitImpl* outputHit = new IMPL::TrackerHitImpl(); //Call the local2masterHit/master2localHit function defined int EUTelGeometryTelescopeDescription int properties = hitDecoder(inputHit)["properties"]; int sensorID = hitDecoder(inputHit)["sensorID"]; const double* inputPos = inputHit->getPosition(); double outputPos[3]; if( !(properties & kHitInGlobalCoord) && !_undoAlignment ) { streamlog_out(DEBUG5) << "Transforming hit from local to global!" << std::endl; // std::cout<<"Local Sensor: " << sensorID << " " << inputPos[0]<< " " << inputPos[1]<< " " << inputPos[2]<<std::endl; geo::gGeometry().local2Master(sensorID, inputPos, outputPos); // std::cout<<"Global Sensor: " << sensorID << " " << outputPos[0]<< " " << outputPos[1]<< " " << outputPos[2]<<std::endl; } else if( (properties & kHitInGlobalCoord) && _undoAlignment ) { streamlog_out(DEBUG5) << "Transforming hit from global to local!" << std::endl; geo::gGeometry().master2Local(sensorID, inputPos, outputPos); } else { std::cout << "Properties: " << properties <<std::endl; std::string errMsg; if(!_undoAlignment) errMsg = "Provided global hit, but trying to transform into global. Something is wrong!"; else errMsg = "Provided local hit, but trying to transform into local. Something is wrong!"; throw InvalidGeometryException(errMsg); } //Fill the new outputHit with information outputHit->setPosition(outputPos); outputHit->setCovMatrix( inputHit->getCovMatrix()); outputHit->setType( inputHit->getType() ); outputHit->setTime( inputHit->getTime() ); outputHit->setCellID0( inputHit->getCellID0() ); outputHit->setCellID1( inputHit->getCellID1() ); outputHit->setQuality( inputHit->getQuality() ); outputHit->rawHits() = inputHit->getRawHits(); cellReencoder.readValues(outputHit); //^= is a bitwise XOR i.e. we will switch the coordinate sytsem cellReencoder["properties"] = properties ^= kHitInGlobalCoord; cellReencoder.setCellID(outputHit); outputCollection->push_back(outputHit); } //Now push the hit for this event onto the collection try { event->addCollection(outputCollection, _hitCollectionNameOutput ); } catch(...) { streamlog_out ( WARNING5 ) << "Problem with pushing collection onto event" << std::endl; } }
/* Example program for (re) fitting LCIO tracks with aidaTT. * */ int main(int argc, char** argv) { if(argc < 3) { std::cout << " usage: ./lcio_tracks compact.xml input_tracks.slcio [output_file.slcio]" << std::endl ; return 1; } #ifdef AIDATT_USE_STREAMLOG streamlog::out.init( std::cout , "lcio_tracks" ) ; streamlog::logscope scope(streamlog::out) ; scope.setLevel<VERBOSITY>() ; #endif std::string inFile = argv[1] ; const aidaTT::IGeometry& geom = aidaTT::IGeometry::instance( inFile ) ; const SurfaceVec& surfaces = geom.getSurfaces() ; // create map of surfaces for(std::vector<const aidaTT::ISurface*>::const_iterator surf = surfaces.begin() ; surf != surfaces.end() ; ++surf){ surfMap[(*surf)->id() ] = (*surf) ; } //********************************************************************* /// lcio stuff std::string lcioFileName = argv[2] ; int counter = -1 ; LCReader* rdr = LCFactory::getInstance()->createLCReader() ; rdr->open(lcioFileName) ; LCWriter* wrt = LCFactory::getInstance()->createLCWriter() ; if(argc == 4) { std::string outFile = argv[3]; wrt->open(outFile) ; } else { wrt->open("aidaTT_tracks.slcio", lcio::LCIO::WRITE_NEW ) ; } LCEvent* evt = 0 ; UTIL::BitField64 idDecoder(LCTrackerCellID::encoding_string()) ; // create the propagation object aidaTT::analyticalPropagation* propagation = new aidaTT::analyticalPropagation(); //aidaTT::simplifiedPropagation* propagation = new aidaTT::simplifiedPropagation(); // create the fitter object aidaTT::GBLInterface* fitter = new aidaTT::GBLInterface(); /// event loop while( (evt = rdr->readNextEvent()) != 0 && ++counter < maxEvent ) { LCCollection* trackCollection = evt->getCollection(trackCollectionName) ; // add output track collection to the event LCCollectionVec* outCol = new LCCollectionVec(LCIO::TRACK) ; evt->addCollection( outCol, outColName ) ; LCFlagImpl trkFlag(0) ; trkFlag.setBit(LCIO::TRBIT_HITS) ; outCol->setFlag(trkFlag.getFlag()) ; int nTracks = trackCollection->getNumberOfElements(); // loop over all tracks in the collection for( unsigned i=0 ; i<nTracks ; ++i){ TrackImpl* outTrk = new TrackImpl ; outCol->addElement(outTrk) ; Track* initialTrack = (Track*) trackCollection->getElementAt(i) ; aidaTT::trackParameters iTP( aidaTT::readLCIO( initialTrack->getTrackState( trkStateIndex ) ) ); const TrackerHitVec& initialHits = initialTrack->getTrackerHits(); unsigned nHits = initialHits.size() ; if( nHits < 3) { streamlog_out( DEBUG5 ) << " less than three hits - track is dropped ..." << std::endl ; continue ; } if( compute_start_helix ) { //---------------------------------------------------------------------------------------------------- aidaTT::trackParameters startHelix ; //--------- get the start helix from three points bool backwards = false ; lcio::TrackerHit* h1 = ( backwards ? initialHits[ nHits-1 ] : initialHits[ 0 ] ) ; lcio::TrackerHit* h2 = initialHits[ (nHits+1) / 2 ] ; lcio::TrackerHit* h3 = ( backwards ? initialHits[ 0 ] : initialHits[ nHits-1 ] ) ; const double* pos1 = h1->getPosition() ; const double* pos2 = h2->getPosition() ; const double* pos3 = h3->getPosition() ; aidaTT::Vector3D x1( pos1[0] * dd4hep::mm, pos1[1] * dd4hep::mm , pos1[2] * dd4hep::mm ) ; aidaTT::Vector3D x2( pos2[0] * dd4hep::mm, pos2[1] * dd4hep::mm , pos2[2] * dd4hep::mm ) ; aidaTT::Vector3D x3( pos3[0] * dd4hep::mm, pos3[1] * dd4hep::mm , pos3[2] * dd4hep::mm ) ; calculateStartHelix( x1, x2, x3 , startHelix , backwards ) ; moveHelixTo( startHelix, aidaTT::Vector3D(), false ) ; // move to origin // --- set some large errors to the covariance matrix startHelix.covarianceMatrix().Unit() ; startHelix.covarianceMatrix()( aidaTT::OMEGA, aidaTT::OMEGA ) = 1.e-2 ; startHelix.covarianceMatrix()( aidaTT::TANL , aidaTT::TANL ) = 1.e2 ; startHelix.covarianceMatrix()( aidaTT::PHI0 , aidaTT::PHI0 ) = 1.e2 ; startHelix.covarianceMatrix()( aidaTT::D0 , aidaTT::D0 ) = 1.e5 ; startHelix.covarianceMatrix()( aidaTT::Z0 , aidaTT::Z0 ) = 1.e5 ; streamlog_out( DEBUG4 ) << " start helix from three points : " << startHelix << std::endl ; // use this helix as start for the fit: iTP = ( run_prefit ? createPreFit( startHelix , initialHits ) : startHelix ) ; } TrackStateImpl* ts; bool success; aidaTT::trajectory fitTrajectory( iTP, fitter, propagation, &geom); const aidaTT::fitResults* result = 0 ; //fitTrajectory.getFitResults(); streamlog_out( DEBUG1 ) << " magnetic field at origin " << fitTrajectory.geometry()->getBField( aidaTT::Vector3D() ) << std::endl ; // copy the hits in order to get strip hits in case of spacepoints TrackerHitVec lcioHits ; for(unsigned i=0 ; i < nHits ; ++i){ TrackerHit* trkHit = initialHits[i] ; outTrk->addHit( trkHit ) ; if( UTIL::BitSet32( trkHit->getType() )[ UTIL::ILDTrkHitTypeBit::COMPOSITE_SPACEPOINT ] ){ const EVENT::LCObjectVec rawObjects = trkHit->getRawHits(); for( unsigned k=0; k< rawObjects.size(); k++ ){ EVENT::TrackerHit* rawHit = dynamic_cast< EVENT::TrackerHit* >( rawObjects[k] ); lcioHits.push_back( rawHit ) ; } } else { // normal non composite hit lcioHits.push_back( trkHit ) ; } } // ==== store hits in a map and in track =============== std::map< int, EVENT::TrackerHit*> hitMap ; for(unsigned i=0 ; i < lcioHits.size() ; ++i){ hitMap[ lcioHits[i]->getCellID0() ] = lcioHits[i] ; } //==== compute _all_ surface intersections ====================== const IntersectionVec* intersections = &fitTrajectory.getIntersectionsWithSurfaces( surfaces ) ; // now we have all surface intersections of the initial track seed // however the hits might be on neighbouring sensors really ... // ... to be sorted out ... //========= loop over all intersections ========= int pointLabel = 0 ; for( std::vector<std::pair<double, const aidaTT::ISurface*> >::const_iterator it = intersections->begin() ; it != intersections->end() ; ++it ){ const aidaTT::ISurface* surf = it->second ; EVENT::TrackerHit* hit = hitMap[ surf->id() ] ; streamlog_out(DEBUG4) << "intersection - current pointLabel : " << pointLabel << ": at s = " << it->first << " surface id : " << cellIDString( surf->id() ) << std::endl ; streamlog_out(DEBUG1) << aidaTT::pointAt(it->first, iTP ) << std::endl ; streamlog_out(DEBUG) << *surf << std::endl ; if( hit != 0 ){ //-------- we have to add a measurement double hitpos[3] ; std::vector<double> precision ; getHitInfo( hit, hitpos, precision , surf) ; fitTrajectory.addMeasurement( hitpos, precision, *surf, hit , useQMS ); ++pointLabel ; streamlog_out(DEBUG3) << "addMeasurement called for pointLabel : " << pointLabel << std::endl ; } else { // we just add a scatterer if ( useQMS ){ // ignore virtual surface with no material (e.g. inside the beam pipe ) if( ! ( surf->innerMaterial().density() < 1e-6 && surf->outerMaterial().density() < 1e-6 ) ) { fitTrajectory.addScatterer( *surf ) ; ++pointLabel ; streamlog_out(DEBUG3) << " addScatterer called for pointLabel : " << pointLabel << std::endl ; } } } } fitTrajectory.prepareForFitting(); success = fitTrajectory.fit(); result = fitTrajectory.getFitResults(); //*********************************************************************************************************** if( ! success ) { streamlog_out( ERROR ) << " ********** ERROR: Fit Failed !!!!! ****" << std::endl ; } streamlog_out( DEBUG ) << " End of the loop " << std::endl ; streamlog_out( DEBUG ) << " initial values " << std::endl; streamlog_out( DEBUG ) << iTP << std::endl; streamlog_out( DEBUG ) << " refitted values " << std::endl; streamlog_out( DEBUG ) << result->estimatedParameters() << std::endl; // add Track State to track: ts = aidaTT::createLCIO( result->estimatedParameters() ); //DEBUG: return seed track: ts = aidaTT::createLCIO( iTP ); outTrk->setChi2( result->chiSquare() ) ; outTrk->setNdf( result->ndf() ) ; outTrk->subdetectorHitNumbers().resize(10.) ; outTrk->subdetectorHitNumbers()[0] = outTrk->getTrackerHits().size() ; float ref[3] = { 0., 0. , 0. } ; ts->setReferencePoint(ref); ts->setLocation(lcio::TrackState::AtIP); // checking the covariance matrix //-------------------------------------------------------------------- std::vector<float> cm = ts->getCovMatrix(); trackParameters finalAidaTP = result->estimatedParameters(); fiveByFiveMatrix finalAidaCovMat = finalAidaTP.covarianceMatrix(); //--------------------------------------------------------------------- outTrk->addTrackState(ts); } wrt->writeEvent(evt) ; } streamlog_out( DEBUG ) << " counter = " << counter << std::endl ; return 0; }