00001
00002
00003
00004
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <memory>
00020 #include <utility>
00021 #include <iostream>
00022
00023
00024 #include "FWCore/Framework/interface/Frameworkfwd.h"
00025 #include "FWCore/Framework/interface/EDAnalyzer.h"
00026
00027 #include "FWCore/Framework/interface/Event.h"
00028 #include "FWCore/Framework/interface/MakerMacros.h"
00029
00030 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00031
00032 #include "SimDataFormats/CrossingFrame/interface/CrossingFrame.h"
00033 #include "SimDataFormats/CrossingFrame/interface/MixCollection.h"
00034 #include "SimDataFormats/TrackingHit/interface/PSimHit.h"
00035
00036 #include "TestMix.h"
00037
00038 #include "SimDataFormats/CaloHit/interface/PCaloHitContainer.h"
00039 #include "SimDataFormats/Track/interface/SimTrackContainer.h"
00040 #include "SimDataFormats/Vertex/interface/SimVertexContainer.h"
00041 #include "SimDataFormats/HepMCProduct/interface/HepMCProduct.h"
00042
00043
00044 using namespace edm;
00045
00046 TestMix::TestMix(const edm::ParameterSet& iConfig):
00047 level_(iConfig.getUntrackedParameter<int>("PrintLevel"))
00048 {
00049 std::cout << "Constructed testMix , level "<<level_<<std::endl;
00050
00051 track_containers_.push_back("TrackerHitsTECHighTof");
00052 track_containers_.push_back("TrackerHitsTECLowTof");
00053
00054 track_containers2_.push_back("TrackerHitsTECLowTof");
00055 track_containers2_.push_back("TrackerHitsTECHighTof");
00056
00057 }
00058
00059
00060 TestMix::~TestMix()
00061 {
00062
00063
00064
00065
00066 }
00067
00068
00069
00070
00071
00072
00073
00074 void
00075 TestMix::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00076 {
00077 using namespace edm;
00078
00079
00080
00081
00082
00083
00084
00085 edm::Handle<CrossingFrame<SimTrack> > cf_simtrack;
00086 iEvent.getByLabel("mix",cf_simtrack);
00087
00088 std::vector<SimTrack>::const_iterator first;
00089 std::vector<SimTrack>::const_iterator last;
00090 cf_simtrack->getPileups(first,last);
00091 unsigned int ic=0;
00092 for (std::vector<SimTrack>::const_iterator it=first;it!=last;it++) {
00093
00094 ic++;
00095 }
00096
00097
00098 const std::string subdet("TrackerHitsTECHighTof");
00099 edm::Handle<CrossingFrame<PSimHit> > cf_simhit;
00100 iEvent.getByLabel("mix",subdet,cf_simhit);
00101 std::cout<<"\n\n=================== Starting SimHit access, subdet "<<subdet<<" ==================="<<std::endl;
00102
00103 std::auto_ptr<MixCollection<PSimHit> > col(new MixCollection<PSimHit>(cf_simhit.product(),std::pair<int,int>(-1,1)));
00104 std::cout<<*(col.get())<<std::endl;
00105 MixCollection<PSimHit>::iterator cfi;
00106 int count=0;
00107 for (cfi=col->begin(); cfi!=col->end();cfi++) {
00108 std::cout<<" Hit "<<count<<" has tof "<<cfi->timeOfFlight()<<" trackid "<<cfi->trackId() <<" bunchcr "<<cfi.bunch()<<" trigger "<<cfi.getTrigger()<<", from EncodedEventId: "<<cfi->eventId().bunchCrossing()<<" " <<cfi->eventId().event() <<" bcr from MixCol "<<cfi.bunch()<<std::endl;
00109
00110 count++;
00111 }
00112
00113
00114 const std::string subdetcalo("EcalHitsEB");
00115 edm::Handle<CrossingFrame<PCaloHit> > cf_calo;
00116 iEvent.getByLabel("mix",subdetcalo,cf_calo);
00117 std::cout<<"\n\n=================== Starting CaloHit access, subdet "<<subdetcalo<<" ==================="<<std::endl;
00118 std::auto_ptr<MixCollection<PCaloHit> > colcalo(new MixCollection<PCaloHit>(cf_calo.product(), std::pair<int,int>(-1,1)));
00119 std::cout<<*(colcalo.get())<<std::endl;
00120 MixCollection<PCaloHit>::iterator cficalo;
00121 count=0;
00122 for (cficalo=colcalo->begin(); cficalo!=colcalo->end();cficalo++) {
00123 std::cout<<" CaloHit "<<count<<" has tof "<<cficalo->time()<<" trackid "<<cficalo->geantTrackId() <<" bunchcr "<<cficalo.bunch()<<" trigger "<<cficalo.getTrigger()<<", from EncodedEventId: "<<cficalo->eventId().bunchCrossing()<<" " <<cficalo->eventId().event() <<std::endl;
00124
00125 count++;
00126 }
00127
00128
00129 std::cout<<"\n=================== Starting SimTrack access ==================="<<std::endl;
00130
00131
00132 std::auto_ptr<MixCollection<SimTrack> > col2(new MixCollection<SimTrack>(cf_simtrack.product()));
00133 MixCollection<SimTrack>::iterator cfi2;
00134 int count2=0;
00135 std::cout <<" \nWe got "<<col2->sizeSignal()<<" signal tracks and "<<col2->sizePileup()<<" pileup tracks, total: "<<col2->size()<<std::endl;
00136 for (cfi2=col2->begin(); cfi2!=col2->end();cfi2++) {
00137 std::cout<<" SimTrack "<<count2<<" has genpart index "<<cfi2->genpartIndex()<<" vertex Index "<<cfi2->vertIndex() <<" bunchcr "<<cfi2.bunch()<<" trigger "<<cfi2.getTrigger()<<", from EncodedEventId: "<<cfi2->eventId().bunchCrossing() <<" "<<cfi2->eventId().event() <<std::endl;
00138 count2++;
00139 }
00140
00141
00142 std::cout<<"\n=================== Starting SimVertex access ==================="<<std::endl;
00143 edm::Handle<CrossingFrame<SimVertex> > cf_simvtx;
00144 iEvent.getByLabel("mix",cf_simvtx);
00145 std::auto_ptr<MixCollection<SimVertex> > col3(new MixCollection<SimVertex>(cf_simvtx.product()));
00146 MixCollection<SimVertex>::iterator cfi3;
00147 int count3=0;
00148 std::cout <<" \nWe got "<<col3->sizeSignal()<<" signal vertices and "<<col3->sizePileup()<<" pileup vertices, total: "<<col3->size()<<std::endl;
00149 for (cfi3=col3->begin(); cfi3!=col3->end();cfi3++) {
00150 std::cout<<" SimVertex "<<count3<<" has parent index "<<cfi3->parentIndex()<<" bunchcr "<<cfi3.bunch()<<" trigger "<<cfi3.getTrigger()<<", from EncodedEventId: "<<cfi3->eventId().bunchCrossing() <<" "<<cfi3->eventId().event() <<std::endl;
00151 count3++;
00152 }
00153
00154
00155 std::cout<<"\n=================== Starting test for coll of several ROU-s ==================="<<std::endl;
00156
00157 std::vector<const CrossingFrame<PSimHit> *> cfvec;
00158 iEvent.getByLabel("mix",track_containers_[0],cf_simhit);
00159 cfvec.push_back(cf_simhit.product());
00160 std::cout <<" \nFirst container "<<track_containers_[0]<<" Nr signals "<<cf_simhit->getNrSignals() << ", Nr pileups "<<cf_simhit->getNrPileups() <<std::endl;
00161 iEvent.getByLabel("mix",track_containers_[1],cf_simhit);
00162 cfvec.push_back(cf_simhit.product());
00163 std::cout <<" \nSecond container "<<track_containers_[1]<<" Nr signals "<<cf_simhit->getNrSignals() << ", Nr pileups "<<cf_simhit->getNrPileups() <<std::endl;
00164 std::auto_ptr<MixCollection<PSimHit> > all_trackhits(new MixCollection<PSimHit>(cfvec));
00165
00166 std::cout <<" \nFor all containers we got "<<all_trackhits->sizeSignal()<<" signal hits and "<<all_trackhits->sizePileup()<<" pileup hits, total: "<<all_trackhits->size()<<std::endl;
00167
00168 MixCollection<PSimHit>::iterator it;
00169 int ii=0;
00170 for (it=all_trackhits->begin(); it!= all_trackhits->end();it++) {
00171 std::cout<<" Hit "<<ii<<" of all hits has tof "<<it->timeOfFlight()<<" trackid "<<it->trackId() <<" bunchcr "<<it.bunch()<<" trigger "<<it.getTrigger()<<", from EncodedEventId: "<<it->eventId().bunchCrossing() <<" "<<it->eventId().event()<<std::endl;
00172 ii++;
00173 }
00174
00175
00176 std::vector<const CrossingFrame<PSimHit> *> cfvec2;
00177 iEvent.getByLabel("mix",track_containers2_[0],cf_simhit);
00178 cfvec2.push_back(cf_simhit.product());
00179 iEvent.getByLabel("mix",track_containers2_[1],cf_simhit);
00180 cfvec2.push_back(cf_simhit.product());
00181 std::auto_ptr<MixCollection<PSimHit> > all_trackhits2(new MixCollection<PSimHit>(cfvec2));
00182 std::cout <<" \nSame containers, different order: we got "<<all_trackhits2->sizeSignal()<<" signal hits and "<<all_trackhits2->sizePileup()<<" pileup hits, total: "<<all_trackhits2->size()<<std::endl;
00183 MixCollection<PSimHit>::iterator it2;
00184 int ii2=0;
00185 for (it2=all_trackhits2->begin(); it2!= all_trackhits2->end();it2++) {
00186 std::cout<<" Hit "<<ii2<<" of all hits has tof "<<it2->timeOfFlight()<<" trackid "<<it2->trackId() <<" bunchcr "<<it2.bunch()<<" trigger "<<it2.getTrigger()<<", bcr from Id: "<<it2->eventId().bunchCrossing() <<" evtnr in id "<<it2->eventId().event()<<std::endl;
00187 ii2++;
00188 }
00189
00190
00191
00192 edm::Handle<CrossingFrame<edm::HepMCProduct> > cf_hepmc;
00193 iEvent.getByLabel("mix",cf_hepmc);
00194 std::auto_ptr<MixCollection<edm::HepMCProduct> > colhepmc(new MixCollection<edm::HepMCProduct>(cf_hepmc.product()));
00195 MixCollection<edm::HepMCProduct>::iterator cfihepmc;
00196 int counthepmc=0;
00197 std::cout <<" \nWe got "<<colhepmc->sizeSignal()<<" signal hepmc products and "<<colhepmc->sizePileup()<<" pileup hepmcs, total: "<<colhepmc->size()<<std::endl;
00198 for (cfihepmc=colhepmc->begin(); cfihepmc!=colhepmc->end();cfihepmc++) {
00199 std::cout<<" edm::HepMCProduct "<<counthepmc<<" has event number "<<cfihepmc->GetEvent()->event_number()<<", "<< cfihepmc->GetEvent()->particles_size()<<" particles and "<<cfihepmc->GetEvent()->vertices_size()<<" vertices, bunchcr= "<<cfihepmc.bunch()<<" trigger= "<<cfihepmc.getTrigger() <<" sourcetype= "<<cfihepmc.getSourceType()<<std::endl;
00200 counthepmc++;
00201 }
00202
00203
00204
00205
00206
00207
00208 int ii3=0;
00209 for (it2=all_trackhits2->begin(); it2!= all_trackhits2->end();it2++) ii3++;
00210 if (ii3!=ii2) std::cout<<" Problem when re-using iterator!!"<<std::endl;
00211 else std::cout<<" \nNo problem when re-using iterator."<<std::endl;
00212
00213
00214
00215
00216
00217 std::cout<<"\n=================== Starting tests for abnormal conditions ==================="<<std::endl;
00218
00219
00220 std::cout<<"\n[ Testing abnormal conditions case 0]Should be all ok: registry: "<<all_trackhits->inRegistry()<<" size: "<<all_trackhits->size()<<std::endl;
00221
00222
00223 std::cout<<"\n[ Testing abnormal conditions case 1] Should throw an exception " <<std::endl;
00224 MixCollection<PSimHit> * col21=0;
00225 col21=new MixCollection<PSimHit>(cf_simhit.product(),std::pair<int,int>(-10,20));
00226 }
00227