CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/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.13 2012/10/10 14:39:02 wdd 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   cfTrackTag_(iConfig.getParameter<edm::InputTag>("cfTrackTag")),
00043   cfVertexTag_(iConfig.getParameter<edm::InputTag>("cfVertexTag"))
00044 {
00045   std::cout << "Constructed testSuite , bunchcr "<<bunchcr_<<" filename: "<<filename_<<std::endl;
00046 
00047 }
00048 
00049 
00050 TestSuite::~TestSuite()
00051 {
00052  
00053    // do anything here that needs to be done at desctruction time
00054    // (e.g. close files, deallocate resources etc.)
00055 }
00056 
00057 void TestSuite::beginJob() {
00058 
00059   // get hold of back-end interface
00060   dbe_ = Service<DQMStore>().operator->(); 
00061   dbe_->showDirStructure();
00062   dbe_->setCurrentFolder("MixingV/Mixing");
00063 } 
00064 
00065 void TestSuite::endJob() {
00066  if (filename_.size() != 0 && dbe_ ) dbe_->save(filename_);
00067 }
00068 
00069 
00070 
00071 // ------------ method called to analyze the data  ------------
00072 void
00073 TestSuite::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00074 {
00075   using namespace edm;
00076 
00077 // Get input
00078     edm::Handle<CrossingFrame<SimTrack> > cf_track;
00079     edm::Handle<CrossingFrame<SimVertex> > cf_vertex;
00080     edm::Handle<CrossingFrame<PSimHit> > cf_simhit;
00081     edm::Handle<CrossingFrame<PCaloHit> > cf_calohitEcal;
00082     edm::Handle<CrossingFrame<PCaloHit> > cf_calohitHcal;
00083     std::string subdetTracker("g4SimHitsTrackerHitsTECLowTof");
00084     std::string ecalsubdet("g4SimHitsEcalHitsEB");
00085     std::string hcalsubdet("g4SimHitsHcalHits");
00086     iEvent.getByLabel(cfTrackTag_, cf_track);
00087     iEvent.getByLabel(cfVertexTag_, cf_vertex);
00088     iEvent.getByLabel("mix",subdetTracker,cf_simhit);
00089     iEvent.getByLabel("mix",ecalsubdet,cf_calohitEcal);
00090     iEvent.getByLabel("mix",hcalsubdet,cf_calohitHcal);
00091 
00092 // use MixCollection and its iterator
00093 // Please note that bunch() and getTrigger() are methods of the iterator itself
00094 // while operator-> points to the templated objects!!!!
00095 
00096 //track histo
00097     char histotracks[30],sighistotracks[30],histotracksindsig[30],histotracksind[30];
00098     sprintf(histotracks,"Tracks_bcr_%d",bunchcr_);
00099     sprintf(sighistotracks,"SignalTracks_bcr_%d",bunchcr_);
00100     sprintf(histotracksind,"VtxPointers_%d",bunchcr_);
00101     sprintf(histotracksindsig,"VtxPointers_signal_%d",bunchcr_);
00102     MonitorElement * trhist = dbe_->book1D(histotracks,"Bunchcrossings",maxbunch_-minbunch_+1,minbunch_,maxbunch_+1);
00103     MonitorElement * trhistsig = dbe_->book1D(sighistotracks,"Bunchcrossings",maxbunch_-minbunch_+1,minbunch_,maxbunch_+1);
00104     MonitorElement * trindhist = dbe_->book1D(histotracksind,"Track to Vertex indices",100,0,500);
00105     MonitorElement * trindhistsig = dbe_->book1D(histotracksindsig,"Signal Track to Vertex indices",100,0,500);
00106     std::auto_ptr<MixCollection<SimTrack> > col1(new MixCollection<SimTrack>(cf_track.product()));
00107     MixCollection<SimTrack>::iterator cfi1;
00108     for (cfi1=col1->begin(); cfi1!=col1->end();cfi1++) {
00109        if (cfi1.getTrigger()==0) {
00110          trhist->Fill(cfi1.bunch());
00111          trindhist->Fill(cfi1->vertIndex());
00112        } else {
00113          trindhistsig->Fill(cfi1->vertIndex());
00114          trhistsig->Fill(cfi1.bunch());
00115        }
00116      }
00117 
00118 
00119 //vertex histo
00120     char histovertices[30], sighistovertices[30],histovertexindices[30],histovertexindicessig[30];
00121     sprintf(histovertices,"Vertices_bcr_%d",bunchcr_);
00122     sprintf(sighistovertices,"SignalVertices_bcr_%d",bunchcr_);
00123     sprintf(histovertexindices,"TrackPointers_%d",bunchcr_);
00124     sprintf(histovertexindicessig,"TrackPointers_signal_%d",bunchcr_);
00125     MonitorElement * vtxhist = dbe_->book1D(histovertices,"Bunchcrossings",maxbunch_-minbunch_+1,minbunch_,maxbunch_+1);
00126     MonitorElement * vtxhistsig = dbe_->book1D(sighistovertices,"Bunchcrossings",maxbunch_-minbunch_+1,minbunch_,maxbunch_+1);
00127     MonitorElement * vtxindhist = dbe_->book1D(histovertexindices,"Vertex to Track Indices",100,0,300);
00128     MonitorElement * vtxindhistsig = dbe_->book1D(histovertexindicessig,"Signal Vertex to Track Indices",100,0,300);
00129     std::auto_ptr<MixCollection<SimVertex> > col2(new MixCollection<SimVertex>(cf_vertex.product()));
00130     MixCollection<SimVertex>::iterator cfi2;
00131     for (cfi2=col2->begin(); cfi2!=col2->end();cfi2++) {
00132         if (cfi2.getTrigger()==0) {
00133           vtxhist->Fill(cfi2.bunch());
00134           if (!cfi2->noParent())        vtxindhist->Fill(cfi2->parentIndex());
00135         } else {
00136           vtxhistsig->Fill(cfi2.bunch());
00137           if (!cfi2->noParent())        vtxindhistsig->Fill(cfi2->parentIndex());
00138         }
00139     }
00140         
00141     //tracker
00142     int bsp=cf_simhit->getBunchSpace();
00143     char tof[30];
00144 
00145     sprintf(tof,"TrackerHit_Tof_bcr_%d",bunchcr_);
00146     MonitorElement * tofhist = dbe_->book1D(tof,"TrackerHit_ToF",100,float(bsp*minbunch_),float(bsp*maxbunch_)+50.);
00147     sprintf(tof,"SignalTrackerHit_Tof_bcr_%d",bunchcr_);
00148     MonitorElement * tofhist_sig = dbe_->book1D(tof,"TrackerHit_ToF",100,float(bsp*minbunch_),float(bsp*maxbunch_)+50.);
00149     std::auto_ptr<MixCollection<PSimHit> > colsh(new MixCollection<PSimHit>(cf_simhit.product()));
00150     MixCollection<PSimHit>::iterator cfish;
00151     for (cfish=colsh->begin(); cfish!=colsh->end();cfish++) {
00152       if (cfish.getTrigger())  {
00153         tofhist_sig->Fill(cfish->timeOfFlight());
00154       }
00155       else  {
00156         tofhist->Fill(cfish->timeOfFlight());
00157       }
00158     }
00159 
00160     //Ecal
00161     sprintf(tof,"EcalEBHit_Tof_bcr_%d",bunchcr_);
00162     MonitorElement * tofecalhist = dbe_->book1D(tof,"EcalEBHit_ToF",100,float(bsp*minbunch_),float(bsp*maxbunch_)+50.);
00163     sprintf(tof,"SignalEcalEBHit_Tof_bcr_%d",bunchcr_);
00164     MonitorElement * tofecalhist_sig = dbe_->book1D(tof,"EcalEBHit_ToF",100,float(bsp*minbunch_),float(bsp*maxbunch_)+50.);
00165                                                  //    std::string ecalsubdet("EcalHitsEB");
00166     std::auto_ptr<MixCollection<PCaloHit> > colecal(new MixCollection<PCaloHit>(cf_calohitEcal.product()));
00167     MixCollection<PCaloHit>::iterator cfiecal;
00168     for (cfiecal=colecal->begin(); cfiecal!=colecal->end();cfiecal++) {
00169       if (cfiecal.getTrigger())    tofecalhist_sig->Fill(cfiecal->time());
00170       else    tofecalhist->Fill(cfiecal->time());
00171     }
00172 
00173     // Hcal
00174     sprintf(tof,"HcalHit_Tof_bcr_%d",bunchcr_);
00175     MonitorElement * tofhcalhist = dbe_->book1D(tof,"HcalHit_ToF",100,float(bsp*minbunch_),float(bsp*maxbunch_)+50.);
00176     sprintf(tof,"SignalHcalHit_Tof_bcr_%d",bunchcr_);
00177     MonitorElement * tofhcalhist_sig = dbe_->book1D(tof,"HcalHit_ToF",100,float(bsp*minbunch_),float(bsp*maxbunch_)+50.);
00178                                                     //    std::string hcalsubdet("HcalHits");
00179     std::auto_ptr<MixCollection<PCaloHit> > colhcal(new MixCollection<PCaloHit>(cf_calohitHcal.product()));
00180     MixCollection<PCaloHit>::iterator cfihcal;
00181     
00182     for (cfihcal=colhcal->begin(); cfihcal!=colhcal->end();cfihcal++) {
00183       if (cfihcal.getTrigger())  tofhcalhist_sig->Fill(cfihcal->time());
00184       else  tofhcalhist->Fill(cfihcal->time());
00185     }
00186 }
00187