CMS 3D CMS Logo

ZToLLEdmNtupleDumper.cc

Go to the documentation of this file.
00001 /* \class ZToLLEdmNtupleDumper
00002  *
00003  * \author Luca Lista, INFN
00004  *
00005  */
00006 #include "FWCore/Framework/interface/EDProducer.h"
00007 #include "FWCore/ParameterSet/interface/InputTag.h"
00008 #include <vector> 
00009 
00010 class ZToLLEdmNtupleDumper : public edm::EDProducer {
00011 public:
00012   ZToLLEdmNtupleDumper( const edm::ParameterSet & );
00013 private:
00014   void produce( edm::Event &, const edm::EventSetup & );
00015   std::vector<std::string> zName_;
00016   std::vector<edm::InputTag> z_, zGenParticlesMatch_, isolations1_, isolations2_;
00017 };
00018 
00019 #include "DataFormats/Common/interface/Handle.h"
00020 #include "FWCore/Framework/interface/Event.h"
00021 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00022 #include "DataFormats/Candidate/interface/Candidate.h"
00023 #include "DataFormats/Candidate/interface/CandMatchMap.h"
00024 #include "DataFormats/Common/interface/AssociationVector.h"
00025 
00026 using namespace edm;
00027 using namespace std;
00028 using namespace reco;
00029 
00030 ZToLLEdmNtupleDumper::ZToLLEdmNtupleDumper( const ParameterSet & cfg ) {
00031   string alias;
00032   vector<ParameterSet> psets = cfg.getParameter<vector<ParameterSet> > ( "zBlocks" );
00033   for( std::vector<edm::ParameterSet>::const_iterator i = psets.begin(); i != psets.end(); ++ i ) {
00034     string zName = i->getParameter<string>( "zName" );
00035     InputTag z =  i->getParameter<InputTag>( "z" );
00036     InputTag zGenParticlesMatch = i->getParameter<InputTag>( "zGenParticlesMatch" );
00037     InputTag isolations1 = i->getParameter<InputTag>( "isolations1" );
00038     InputTag isolations2 = i->getParameter<InputTag>( "isolations2" );
00039     zName_.push_back( zName );
00040     z_.push_back( z );
00041     zGenParticlesMatch_.push_back( zGenParticlesMatch );
00042     isolations1_.push_back( isolations1 );
00043     isolations2_.push_back( isolations2 );
00044     produces<vector<float> >( alias = zName + "Mass" ).setBranchAlias( alias );
00045     produces<vector<float> >( alias = zName + "Pt" ).setBranchAlias( alias );
00046     produces<vector<float> >( alias = zName + "Eta" ).setBranchAlias( alias );
00047     produces<vector<float> >( alias = zName + "Phi" ).setBranchAlias( alias );
00048     produces<vector<float> >( alias = zName + "Y" ).setBranchAlias( alias );
00049     produces<vector<float> >( alias = zName + "Dau1Pt" ).setBranchAlias( alias );
00050     produces<vector<float> >( alias = zName + "Dau2Pt" ).setBranchAlias( alias );
00051     produces<vector<float> >( alias = zName + "Dau1Eta" ).setBranchAlias( alias );
00052     produces<vector<float> >( alias = zName + "Dau2Eta" ).setBranchAlias( alias );
00053     produces<vector<float> >( alias = zName + "Dau1Phi" ).setBranchAlias( alias );
00054     produces<vector<float> >( alias = zName + "Dau2Phi" ).setBranchAlias( alias );
00055     produces<vector<float> >( alias = zName + "Dau1Iso" ).setBranchAlias( alias );
00056     produces<vector<float> >( alias = zName + "Dau2Iso" ).setBranchAlias( alias );
00057     produces<vector<float> >( alias = zName + "TrueMass" ).setBranchAlias( alias );
00058     produces<vector<float> >( alias = zName + "TruePt" ).setBranchAlias( alias );
00059     produces<vector<float> >( alias = zName + "TrueEta" ).setBranchAlias( alias );
00060     produces<vector<float> >( alias = zName + "TruePhi" ).setBranchAlias( alias );
00061     produces<vector<float> >( alias = zName + "TrueY" ).setBranchAlias( alias );
00062   }
00063 }
00064 
00065 void ZToLLEdmNtupleDumper::produce( Event & evt, const EventSetup & ) {
00066   size_t size = z_.size();
00067   for( size_t c = 0; c < size; ++ c ) {
00068     Handle<CandidateCollection> zColl;
00069     evt.getByLabel( z_[c], zColl );
00070     Handle<CandMatchMap> zGenParticlesMatch;
00071     evt.getByLabel( zGenParticlesMatch_[c], zGenParticlesMatch );
00072     typedef AssociationVector<CandidateRefProd,vector<double> > IsolationCollection;
00073     Handle<IsolationCollection> isolations1, isolations2;
00074     evt.getByLabel( isolations1_[c], isolations1 );
00075     evt.getByLabel( isolations2_[c], isolations2 );
00076     size_t zSize = zColl->size();
00077     auto_ptr<vector<float> > zMass( new vector<float> );
00078     auto_ptr<vector<float> > zPt( new vector<float> );
00079     auto_ptr<vector<float> > zEta( new vector<float> );
00080     auto_ptr<vector<float> > zPhi( new vector<float> );
00081     auto_ptr<vector<float> > zY( new vector<float> );
00082     auto_ptr<vector<float> > zDau1Pt( new vector<float> );
00083     auto_ptr<vector<float> > zDau2Pt( new vector<float> );
00084     auto_ptr<vector<float> > zDau1Eta( new vector<float> );
00085     auto_ptr<vector<float> > zDau2Eta( new vector<float> );
00086     auto_ptr<vector<float> > zDau1Phi( new vector<float> );
00087     auto_ptr<vector<float> > zDau2Phi( new vector<float> );
00088     auto_ptr<vector<float> > zDau1Iso( new vector<float> );
00089     auto_ptr<vector<float> > zDau2Iso( new vector<float> );
00090     auto_ptr<vector<float> > trueZMass( new vector<float> );
00091     auto_ptr<vector<float> > trueZPt( new vector<float> );
00092     auto_ptr<vector<float> > trueZEta( new vector<float> );
00093     auto_ptr<vector<float> > trueZPhi( new vector<float> );
00094     auto_ptr<vector<float> > trueZY( new vector<float> );
00095     for( size_t i = 0; i < zSize; ++ i ) {
00096       const Candidate & z = (*zColl)[ i ];
00097       CandidateRef zRef( zColl, i );
00098       zMass->push_back( z.mass() );
00099       zPt->push_back( z.pt() );
00100       zEta->push_back( z.eta() );
00101       zPhi->push_back( z.phi() );
00102       zY->push_back( z.rapidity() );
00103       const Candidate * dau1 = z.daughter(0); 
00104       const Candidate * dau2 = z.daughter(1); 
00105       zDau1Pt->push_back( dau1->pt() );
00106       zDau2Pt->push_back( dau2->pt() );
00107       zDau1Eta->push_back( dau1->eta() );
00108       zDau2Eta->push_back( dau2->eta() );
00109       zDau1Phi->push_back( dau1->phi() );
00110       zDau2Phi->push_back( dau2->phi() );
00111       double iso1 = (*isolations1)[ dau1->masterClone().castTo<CandidateRef>() ];
00112       double iso2 = (*isolations2)[ dau2->masterClone().castTo<CandidateRef>() ];
00113       zDau1Iso->push_back( iso1 );
00114       zDau2Iso->push_back( iso2 );
00115       CandMatchMap::const_iterator trueZIter = zGenParticlesMatch->find( zRef );
00116       if ( trueZIter != zGenParticlesMatch->end() ) {
00117         CandidateRef trueZRef = trueZIter->val;
00118         if( trueZRef.isNonnull() ) {
00119           const Candidate & z = * trueZRef;
00120           trueZMass->push_back( z.mass() );
00121           trueZPt->push_back( z.pt() );
00122           trueZEta->push_back( z.eta() );      
00123           trueZPhi->push_back( z.phi() );      
00124           trueZY->push_back( z.rapidity() );      
00125         } else {
00126           trueZMass->push_back( -100 );
00127           trueZPt->push_back( -100 );
00128           trueZEta->push_back( -100 );      
00129           trueZPhi->push_back( -100 );      
00130           trueZY->push_back( -100 );      
00131         }
00132       }
00133     }
00134     const string & zName = zName_[c];
00135     evt.put( zMass, zName +  "Mass" );
00136     evt.put( zPt, zName + "Pt" );
00137     evt.put( zEta, zName + "Eta" );
00138     evt.put( zPhi, zName + "Phi" );
00139     evt.put( zY, zName + "Y" );
00140     evt.put( zDau1Pt, zName + "Dau1Pt" );
00141     evt.put( zDau2Pt, zName + "Dau2Pt" );
00142     evt.put( zDau1Eta, zName + "Dau1Eta" );
00143     evt.put( zDau2Eta, zName + "Dau2Eta" );
00144     evt.put( zDau1Phi, zName + "Dau1Phi" );
00145     evt.put( zDau2Phi, zName + "Dau2Phi" );
00146     evt.put( zDau1Iso, zName + "Dau1Iso" );
00147     evt.put( zDau2Iso, zName + "Dau2Iso" );
00148     evt.put( trueZMass, zName +  "TrueMass" );
00149     evt.put( trueZPt, zName + "TruePt" );
00150     evt.put( trueZEta, zName + "TrueEta" );
00151     evt.put( trueZPhi, zName + "TruePhi" );
00152     evt.put( trueZY, zName + "TrueY" );
00153   }
00154 }
00155 
00156 #include "FWCore/Framework/interface/MakerMacros.h"
00157 
00158 DEFINE_FWK_MODULE( ZToLLEdmNtupleDumper );
00159 

Generated on Tue Jun 9 17:34:19 2009 for CMSSW by  doxygen 1.5.4