CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

edm::TestMixedSource Class Reference

#include <TestMixedSource.h>

Inheritance diagram for edm::TestMixedSource:
edm::EDAnalyzer edm::EDConsumerBase

List of all members.

Public Member Functions

 TestMixedSource (const edm::ParameterSet &)
 ~TestMixedSource ()

Private Member Functions

virtual void analyze (const edm::Event &, const edm::EventSetup &) override
virtual void beginJob ()
virtual void endJob ()

Private Attributes

int bunchcr_
std::string fileName_
TFile * histFile_
TH1I * histHepMCProduct_bunch_
TH1I * histPCaloHit_bunch_
TH1I * histPSimHit_bunchPileups_MuonCSCHits_
TH1I * histPSimHit_bunchPileups_TrackerHitsTECHighTof_
TH1I * histPSimHit_bunchSignal_MuonCSCHits_
TH1I * histPSimHit_bunchSignal_TrackerHitsTECHighTof_
TH1I * histTrack_bunchPileups_
TH1I * histTrack_bunchSignal_
TH1I * histVertex_bunch_
int maxbunch_
int minbunch_
ofstream outputFile
TH1I * tofhist_
TH1I * tofhist_sig_

Detailed Description

Definition at line 46 of file TestMixedSource.h.


Constructor & Destructor Documentation

TestMixedSource::TestMixedSource ( const edm::ParameterSet iConfig) [explicit]

Definition at line 56 of file TestMixedSource.cc.

References histHepMCProduct_bunch_, histPCaloHit_bunch_, histPSimHit_bunchPileups_MuonCSCHits_, histPSimHit_bunchPileups_TrackerHitsTECHighTof_, histPSimHit_bunchSignal_MuonCSCHits_, histPSimHit_bunchSignal_TrackerHitsTECHighTof_, histTrack_bunchPileups_, histTrack_bunchSignal_, histVertex_bunch_, maxbunch_, minbunch_, tofhist_, and tofhist_sig_.

: fileName_(iConfig.getParameter<std::string>("fileName")), minbunch_(iConfig.getParameter<int>("minBunch")),maxbunch_(iConfig.getParameter<int>("maxBunch"))
{ 
  
  histTrack_bunchSignal_ = new TH1I("histoTrackSignal","Bunchcrossings",maxbunch_-minbunch_+1,minbunch_,maxbunch_+1);
  histTrack_bunchPileups_ = new TH1I("histoTrackPileups","Bunchcrossings",maxbunch_-minbunch_+1,minbunch_,maxbunch_+1);

  // Vertex
  histVertex_bunch_ = new TH1I("histoVertex","Bunchcrossings",maxbunch_-minbunch_+1,minbunch_,maxbunch_+1);
  
  // PCaloHit
  histPCaloHit_bunch_ = new TH1I("histoPCaloHit","Bunchcrossings",maxbunch_-minbunch_+1,minbunch_,maxbunch_+1);
  
  // PSimHit
  histPSimHit_bunchSignal_TrackerHitsTECHighTof_ = new TH1I("histoPSimHitTrackerHitsTECHighTofSignal","Bunchcrossings",maxbunch_-minbunch_+1,minbunch_,maxbunch_+1);
  histPSimHit_bunchPileups_TrackerHitsTECHighTof_ = new TH1I("histoPSimHitTrackerHitsTECHighTofPileups","Bunchcrossings",maxbunch_-minbunch_+1,minbunch_,maxbunch_+1);
  histPSimHit_bunchSignal_MuonCSCHits_ = new TH1I("histoPSimHitMuonCSCHitsSignal","Bunchcrossings",maxbunch_-minbunch_+1,minbunch_,maxbunch_+1);
  histPSimHit_bunchPileups_MuonCSCHits_ = new TH1I("histoPSimHitMuonCSCHitsPileups","Bunchcrossings",maxbunch_-minbunch_+1,minbunch_,maxbunch_+1);

  int bsp = 25;//bunchspace
  tofhist_ = new TH1I ("TrackerHit_Tof_bcr","TrackerHit_ToF",100,float(bsp*minbunch_),float(bsp*maxbunch_)+50.);
  tofhist_sig_ = new TH1I("SignalTrackerHit_Tof_bcr","TrackerHit_ToF",100,float(bsp*minbunch_),float(bsp*maxbunch_)+50.);


  // HepMCProduct
  histHepMCProduct_bunch_ = new TH1I("histoHepMCProduct","Bunchcrossings",maxbunch_-minbunch_+1,minbunch_,maxbunch_+1);

}
TestMixedSource::~TestMixedSource ( )

Definition at line 86 of file TestMixedSource.cc.

References gather_cfg::cout.

{ std::cout << " Destructor TestMixed"  << std::endl;

}

Member Function Documentation

