CMS 3D CMS Logo

GlobalTest.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Class:      GlobalTest
00004 // 
00010 //
00011 // Original Author:  Ursula Berthon
00012 //         Created:  Fri Sep 23 11:38:38 CEST 2005
00013 // $Id: GlobalTest.cc,v 1.6 2008/02/29 20:48:53 ksmith Exp $
00014 //
00015 //
00016 
00017 
00018 // system include files
00019 #include <memory>
00020 #include <utility>
00021 
00022 // user include files
00023 #include "FWCore/Framework/interface/Frameworkfwd.h"
00024 #include "FWCore/Framework/interface/EDAnalyzer.h"
00025 
00026 #include "FWCore/Framework/interface/Event.h"
00027 #include "FWCore/Framework/interface/MakerMacros.h"
00028 
00029 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00030 
00031 #include "SimDataFormats/CrossingFrame/interface/CrossingFrame.h"
00032 #include "SimDataFormats/CrossingFrame/interface/MixCollection.h"
00033 #include "SimDataFormats/TrackingHit/interface/PSimHit.h"
00034 
00035 #include "SimDataFormats/CaloHit/interface/PCaloHitContainer.h"
00036 #include "SimDataFormats/Track/interface/SimTrackContainer.h"
00037 
00038 #include "Validation/Mixing/interface/GlobalTest.h"
00039 #include "TFile.h"
00040 #include "DQMServices/Core/interface/DQMStore.h"
00041 #include "DQMServices/Core/interface/MonitorElement.h"
00042 
00043 using namespace edm;
00044 
00045 GlobalTest::GlobalTest(const edm::ParameterSet& iConfig): filename_(iConfig.getParameter<std::string>("fileName")), minbunch_(iConfig.getParameter<int>("minBunch")),maxbunch_(iConfig.getParameter<int>("maxBunch")),  dbe_(0)
00046 {
00047   std::cout << "Constructed GlobalTest, filename: "<<filename_<<" minbunch: "<<minbunch_<<", maxbunch: "<<maxbunch_<<std::endl;
00048 
00049 }
00050 
00051 GlobalTest::~GlobalTest()
00052 {
00053  
00054    // do anything here that needs to be done at desctruction time
00055    // (e.g. close files, deallocate resources etc.)
00056 }
00057 
00058 void GlobalTest::beginJob(edm::EventSetup const&iSetup) {
00059 
00060   // get hold of back-end interface
00061   dbe_ = Service<DQMStore>().operator->(); 
00062   dbe_->showDirStructure();
00063   dbe_->setCurrentFolder("MixingV/Mixing");
00064   //book histos
00065   const int nrHistos=6;
00066   char * labels[nrHistos];
00067   labels[0]="NrPileupEvts";
00068   labels[1]="NrVertices";
00069   labels[2]="NrTracks";
00070   labels[3]="TrackPartId";
00071   labels[4]="CaloEnergyEB";
00072   labels[5]="CaloEnergyEE";
00073 
00075   //FIXME: test for max nr of histos
00076   for (int i=minbunch_;i<=maxbunch_;++i) {
00077     int ii=i-minbunch_;
00078     char label[50];
00079     sprintf(label,"%s_%d",labels[0],i);
00080     nrPileupsH_[ii]    = dbe_->book1D(label,label,100,0,100);
00081     sprintf(label,"%s_%d",labels[1],i);
00082     nrVerticesH_[ii]   = dbe_->book1D(label,label,100,0,5000);
00083     sprintf(label,"%s_%d",labels[2],i);
00084     nrTracksH_[ii]     = dbe_->book1D(label,label,100,0,10000);
00085     sprintf(label,"%s_%d",labels[3],i);
00086     trackPartIdH_[ii]  =  dbe_->book1D(label,label,100,0,100);
00087     sprintf(label,"%s_%d",labels[4],i);
00088     caloEnergyEBH_ [ii]  = dbe_->book1D(label,label,100,0.,1000.);
00089     sprintf(label,"%s_%d",labels[5],i);
00090     caloEnergyEEH_ [ii]  = dbe_->book1D(label,label,100,0.,1000.);
00091   }
00092 } 
00093 
00094 
00095 void GlobalTest::endJob() {
00096  if (filename_.size() != 0 && dbe_ ) dbe_->save(filename_);
00097 }
00098 
00099 //
00100 // member functions
00101 //
00102 
00103 // ------------ method called to analyze the data  ------------
00104 void
00105 GlobalTest::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00106 {
00107    using namespace edm;
00108 
00109 // Get input
00110     edm::Handle<CrossingFrame<SimTrack> > cf_track;
00111     edm::Handle<CrossingFrame<SimTrack> > cf_vertex;
00112     edm::Handle<CrossingFrame<PCaloHit> > cf_calohitE;
00113     edm::Handle<CrossingFrame<PCaloHit> > cf_calohitB;
00114     std::string ecalsubdetb("EcalHitsEB");
00115     std::string ecalsubdete("EcalHitsEE");
00116     iEvent.getByType(cf_track);
00117     iEvent.getByType(cf_vertex);
00118     iEvent.getByLabel("mix",ecalsubdetb,cf_calohitB);
00119     iEvent.getByLabel("mix",ecalsubdete,cf_calohitE);
00120 
00121     // number of events/bcr ??
00122 
00123     // number of tracks 
00124     for (int i=minbunch_;i<=maxbunch_;++i) {
00125        nrTracksH_[i-minbunch_]->Fill(cf_track->getNrPileups(i));
00126     }
00127 
00128     // number of vertices
00129     for (int i=minbunch_;i<=maxbunch_;++i) {
00130        nrVerticesH_[i-minbunch_]->Fill(cf_vertex->getNrPileups(i));
00131     }
00132 
00133    // part id for each track
00134     std::auto_ptr<MixCollection<SimTrack> > coltr(new MixCollection<SimTrack>(cf_track.product()));
00135     MixCollection<SimTrack>::iterator cfitr;
00136     for (cfitr=coltr->begin(); cfitr!=coltr->end();cfitr++) {
00137          trackPartIdH_[cfitr.bunch()-minbunch_]->Fill(cfitr->type());
00138      }
00139 
00140     // energy sum
00141     double sumE[10]={0.,0.,0.,0.,0.,0.,0.,0.,0.,0.};
00142     std::auto_ptr<MixCollection<PCaloHit> > colecalb(new MixCollection<PCaloHit>(cf_calohitB.product()));
00143     MixCollection<PCaloHit>::iterator cfiecalb;
00144     for (cfiecalb=colecalb->begin(); cfiecalb!=colecalb->end();cfiecalb++) {
00145        sumE[cfiecalb.bunch()-minbunch_]+=cfiecalb->energy();
00146       //      if (cfiecal.getTrigger())    tofecalhist_sig->Fill(cfiecal->time());
00147       //      else    tofecalhist->Fill(cfiecal->time());
00148     }
00149     for (int i=minbunch_;i<=maxbunch_;++i) {
00150        caloEnergyEBH_[i-minbunch_]->Fill(sumE[i-minbunch_]);
00151     }
00152     double sumEE[10]={0.,0.,0.,0.,0.,0.,0.,0.,0.,0.};
00153     std::auto_ptr<MixCollection<PCaloHit> > colecale(new MixCollection<PCaloHit>(cf_calohitE.product()));
00154     MixCollection<PCaloHit>::iterator cfiecale;
00155     for (cfiecale=colecale->begin(); cfiecale!=colecale->end();cfiecale++) {
00156        sumEE[cfiecale.bunch()-minbunch_]+=cfiecale->energy();
00157       //      if (cfiecal.getTrigger())    tofecalhist_sig->Fill(cfiecal->time());
00158       //      else    tofecalhist->Fill(cfiecal->time());
00159     }
00160     for (int i=minbunch_;i<=maxbunch_;++i) {
00161        caloEnergyEEH_[i-minbunch_]->Fill(sumEE[i-minbunch_]);
00162     }
00163 }
00164 

Generated on Tue Jun 9 17:49:24 2009 for CMSSW by  doxygen 1.5.4