CMS 3D CMS Logo

RPCMonitorSync.cc

Go to the documentation of this file.
00001 
00011 #include <DQM/RPCMonitorDigi/interface/RPCMonitorSync.h>
00012 
00013 
00014 
00015 // RPC Digi
00016 #include "DataFormats/MuonDetId/interface/RPCDetId.h"
00017 #include "DataFormats/RPCDigi/interface/RPCDigiCollection.h"
00018 
00020 #include <FWCore/MessageLogger/interface/MessageLogger.h>
00021 
00022 #include <vector>
00023 #include <ctime>
00024 
00025 using namespace std;
00026 using namespace edm;
00027 
00028 // Detector overview historam booking routines
00029 
00030 MonitorElement *RPCMonitorSync::barrelOffsetHist( char *name, char *title ) {
00031   char htit[128];
00032   sprintf(htit,"Synchronization offset - %s",title);
00033   dbe->setCurrentFolder("Global");
00034   MonitorElement *hist = dbe->book2D(name,title,18,1,7,24,1,13);
00035   return hist;
00036 } 
00037 
00038 MonitorElement *RPCMonitorSync::endcapOffsetHist( char *name, char *title ) {
00039   char htit[128];
00040   sprintf(htit,"Synchronization offset - %s",title);
00041   dbe->setCurrentFolder("Global");
00042   MonitorElement *hist = dbe->book2D(name,title,12,1,4,36,1,7);
00043   return hist;
00044 } 
00045 
00046 MonitorElement *RPCMonitorSync::barrelWidthHist( char *name, char *title ) {
00047   char htit[128];
00048   sprintf(htit,"Synchronization width - %s",title);
00049   dbe->setCurrentFolder("Global");
00050   MonitorElement *hist = dbe->book2D(name,title,18,1,7,24,1,13);
00051   return hist;
00052 } 
00053 
00054 MonitorElement *RPCMonitorSync::endcapWidthHist( char *name, char *title ) {
00055   char htit[128];
00056   sprintf(htit,"Synchronization width - %s",title);
00057   dbe->setCurrentFolder("Global");
00058   MonitorElement *hist = dbe->book2D(name,title,12,1,4,36,1,7);
00059   return hist;
00060 } 
00061 
00062 
00063 // Class constructor and destructor
00064 
00065 RPCMonitorSync::RPCMonitorSync( const edm::ParameterSet& pset )
00066 {
00067   counter=0;
00068 
00069   nameInLog = pset.getUntrackedParameter<std::string>("moduleLogName", "RPC_DQM");
00070 
00071   saveRootFile  = pset.getUntrackedParameter<bool>("SyncDQMSaveRootFile", false); 
00072   saveRootFileEventsInterval  = pset.getUntrackedParameter<int>("SyncEventsInterval", 10000); 
00073   RootFileName  = pset.getUntrackedParameter<std::string>("RootFileNameSync", "RPCMonitorSync.root"); 
00075   dbe = edm::Service<DQMStore>().operator->();
00076   dbe->showDirStructure();
00077 }
00078 
00079 RPCMonitorSync::~RPCMonitorSync(){
00080   cout << "Destruct RPCMonitorSync..." << endl;
00081 }
00082 
00083 
00084 // Histogram for individual DetUnit - booking routine
00085 
00086 std::map<std::string, MonitorElement*> RPCMonitorSync::bookDetUnitME(RPCDetId & detId) {
00087 
00088   std::map<std::string, MonitorElement*> meMap;
00089   std::string regionName;
00090   std::string ringType;
00091 
00092   if(detId.region() ==  0) {
00093     regionName="Barrel";
00094     ringType="Wheel";
00095   } else {
00096     ringType="Disk";
00097     if(detId.region() == -1) regionName="Encap-";
00098     if(detId.region() ==  1) regionName="Encap+";
00099   }
00100  
00101   char folder[120];
00102   sprintf(folder,"%s/%s_%d/station_%d/sector_%d",regionName.c_str(),ringType.c_str(),
00103                                 detId.ring(),detId.station(),detId.sector());
00104  
00105   dbe->setCurrentFolder(folder);
00106 
00107   // Name components common to current RPDDetId  
00108   char detUnitLabel[128];
00109   char layerLabel[128];
00110   sprintf(detUnitLabel ,"%d",detId());
00111   sprintf(layerLabel ,"layer%d_subsector%d_roll%d",detId.layer(),detId.subsector(),detId.roll());
00112 
00113   char meId [128];
00114   char meTitle [128];
00115   
00116   sprintf(meId,"Sync_%s",detUnitLabel);
00117   sprintf(meTitle,"Sychronization_for_%s",layerLabel);
00118   meMap[meId] = dbe->book1D(meId, meTitle, 9, -4.5, 4.5);
00119   
00120   return meMap;
00121 }
00122 
00123 
00124 // Fill histograms and save data
00125 
00126 void RPCMonitorSync::endJob(void)
00127 {
00128   int station_map[8]={1,2,3,4,5,0,6,0}; // map RPC layer numbers to histogram bins
00129     
00130   MonitorElement *hOffsetMBp1 = barrelOffsetHist("hOffsetMBp1","Barrell Wheel +1");
00131   MonitorElement *hOffsetMBp2 = barrelOffsetHist("hOffsetMBp2","Barrell Wheel +2");
00132   MonitorElement *hOffsetMB0  = barrelOffsetHist("hOffsetMB0" ,"Barrell Wheel 0");
00133   MonitorElement *hOffsetMBm1 = barrelOffsetHist("hOffsetMBm1","Barrell Wheel -1");
00134   MonitorElement *hOffsetMBm2 = barrelOffsetHist("hOffsetMBm2","Barrell Wheel -2");
00135   MonitorElement *hOffsetMEp1 = endcapOffsetHist("hOffsetMEp1","Endcap Disk +1");
00136   MonitorElement *hOffsetMEp2 = endcapOffsetHist("hOffsetMEp2","Endcap Disk +2");
00137   MonitorElement *hOffsetMEp3 = endcapOffsetHist("hOffsetMEp3","Endcap Disk +3");
00138   MonitorElement *hOffsetMEm1 = endcapOffsetHist("hOffsetMEm1","Endcap Disk -1");
00139   MonitorElement *hOffsetMEm2 = endcapOffsetHist("hOffsetMEm2","Endcap Disk -2");
00140   MonitorElement *hOffsetMEm3 = endcapOffsetHist("hOffsetMEm3","Endcap Disk -3");
00141 
00142   MonitorElement *hWidthMBp1 = barrelWidthHist("hWidthMBp1","Barrell Wheel +1");
00143   MonitorElement *hWidthMBp2 = barrelWidthHist("hWidthMBp2","Barrell Wheel +2");
00144   MonitorElement *hWidthMB0  = barrelWidthHist("hWidthMB0" ,"Barrell Wheel 0");
00145   MonitorElement *hWidthMBm1 = barrelWidthHist("hWidthMBm1","Barrell Wheel -1");
00146   MonitorElement *hWidthMBm2 = barrelWidthHist("hWidthMBm2","Barrell Wheel -2");
00147   MonitorElement *hWidthMEp1 = endcapWidthHist("hWidthMEp1","Endcap Disk +1");
00148   MonitorElement *hWidthMEp2 = endcapWidthHist("hWidthMEp2","Endcap Disk +2");
00149   MonitorElement *hWidthMEp3 = endcapWidthHist("hWidthMEp3","Endcap Disk +3");
00150   MonitorElement *hWidthMEm1 = endcapWidthHist("hWidthMEm1","Endcap Disk -1");
00151   MonitorElement *hWidthMEm2 = endcapWidthHist("hWidthMEm2","Endcap Disk -2");
00152   MonitorElement *hWidthMEm3 = endcapWidthHist("hWidthMEm3","Endcap Disk -3");
00153  
00154   map <uint32_t,timing>::const_iterator ci;
00155   float offset,width;
00156   float xf=0,yf=0;
00157 
00158   for(ci=synchroMap.begin();ci!=synchroMap.end();ci++){
00159     uint32_t id = ci->first;
00160     RPCDetId detId(id);
00161     
00162     offset = ci->second.offset();
00163     width = ci->second.width();
00164 
00165     RPCDetId *tempDetId=new RPCDetId(ci->first); 
00166         
00167     cout << "id: " << ci->first << "    " << *tempDetId << "    offset: " << offset
00168          << "    width: " << width << endl;     
00169     
00170     if( detId.region()==0 ) {
00171       // Fill barrel histogram
00172       xf=station_map[detId.station()*2+detId.layer()-3]+((float)(detId.roll()-0.5)/3.);
00173       yf=detId.sector()+((float)(detId.subsector()-0.5)/2.);
00174       if ((detId.sector()==4) && (detId.station()==4)) 
00175         yf=detId.sector()+((float)(detId.subsector()-0.5)/4.);
00176 
00177       if (detId.ring()==1) hOffsetMBp1->Fill(xf,yf,offset);
00178       if (detId.ring()==2) hOffsetMBp2->Fill(xf,yf,offset);
00179       if (detId.ring()==-1) hOffsetMBm1->Fill(xf,yf,offset);
00180       if (detId.ring()==-2) hOffsetMBm2->Fill(xf,yf,offset);
00181       if (detId.ring()==0) hOffsetMB0->Fill(xf,yf,offset);
00182       if (detId.ring()==1) hWidthMBp1->Fill(xf,yf,width);
00183       if (detId.ring()==2) hWidthMBp2->Fill(xf,yf,width);
00184       if (detId.ring()==-1) hWidthMBm1->Fill(xf,yf,width);
00185       if (detId.ring()==-2) hWidthMBm2->Fill(xf,yf,width);
00186       if (detId.ring()==0) hWidthMB0->Fill(xf,yf,width);
00187     } else {
00188       // Fill endcap histogram
00189       xf=detId.ring()  +((float)(detId.roll()-0.5)/4.);
00190       yf=detId.sector()+((float)(detId.subsector()-0.5)/6.);
00191 
00192       if (detId.region()==1) {
00193         if (detId.station()==1) hOffsetMEp1->Fill(xf,yf,offset);
00194         if (detId.station()==2) hOffsetMEp2->Fill(xf,yf,offset);
00195         if (detId.station()==3) hOffsetMEp3->Fill(xf,yf,offset);
00196         if (detId.station()==1) hWidthMEp1->Fill(xf,yf,width);
00197         if (detId.station()==2) hWidthMEp2->Fill(xf,yf,width);
00198         if (detId.station()==3) hWidthMEp3->Fill(xf,yf,width);
00199       }
00200       if (detId.region()==-1) {
00201         if (detId.station()==1) hOffsetMEm1->Fill(xf,yf,offset);
00202         if (detId.station()==2) hOffsetMEm2->Fill(xf,yf,offset);
00203         if (detId.station()==3) hOffsetMEm3->Fill(xf,yf,offset);
00204         if (detId.station()==1) hWidthMEm1->Fill(xf,yf,width);
00205         if (detId.station()==2) hWidthMEm2->Fill(xf,yf,width);
00206         if (detId.station()==3) hWidthMEm3->Fill(xf,yf,width);
00207       }
00208     } // end histogram filling
00209 
00210 //    cout << "xf= "<<xf<<"   yf= "<<yf<<endl;  
00211 
00212   } // end loop over synchroMap
00213 
00214   if(saveRootFile) 
00215     dbe->save(RootFileName);
00216 
00217 }
00218 
00219 
00220 // Loop over Digis and read synchronization information
00221 
00222 void RPCMonitorSync::readRPCDAQStrips(const edm::Event& iEvent) {
00223 
00224   timing aTiming;
00225   aTiming.inTime = 0;
00226   for (int i=0;i<4;i++) {
00227     aTiming.early_all[i] = 0;
00228     aTiming.late_all[i] = 0;
00229   }
00230 
00231   char detUnitLabel[128];
00232   char layerLabel[128];
00233   char meId [128];
00234 
00235   edm::Handle<RPCDigiCollection> rpcDigis;
00236 //  LogInfo (nameInLog) << "   RPC Digis: " << rpcDigis->size() << endl;
00237   iEvent.getByType(rpcDigis);
00238   RPCDigiCollection::DigiRangeIterator rpcDigiCI;
00239   for(rpcDigiCI = rpcDigis->begin();rpcDigiCI!=rpcDigis->end();rpcDigiCI++){
00240     cout << (*rpcDigiCI).first << endl;
00241     RPCDetId detId=(*rpcDigiCI).first; 
00242     uint32_t id=detId(); 
00243 
00244     sprintf(detUnitLabel ,"%d",detId());
00245     sprintf(layerLabel ,"layer%d_subsector%d_roll%d",detId.layer(),detId.subsector(),detId.roll());
00246  
00247     std::map<uint32_t, std::map<std::string,MonitorElement*> >::iterator meItr = meCollection.find(id);
00248     if (meItr == meCollection.end() || (meCollection.size()==0)) {
00249       meCollection[id]=bookDetUnitME(detId);
00250     }
00251     std::map<std::string, MonitorElement*> meMap=meCollection[id];
00252 
00253     if(synchroMap.find(id)==synchroMap.end()) { 
00254       synchroMap[id] = aTiming;
00255     }
00256     const RPCDigiCollection::Range& range = (*rpcDigiCI).second;
00257     int aBX=4;    
00258     for (RPCDigiCollection::const_iterator digiIt = range.first; digiIt!=range.second; ++digiIt){
00259       if( digiIt->bx()<aBX) aBX=digiIt->bx();
00260     }
00261     if (abs(aBX)<4) {
00262       if(aBX<0) synchroMap[id].early_all[-aBX]++;
00263       if(aBX==0) synchroMap[id].inTime++;
00264       if(aBX>0) synchroMap[id].late_all[aBX]++;
00265     }
00266     sprintf(meId,"Sync_%s",detUnitLabel);
00267     meMap[meId]->Fill(aBX);
00268   }
00269   if((!(counter%saveRootFileEventsInterval))&&(saveRootFile) ) dbe->save(RootFileName);
00270 }
00271 
00272 
00273 // Process event
00274 
00275 void RPCMonitorSync::analyze( const edm::Event& iEvent, const edm::EventSetup& iSetup ) {
00276   
00277    LogInfo (nameInLog) << "Beginning analyzing event " << counter++;
00278    cout << "=== RPCMonitorSync" << endl;
00279    cout << "--- Run: " << iEvent.id().run()
00280         << " Event: " << iEvent.id().event() 
00281         << " time: "<<iEvent.time().value();
00282    time_t aTime = iEvent.time().value();
00283    cout<<" "<<ctime(&aTime)<<endl;
00284    
00285    readRPCDAQStrips(iEvent);
00286 
00287    return;
00288 }

Generated on Tue Jun 9 17:33:19 2009 for CMSSW by  doxygen 1.5.4