CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/Validation/Mixing/src/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.10 2011/01/10 09:22:24 fwyzard Exp $
00014 //
00015 //
00016 
00017 
00018 // system include files
00019 #include <memory>
00020 #include <utility>
00021 
00022 #include <string>
00023 
00024 // user include files
00025 #include "FWCore/Framework/interface/Frameworkfwd.h"
00026 #include "FWCore/Framework/interface/EDAnalyzer.h"
00027 
00028 #include "FWCore/Framework/interface/Event.h"
00029 #include "FWCore/Framework/interface/MakerMacros.h"
00030 
00031 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00032 
00033 #include "SimDataFormats/CrossingFrame/interface/CrossingFrame.h"
00034 #include "SimDataFormats/CrossingFrame/interface/MixCollection.h"
00035 #include "SimDataFormats/TrackingHit/interface/PSimHit.h"
00036 
00037 #include "SimDataFormats/CaloHit/interface/PCaloHitContainer.h"
00038 #include "SimDataFormats/Track/interface/SimTrackContainer.h"
00039 
00040 #include "Validation/Mixing/interface/GlobalTest.h"
00041 #include "TFile.h"
00042 #include "DQMServices/Core/interface/DQMStore.h"
00043 #include "DQMServices/Core/interface/MonitorElement.h"
00044 
00045 using namespace edm;
00046 
00047 GlobalTest::GlobalTest(const edm::ParameterSet& iConfig):
00048 filename_(iConfig.getParameter<std::string>("fileName")),
00049 minbunch_(iConfig.getParameter<int>("minBunch")),maxbunch_(iConfig.getParameter<int>("maxBunch")), dbe_(0)
00050 {
00051   std::cout << "Constructed GlobalTest, filename: "<<filename_<<" minbunch: "<<minbunch_<<", maxbunch: "<<maxbunch_<<std::endl;
00052 
00053 }
00054 
00055 GlobalTest::~GlobalTest()
00056 {
00057  
00058    // do anything here that needs to be done at desctruction time
00059    // (e.g. close files, deallocate resources etc.)
00060 }
00061 
00062 void GlobalTest::beginJob() {
00063   using namespace std;
00064   
00065   // get hold of back-end interface
00066   dbe_ = Service<DQMStore>().operator->(); 
00067   dbe_->showDirStructure();
00068   dbe_->setCurrentFolder("MixingV/Mixing");
00069   //book histos
00070   std::string NrPileupEvts = "NrPileupEvts";
00071   size_t NrPileupEvtsSize = NrPileupEvts.size() + 1;
00072   std::string NrVertices = "NrVertices";
00073   size_t NrVerticesSize = NrVertices.size() + 1;
00074   std::string NrTracks = "NrTracks";
00075   size_t NrTracksSize = NrTracks.size() + 1;
00076   std::string TrackPartId = "TrackPartId";
00077   size_t TrackPartIdSize = TrackPartId.size() + 1;
00078   std::string CaloEnergyEB = "CaloEnergyEB";
00079   size_t CaloEnergyEBSize = CaloEnergyEB.size() + 1;
00080   std::string CaloEnergyEE = "CaloEnergyEE";
00081   size_t CaloEnergyEESize = CaloEnergyEE.size() + 1;
00082   
00083   labels[0] = new char [NrPileupEvtsSize];
00084   strncpy(labels[0], NrPileupEvts.c_str(), NrPileupEvtsSize);
00085   labels[1] = new char [NrVerticesSize];
00086   strncpy(labels[1], NrVertices.c_str(), NrVerticesSize); 
00087   labels[2] = new char [NrTracksSize];
00088   strncpy(labels[2], NrTracks.c_str(), NrTracksSize);
00089   labels[3] = new char [TrackPartIdSize];
00090   strncpy(labels[3], TrackPartId.c_str(), TrackPartIdSize);
00091   labels[4] = new char [CaloEnergyEBSize];
00092   strncpy(labels[4], CaloEnergyEB.c_str(), CaloEnergyEBSize);
00093   labels[5] = new char [CaloEnergyEESize];
00094   strncpy(labels[5], CaloEnergyEE.c_str(), CaloEnergyEESize);
00095   
00096   //FIXME: test for max nr of histos
00097   for (int i=minbunch_;i<=maxbunch_;++i) {
00098     int ii=i-minbunch_;
00099     char label[50];
00100     sprintf(label,"%s_%d",labels[0],i);
00101     nrPileupsH_[ii]    = dbe_->book1D(label,label,100,0,100);
00102     sprintf(label,"%s_%d",labels[1],i);
00103     nrVerticesH_[ii]   = dbe_->book1D(label,label,100,0,5000);
00104     sprintf(label,"%s_%d",labels[2],i);
00105     nrTracksH_[ii]     = dbe_->book1D(label,label,100,0,10000);
00106     sprintf(label,"%s_%d",labels[3],i);
00107     trackPartIdH_[ii]  =  dbe_->book1D(label,label,100,0,100);
00108     sprintf(label,"%s_%d",labels[4],i);
00109     caloEnergyEBH_ [ii]  = dbe_->book1D(label,label,100,0.,1000.);
00110     sprintf(label,"%s_%d",labels[5],i);
00111     caloEnergyEEH_ [ii]  = dbe_->book1D(label,label,100,0.,1000.);
00112   }
00113 } 
00114 
00115 
00116 void GlobalTest::endJob() {
00117  if (filename_.size() != 0 && dbe_ ) dbe_->save(filename_);
00118  
00119  for (int i = 0; i < 6; i++) delete[] labels[i];
00120 }
00121 
00122 //
00123 // member functions
00124 //
00125 
00126 // ------------ method called to analyze the data  ------------
00127 void
00128 GlobalTest::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00129 {
00130    using namespace edm;
00131    using namespace std;
00132    
00133 // Get input
00134     edm::Handle<CrossingFrame<SimTrack> > cf_track;
00135     edm::Handle<CrossingFrame<SimTrack> > cf_vertex;
00136     edm::Handle<CrossingFrame<PCaloHit> > cf_calohitE;
00137     edm::Handle<CrossingFrame<PCaloHit> > cf_calohitB;
00138     std::string ecalsubdetb("g4SimHitsEcalHitsEB");
00139     std::string ecalsubdete("g4SimHitsEcalHitsEE");
00140     iEvent.getByType(cf_track);
00141     iEvent.getByType(cf_vertex);
00142     iEvent.getByLabel("mix",ecalsubdetb,cf_calohitB);
00143     iEvent.getByLabel("mix",ecalsubdete,cf_calohitE);
00144 
00145     // number of events/bcr ??
00146 
00147     // number of tracks 
00148     for (int i=minbunch_;i<=maxbunch_;++i) {
00149        nrTracksH_[i-minbunch_]->Fill(cf_track->getNrPileups(i));
00150     }
00151 
00152     // number of vertices
00153     for (int i=minbunch_;i<=maxbunch_;++i) {
00154        nrVerticesH_[i-minbunch_]->Fill(cf_vertex->getNrPileups(i));
00155     }
00156 
00157    // part id for each track
00158     std::auto_ptr<MixCollection<SimTrack> > coltr(new MixCollection<SimTrack>(cf_track.product()));
00159     MixCollection<SimTrack>::iterator cfitr;
00160     for (cfitr=coltr->begin(); cfitr!=coltr->end();cfitr++) {
00161          trackPartIdH_[cfitr.bunch()-minbunch_]->Fill(cfitr->type());
00162      }
00163 
00164     // energy sum
00165     double sumE[10]={0.,0.,0.,0.,0.,0.,0.,0.,0.,0.};
00166     std::auto_ptr<MixCollection<PCaloHit> > colecalb(new MixCollection<PCaloHit>(cf_calohitB.product()));
00167     MixCollection<PCaloHit>::iterator cfiecalb;
00168     for (cfiecalb=colecalb->begin(); cfiecalb!=colecalb->end();cfiecalb++) {
00169        sumE[cfiecalb.bunch()-minbunch_]+=cfiecalb->energy();
00170       //      if (cfiecal.getTrigger())    tofecalhist_sig->Fill(cfiecal->time());
00171       //      else    tofecalhist->Fill(cfiecal->time());
00172     }
00173     for (int i=minbunch_;i<=maxbunch_;++i) {
00174        caloEnergyEBH_[i-minbunch_]->Fill(sumE[i-minbunch_]);
00175     }
00176     double sumEE[10]={0.,0.,0.,0.,0.,0.,0.,0.,0.,0.};
00177     std::auto_ptr<MixCollection<PCaloHit> > colecale(new MixCollection<PCaloHit>(cf_calohitE.product()));
00178     MixCollection<PCaloHit>::iterator cfiecale;
00179     for (cfiecale=colecale->begin(); cfiecale!=colecale->end();cfiecale++) {
00180        sumEE[cfiecale.bunch()-minbunch_]+=cfiecale->energy();
00181       //      if (cfiecal.getTrigger())    tofecalhist_sig->Fill(cfiecal->time());
00182       //      else    tofecalhist->Fill(cfiecal->time());
00183     }
00184     for (int i=minbunch_;i<=maxbunch_;++i) {
00185        caloEnergyEEH_[i-minbunch_]->Fill(sumEE[i-minbunch_]);
00186     }
00187 }
00188