CMS 3D CMS Logo

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