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; } }