CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/Validation/Mixing/src/TestSuite.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Class:      TestSuite
00004 // 
00010 //
00011 // Original Author:  Ursula Berthon
00012 //         Created:  Fri Sep 23 11:38:38 CEST 2005
00013 // $Id: TestSuite.cc,v 1.12 2009/12/21 14:46:56 ebecheva Exp $
00014 //
00015 //
00016 
00017 
00018 // system include files
00019 #include <memory>
00020 #include <utility>
00021 
00022 // user include files
00023 
00024 #include "SimDataFormats/CrossingFrame/interface/CrossingFrame.h"
00025 #include "SimDataFormats/CrossingFrame/interface/MixCollection.h"
00026 #include "SimDataFormats/TrackingHit/interface/PSimHit.h"
00027 
00028 #include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
00029 #include "SimDataFormats/CaloHit/interface/PCaloHitContainer.h"
00030 #include "SimDataFormats/Track/interface/SimTrackContainer.h"
00031 #include "SimDataFormats/Vertex/interface/SimVertexContainer.h"
00032 
00033 #include "Validation/Mixing/interface/TestSuite.h"
00034 
00035 #include "TFile.h"
00036 #include "DQMServices/Core/interface/DQMStore.h"
00037 #include "DQMServices/Core/interface/MonitorElement.h"
00038 
00039 using namespace edm;
00040 
00041 TestSuite::TestSuite(const edm::ParameterSet& iConfig): filename_(iConfig.getParameter<std::string>("fileName")), bunchcr_(iConfig.getParameter<int>("BunchNr")), minbunch_(iConfig.getParameter<int>("minBunch")),maxbunch_(iConfig.getParameter<int>("maxBunch")),  dbe_(0)
00042 {
00043   std::cout << "Constructed testSuite , bunchcr "<<bunchcr_<<" filename: "<<filename_<<std::endl;
00044 
00045 }
00046 
00047 
00048 TestSuite::~TestSuite()
00049 {
00050  
00051    // do anything here that needs to be done at desctruction time
00052    // (e.g. close files, deallocate resources etc.)
00053 }
00054 
00055 void TestSuite::beginJob() {
00056 
00057   // get hold of back-end interface
00058   dbe_ = Service<DQMStore>().operator->(); 
00059   dbe_->showDirStructure();
00060   dbe_->setCurrentFolder("MixingV/Mixing");
00061 } 
00062 
00063 void TestSuite::endJob() {
00064  if (filename_.size() != 0 && dbe_ ) dbe_->save(filename_);
00065 }
00066 
00067 
00068 
00069 // ------------ method called to analyze the data  ------------
00070 void
00071 TestSuite::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00072 {
00073   using namespace edm;
00074 
00075 // Get input
00076     edm::Handle<CrossingFrame<SimTrack> > cf_track;
00077     edm::Handle<CrossingFrame<SimVertex> > cf_vertex;
00078     edm::Handle<CrossingFrame<PSimHit> > cf_simhit;
00079     edm::Handle<CrossingFrame<PCaloHit> > cf_calohitEcal;
00080     edm::Handle<CrossingFrame<PCaloHit> > cf_calohitHcal;
00081     std::string subdetTracker("g4SimHitsTrackerHitsTECLowTof");
00082     std::string ecalsubdet("g4SimHitsEcalHitsEB");
00083     std::string hcalsubdet("g4SimHitsHcalHits");
00084     iEvent.getByType(cf_track);
00085     iEvent.getByType(cf_vertex);
00086     iEvent.getByLabel("mix",subdetTracker,cf_simhit);
00087     iEvent.getByLabel("mix",ecalsubdet,cf_calohitEcal);
00088     iEvent.getByLabel("mix",hcalsubdet,cf_calohitHcal);
00089 
00090 // use MixCollection and its iterator
00091 // Please note that bunch() and getTrigger() are methods of the iterator itself
00092 // while operator-> points to the templated objects!!!!
00093 
00094 //track histo
00095     char histotracks[30],sighistotracks[30],histotracksindsig[30],histotracksind[30];
00096     sprintf(histotracks,"Tracks_bcr_%d",bunchcr_);
00097     sprintf(sighistotracks,"SignalTracks_bcr_%d",bunchcr_);
00098     sprintf(histotracksind,"VtxPointers_%d",bunchcr_);
00099     sprintf(histotracksindsig,"VtxPointers_signal_%d",bunchcr_);
00100     MonitorElement * trhist = dbe_->book1D(histotracks,"Bunchcrossings",maxbunch_-minbunch_+1,minbunch_,maxbunch_+1);
00101     MonitorElement * trhistsig = dbe_->book1D(sighistotracks,"Bunchcrossings",maxbunch_-minbunch_+1,minbunch_,maxbunch_+1);
00102     MonitorElement * trindhist = dbe_->book1D(histotracksind,"Track to Vertex indices",100,0,500);
00103     MonitorElement * trindhistsig = dbe_->book1D(histotracksindsig,"Signal Track to Vertex indices",100,0,500);
00104     std::auto_ptr<MixCollection<SimTrack> > col1(new MixCollection<SimTrack>(cf_track.product()));
00105     MixCollection<SimTrack>::iterator cfi1;
00106     for (cfi1=col1->begin(); cfi1!=col1->end();cfi1++) {
00107        if (cfi1.getTrigger()==0) {
00108          trhist->Fill(cfi1.bunch());
00109          trindhist->Fill(cfi1->vertIndex());
00110        } else {
00111          trindhistsig->Fill(cfi1->vertIndex());
00112          trhistsig->Fill(cfi1.bunch());
00113        }
00114      }
00115 
00116 
00117 //vertex histo
00118     char histovertices[30], sighistovertices[30],histovertexindices[30],histovertexindicessig[30];
00119     sprintf(histovertices,"Vertices_bcr_%d",bunchcr_);
00120     sprintf(sighistovertices,"SignalVertices_bcr_%d",bunchcr_);
00121     sprintf(histovertexindices,"TrackPointers_%d",bunchcr_);
00122     sprintf(histovertexindicessig,"TrackPointers_signal_%d",bunchcr_);
00123     MonitorElement * vtxhist = dbe_->book1D(histovertices,"Bunchcrossings",maxbunch_-minbunch_+1,minbunch_,maxbunch_+1);
00124     MonitorElement * vtxhistsig = dbe_->book1D(sighistovertices,"Bunchcrossings",maxbunch_-minbunch_+1,minbunch_,maxbunch_+1);
00125     MonitorElement * vtxindhist = dbe_->book1D(histovertexindices,"Vertex to Track Indices",100,0,300);
00126     MonitorElement * vtxindhistsig = dbe_->book1D(histovertexindicessig,"Signal Vertex to Track Indices",100,0,300);
00127     std::auto_ptr<MixCollection<SimVertex> > col2(new MixCollection<SimVertex>(cf_vertex.product()));
00128     MixCollection<SimVertex>::iterator cfi2;
00129     for (cfi2=col2->begin(); cfi2!=col2->end();cfi2++) {
00130         if (cfi2.getTrigger()==0) {
00131           vtxhist->Fill(cfi2.bunch());
00132           if (!cfi2->noParent())        vtxindhist->Fill(cfi2->parentIndex());
00133         } else {
00134           vtxhistsig->Fill(cfi2.bunch());
00135           if (!cfi2->noParent())        vtxindhistsig->Fill(cfi2->parentIndex());
00136         }
00137     }
00138         
00139     //tracker
00140     int bsp=cf_simhit->getBunchSpace();
00141     char tof[30];
00142 
00143     sprintf(tof,"TrackerHit_Tof_bcr_%d",bunchcr_);
00144     MonitorElement * tofhist = dbe_->book1D(tof,"TrackerHit_ToF",100,float(bsp*minbunch_),float(bsp*maxbunch_)+50.);
00145     sprintf(tof,"SignalTrackerHit_Tof_bcr_%d",bunchcr_);
00146     MonitorElement * tofhist_sig = dbe_->book1D(tof,"TrackerHit_ToF",100,float(bsp*minbunch_),float(bsp*maxbunch_)+50.);
00147     std::auto_ptr<MixCollection<PSimHit> > colsh(new MixCollection<PSimHit>(cf_simhit.product()));
00148     MixCollection<PSimHit>::iterator cfish;
00149     for (cfish=colsh->begin(); cfish!=colsh->end();cfish++) {
00150       if (cfish.getTrigger())  {
00151         tofhist_sig->Fill(cfish->timeOfFlight());
00152       }
00153       else  {
00154         tofhist->Fill(cfish->timeOfFlight());
00155       }
00156     }
00157 
00158     //Ecal
00159     sprintf(tof,"EcalEBHit_Tof_bcr_%d",bunchcr_);
00160     MonitorElement * tofecalhist = dbe_->book1D(tof,"EcalEBHit_ToF",100,float(bsp*minbunch_),float(bsp*maxbunch_)+50.);
00161     sprintf(tof,"SignalEcalEBHit_Tof_bcr_%d",bunchcr_);
00162     MonitorElement * tofecalhist_sig = dbe_->book1D(tof,"EcalEBHit_ToF",100,float(bsp*minbunch_),float(bsp*maxbunch_)+50.);
00163                                                  //    std::string ecalsubdet("EcalHitsEB");
00164     std::auto_ptr<MixCollection<PCaloHit> > colecal(new MixCollection<PCaloHit>(cf_calohitEcal.product()));
00165     MixCollection<PCaloHit>::iterator cfiecal;
00166     for (cfiecal=colecal->begin(); cfiecal!=colecal->end();cfiecal++) {
00167       if (cfiecal.getTrigger())    tofecalhist_sig->Fill(cfiecal->time());
00168       else    tofecalhist->Fill(cfiecal->time());
00169     }
00170 
00171     // Hcal
00172     sprintf(tof,"HcalHit_Tof_bcr_%d",bunchcr_);
00173     MonitorElement * tofhcalhist = dbe_->book1D(tof,"HcalHit_ToF",100,float(bsp*minbunch_),float(bsp*maxbunch_)+50.);
00174     sprintf(tof,"SignalHcalHit_Tof_bcr_%d",bunchcr_);
00175     MonitorElement * tofhcalhist_sig = dbe_->book1D(tof,"HcalHit_ToF",100,float(bsp*minbunch_),float(bsp*maxbunch_)+50.);
00176                                                     //    std::string hcalsubdet("HcalHits");
00177     std::auto_ptr<MixCollection<PCaloHit> > colhcal(new MixCollection<PCaloHit>(cf_calohitHcal.product()));
00178     MixCollection<PCaloHit>::iterator cfihcal;
00179     
00180     for (cfihcal=colhcal->begin(); cfihcal!=colhcal->end();cfihcal++) {
00181       if (cfihcal.getTrigger())  tofhcalhist_sig->Fill(cfihcal->time());
00182       else  tofhcalhist->Fill(cfihcal->time());
00183     }
00184 }
00185