void TestMixedSource::analyze ( const edm::Event iEvent,
const edm::EventSetup iSetup 
) [override, private, virtual]

Implements edm::EDAnalyzer.

Definition at line 98 of file TestMixedSource.cc.

References a, b, MixCollection< T >::begin(), MixCollection< T >::MixItr::bunch(), trackerHits::c, cuy::col, gather_cfg::cout, alignCSCRings::e, MixCollection< T >::end(), edm::Event::getByLabel(), MixCollection< T >::MixItr::getTrigger(), histHepMCProduct_bunch_, histPCaloHit_bunch_, histPSimHit_bunchPileups_MuonCSCHits_, histPSimHit_bunchPileups_TrackerHitsTECHighTof_, histPSimHit_bunchSignal_MuonCSCHits_, histPSimHit_bunchSignal_TrackerHitsTECHighTof_, histTrack_bunchPileups_, histTrack_bunchSignal_, histVertex_bunch_, outputFile, edm::Handle< T >::product(), AlCaHLTBitMon_QueryRunRegistry::string, tofhist_, and tofhist_sig_.

{ 
  // test SimTracks
  //----------------------
  edm::Handle<CrossingFrame<SimTrack> > cf_simtrack;
  bool gotTracks = iEvent.getByLabel("mix","g4SimHits",cf_simtrack);
  if (!gotTracks)  outputFile<<" Could not read SimTracks!!!!" 
                   << " Please, check if the object SimTracks has been declared in the"
                   << " MixingModule configuration file."<<std::endl;
  
  if (gotTracks) {
    outputFile<<"\n=================== Starting SimTrack access ==================="<<std::endl;

    std::auto_ptr<MixCollection<SimTrack> > col1(new MixCollection<SimTrack>(cf_simtrack.product()));
    MixCollection<SimTrack>::iterator cfi1;
    int count1=0;
    std::cout <<" \nWe got "<<col1->sizeSignal()<<" signal tracks and "<<col1->sizePileup()<<" pileup tracks, total: "<<col1->size()<<std::endl;
    for (cfi1=col1->begin(); cfi1!=col1->end();cfi1++) {
      //std::cout << " BUNCH cfi1.bunch() = " << cfi1.bunch() << std::endl;
      if (cfi1.getTrigger()==0){
      histTrack_bunchPileups_->Fill(cfi1.bunch());
      }
      
      if (cfi1.getTrigger()==1){
      histTrack_bunchSignal_->Fill(cfi1.bunch());
      }

      
      int a = count1%4;
      if (a==3){
      outputFile<<" SimTrack "<<count1<<" has genpart index  "<<cfi1->genpartIndex()<<" vertex Index "<<cfi1->vertIndex() <<" bunchcr "<<cfi1.bunch()<<" trigger "<<cfi1.getTrigger()<<", from EncodedEventId: "<<cfi1->eventId().bunchCrossing() <<" "<<cfi1->eventId().event() <<std::endl;
      }
      count1++; 
    }
  }

  
  // test SimVertices
  //---------------------
  edm::Handle<CrossingFrame<SimVertex> > cf_simvtx;
  bool gotSimVertex = iEvent.getByLabel("mix","g4SimHits",cf_simvtx);
  if (!gotSimVertex) outputFile<<" Could not read Simvertices !!!!"<<std::endl;
  else {
    outputFile<<"\n=================== Starting SimVertex access ==================="<<std::endl;
    std::auto_ptr<MixCollection<SimVertex> > col2(new MixCollection<SimVertex>(cf_simvtx.product()));
    MixCollection<SimVertex>::iterator cfi2;
    int count2=0;
    outputFile <<" \nWe got "<<col2->sizeSignal()<<" signal vertices and "<<col2->sizePileup()<<" pileup vertices, total: "<<col2->size()<<std::endl;
    for (cfi2=col2->begin(); cfi2!=col2->end();cfi2++) {
      histVertex_bunch_->Fill(cfi2.bunch());
      int b = count2%4;
      if (count2 == 0 || b==3){
      //outputFile<<" SimVertex "<<count2<<" has parent index  "<<cfi2->parentIndex()<<" bunchcr "<<cfi2.bunch()<<" trigger "<<cfi2.getTrigger()<<", from EncodedEventId: "<<cfi2->eventId().bunchCrossing() <<" "<<cfi2->eventId().event() <<std::endl;
      }
      //SimVertex myvtx=(*cfi2);
      //outputFile<<"Same with op*: "<<count2<<" has parent index  "<<myvtx.parentIndex()<<" bunchcr "<<cfi2.bunch()<<" trigger "<<cfi2.getTrigger()<<", from EncodedEventId: "<<myvtx.eventId().bunchCrossing() <<" "<<myvtx.eventId().event() <<std::endl;
      count2++; 
    }
  }
  
  
  //test HepMCProducts
  //------------------------------------
  edm::Handle<CrossingFrame<edm::HepMCProduct> > cf_hepmc;
  bool gotHepMCP = iEvent.getByLabel("mix","generator",cf_hepmc);
  if (!gotHepMCP) std::cout<<" Could not read HepMCProducts!!!!"<<std::endl;
  else {
    outputFile<<"\n=================== Starting HepMCProduct access ==================="<<std::endl;
    std::auto_ptr<MixCollection<edm::HepMCProduct> > colhepmc(new MixCollection<edm::HepMCProduct>(cf_hepmc.product()));
    MixCollection<edm::HepMCProduct>::iterator cfihepmc;
    
    int count3=0;
    outputFile <<" \nWe got "<<colhepmc->sizeSignal()<<" signal hepmc products and "<<colhepmc->sizePileup()<<" pileup hepmcs, total: "<<colhepmc->size()<<std::endl;
    for (cfihepmc=colhepmc->begin(); cfihepmc!=colhepmc->end();cfihepmc++) {
      histHepMCProduct_bunch_->Fill(cfihepmc.bunch());
      int c = count3%4;
      if (count3==0 || c==3){
      //outputFile<<" edm::HepMCProduct "<<count3<<" has event number "<<cfihepmc->GetEvent()->event_number()<<", "<< cfihepmc->GetEvent()->particles_size()<<" particles and "<<cfihepmc->GetEvent()->vertices_size()<<" vertices,  bunchcr= "<<cfihepmc.bunch()<<" trigger= "<<cfihepmc.getTrigger() <<" sourcetype= "<<cfihepmc.getSourceType()<<std::endl;
      }
      HepMCProduct myprod=colhepmc->getObject(count3);
      //outputFile<<"same with getObject:hepmc product   "<<count3<<" has event number "<<myprod.GetEvent()->event_number()<<", "<<myprod.GetEvent()->particles_size()<<" particles and "<<myprod.GetEvent()->vertices_size()<<" vertices"<<std::endl;
      count3++;
    }
  }


  // test CaloHits
  //--------------------------  
  const std::string subdetcalo("g4SimHitsEcalHitsEB");
  edm::Handle<CrossingFrame<PCaloHit> > cf_calo;
  bool gotPCaloHit = iEvent.getByLabel("mix",subdetcalo,cf_calo);
  if (!gotPCaloHit) outputFile<<" Could not read CaloHits with label "<<subdetcalo<<"!!!!"<<std::endl;
  else {
    outputFile<<"\n\n=================== Starting CaloHit access, subdet "<<subdetcalo<<"  ==================="<<std::endl;
    std::auto_ptr<MixCollection<PCaloHit> > colcalo(new MixCollection<PCaloHit>(cf_calo.product()));
    //outputFile<<*(colcalo.get())<<std::endl;
    MixCollection<PCaloHit>::iterator cficalo;
    int count4=0;
    for (cficalo=colcalo->begin(); cficalo!=colcalo->end();cficalo++) {
      histPCaloHit_bunch_->Fill(cficalo.bunch());
      int d = count4%4;
      if (count4==0 || d==3){
      //outputFile<<" CaloHit "<<count4<<" has tof "<<cficalo->time()<<" trackid "<<cficalo->geantTrackId() <<" bunchcr "<<cficalo.bunch()<<" trigger "<<cficalo.getTrigger()<<", from EncodedEventId: "<<cficalo->eventId().bunchCrossing()<<" " <<cficalo->eventId().event() <<std::endl;
      }
      count4++;
    }
  }

  
  // test PSimHit for one particular subdet
  //---------------------------------------
  
  
  const std::string subdet("g4SimHitsTrackerHitsTECHighTof");
  edm::Handle<CrossingFrame<PSimHit> > cf_simhit;
  bool gotPSimHit = iEvent.getByLabel("mix",subdet,cf_simhit);
  if (!gotPSimHit) outputFile<<" Could not read SimHits with label "<<subdet<<"!!!!"<<std::endl;
  else {
    outputFile<<"\n\n=================== Starting SimHit access, subdet "<<subdet<<"  ==================="<<std::endl;

    std::auto_ptr<MixCollection<PSimHit> > col(new MixCollection<PSimHit>(cf_simhit.product()));
    //outputFile<<*(col.get())<<std::endl;
    MixCollection<PSimHit>::iterator cfi;
    int count5=0;
    for (cfi=col->begin(); cfi!=col->end();cfi++) {
      
      // Signal
      if (cfi.getTrigger()==1){ 
        histPSimHit_bunchSignal_TrackerHitsTECHighTof_->Fill(cfi.bunch());
        tofhist_sig_->Fill(cfi->timeOfFlight());
      }
      
      // Pileups
      if (cfi.getTrigger()==0){
       histPSimHit_bunchPileups_TrackerHitsTECHighTof_->Fill(cfi.bunch());
       std::cout << " cfi->timeOfFlight() = " << cfi->timeOfFlight() << std::endl;
       tofhist_->Fill(cfi->timeOfFlight()); 
      }
      
      int e = count5%4;
      if (e==3){
      outputFile<<" Hit "<<count5<<" has tof "<<cfi->timeOfFlight()<<" trackid "<<cfi->trackId() <<" bunchcr "<<cfi.bunch()<<" trigger "<<cfi.getTrigger()<<", from EncodedEventId: "<<cfi->eventId().bunchCrossing()<<" " <<cfi->eventId().event() <<" bcr from MixCol "<<cfi.bunch()<<std::endl;
      }
      count5++;
    }
  }
  
  const std::string subdet1("g4SimHitsMuonCSCHits");
  edm::Handle<CrossingFrame<PSimHit> > cf_simhit1;
  bool gotPSimHit1 = iEvent.getByLabel("mix",subdet1,cf_simhit1);
  if (!gotPSimHit1) outputFile<<" Could not read SimHits with label "<<subdet1<<"!!!!"<<std::endl;
  else {
    outputFile<<"\n\n=================== Starting SimHit access, subdet "<<subdet1<<"  ==================="<<std::endl;

    std::auto_ptr<MixCollection<PSimHit> > col(new MixCollection<PSimHit>(cf_simhit1.product()));
    //outputFile<<*(col.get())<<std::endl;
    MixCollection<PSimHit>::iterator cfi;
    int count5=0;
    for (cfi=col->begin(); cfi!=col->end();cfi++) {
      
      if (cfi.getTrigger()==1) histPSimHit_bunchSignal_MuonCSCHits_->Fill(cfi.bunch());
      
      if (cfi.getTrigger()==0) histPSimHit_bunchPileups_MuonCSCHits_->Fill(cfi.bunch());
      
      int e = count5%4;
      if (e==3){
      outputFile<<" Hit "<<count5<<" has tof "<<cfi->timeOfFlight()<<" trackid "<<cfi->trackId() <<" bunchcr "<<cfi.bunch()<<" trigger "<<cfi.getTrigger()<<", from EncodedEventId: "<<cfi->eventId().bunchCrossing()<<" " <<cfi->eventId().event() <<" bcr from MixCol "<<cfi.bunch()<<std::endl;
      }
      count5++;
    }
  }
  


}
void TestMixedSource::beginJob ( void  ) [private, virtual]

