CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/DQM/RPCMonitorDigi/src/RPCMonitorSync.cc

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