/****************************************************************\ | This file is part of the PAX example files for CDF | | -------------------------------------------------------------- | | Author of the last change: $Author: erdmann $ | Date of last change: $Date: 2003/11/18 15:13:17 $ | Revision number: $Revision: 1.2 $ \****************************************************************/ // //! example pax algorithm: // //! MergeElectrons merges a calorimeter event interpretations and an electron //! event interpretation into one combined event interpretation without double //! counting of energy. // //! The electrons are found within the calorimeter event interpretation //! by the eta-phi tower assignment. The calorimeter tower energy is then //! replaced by the kinematics of the electron. // //! The algorithm contains an example how to access from a pax fourvector //! the original member function EtaPhi() of the calorimeter tower. // #include "TPAXAnaModule.hh" #include "PAX/PAXexperimentclass.hh" #include "PAX/PAXfourvector.hh" #include "PAX/PAXinterpret.hh" #include "PAX/PAXiterator.hh" #include "PAX/PAXmap.hh" #include "PAX/PAXvertex.hh" #include int TPAXAnaModule::MergeElectrons( PaxEventInterpret* calorimeter, PaxEventInterpret* electron, PaxEventInterpret* merged_event_interpretation ) { string name_event_interpretation = "electrons merged with caltowers"; int number_of_electrons = 0; // -------------------------------------------------------------------- // check input // -------------------------------------------------------------------- // if output event interpretation is not empty: clear it if ( ! merged_event_interpretation->IsEmpty() ) merged_event_interpretation->clear(); // check for proper input if ( calorimeter->IsEmpty() && electron->IsEmpty() ) { cout << "makeElectron: proper input missing" << endl; return number_of_electrons;; } // if calorimeter event interpretation is empty, return electrons if ( calorimeter->IsEmpty() ) { // copy electron event interpretation merged_event_interpretation->copy( electron ); // set name of event interpretation merged_event_interpretation->SetPaxName( name_event_interpretation ); // get number of fourvectors from the size of the fourvector map number_of_electrons = merged_event_interpretation->fourvector->size(); return number_of_electrons; } // fill output event interpretation with calorimeter event interpretation // and correct the electron towers below merged_event_interpretation->copy( calorimeter ); // set name of event interpretation merged_event_interpretation->SetPaxName( name_event_interpretation ); // if electron event interpretation is empty, return calorimeter if ( electron->IsEmpty() ) return number_of_electrons;; // -------------------------------------------------------------------- // for fast match between calorimeter towers and electrons: // fill map of calorimeter towers with integer eta-phi key and pointer // to the calorimeter PaxFourVector // -------------------------------------------------------------------- PaxFourVectorMap* calomap = new PaxFourVectorMap; // for eta-phi-key need to access original CDF class string experiment_class_manager="TCalTower"; // iterator for fourvectors PaxIterator* iter_calo = merged_event_interpretation->fourvector->GetIterator(); // loop over all calorimeter towers for ( iter_calo->First(); !iter_calo->IsDone(); iter_calo->Next() ) { // check if manager for experiment class relation exists if ( iter_calo->CurrentItem()->map_experimentclass_relations ->findItemByKey( experiment_class_manager )) { // loop over the relations to the CDF class (here only one) PaxIterator* iter_ec = iter_calo->CurrentItem()->map_experimentclass_relations ->findItemByKey( experiment_class_manager )->GetIterator(); for (iter_ec->First(); !iter_ec->IsDone(); iter_ec->Next() ) { // downcast from pax experiment class to detector class PaxExperiment* calorimeter_tower = dynamic_cast* > (iter_ec->CurrentItem()); // get the eta-phi key int ietaphi = calorimeter_tower->data->EtaPhi(); // fill calorimeter map according to the eta-phi key calomap->add( ietaphi, iter_calo->CurrentItem() ); } } } // -------------------------------------------------------------------- // for all electrons find the corresponding calorimeter tower // using the eta-phi-key, and correct the tower energy // -------------------------------------------------------------------- // loop over the electron fourvectors PaxIterator* iter_electron = electron->fourvector->GetIterator(); for ( iter_electron->First(); !iter_electron->IsDone(); iter_electron->Next()) { PaxFourVector* fv_electron = iter_electron->CurrentItem(); // check if manager for experiment class relation exists if (fv_electron->map_experimentclass_relations ->findItemByKey( experiment_class_manager ) ) { // loop over the relations to the CDF class (here only one) PaxIterator* iter_ec = fv_electron->map_experimentclass_relations ->findItemByKey( experiment_class_manager )->GetIterator(); for (iter_ec->First(); !iter_ec->IsDone(); iter_ec->Next() ) { // downcast from pax experimentclass to detector class PaxExperiment* electron_tower = dynamic_cast* > (iter_ec->CurrentItem()); // get the eta-phi key int ietaphi = electron_tower->data->EtaPhi(); // find the corresponding tower in the calorimeter map PaxFourVector* fv_calo = calomap->findItemByKey( ietaphi ); if ( fv_calo ) { // replace kinematics of calorimeter tower // by the electron kinematics fv_calo->setPx ( fv_electron->px() ); fv_calo->setPy ( fv_electron->py() ); fv_calo->setPz ( fv_electron->pz() ); fv_calo->setE ( fv_electron->e () ); fv_calo->setCharge ( fv_electron->getCharge () ); fv_calo->setPaxName ( fv_electron->getPaxName() ); fv_calo->setParticleId( fv_electron->getParticleId() ); fv_calo->addExperimentClassRelations( fv_electron ); // increment number of electrons number_of_electrons++; } } } } // clear memory delete calomap; return number_of_electrons; } //_____________________________________________________________________________