Reimplemented from edm::EDAnalyzer.

Definition at line 277 of file TestMixedSource.cc.

References gather_cfg::cout, and outputFile.

{ 
   outputFile.open("test.log");
   if (!outputFile.is_open())
   {
     std::cout << "Unable to open file!" << std::endl;
   } 
   
}
void TestMixedSource::endJob ( void  ) [private, virtual]

Member Data Documentation

Definition at line 60 of file TestMixedSource.h.

std::string edm::TestMixedSource::fileName_ [private]

Definition at line 59 of file TestMixedSource.h.

Referenced by endJob().

Definition at line 74 of file TestMixedSource.h.

Referenced by endJob().

Definition at line 73 of file TestMixedSource.h.

Referenced by analyze(), endJob(), and TestMixedSource().

Definition at line 66 of file TestMixedSource.h.

Referenced by analyze(), endJob(), and TestMixedSource().

Definition at line 72 of file TestMixedSource.h.

Referenced by analyze(), endJob(), and TestMixedSource().

Definition at line 68 of file TestMixedSource.h.

Referenced by analyze(), endJob(), and TestMixedSource().

Definition at line 71 of file TestMixedSource.h.

Referenced by analyze(), endJob(), and TestMixedSource().

Definition at line 67 of file TestMixedSource.h.

Referenced by analyze(), endJob(), and TestMixedSource().

Definition at line 63 of file TestMixedSource.h.

Referenced by analyze(), endJob(), and TestMixedSource().

Definition at line 64 of file TestMixedSource.h.

Referenced by analyze(), endJob(), and TestMixedSource().

Definition at line 65 of file TestMixedSource.h.

Referenced by analyze(), endJob(), and TestMixedSource().

Definition at line 62 of file TestMixedSource.h.

Referenced by TestMixedSource().

Definition at line 61 of file TestMixedSource.h.

Referenced by TestMixedSource().

Definition at line 58 of file TestMixedSource.h.

Referenced by analyze(), beginJob(), and endJob().

Definition at line 69 of file TestMixedSource.h.

Referenced by analyze(), endJob(), and TestMixedSource().

Definition at line 70 of file TestMixedSource.h.

Referenced by analyze(), endJob(), and TestMixedSource().