00001
00002
00003
00004
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <memory>
00020 #include <utility>
00021
00022 #include <string>
00023
00024
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 cfTrackTag_(iConfig.getParameter<edm::InputTag>("cfTrackTag")),
00051 cfVertexTag_(iConfig.getParameter<edm::InputTag>("cfVertexTag"))
00052 {
00053 std::cout << "Constructed GlobalTest, filename: "<<filename_<<" minbunch: "<<minbunch_<<", maxbunch: "<<maxbunch_<<std::endl;
00054
00055 }
00056
00057 GlobalTest::~GlobalTest()
00058 {
00059
00060
00061
00062 }
00063
00064 void GlobalTest::beginJob() {
00065 using namespace std;
00066
00067
00068 dbe_ = Service<DQMStore>().operator->();
00069 dbe_->showDirStructure();
00070 dbe_->setCurrentFolder("MixingV/Mixing");
00071
00072 std::string NrPileupEvts = "NrPileupEvts";
00073 size_t NrPileupEvtsSize = NrPileupEvts.size() + 1;
00074 std::string NrVertices = "NrVertices";
00075 size_t NrVerticesSize = NrVertices.size() + 1;
00076 std::string NrTracks = "NrTracks";
00077 size_t NrTracksSize = NrTracks.size() + 1;
00078 std::string TrackPartId = "TrackPartId";
00079 size_t TrackPartIdSize = TrackPartId.size() + 1;
00080 std::string CaloEnergyEB = "CaloEnergyEB";
00081 size_t CaloEnergyEBSize = CaloEnergyEB.size() + 1;
00082 std::string CaloEnergyEE = "CaloEnergyEE";
00083 size_t CaloEnergyEESize = CaloEnergyEE.size() + 1;
00084
00085 labels[0] = new char [NrPileupEvtsSize];
00086 strncpy(labels[0], NrPileupEvts.c_str(), NrPileupEvtsSize);
00087 labels[1] = new char [NrVerticesSize];
00088 strncpy(labels[1], NrVertices.c_str(), NrVerticesSize);
00089 labels[2] = new char [NrTracksSize];
00090 strncpy(labels[2], NrTracks.c_str(), NrTracksSize);
00091 labels[3] = new char [TrackPartIdSize];
00092 strncpy(labels[3], TrackPartId.c_str(), TrackPartIdSize);
00093 labels[4] = new char [CaloEnergyEBSize];
00094 strncpy(labels[4], CaloEnergyEB.c_str(), CaloEnergyEBSize);
00095 labels[5] = new char [CaloEnergyEESize];
00096 strncpy(labels[5], CaloEnergyEE.c_str(), CaloEnergyEESize);
00097
00098
00099 for (int i=minbunch_;i<=maxbunch_;++i) {
00100 int ii=i-minbunch_;
00101 char label[50];
00102 sprintf(label,"%s_%d",labels[0],i);
00103 nrPileupsH_[ii] = dbe_->book1D(label,label,100,0,100);
00104 sprintf(label,"%s_%d",labels[1],i);
00105 nrVerticesH_[ii] = dbe_->book1D(label,label,100,0,5000);
00106 sprintf(label,"%s_%d",labels[2],i);
00107 nrTracksH_[ii] = dbe_->book1D(label,label,100,0,10000);
00108 sprintf(label,"%s_%d",labels[3],i);
00109 trackPartIdH_[ii] = dbe_->book1D(label,label,100,0,100);
00110 sprintf(label,"%s_%d",labels[4],i);
00111 caloEnergyEBH_ [ii] = dbe_->book1D(label,label,100,0.,1000.);
00112 sprintf(label,"%s_%d",labels[5],i);
00113 caloEnergyEEH_ [ii] = dbe_->book1D(label,label,100,0.,1000.);
00114 }
00115 }
00116
00117
00118 void GlobalTest::endJob() {
00119 if (filename_.size() != 0 && dbe_ ) dbe_->save(filename_);
00120
00121 for (int i = 0; i < 6; i++) delete[] labels[i];
00122 }
00123
00124
00125
00126
00127
00128
00129 void
00130 GlobalTest::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00131 {
00132 using namespace edm;
00133 using namespace std;
00134
00135
00136 edm::Handle<CrossingFrame<SimTrack> > cf_track;
00137 edm::Handle<CrossingFrame<SimTrack> > cf_vertex;
00138 edm::Handle<CrossingFrame<PCaloHit> > cf_calohitE;
00139 edm::Handle<CrossingFrame<PCaloHit> > cf_calohitB;
00140 std::string ecalsubdetb("g4SimHitsEcalHitsEB");
00141 std::string ecalsubdete("g4SimHitsEcalHitsEE");
00142 iEvent.getByLabel(cfTrackTag_, cf_track);
00143 iEvent.getByLabel(cfVertexTag_, cf_vertex);
00144 iEvent.getByLabel("mix",ecalsubdetb,cf_calohitB);
00145 iEvent.getByLabel("mix",ecalsubdete,cf_calohitE);
00146
00147
00148
00149
00150 for (int i=minbunch_;i<=maxbunch_;++i) {
00151 nrTracksH_[i-minbunch_]->Fill(cf_track->getNrPileups(i));
00152 }
00153
00154
00155 for (int i=minbunch_;i<=maxbunch_;++i) {
00156 nrVerticesH_[i-minbunch_]->Fill(cf_vertex->getNrPileups(i));
00157 }
00158
00159
00160 std::auto_ptr<MixCollection<SimTrack> > coltr(new MixCollection<SimTrack>(cf_track.product()));
00161 MixCollection<SimTrack>::iterator cfitr;
00162 for (cfitr=coltr->begin(); cfitr!=coltr->end();cfitr++) {
00163 trackPartIdH_[cfitr.bunch()-minbunch_]->Fill(cfitr->type());
00164 }
00165
00166
00167 double sumE[10]={0.,0.,0.,0.,0.,0.,0.,0.,0.,0.};
00168 std::auto_ptr<MixCollection<PCaloHit> > colecalb(new MixCollection<PCaloHit>(cf_calohitB.product()));
00169 MixCollection<PCaloHit>::iterator cfiecalb;
00170 for (cfiecalb=colecalb->begin(); cfiecalb!=colecalb->end();cfiecalb++) {
00171 sumE[cfiecalb.bunch()-minbunch_]+=cfiecalb->energy();
00172
00173
00174 }
00175 for (int i=minbunch_;i<=maxbunch_;++i) {
00176 caloEnergyEBH_[i-minbunch_]->Fill(sumE[i-minbunch_]);
00177 }
00178 double sumEE[10]={0.,0.,0.,0.,0.,0.,0.,0.,0.,0.};
00179 std::auto_ptr<MixCollection<PCaloHit> > colecale(new MixCollection<PCaloHit>(cf_calohitE.product()));
00180 MixCollection<PCaloHit>::iterator cfiecale;
00181 for (cfiecale=colecale->begin(); cfiecale!=colecale->end();cfiecale++) {
00182 sumEE[cfiecale.bunch()-minbunch_]+=cfiecale->energy();
00183
00184
00185 }
00186 for (int i=minbunch_;i<=maxbunch_;++i) {
00187 caloEnergyEEH_[i-minbunch_]->Fill(sumEE[i-minbunch_]);
00188 }
00189 }
00190