//example of testHistoSource #include "Utilities/Configuration/interface/Architecture.h" #include "CARF/G3Event/interface/G3EventProxy.h" #include "SubfarmManager/RootMonitorThread/interface/RootMonitorThread.h" #include "DaqPrototype/DaqMonitor/interface/MonitorElement.h" #include "DaqPrototype/DaqMonitorRoot/interface/DaqMonitorROOTBackEnd.h" #include "Tracker/TkLayout/interface/CmsTracker.h" #include "Tracker/TkLayout/interface/FullTracker.h" #include "CommonDet/DetLayout/interface/DetLayer.h" #include "CommonDet/BasicDet/interface/SimDet.h" #include "CommonDet/BasicDet/interface/DetUnit.h" #include "CommonDet/BasicDet/interface/DetType.h" #include "Utilities/Notification/interface/PackageInitializer.h" #include "Utilities/Notification/interface/Observer.h" #include // forward declare classes we have only pointers to class G3EventProxy; class BuildMap : private Observer { public: BuildMap(); //!< default constructor ~BuildMap(); //!< default destructor /// this method will do the user analysis void myAnalysis(G3EventProxy * ev); private: /// don't change the name "upDate" - this method is mandatory. void upDate(G3EventProxy * ev) {if (ev!=0) myAnalysis(ev);} int eventsAnalysed; //!< just to count events that have been analysed int PUeventsUsed; //!< just to count events that have been analysed int runsAnalysed; //!< count the runs int lastrun; //!< to remember the last run analysed MonitorElement * h2; }; // ----------------------------------------------------------------------------- // In the constructor we can initialize. It is automatically called when an // instance of the class is created. // ----------------------------------------------------------------------------- BuildMap::BuildMap() { cout << "===========================================================" << endl; cout << "=== Start create new BuildMap ===" << endl; // Initialise observer init(); // Initialise counters eventsAnalysed = 0; PUeventsUsed = 0; runsAnalysed = 0; lastrun = 0; cout << "=== Done create new BuildMap ==" << endl; cout << "===========================================================" << endl; } BuildMap::~BuildMap() { cout << "===========================================================" << endl; cout << "=== Start delete BuildMap ===" << endl; cout << " Number of events analysed: " << eventsAnalysed << endl; cout << " Number of pileup events used: " << PUeventsUsed << endl; cout << " Number of runs analysed: " << runsAnalysed << endl; cout << "=== Done delete BuildMap ===" << endl; cout << "===========================================================" << endl; } void BuildMap::myAnalysis(G3EventProxy * ev) { static bool firstevt = true; if(firstevt){ firstevt=false; // default source name string sfuname = "FU0"; // default collector host name string hostname = "localhost"; // default monitoring period (microsecs) int period = 1000000; // default # of monitoring cycles //unsigned int n_cycles = 20000; cout << " Source " << sfuname << " begins sending monitoring to host " << hostname << "\n with period " << period << " microsecs" << endl; RootMonitorThread *od = new RootMonitorThread(hostname, 9090, period, sfuname); // start back-end interface instance DaqMonitorBEInterface *dbe = DaqMonitorROOTBackEnd::instance(); int NBINS =0 ; int NBINS1 =0; //float XMIN ; float XMAX ; // book some histograms here CmsTracker::LayerIterator ilayer; const CmsTracker::LayerContainer& bl = FullTracker::instance()->allLayers(); for ( ilayer = bl.begin(); ilayer != bl.end(); ilayer++) { //loop over layers NBINS++; //Module theModule = ilayer->module(); Det::DetUnitContainer theDets = ilayer->detUnits(); Det::DetUnitContainer::iterator idet; int nmod =0; for ( idet = theDets.begin(); idet != theDets.end(); idet++) { //loop on detunits nmod++; } if(nmod>NBINS1)NBINS1=nmod; } // create and cd into new folder dbe->setCurrentFolder("C1"); h2 = dbe->book2D("histo2", "Example 2 2D histogram.", NBINS, 0, float (NBINS), NBINS1, 0.0, NBINS1); dbe->showDirStructure(); od->release(); } int simHitsEv = 0; cout << "===========================================================" << endl; cout << "=== Private analysis of " << eventsAnalysed << " event #"<< ev->simSignal()->id().eventInRun() << " in run #" << ev->simSignal()->id().runNumber() ; eventsAnalysed++; // some statistics: count events and runs processed CmsTracker::LayerIterator ilayer; const CmsTracker::LayerContainer& bl = FullTracker::instance()->allLayers(); int idLayer=0; for ( ilayer = bl.begin(); ilayer != bl.end(); ilayer++) { //loop over layers //Module theModule = ilayer->module(); Det::DetUnitContainer theDets = ilayer->detUnits(); Det::DetUnitContainer::iterator idet; int idModule =0; for ( idet = theDets.begin(); idet != theDets.end(); idet++) { //loop on detunits int simHitsSize = 0; const SimDet* simDetP = (*idet)->simDet(); // Get simhits if(simDetP!=0 && !simDetP->simHits().empty() ){ simHitsSize = simDetP->simHits().size(); simHitsEv = simHitsEv + simHitsSize; h2->Fill(idLayer+1,idModule+1); // usleep(15000); // this is 15 ms } idModule++; // (*(*i1))++; usleep(1500); // this is 15 ms } idLayer++; cout << idLayer << endl; } cout << "************************** simHits ************************ " << simHitsEv << endl; if (ev->simSignal()->id().runNumber() != lastrun) { lastrun = ev->simSignal()->id().runNumber(); runsAnalysed++; } cout << "===========================================================" << endl; }; static PKBuilder mybuilder("BuildMapBuilder");