TesIO.cxx

Go to the documentation of this file.
00001 #include "AtlfastUtils/TesIO.h"
00002 #include <cmath> 
00003 #include <algorithm>
00004 #include "AtlfastUtils/FunctionObjects.h"
00005 #include "GeneratorObjects/McEventCollection.h"
00006 #include "AtlfastUtils/HepMC_helper/IMCselector.h"
00007 #include "AtlfastUtils/HepMC_helper/All.h"
00008 #include "AtlfastEvent/CollectionDefs.h"
00009 #include "HepMC/GenEvent.h"
00010 #include "HepMC/GenParticle.h"
00011 
00012 namespace Atlfast {
00013 
00014 
00015   //Wrapper class for  polymorphic selectors:  STL
00016   //passes function objects by value...(Meyers, Effective STL item 38)
00017   
00018   class SelectorBridge{
00019   public:
00020     SelectorBridge(const HepMC_helper::IMCselector* s):m_selector(s){}
00021     bool operator()(const GenParticle* p) {
00022       return m_selector->operator()(p);
00023     }
00024   private:
00025     const HepMC_helper::IMCselector* m_selector;
00026   };
00027   
00028   TesIoStat TesIO::getMC(MCparticleCollection& mcParticles) const {
00029     HepMC_helper::All selector;
00030     TesIoStat stat = this->getMC(mcParticles, &selector);
00031     return stat;
00032   }
00033 
00034   
00035   TesIoStat TesIO::getMC(MCparticleCollection& mcParticles, 
00036                          const HepMC_helper::IMCselector* selector) const {
00037     
00038     const McEventCollection* mcCollptr(0);
00039     TesIoStat stat;
00040     if(m_mcLocation==""){
00041       // std::cout<<"MCLOCATION1=BLANK"<<std::endl;
00042       stat = this->getDH(mcCollptr);
00043     }else{
00044       // std::cout<<"MCLOCATION1=NONBLANK"<<std::endl;
00045       stat = this->getDH(mcCollptr,m_mcLocation);
00046     }
00047     
00048     if(!stat){
00049       return TesIoStat(StatusCode::FAILURE,"Could not find MC ptcles in TES");
00050     }
00051     
00052     //    HepMC_helper::MCselectorWrapper wrappedSelector(selector);
00053     
00054     // Iterate over all McEvent records
00055     McEventCollection::const_iterator itr;
00056     for (itr = mcCollptr->begin(); itr!=mcCollptr->end(); ++itr) {
00057       
00058       // For 12.0.4, GenEvents are not aware of their status (hard scatter,
00059       // pileup, etc.. The following line ensures only the first event in the 
00060       // McEventCollection is considered until the situation changes and 
00061       // IsFromHardScatter can do more than just return true!
00062       
00063       if ( m_justHardScatter && itr != mcCollptr->begin() ) continue;
00064       
00065       //16/10/03 Genevt has been removed
00066       // Access the HepMC record which is wrapped within McEvent
00067       //16/10/03      HepMC::GenEvent* genEvt = (*itr)->pGenEvt()  ;
00068       //16/10/03      if(genEvt == 0) return TesIoStat(StatusCode::FAILURE,
00069       //16/10/03                                       "Could not find HEP Gen event");
00070       
00071       
00072       
00073       /* idiot test - range inserter DOES NOT WORL!!    
00074       HepMC::GenEvent::particle_const_iterator j= (*itr)->particles_begin();
00075       HepMC::GenEvent::particle_const_iterator jj= (*itr)->particles_end();
00076       MCparticleCollection junk(j, jj);
00077       MCparticleCollection junk1;
00078       for(;j!=jj;++j){junk1.push_back(*j);}
00079       */
00080       //Copy ALL particles into mcParticles
00081 
00082         /*
00083        mcParticles.insert(mcParticles.end(),
00084                           (*itr)->particles_begin(),
00085                           (*itr)->particles_end()                        
00086                           );
00087         */
00088 
00089       //partition moves the unselected particles to the back of
00090       //the vector. Use erase to regain space and reset the constianer end.
00091       
00092       //mcParticles.erase(
00093       //                std::partition(mcParticles.begin(),
00094       //                               mcParticles.end(),
00095       //                               SelectorBridge(selector)
00096       //                               ),
00097       //                mcParticles.end()
00098       //                );
00099       
00100       
00101     
00102       
00103       HepMC::GenEvent::particle_const_iterator it= (*itr)->particles_begin();
00104       HepMC::GenEvent::particle_const_iterator en= (*itr)->particles_end();
00105       for(; it!=en; ++it){
00106         if((*selector)(*it)){mcParticles.push_back(*it);}
00107       }
00108       
00109     }
00110     return TesIoStat(StatusCode::SUCCESS);
00111   }
00113   TesIoStat 
00114   TesIO::getMCweightContainers(MCweightContainerCollection& 
00115                                mcWeightContainers)const {
00116     
00117     const McEventCollection* mcCollptr(0);
00118     TesIoStat stat;
00119     if(m_mcLocation==""){
00120       // std::cout<<"MCLOCATION2=BLANK"<<std::endl;
00121     stat = this->getDH(mcCollptr);
00122     }else{
00123     stat = this->getDH(mcCollptr, m_mcLocation);
00124     // std::cout<<"MCLOCATION2=NONBLANK"<<std::endl;
00125     }
00126     if(!stat){
00127       return TesIoStat(StatusCode::FAILURE,"Could not find MCEventCollection");
00128     }
00129       
00130     //    HepMC_helper::MCselectorWrapper wrappedSelector(selector);
00131     
00132     // Iterate over all McEvent records
00133     McEventCollection::const_iterator itr;
00134     for (itr = mcCollptr->begin(); itr!=mcCollptr->end(); ++itr) {
00135 
00136       //having a real hard time (as usual) with HepMC containers
00137       //intead, do a little copying...
00138       
00139       MCweightContainer container( ((*itr)->weights()).begin(), 
00140                                    ((*itr)->weights()).end()
00141                                    ); 
00142       mcWeightContainers.push_back( container );
00143     }
00144       
00145     return TesIoStat(StatusCode::SUCCESS);
00146   }
00147 }//namespace
00148 
00149 
00150 
00151 
00152 
00153 
00154 
00155 
00156 
00157 
00158 
00159 
00160 

Generated on Fri Sep 21 13:20:37 2007 for AtlfastUtils by  doxygen 1.5.1