CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/DQMOffline/Muon/src/CSCOfflineMonitor.cc

Go to the documentation of this file.
00001 /*
00002  *  Offline DQM module for CSC local reconstruction.
00003  *
00004  *  Andy Kubik
00005  *  Northwestern University
00006  */
00007 
00008 #include "DQMOffline/Muon/src/CSCOfflineMonitor.h"
00009 
00010 using namespace std;
00011 using namespace edm;
00012 
00013 
00015 //  CONSTRUCTOR  //
00017 CSCOfflineMonitor::CSCOfflineMonitor(const ParameterSet& pset){
00018 
00019   param = pset;
00020 
00021   stripDigiTag_  = pset.getParameter<edm::InputTag>("stripDigiTag");
00022   wireDigiTag_   = pset.getParameter<edm::InputTag>("wireDigiTag"); 
00023   alctDigiTag_   = pset.getParameter<edm::InputTag>("alctDigiTag");
00024   clctDigiTag_   = pset.getParameter<edm::InputTag>("clctDigiTag"); 
00025   cscRecHitTag_  = pset.getParameter<edm::InputTag>("cscRecHitTag");
00026   cscSegTag_     = pset.getParameter<edm::InputTag>("cscSegTag");
00027   FEDRawDataCollectionTag_  = pset.getParameter<edm::InputTag>("FEDRawDataCollectionTag");
00028 
00029   finalizedHistograms_=false;
00030 
00031 }
00032 
00033 void CSCOfflineMonitor::beginJob(void){
00034       dbe = Service<DQMStore>().operator->();
00035   
00036       // Occupancies
00037       dbe->setCurrentFolder("CSC/CSCOfflineMonitor/Occupancy");
00038       hCSCOccupancy = dbe->book1D("hCSCOccupancy","overall CSC occupancy",13,-0.5,12.5);
00039       hCSCOccupancy->setBinLabel(2,"Total Events");
00040       hCSCOccupancy->setBinLabel(4,"# Events with Wires");
00041       hCSCOccupancy->setBinLabel(6,"# Events with Strips");
00042       hCSCOccupancy->setBinLabel(8,"# Events with Wires&Strips");
00043       hCSCOccupancy->setBinLabel(10,"# Events with Rechits");
00044       hCSCOccupancy->setBinLabel(12,"# Events with Segments");
00045       hOWiresAndCLCT = dbe->book2D("hOWiresAndCLCT","Wire and CLCT Digi Occupancy ",36,0.5,36.5,20,0.5,20.5);
00046       applyCSClabels(hOWiresAndCLCT);
00047       hOWires = dbe->book2D("hOWires","Wire Digi Occupancy",36,0.5,36.5,20,0.5,20.5);
00048       applyCSClabels(hOWires);
00049       hOWireSerial = dbe->book1D("hOWireSerial","Wire Occupancy by Chamber Serial",601,-0.5,600.5);
00050       hOWireSerial->setAxisTitle("Chamber Serial Number");
00051       hOStrips = dbe->book2D("hOStrips","Strip Digi Occupancy",36,0.5,36.5,20,0.5,20.5);
00052       applyCSClabels(hOStrips);
00053       hOStripSerial = dbe->book1D("hOStripSerial","Strip Occupancy by Chamber Serial",601,-0.5,600.5);
00054       hOStripSerial->setAxisTitle("Chamber Serial Number");
00055       hOStripsAndWiresAndCLCT = dbe->book2D("hOStripsAndWiresAndCLCT","Strip And Wire And CLCT Digi Occupancy",36,0.5,36.5,20,0.5,20.5);
00056       applyCSClabels(hOStripsAndWiresAndCLCT);
00057       hORecHits = dbe->book2D("hORecHits","RecHit Occupancy",36,0.5,36.5,20,0.5,20.5);
00058       applyCSClabels(hORecHits);
00059       hORecHitsSerial = dbe->book1D("hORecHitSerial","RecHit Occupancy by Chamber Serial",601,-0.5,600.5);
00060       hORecHitsSerial->setAxisTitle("Chamber Serial Number");
00061       hOSegments = dbe->book2D("hOSegments","Segment Occupancy",36,0.5,36.5,20,0.5,20.5);
00062       applyCSClabels(hOSegments);
00063       hOSegmentsSerial = dbe->book1D("hOSegmentSerial","Segment Occupancy by Chamber Serial",601,-0.5,600.5);
00064       hOSegmentsSerial->setAxisTitle("Chamber Serial Number");
00065 
00066       // wire digis
00067       dbe->setCurrentFolder("CSC/CSCOfflineMonitor/Digis");
00068       hWirenGroupsTotal = dbe->book1D("hWirenGroupsTotal","Fired Wires per Event; # Wiregroups Fired",61,-0.5,60.5);
00069       hWireTBin.push_back(dbe->book1D("hWireTBin_m42","Wire TBin Fired (ME -4/2); Time Bin (25ns)",17,-0.5,16.5));
00070       hWireTBin.push_back(dbe->book1D("hWireTBin_m41","Wire TBin Fired (ME -4/1); Time Bin (25ns)",17,-0.5,16.5));
00071       hWireTBin.push_back(dbe->book1D("hWireTBin_m32","Wire TBin Fired (ME -3/2); Time Bin (25ns)",17,-0.5,16.5));
00072       hWireTBin.push_back(dbe->book1D("hWireTBin_m31","Wire TBin Fired (ME -3/1); Time Bin (25ns)",17,-0.5,16.5));
00073       hWireTBin.push_back(dbe->book1D("hWireTBin_m22","Wire TBin Fired (ME -2/2); Time Bin (25ns)",17,-0.5,16.5));
00074       hWireTBin.push_back(dbe->book1D("hWireTBin_m21","Wire TBin Fired (ME -2/1); Time Bin (25ns)",17,-0.5,16.5));
00075       hWireTBin.push_back(dbe->book1D("hWireTBin_m11a","Wire TBin Fired (ME -1/1a); Time Bin (25ns)",17,-0.5,16.5));
00076       hWireTBin.push_back(dbe->book1D("hWireTBin_m13","Wire TBin Fired (ME -1/3); Time Bin (25ns)",17,-0.5,16.5));
00077       hWireTBin.push_back(dbe->book1D("hWireTBin_m12","Wire TBin Fired (ME -1/2); Time Bin (25ns)",17,-0.5,16.5));
00078       hWireTBin.push_back(dbe->book1D("hWireTBin_m11b","Wire TBin Fired (ME -1/1b); Time Bin (25ns)",17,-0.5,16.5));
00079       hWireTBin.push_back(dbe->book1D("hWireTBin_p11b","Wire TBin Fired (ME +1/1b); Time Bin (25ns)",17,-0.5,16.5));
00080       hWireTBin.push_back(dbe->book1D("hWireTBin_p12","Wire TBin Fired (ME +1/2); Time Bin (25ns)",17,-0.5,16.5));
00081       hWireTBin.push_back(dbe->book1D("hWireTBin_p13","Wire TBin Fired (ME +1/3); Time Bin (25ns)",17,-0.5,16.5));
00082       hWireTBin.push_back(dbe->book1D("hWireTBin_p11a","Wire TBin Fired (ME +1/1a); Time Bin (25ns)",17,-0.5,16.5));
00083       hWireTBin.push_back(dbe->book1D("hWireTBin_p21","Wire TBin Fired (ME +2/1); Time Bin (25ns)",17,-0.5,16.5));
00084       hWireTBin.push_back(dbe->book1D("hWireTBin_p22","Wire TBin Fired (ME +2/2); Time Bin (25ns)",17,-0.5,16.5));
00085       hWireTBin.push_back(dbe->book1D("hWireTBin_p31","Wire TBin Fired (ME +3/1); Time Bin (25ns)",17,-0.5,16.5));
00086       hWireTBin.push_back(dbe->book1D("hWireTBin_p32","Wire TBin Fired (ME +3/2); Time Bin (25ns)",17,-0.5,16.5));
00087       hWireTBin.push_back(dbe->book1D("hWireTBin_p41","Wire TBin Fired (ME +4/1); Time Bin (25ns)",17,-0.5,16.5));
00088       hWireTBin.push_back(dbe->book1D("hWireTBin_p42","Wire TBin Fired (ME +4/2); Time Bin (25ns)",17,-0.5,16.5));
00089       hWireNumber.push_back(dbe->book1D("hWireNumber_m42","Wiregroup Number Fired (ME -4/2); Wiregroup #",113,-0.5,112.5));
00090       hWireNumber.push_back(dbe->book1D("hWireNumber_m41","Wiregroup Number Fired (ME -4/1); Wiregroup #",113,-0.5,112.5));
00091       hWireNumber.push_back(dbe->book1D("hWireNumber_m32","Wiregroup Number Fired (ME -3/2); Wiregroup #",113,-0.5,112.5));
00092       hWireNumber.push_back(dbe->book1D("hWireNumber_m31","Wiregroup Number Fired (ME -3/1); Wiregroup #",113,-0.5,112.5));
00093       hWireNumber.push_back(dbe->book1D("hWireNumber_m22","Wiregroup Number Fired (ME -2/2); Wiregroup #",113,-0.5,112.5));
00094       hWireNumber.push_back(dbe->book1D("hWireNumber_m21","Wiregroup Number Fired (ME -2/1); Wiregroup #",113,-0.5,112.5));
00095       hWireNumber.push_back(dbe->book1D("hWireNumber_m11a","Wiregroup Number Fired (ME -1/1a); Wiregroup #",113,-0.5,112.5));
00096       hWireNumber.push_back(dbe->book1D("hWireNumber_m13","Wiregroup Number Fired (ME -1/3); Wiregroup #",113,-0.5,112.5));
00097       hWireNumber.push_back(dbe->book1D("hWireNumber_m12","Wiregroup Number Fired (ME -1/2); Wiregroup #",113,-0.5,112.5));
00098       hWireNumber.push_back(dbe->book1D("hWireNumber_m11b","Wiregroup Number Fired (ME -1/1b); Wiregroup #",113,-0.5,112.5));
00099       hWireNumber.push_back(dbe->book1D("hWireNumber_p11b","Wiregroup Number Fired (ME +1/1b); Wiregroup #",113,-0.5,112.5));
00100       hWireNumber.push_back(dbe->book1D("hWireNumber_p12","Wiregroup Number Fired (ME +1/2); Wiregroup #",113,-0.5,112.5));
00101       hWireNumber.push_back(dbe->book1D("hWireNumber_p13","Wiregroup Number Fired (ME +1/3); Wiregroup #",113,-0.5,112.5));
00102       hWireNumber.push_back(dbe->book1D("hWireNumber_p11a","Wiregroup Number Fired (ME +1/1a); Wiregroup #",113,-0.5,112.5));
00103       hWireNumber.push_back(dbe->book1D("hWireNumber_p21","Wiregroup Number Fired (ME +2/1); Wiregroup #",113,-0.5,112.5));
00104       hWireNumber.push_back(dbe->book1D("hWireNumber_p22","Wiregroup Number Fired (ME +2/2); Wiregroup #",113,-0.5,112.5));
00105       hWireNumber.push_back(dbe->book1D("hWireNumber_p31","Wiregroup Number Fired (ME +3/1); Wiregroup #",113,-0.5,112.5));
00106       hWireNumber.push_back(dbe->book1D("hWireNumber_p32","Wiregroup Number Fired (ME +3/2); Wiregroup #",113,-0.5,112.5));
00107       hWireNumber.push_back(dbe->book1D("hWireNumber_p41","Wiregroup Number Fired (ME +4/1); Wiregroup #",113,-0.5,112.5));
00108       hWireNumber.push_back(dbe->book1D("hWireNumber_p42","Wiregroup Number Fired (ME +4/2); Wiregroup #",113,-0.5,112.5));
00109 
00110       // strip digis
00111       hStripNFired = dbe->book1D("hStripNFired","Fired Strips per Event; # Strips Fired (above 13 ADC)",101,-0.5,100.5);
00112       hStripNumber.push_back(dbe->book1D("hStripNumber_m42","Strip Number Fired (ME -4/2); Strip # Fired (above 13 ADC)",81,-0.5,80.5));
00113       hStripNumber.push_back(dbe->book1D("hStripNumber_m41","Strip Number Fired (ME -4/1); Strip # Fired (above 13 ADC)",81,-0.5,80.5));
00114       hStripNumber.push_back(dbe->book1D("hStripNumber_m32","Strip Number Fired (ME -3/2); Strip # Fired (above 13 ADC)",81,-0.5,80.5));
00115       hStripNumber.push_back(dbe->book1D("hStripNumber_m31","Strip Number Fired (ME -3/1); Strip # Fired (above 13 ADC)",81,-0.5,80.5));
00116       hStripNumber.push_back(dbe->book1D("hStripNumber_m22","Strip Number Fired (ME -2/2); Strip # Fired (above 13 ADC)",81,-0.5,80.5));
00117       hStripNumber.push_back(dbe->book1D("hStripNumber_m21","Strip Number Fired (ME -2/1); Strip # Fired (above 13 ADC)",81,-0.5,80.5));
00118       hStripNumber.push_back(dbe->book1D("hStripNumber_m11a","Strip Number Fired (ME -1/1a); Strip # Fired (above 13 ADC)",81,-0.5,80.5));
00119       hStripNumber.push_back(dbe->book1D("hStripNumber_m13","Strip Number Fired (ME -1/3); Strip # Fired (above 13 ADC)",81,-0.5,80.5));
00120       hStripNumber.push_back(dbe->book1D("hStripNumber_m12","Strip Number Fired (ME -1/2); Strip # Fired (above 13 ADC)",81,-0.5,80.5));
00121       hStripNumber.push_back(dbe->book1D("hStripNumber_m11b","Strip Number Fired (ME -1/1b); Strip # Fired (above 13 ADC)",81,-0.5,80.5));
00122       hStripNumber.push_back(dbe->book1D("hStripNumber_p11b","Strip Number Fired (ME +1/1b); Strip # Fired (above 13 ADC)",81,-0.5,80.5));
00123       hStripNumber.push_back(dbe->book1D("hStripNumber_p12","Strip Number Fired (ME +1/2); Strip # Fired (above 13 ADC)",81,-0.5,80.5));
00124       hStripNumber.push_back(dbe->book1D("hStripNumber_p13","Strip Number Fired (ME +1/3); Strip # Fired (above 13 ADC)",81,-0.5,80.5));
00125       hStripNumber.push_back(dbe->book1D("hStripNumber_p11a","Strip Number Fired (ME +1/1a); Strip # Fired (above 13 ADC)",81,-0.5,80.5));
00126       hStripNumber.push_back(dbe->book1D("hStripNumber_p21","Strip Number Fired (ME +2/1); Strip # Fired (above 13 ADC)",81,-0.5,80.5));
00127       hStripNumber.push_back(dbe->book1D("hStripNumber_p22","Strip Number Fired (ME +2/2); Strip # Fired (above 13 ADC)",81,-0.5,80.5));
00128       hStripNumber.push_back(dbe->book1D("hStripNumber_p31","Strip Number Fired (ME +3/1); Strip # Fired (above 13 ADC)",81,-0.5,80.5));
00129       hStripNumber.push_back(dbe->book1D("hStripNumber_p32","Strip Number Fired (ME +3/2); Strip # Fired (above 13 ADC)",81,-0.5,80.5));
00130       hStripNumber.push_back(dbe->book1D("hStripNumber_p41","Strip Number Fired (ME +4/1); Strip # Fired (above 13 ADC)",81,-0.5,80.5));
00131       hStripNumber.push_back(dbe->book1D("hStripNumber_p42","Stripgroup Number Fired (ME +4/2); Strip # Fired (above 13 ADC)",81,-0.5,80.5));
00132 
00133       //Pedestal Noise Plots
00134       dbe->setCurrentFolder("CSC/CSCOfflineMonitor/PedestalNoise");
00135       hStripPed.push_back(dbe->book1D("hStripPedMEm42","Pedestal Noise Distribution Chamber ME -4/2; ADC Counts",50,-25.,25.));
00136       hStripPed.push_back(dbe->book1D("hStripPedMEm41","Pedestal Noise Distribution Chamber ME -4/1; ADC Counts",50,-25.,25.));
00137       hStripPed.push_back(dbe->book1D("hStripPedMEm32","Pedestal Noise Distribution Chamber ME -3/2; ADC Counts",50,-25.,25.));
00138       hStripPed.push_back(dbe->book1D("hStripPedMEm31","Pedestal Noise Distribution Chamber ME -3/1; ADC Counts",50,-25.,25.));
00139       hStripPed.push_back(dbe->book1D("hStripPedMEm22","Pedestal Noise Distribution Chamber ME -2/2; ADC Counts",50,-25.,25.));
00140       hStripPed.push_back(dbe->book1D("hStripPedMEm21","Pedestal Noise Distribution Chamber ME -2/1; ADC Counts",50,-25.,25.));
00141       hStripPed.push_back(dbe->book1D("hStripPedMEm11a","Pedestal Noise Distribution Chamber ME -1/1; ADC Counts",50,-25.,25.));
00142       hStripPed.push_back(dbe->book1D("hStripPedMEm13","Pedestal Noise Distribution Chamber ME -1/3; ADC Counts",50,-25.,25.));
00143       hStripPed.push_back(dbe->book1D("hStripPedMEm12","Pedestal Noise Distribution Chamber ME -1/2; ADC Counts",50,-25.,25.));
00144       hStripPed.push_back(dbe->book1D("hStripPedMEm11b","Pedestal Noise Distribution Chamber ME -1/1; ADC Counts",50,-25.,25.));
00145       hStripPed.push_back(dbe->book1D("hStripPedMEp11b","Pedestal Noise Distribution Chamber ME +1/1; ADC Counts",50,-25.,25.));
00146       hStripPed.push_back(dbe->book1D("hStripPedMEp12","Pedestal Noise Distribution Chamber ME +1/2; ADC Counts",50,-25.,25.));
00147       hStripPed.push_back(dbe->book1D("hStripPedMEp13","Pedestal Noise Distribution Chamber ME +1/3; ADC Counts",50,-25.,25.));
00148       hStripPed.push_back(dbe->book1D("hStripPedMEp11a","Pedestal Noise Distribution Chamber ME +1/1; ADC Counts",50,-25.,25.));
00149       hStripPed.push_back(dbe->book1D("hStripPedMEp21","Pedestal Noise Distribution Chamber ME +2/1; ADC Counts",50,-25.,25.));
00150       hStripPed.push_back(dbe->book1D("hStripPedMEp22","Pedestal Noise Distribution Chamber ME +2/2; ADC Counts",50,-25.,25.));
00151       hStripPed.push_back(dbe->book1D("hStripPedMEp31","Pedestal Noise Distribution Chamber ME +3/1; ADC Counts",50,-25.,25.));
00152       hStripPed.push_back(dbe->book1D("hStripPedMEp32","Pedestal Noise Distribution Chamber ME +3/2; ADC Counts",50,-25.,25.));
00153       hStripPed.push_back(dbe->book1D("hStripPedMEp41","Pedestal Noise Distribution Chamber ME +4/1; ADC Counts",50,-25.,25.));
00154       hStripPed.push_back(dbe->book1D("hStripPedMEp42","Pedestal Noise Distribution Chamber ME +4/2; ADC Counts",50,-25.,25.));
00155 
00156       // recHits
00157       dbe->setCurrentFolder("CSC/CSCOfflineMonitor/recHits");
00158       hRHnrechits = dbe->book1D("hRHnrechits","recHits per Event (all chambers); # of RecHits",50,0,50);
00159       hRHGlobal.push_back(dbe->book2D("hRHGlobalp1","recHit global X,Y station +1; Global X (cm); Global Y (cm)",100,-800.,800.,100,-800.,800.));
00160       hRHGlobal.push_back(dbe->book2D("hRHGlobalp2","recHit global X,Y station +2; Global X (cm); Global Y (cm)",100,-800.,800.,100,-800.,800.));
00161       hRHGlobal.push_back(dbe->book2D("hRHGlobalp3","recHit global X,Y station +3; Global X (cm); Global Y (cm)",100,-800.,800.,100,-800.,800.));
00162       hRHGlobal.push_back(dbe->book2D("hRHGlobalp4","recHit global X,Y station +4; Global X (cm); Global Y (cm)",100,-800.,800.,100,-800.,800.));
00163       hRHGlobal.push_back(dbe->book2D("hRHGlobalm1","recHit global X,Y station -1; Global X (cm); Global Y (cm)",100,-800.,800.,100,-800.,800.));
00164       hRHGlobal.push_back(dbe->book2D("hRHGlobalm2","recHit global X,Y station -2; Global X (cm); Global Y (cm)",100,-800.,800.,100,-800.,800.));
00165       hRHGlobal.push_back(dbe->book2D("hRHGlobalm3","recHit global X,Y station -3; Global X (cm); Global Y (cm)",100,-800.,800.,100,-800.,800.));
00166       hRHGlobal.push_back(dbe->book2D("hRHGlobalm4","recHit global X,Y station -4; Global X (cm); Global Y (cm)",100,-800.,800.,100,-800.,800.));
00167       hRHSumQ.push_back(dbe->book1D("hRHSumQm42","Sum 3x3 recHit Charge (ME -4/2); ADC counts",100,0,2000));
00168       hRHSumQ.push_back(dbe->book1D("hRHSumQm41","Sum 3x3 recHit Charge (ME -4/1); ADC counts",100,0,2000));
00169       hRHSumQ.push_back(dbe->book1D("hRHSumQm32","Sum 3x3 recHit Charge (ME -3/2); ADC counts",100,0,2000));
00170       hRHSumQ.push_back(dbe->book1D("hRHSumQm31","Sum 3x3 recHit Charge (ME -3/1); ADC counts",100,0,2000));
00171       hRHSumQ.push_back(dbe->book1D("hRHSumQm22","Sum 3x3 recHit Charge (ME -2/2); ADC counts",100,0,2000));
00172       hRHSumQ.push_back(dbe->book1D("hRHSumQm21","Sum 3x3 recHit Charge (ME -2/1); ADC counts",100,0,2000));
00173       hRHSumQ.push_back(dbe->book1D("hRHSumQm11a","Sum 3x3 recHit Charge (ME -1/1a); ADC counts",100,0,4000));
00174       hRHSumQ.push_back(dbe->book1D("hRHSumQm13","Sum 3x3 recHit Charge (ME -1/3); ADC counts",100,0,2000));
00175       hRHSumQ.push_back(dbe->book1D("hRHSumQm12","Sum 3x3 recHit Charge (ME -1/2); ADC counts",100,0,2000));
00176       hRHSumQ.push_back(dbe->book1D("hRHSumQm11b","Sum 3x3 recHit Charge (ME -1/1b); ADC counts",100,0,4000));
00177       hRHSumQ.push_back(dbe->book1D("hRHSumQp11b","Sum 3x3 recHit Charge (ME +1/1b); ADC counts",100,0,4000));
00178       hRHSumQ.push_back(dbe->book1D("hRHSumQp12","Sum 3x3 recHit Charge (ME +1/2); ADC counts",100,0,2000));
00179       hRHSumQ.push_back(dbe->book1D("hRHSumQp13","Sum 3x3 recHit Charge (ME +1/3); ADC counts",100,0,2000));
00180       hRHSumQ.push_back(dbe->book1D("hRHSumQp11a","Sum 3x3 recHit Charge (ME +1/1a); ADC counts",100,0,4000));
00181       hRHSumQ.push_back(dbe->book1D("hRHSumQp21","Sum 3x3 recHit Charge (ME +2/1); ADC counts",100,0,2000));
00182       hRHSumQ.push_back(dbe->book1D("hRHSumQp22","Sum 3x3 recHit Charge (ME +2/2); ADC counts",100,0,2000));
00183       hRHSumQ.push_back(dbe->book1D("hRHSumQp31","Sum 3x3 recHit Charge (ME +3/1); ADC counts",100,0,2000));
00184       hRHSumQ.push_back(dbe->book1D("hRHSumQp32","Sum 3x3 recHit Charge (ME +3/2); ADC counts",100,0,2000));
00185       hRHSumQ.push_back(dbe->book1D("hRHSumQp41","Sum 3x3 recHit Charge (ME +4/1); ADC counts",100,0,2000));
00186       hRHSumQ.push_back(dbe->book1D("hRHSumQp42","Sum 3x3 recHit Charge (ME +4/2); ADC counts",100,0,2000));
00187       hRHRatioQ.push_back(dbe->book1D("hRHRatioQm42","Charge Ratio (Ql+Qr)/Qt (ME -4/2); (Ql+Qr)/Qt",100,-0.1,1.1));
00188       hRHRatioQ.push_back(dbe->book1D("hRHRatioQm41","Charge Ratio (Ql+Qr)/Qt (ME -4/1); (Ql+Qr)/Qt",100,-0.1,1.1));
00189       hRHRatioQ.push_back(dbe->book1D("hRHRatioQm32","Charge Ratio (Ql+Qr)/Qt (ME -3/2); (Ql+Qr)/Qt",100,-0.1,1.1));
00190       hRHRatioQ.push_back(dbe->book1D("hRHRatioQm31","Charge Ratio (Ql+Qr)/Qt (ME -3/1); (Ql+Qr)/Qt",100,-0.1,1.1));
00191       hRHRatioQ.push_back(dbe->book1D("hRHRatioQm22","Charge Ratio (Ql+Qr)/Qt (ME -2/2); (Ql+Qr)/Qt",100,-0.1,1.1));
00192       hRHRatioQ.push_back(dbe->book1D("hRHRatioQm21","Charge Ratio (Ql+Qr)/Qt (ME -2/1); (Ql+Qr)/Qt",100,-0.1,1.1));
00193       hRHRatioQ.push_back(dbe->book1D("hRHRatioQm11a","Charge Ratio (Ql+Qr)/Qt (ME -1/1a); (Ql+Qr)/Qt",100,-0.1,1.1));
00194       hRHRatioQ.push_back(dbe->book1D("hRHRatioQm13","Charge Ratio (Ql+Qr)/Qt (ME -1/3); (Ql+Qr)/Qt",100,-0.1,1.1));
00195       hRHRatioQ.push_back(dbe->book1D("hRHRatioQm12","Charge Ratio (Ql+Qr)/Qt (ME -1/2); (Ql+Qr)/Qt",100,-0.1,1.1));
00196       hRHRatioQ.push_back(dbe->book1D("hRHRatioQm11b","Charge Ratio (Ql+Qr)/Qt (ME -1/1b); (Ql+Qr)/Qt",100,-0.1,1.1));
00197       hRHRatioQ.push_back(dbe->book1D("hRHRatioQp11b","Charge Ratio (Ql+Qr)/Qt (ME +1/1b); (Ql+Qr)/Qt",100,-0.1,1.1));
00198       hRHRatioQ.push_back(dbe->book1D("hRHRatioQp12","Charge Ratio (Ql+Qr)/Qt (ME +1/2); (Ql+Qr)/Qt",100,-0.1,1.1));
00199       hRHRatioQ.push_back(dbe->book1D("hRHRatioQp13","Charge Ratio (Ql+Qr)/Qt (ME +1/3); (Ql+Qr)/Qt",100,-0.1,1.1));
00200       hRHRatioQ.push_back(dbe->book1D("hRHRatioQp11a","Charge Ratio (Ql+Qr)/Qt (ME +1/1a); (Ql+Qr)/Qt",100,-0.1,1.1));
00201       hRHRatioQ.push_back(dbe->book1D("hRHRatioQp21","Charge Ratio (Ql+Qr)/Qt (ME +2/1); (Ql+Qr)/Qt",100,-0.1,1.1));
00202       hRHRatioQ.push_back(dbe->book1D("hRHRatioQp22","Charge Ratio (Ql+Qr)/Qt (ME +2/2); (Ql+Qr)/Qt",100,-0.1,1.1));
00203       hRHRatioQ.push_back(dbe->book1D("hRHRatioQp31","Charge Ratio (Ql+Qr)/Qt (ME +3/1); (Ql+Qr)/Qt",100,-0.1,1.1));
00204       hRHRatioQ.push_back(dbe->book1D("hRHRatioQp32","Charge Ratio (Ql+Qr)/Qt (ME +3/2); (Ql+Qr)/Qt",100,-0.1,1.1));
00205       hRHRatioQ.push_back(dbe->book1D("hRHRatioQp41","Charge Ratio (Ql+Qr)/Qt (ME +4/1); (Ql+Qr)/Qt",100,-0.1,1.1));
00206       hRHRatioQ.push_back(dbe->book1D("hRHRatioQp42","Charge Ratio (Ql+Qr)/Qt (ME +4/2); (Ql+Qr)/Qt",100,-0.1,1.1));
00207       hRHTiming.push_back(dbe->book1D("hRHTimingm42","recHit Time (ME -4/2); ns",200,-500.,500.));
00208       hRHTiming.push_back(dbe->book1D("hRHTimingm41","recHit Time (ME -4/1); ns",200,-500.,500.));
00209       hRHTiming.push_back(dbe->book1D("hRHTimingm32","recHit Time (ME -3/2); ns",200,-500.,500.));
00210       hRHTiming.push_back(dbe->book1D("hRHTimingm31","recHit Time (ME -3/1); ns",200,-500.,500.));
00211       hRHTiming.push_back(dbe->book1D("hRHTimingm22","recHit Time (ME -2/2); ns",200,-500.,500.));
00212       hRHTiming.push_back(dbe->book1D("hRHTimingm21","recHit Time (ME -2/1); ns",200,-500.,500.));
00213       hRHTiming.push_back(dbe->book1D("hRHTimingm11a","recHit Time (ME -1/1a); ns",200,-500.,500.));
00214       hRHTiming.push_back(dbe->book1D("hRHTimingm13","recHit Time (ME -1/3); ns",200,-500.,500.));
00215       hRHTiming.push_back(dbe->book1D("hRHTimingm12","recHit Time (ME -1/2); ns",200,-500.,500.));
00216       hRHTiming.push_back(dbe->book1D("hRHTimingm11b","recHit Time (ME -1/1b); ns",200,-500.,500.));
00217       hRHTiming.push_back(dbe->book1D("hRHTimingp11b","recHit Time (ME +1/1b); ns",200,-500.,500.));
00218       hRHTiming.push_back(dbe->book1D("hRHTimingp12","recHit Time (ME +1/2); ns",200,-500.,500.));
00219       hRHTiming.push_back(dbe->book1D("hRHTimingp13","recHit Time (ME +1/3); ns",200,-500.,500.));
00220       hRHTiming.push_back(dbe->book1D("hRHTimingp11a","recHit Time (ME +1/1a); ns",200,-500.,500.));
00221       hRHTiming.push_back(dbe->book1D("hRHTimingp21","recHit Time (ME +2/1); ns",200,-500.,500.));
00222       hRHTiming.push_back(dbe->book1D("hRHTimingp22","recHit Time (ME +2/2); ns",200,-500.,500.));
00223       hRHTiming.push_back(dbe->book1D("hRHTimingp31","recHit Time (ME +3/1); ns",200,-500.,500.));
00224       hRHTiming.push_back(dbe->book1D("hRHTimingp32","recHit Time (ME +3/2); ns",200,-500.,500.));
00225       hRHTiming.push_back(dbe->book1D("hRHTimingp41","recHit Time (ME +4/1); ns",200,-500.,500.));
00226       hRHTiming.push_back(dbe->book1D("hRHTimingp42","recHit Time (ME +4/2); ns",200,-500.,500.));
00227       hRHTimingAnode.push_back(dbe->book1D("hRHTimingAnodem42","Anode recHit Time (ME -4/2); ns",80,-500.,500.));
00228       hRHTimingAnode.push_back(dbe->book1D("hRHTimingAnodem41","Anode recHit Time (ME -4/1); ns",80,-500.,500.));
00229       hRHTimingAnode.push_back(dbe->book1D("hRHTimingAnodem32","Anode recHit Time (ME -3/2); ns",80,-500.,500.));
00230       hRHTimingAnode.push_back(dbe->book1D("hRHTimingAnodem31","Anode recHit Time (ME -3/1); ns",80,-500.,500.));
00231       hRHTimingAnode.push_back(dbe->book1D("hRHTimingAnodem22","Anode recHit Time (ME -2/2); ns",80,-500.,500.));
00232       hRHTimingAnode.push_back(dbe->book1D("hRHTimingAnodem21","Anode recHit Time (ME -2/1); ns",80,-500.,500.));
00233       hRHTimingAnode.push_back(dbe->book1D("hRHTimingAnodem11a","Anode recHit Time (ME -1/1a); ns",80,-500.,500.));
00234       hRHTimingAnode.push_back(dbe->book1D("hRHTimingAnodem13","Anode recHit Time (ME -1/3); ns",80,-500.,500.));
00235       hRHTimingAnode.push_back(dbe->book1D("hRHTimingAnodem12","Anode recHit Time (ME -1/2); ns",80,-500.,500.));
00236       hRHTimingAnode.push_back(dbe->book1D("hRHTimingAnodem11b","Anode recHit Time (ME -1/1b); ns",80,-500.,500.));
00237       hRHTimingAnode.push_back(dbe->book1D("hRHTimingAnodep11b","Anode recHit Time (ME +1/1b); ns",80,-500.,500.));
00238       hRHTimingAnode.push_back(dbe->book1D("hRHTimingAnodep12","Anode recHit Time (ME +1/2); ns",80,-500.,500.));
00239       hRHTimingAnode.push_back(dbe->book1D("hRHTimingAnodep13","Anode recHit Time (ME +1/3); ns",80,-500.,500.));
00240       hRHTimingAnode.push_back(dbe->book1D("hRHTimingAnodep11a","Anode recHit Time (ME +1/1a); ns",80,-500.,500.));
00241       hRHTimingAnode.push_back(dbe->book1D("hRHTimingAnodep21","Anode recHit Time (ME +2/1); ns",80,-500.,500.));
00242       hRHTimingAnode.push_back(dbe->book1D("hRHTimingAnodep22","Anode recHit Time (ME +2/2); ns",80,-500.,500.));
00243       hRHTimingAnode.push_back(dbe->book1D("hRHTimingAnodep31","Anode recHit Time (ME +3/1); ns",80,-500.,500.));
00244       hRHTimingAnode.push_back(dbe->book1D("hRHTimingAnodep32","Anode recHit Time (ME +3/2); ns",80,-500.,500.));
00245       hRHTimingAnode.push_back(dbe->book1D("hRHTimingAnodep41","Anode recHit Time (ME +4/1); ns",80,-500.,500.));
00246       hRHTimingAnode.push_back(dbe->book1D("hRHTimingAnodep42","Anode recHit Time (ME +4/2); ns",80,-500.,500.));
00247       hRHstpos.push_back(dbe->book1D("hRHstposm42","Reconstructed Position on Strip (ME -4/2); Strip Widths",120,-0.6,0.6));
00248       hRHstpos.push_back(dbe->book1D("hRHstposm41","Reconstructed Position on Strip (ME -4/1); Strip Widths",120,-0.6,0.6));
00249       hRHstpos.push_back(dbe->book1D("hRHstposm32","Reconstructed Position on Strip (ME -3/2); Strip Widths",120,-0.6,0.6));
00250       hRHstpos.push_back(dbe->book1D("hRHstposm31","Reconstructed Position on Strip (ME -3/1); Strip Widths",120,-0.6,0.6));
00251       hRHstpos.push_back(dbe->book1D("hRHstposm22","Reconstructed Position on Strip (ME -2/2); Strip Widths",120,-0.6,0.6));
00252       hRHstpos.push_back(dbe->book1D("hRHstposm21","Reconstructed Position on Strip (ME -2/1); Strip Widths",120,-0.6,0.6));
00253       hRHstpos.push_back(dbe->book1D("hRHstposm11a","Reconstructed Position on Strip (ME -1/1a); Strip Widths",120,-0.6,0.6));
00254       hRHstpos.push_back(dbe->book1D("hRHstposm13","Reconstructed Position on Strip (ME -1/3); Strip Widths",120,-0.6,0.6));
00255       hRHstpos.push_back(dbe->book1D("hRHstposm12","Reconstructed Position on Strip (ME -1/2); Strip Widths",120,-0.6,0.6));
00256       hRHstpos.push_back(dbe->book1D("hRHstposm11b","Reconstructed Position on Strip (ME -1/1b); Strip Widths",120,-0.6,0.6));
00257       hRHstpos.push_back(dbe->book1D("hRHstposp11b","Reconstructed Position on Strip (ME +1/1b); Strip Widths",120,-0.6,0.6));
00258       hRHstpos.push_back(dbe->book1D("hRHstposp12","Reconstructed Position on Strip (ME +1/2); Strip Widths",120,-0.6,0.6));
00259       hRHstpos.push_back(dbe->book1D("hRHstposp13","Reconstructed Position on Strip (ME +1/3); Strip Widths",120,-0.6,0.6));
00260       hRHstpos.push_back(dbe->book1D("hRHstposp11a","Reconstructed Position on Strip (ME +1/1a); Strip Widths",120,-0.6,0.6));
00261       hRHstpos.push_back(dbe->book1D("hRHstposp21","Reconstructed Position on Strip (ME +2/1); Strip Widths",120,-0.6,0.6));
00262       hRHstpos.push_back(dbe->book1D("hRHstposp22","Reconstructed Position on Strip (ME +2/2); Strip Widths",120,-0.6,0.6));
00263       hRHstpos.push_back(dbe->book1D("hRHstposp31","Reconstructed Position on Strip (ME +3/1); Strip Widths",120,-0.6,0.6));
00264       hRHstpos.push_back(dbe->book1D("hRHstposp32","Reconstructed Position on Strip (ME +3/2); Strip Widths",120,-0.6,0.6));
00265       hRHstpos.push_back(dbe->book1D("hRHstposp41","Reconstructed Position on Strip (ME +4/1); Strip Widths",120,-0.6,0.6));
00266       hRHstpos.push_back(dbe->book1D("hRHstposp42","Reconstructed Position on Strip (ME +4/2); Strip Widths",120,-0.6,0.6));
00267       hRHsterr.push_back(dbe->book1D("hRHsterrm42","Estimated Error on Strip Measurement (ME -4/2); Strip Widths",75,-0.01,0.24));
00268       hRHsterr.push_back(dbe->book1D("hRHsterrm41","Estimated Error on Strip Measurement (ME -4/1); Strip Widths",75,-0.01,0.24));
00269       hRHsterr.push_back(dbe->book1D("hRHsterrm32","Estimated Error on Strip Measurement (ME -3/2); Strip Widths",75,-0.01,0.24));
00270       hRHsterr.push_back(dbe->book1D("hRHsterrm31","Estimated Error on Strip Measurement (ME -3/1); Strip Widths",75,-0.01,0.24));
00271       hRHsterr.push_back(dbe->book1D("hRHsterrm22","Estimated Error on Strip Measurement (ME -2/2); Strip Widths",75,-0.01,0.24));
00272       hRHsterr.push_back(dbe->book1D("hRHsterrm21","Estimated Error on Strip Measurement (ME -2/1); Strip Widths",75,-0.01,0.24));
00273       hRHsterr.push_back(dbe->book1D("hRHsterrm11a","Estimated Error on Strip Measurement (ME -1/1a); Strip Widths",75,-0.01,0.24));
00274       hRHsterr.push_back(dbe->book1D("hRHsterrm13","Estimated Error on Strip Measurement (ME -1/3); Strip Widths",75,-0.01,0.24));
00275       hRHsterr.push_back(dbe->book1D("hRHsterrm12","Estimated Error on Strip Measurement (ME -1/2); Strip Widths",75,-0.01,0.24));
00276       hRHsterr.push_back(dbe->book1D("hRHsterrm11b","Estimated Error on Strip Measurement (ME -1/1b); Strip Widths",75,-0.01,0.24));
00277       hRHsterr.push_back(dbe->book1D("hRHsterrp11b","Estimated Error on Strip Measurement (ME +1/1b); Strip Widths",75,-0.01,0.24));
00278       hRHsterr.push_back(dbe->book1D("hRHsterrp12","Estimated Error on Strip Measurement (ME +1/2); Strip Widths",75,-0.01,0.24));
00279       hRHsterr.push_back(dbe->book1D("hRHsterrp13","Estimated Error on Strip Measurement (ME +1/3); Strip Widths",75,-0.01,0.24));
00280       hRHsterr.push_back(dbe->book1D("hRHsterrp11a","Estimated Error on Strip Measurement (ME +1/1a); Strip Widths",75,-0.01,0.24));
00281       hRHsterr.push_back(dbe->book1D("hRHsterrp21","Estimated Error on Strip Measurement (ME +2/1); Strip Widths",75,-0.01,0.24));
00282       hRHsterr.push_back(dbe->book1D("hRHsterrp22","Estimated Error on Strip Measurement (ME +2/2); Strip Widths",75,-0.01,0.24));
00283       hRHsterr.push_back(dbe->book1D("hRHsterrp31","Estimated Error on Strip Measurement (ME +3/1); Strip Widths",75,-0.01,0.24));
00284       hRHsterr.push_back(dbe->book1D("hRHsterrp32","Estimated Error on Strip Measurement (ME +3/2); Strip Widths",75,-0.01,0.24));
00285       hRHsterr.push_back(dbe->book1D("hRHsterrp41","Estimated Error on Strip Measurement (ME +4/1); Strip Widths",75,-0.01,0.24));
00286       hRHsterr.push_back(dbe->book1D("hRHsterrp42","Estimated Error on Strip Measurement (ME +4/2); Strip Widths",75,-0.01,0.24));
00287 
00288 
00289       // segments
00290       dbe->setCurrentFolder("CSC/CSCOfflineMonitor/Segments");
00291       hSnSegments   = dbe->book1D("hSnSegments","Number of Segments per Event; # of Segments",11,-0.5,10.5);
00292       hSnhitsAll = dbe->book1D("hSnhits","N hits on Segments; # of hits",8,-0.5,7.5);
00293       hSnhits.push_back(dbe->book1D("hSnhitsm42","# of hits on Segments (ME -4/2); # of hits",8,-0.5,7.5));
00294       hSnhits.push_back(dbe->book1D("hSnhitsm41","# of hits on Segments (ME -4/1); # of hits",8,-0.5,7.5));
00295       hSnhits.push_back(dbe->book1D("hSnhitsm32","# of hits on Segments (ME -3/2); # of hits",8,-0.5,7.5));
00296       hSnhits.push_back(dbe->book1D("hSnhitsm31","# of hits on Segments (ME -3/1); # of hits",8,-0.5,7.5));
00297       hSnhits.push_back(dbe->book1D("hSnhitsm22","# of hits on Segments (ME -2/2); # of hits",8,-0.5,7.5));
00298       hSnhits.push_back(dbe->book1D("hSnhitsm21","# of hits on Segments (ME -2/1); # of hits",8,-0.5,7.5));
00299       hSnhits.push_back(dbe->book1D("hSnhitsm11a","# of hits on Segments (ME -1/1a); # of hits",8,-0.5,7.5));
00300       hSnhits.push_back(dbe->book1D("hSnhitsm13","# of hits on Segments (ME -1/3); # of hits",8,-0.5,7.5));
00301       hSnhits.push_back(dbe->book1D("hSnhitsm12","# of hits on Segments (ME -1/2); # of hits",8,-0.5,7.5));
00302       hSnhits.push_back(dbe->book1D("hSnhitsm11b","# of hits on Segments (ME -1/1b); # of hits",8,-0.5,7.5));
00303       hSnhits.push_back(dbe->book1D("hSnhitsp11b","# of hits on Segments (ME +1/1b); # of hits",8,-0.5,7.5));
00304       hSnhits.push_back(dbe->book1D("hSnhitsp12","# of hits on Segments (ME +1/2); # of hits",8,-0.5,7.5));
00305       hSnhits.push_back(dbe->book1D("hSnhitsp13","# of hits on Segments (ME +1/3); # of hits",8,-0.5,7.5));
00306       hSnhits.push_back(dbe->book1D("hSnhitsp11a","# of hits on Segments (ME +1/1a); # of hits",8,-0.5,7.5));
00307       hSnhits.push_back(dbe->book1D("hSnhitsp21","# of hits on Segments (ME +2/1); # of hits",8,-0.5,7.5));
00308       hSnhits.push_back(dbe->book1D("hSnhitsp22","# of hits on Segments (ME +2/2); # of hits",8,-0.5,7.5));
00309       hSnhits.push_back(dbe->book1D("hSnhitsp31","# of hits on Segments (ME +3/1); # of hits",8,-0.5,7.5));
00310       hSnhits.push_back(dbe->book1D("hSnhitsp32","# of hits on Segments (ME +3/2); # of hits",8,-0.5,7.5));
00311       hSnhits.push_back(dbe->book1D("hSnhitsp41","# of hits on Segments (ME +4/1); # of hits",8,-0.5,7.5));
00312       hSnhits.push_back(dbe->book1D("hSnhitsp42","# of hits on Segments (ME +4/2); # of hits",8,-0.5,7.5));
00313       hSChiSqAll = dbe->book1D("hSChiSq","Segment Normalized Chi2; Chi2/ndof",110,-0.05,10.5);
00314       hSChiSq.push_back(dbe->book1D("hSChiSqm42","Segment Normalized Chi2 (ME -4/2); Chi2/ndof",110,-0.05,10.5));
00315       hSChiSq.push_back(dbe->book1D("hSChiSqm41","Segment Normalized Chi2 (ME -4/1); Chi2/ndof",110,-0.05,10.5));
00316       hSChiSq.push_back(dbe->book1D("hSChiSqm32","Segment Normalized Chi2 (ME -3/2); Chi2/ndof",110,-0.05,10.5));
00317       hSChiSq.push_back(dbe->book1D("hSChiSqm31","Segment Normalized Chi2 (ME -3/1); Chi2/ndof",110,-0.05,10.5));
00318       hSChiSq.push_back(dbe->book1D("hSChiSqm22","Segment Normalized Chi2 (ME -2/2); Chi2/ndof",110,-0.05,10.5));
00319       hSChiSq.push_back(dbe->book1D("hSChiSqm21","Segment Normalized Chi2 (ME -2/1); Chi2/ndof",110,-0.05,10.5));
00320       hSChiSq.push_back(dbe->book1D("hSChiSqm11a","Segment Normalized Chi2 (ME -1/1a); Chi2/ndof",110,-0.05,10.5));
00321       hSChiSq.push_back(dbe->book1D("hSChiSqm13","Segment Normalized Chi2 (ME -1/3); Chi2/ndof",110,-0.05,10.5));
00322       hSChiSq.push_back(dbe->book1D("hSChiSqm12","Segment Normalized Chi2 (ME -1/2); Chi2/ndof",110,-0.05,10.5));
00323       hSChiSq.push_back(dbe->book1D("hSChiSqm11b","Segment Normalized Chi2 (ME -1/1b); Chi2/ndof",110,-0.05,10.5));
00324       hSChiSq.push_back(dbe->book1D("hSChiSqp11b","Segment Normalized Chi2 (ME +1/1b); Chi2/ndof",110,-0.05,10.5));
00325       hSChiSq.push_back(dbe->book1D("hSChiSqp12","Segment Normalized Chi2 (ME +1/2); Chi2/ndof",110,-0.05,10.5));
00326       hSChiSq.push_back(dbe->book1D("hSChiSqp13","Segment Normalized Chi2 (ME +1/3); Chi2/ndof",110,-0.05,10.5));
00327       hSChiSq.push_back(dbe->book1D("hSChiSqp11a","Segment Normalized Chi2 (ME +1/1a); Chi2/ndof",110,-0.05,10.5));
00328       hSChiSq.push_back(dbe->book1D("hSChiSqp21","Segment Normalized Chi2 (ME +2/1); Chi2/ndof",110,-0.05,10.5));
00329       hSChiSq.push_back(dbe->book1D("hSChiSqp22","Segment Normalized Chi2 (ME +2/2); Chi2/ndof",110,-0.05,10.5));
00330       hSChiSq.push_back(dbe->book1D("hSChiSqp31","Segment Normalized Chi2 (ME +3/1); Chi2/ndof",110,-0.05,10.5));
00331       hSChiSq.push_back(dbe->book1D("hSChiSqp32","Segment Normalized Chi2 (ME +3/2); Chi2/ndof",110,-0.05,10.5));
00332       hSChiSq.push_back(dbe->book1D("hSChiSqp41","Segment Normalized Chi2 (ME +4/1); Chi2/ndof",110,-0.05,10.5));
00333       hSChiSq.push_back(dbe->book1D("hSChiSqp42","Segment Normalized Chi2 (ME +4/2); Chi2/ndof",110,-0.05,10.5));
00334       hSChiSqProbAll = dbe->book1D("hSChiSqProb","Segment chi2 Probability; Probability",110,-0.05,1.05);
00335       hSChiSqProb.push_back(dbe->book1D("hSChiSqProbm42","Segment chi2 Probability (ME -4/2); Probability",110,-0.05,1.05));
00336       hSChiSqProb.push_back(dbe->book1D("hSChiSqProbm41","Segment chi2 Probability (ME -4/1); Probability",110,-0.05,1.05));
00337       hSChiSqProb.push_back(dbe->book1D("hSChiSqProbm32","Segment chi2 Probability (ME -3/2); Probability",110,-0.05,1.05));
00338       hSChiSqProb.push_back(dbe->book1D("hSChiSqProbm31","Segment chi2 Probability (ME -3/1); Probability",110,-0.05,1.05));
00339       hSChiSqProb.push_back(dbe->book1D("hSChiSqProbm22","Segment chi2 Probability (ME -2/2); Probability",110,-0.05,1.05));
00340       hSChiSqProb.push_back(dbe->book1D("hSChiSqProbm21","Segment chi2 Probability (ME -2/1); Probability",110,-0.05,1.05));
00341       hSChiSqProb.push_back(dbe->book1D("hSChiSqProbm11a","Segment chi2 Probability (ME -1/1a); Probability",110,-0.05,1.05));
00342       hSChiSqProb.push_back(dbe->book1D("hSChiSqProbm13","Segment chi2 Probability (ME -1/3); Probability",110,-0.05,1.05));
00343       hSChiSqProb.push_back(dbe->book1D("hSChiSqProbm12","Segment chi2 Probability (ME -1/2); Probability",110,-0.05,1.05));
00344       hSChiSqProb.push_back(dbe->book1D("hSChiSqProbm11b","Segment chi2 Probability (ME -1/1b); Probability",110,-0.05,1.05));
00345       hSChiSqProb.push_back(dbe->book1D("hSChiSqProbp11b","Segment chi2 Probability (ME +1/1b); Probability",110,-0.05,1.05));
00346       hSChiSqProb.push_back(dbe->book1D("hSChiSqProbp12","Segment chi2 Probability (ME +1/2); Probability",110,-0.05,1.05));
00347       hSChiSqProb.push_back(dbe->book1D("hSChiSqProbp13","Segment chi2 Probability (ME +1/3); Probability",110,-0.05,1.05));
00348       hSChiSqProb.push_back(dbe->book1D("hSChiSqProbp11a","Segment chi2 Probability (ME +1/1a); Probability",110,-0.05,1.05));
00349       hSChiSqProb.push_back(dbe->book1D("hSChiSqProbp21","Segment chi2 Probability (ME +2/1); Probability",110,-0.05,1.05));
00350       hSChiSqProb.push_back(dbe->book1D("hSChiSqProbp22","Segment chi2 Probability (ME +2/2); Probability",110,-0.05,1.05));
00351       hSChiSqProb.push_back(dbe->book1D("hSChiSqProbp31","Segment chi2 Probability (ME +3/1); Probability",110,-0.05,1.05));
00352       hSChiSqProb.push_back(dbe->book1D("hSChiSqProbp32","Segment chi2 Probability (ME +3/2); Probability",110,-0.05,1.05));
00353       hSChiSqProb.push_back(dbe->book1D("hSChiSqProbp41","Segment chi2 Probability (ME +4/1); Probability",110,-0.05,1.05));
00354       hSChiSqProb.push_back(dbe->book1D("hSChiSqProbp42","Segment chi2 Probability (ME +4/2); Probability",110,-0.05,1.05));
00355       hSGlobalTheta = dbe->book1D("hSGlobalTheta","Segment Direction (Global Theta); Global Theta (radians)",136,-0.1,3.3);
00356       hSGlobalPhi   = dbe->book1D("hSGlobalPhi","Segment Direction (Global Phi); Global Phi (radians)",  128,-3.2,3.2);
00357       hSTimeCathode  = dbe->book1D("hSTimeCathode", "Cathode Only Segment Time  [ns]",200,-200,200);
00358       hSTimeCombined = dbe->book1D("hSTimeCombined", "Segment Time (anode+cathode times) [ns]",200,-200,200);
00359       hSTimeVsZ   = dbe->book2D("hSTimeVsZ","Segment Time vs. Z; [ns] vs. [cm]",200,-1200,1200,200,-200,200);
00360       hSTimeVsTOF = dbe->book2D("hSTimeVsTOF","Segment Time vs. Distance from IP; [ns] vs. [cm]",180,500,1400, 200,-200,200);
00361       // Resolution
00362       dbe->setCurrentFolder("CSC/CSCOfflineMonitor/Resolution");
00363       hSResid.push_back(dbe->book1D("hSResidm42","Fitted Position on Strip - Reconstructed for Layer 3 (ME -4/2); Strip Widths",100,-0.5,0.5));
00364       hSResid.push_back(dbe->book1D("hSResidm41","Fitted Position on Strip - Reconstructed for Layer 3 (ME -4/1); Strip Widths",100,-0.5,0.5));
00365       hSResid.push_back(dbe->book1D("hSResidm32","Fitted Position on Strip - Reconstructed for Layer 3 (ME -3/2); Strip Widths",100,-0.5,0.5));
00366       hSResid.push_back(dbe->book1D("hSResidm31","Fitted Position on Strip - Reconstructed for Layer 3 (ME -3/1); Strip Widths",100,-0.5,0.5));
00367       hSResid.push_back(dbe->book1D("hSResidm22","Fitted Position on Strip - Reconstructed for Layer 3 (ME -2/2); Strip Widths",100,-0.5,0.5));
00368       hSResid.push_back(dbe->book1D("hSResidm21","Fitted Position on Strip - Reconstructed for Layer 3 (ME -2/1); Strip Widths",100,-0.5,0.5));
00369       hSResid.push_back(dbe->book1D("hSResidm11a","Fitted Position on Strip - Reconstructed for Layer 3 (ME -1/1a); Strip Widths",100,-0.5,0.5));
00370       hSResid.push_back(dbe->book1D("hSResidm13","Fitted Position on Strip - Reconstructed for Layer 3 (ME -1/3); Strip Widths",100,-0.5,0.5));
00371       hSResid.push_back(dbe->book1D("hSResidm12","Fitted Position on Strip - Reconstructed for Layer 3 (ME -1/2); Strip Widths",100,-0.5,0.5));
00372       hSResid.push_back(dbe->book1D("hSResidm11b","Fitted Position on Strip - Reconstructed for Layer 3 (ME -1/1b); Strip Widths",100,-0.5,0.5));
00373       hSResid.push_back(dbe->book1D("hSResidp11b","Fitted Position on Strip - Reconstructed for Layer 3 (ME +1/1b); Strip Widths",100,-0.5,0.5));
00374       hSResid.push_back(dbe->book1D("hSResidp12","Fitted Position on Strip - Reconstructed for Layer 3 (ME +1/2); Strip Widths",100,-0.5,0.5));
00375       hSResid.push_back(dbe->book1D("hSResidp13","Fitted Position on Strip - Reconstructed for Layer 3 (ME +1/3); Strip Widths",100,-0.5,0.5));
00376       hSResid.push_back(dbe->book1D("hSResidp11a","Fitted Position on Strip - Reconstructed for Layer 3 (ME +1/1a); Strip Widths",100,-0.5,0.5));
00377       hSResid.push_back(dbe->book1D("hSResidp21","Fitted Position on Strip - Reconstructed for Layer 3 (ME +2/1); Strip Widths",100,-0.5,0.5));
00378       hSResid.push_back(dbe->book1D("hSResidp22","Fitted Position on Strip - Reconstructed for Layer 3 (ME +2/2); Strip Widths",100,-0.5,0.5));
00379       hSResid.push_back(dbe->book1D("hSResidp31","Fitted Position on Strip - Reconstructed for Layer 3 (ME +3/1); Strip Widths",100,-0.5,0.5));
00380       hSResid.push_back(dbe->book1D("hSResidp32","Fitted Position on Strip - Reconstructed for Layer 3 (ME +3/2); Strip Widths",100,-0.5,0.5));
00381       hSResid.push_back(dbe->book1D("hSResidp41","Fitted Position on Strip - Reconstructed for Layer 3 (ME +4/1); Strip Widths",100,-0.5,0.5));
00382       hSResid.push_back(dbe->book1D("hSResidp42","Fitted Position on Strip - Reconstructed for Layer 3 (ME +4/2); Strip Widths",100,-0.5,0.5));
00383 
00384       // Efficiency
00385       
00386       dbe->setCurrentFolder("CSC/CSCOfflineMonitor/Efficiency");
00387       hSSTE = new TH1F("hSSTE","hSSTE",40,0.5,40.5);
00388       hRHSTE = new TH1F("hRHSTE","hRHSTE",40,0.5,40.5);
00389       hSEff = dbe->book1D("hSEff","Segment Efficiency",20,0.5,20.5);
00390       hSEff->setBinLabel(1,"ME +1/1b");
00391       hSEff->setBinLabel(2,"ME +1/2");
00392       hSEff->setBinLabel(3,"ME +1/3");
00393       hSEff->setBinLabel(4,"ME +1/1a");
00394       hSEff->setBinLabel(5,"ME +2/1");
00395       hSEff->setBinLabel(6,"ME +2/2");
00396       hSEff->setBinLabel(7,"ME +3/1");
00397       hSEff->setBinLabel(8,"ME +3/2");
00398       hSEff->setBinLabel(9,"ME +4/1");
00399       hSEff->setBinLabel(10,"ME +4/2");
00400       hSEff->setBinLabel(11,"ME -1/1b");
00401       hSEff->setBinLabel(12,"ME -1/2");
00402       hSEff->setBinLabel(13,"ME -1/3");
00403       hSEff->setBinLabel(14,"ME -1/1a");
00404       hSEff->setBinLabel(15,"ME -2/1");
00405       hSEff->setBinLabel(16,"ME -2/2");
00406       hSEff->setBinLabel(17,"ME -3/1");
00407       hSEff->setBinLabel(18,"ME -3/2");
00408       hSEff->setBinLabel(19,"ME -4/1");
00409       hSEff->setBinLabel(20,"ME -4/2");
00410       hRHEff = dbe->book1D("hRHEff","recHit Efficiency",20,0.5,20.5);
00411       hRHEff->setBinLabel(1,"ME +1/1b");
00412       hRHEff->setBinLabel(2,"ME +1/2");
00413       hRHEff->setBinLabel(3,"ME +1/3");
00414       hRHEff->setBinLabel(4,"ME +1/1a");
00415       hRHEff->setBinLabel(5,"ME +2/1");
00416       hRHEff->setBinLabel(6,"ME +2/2");
00417       hRHEff->setBinLabel(7,"ME +3/1");
00418       hRHEff->setBinLabel(8,"ME +3/2");
00419       hRHEff->setBinLabel(9,"ME +4/1");
00420       hRHEff->setBinLabel(10,"ME +4/2");
00421       hRHEff->setBinLabel(11,"ME -1/1b");
00422       hRHEff->setBinLabel(12,"ME -1/2");
00423       hRHEff->setBinLabel(13,"ME -1/3");
00424       hRHEff->setBinLabel(14,"ME -1/1a");
00425       hRHEff->setBinLabel(15,"ME -2/1");
00426       hRHEff->setBinLabel(16,"ME -2/2");
00427       hRHEff->setBinLabel(17,"ME -3/1");
00428       hRHEff->setBinLabel(18,"ME -3/2");
00429       hRHEff->setBinLabel(19,"ME -4/1");
00430       hRHEff->setBinLabel(20,"ME -4/2");
00431       hSSTE2 = new TH2F("hSSTE2","hSSTE2",36,0.5,36.5, 18, 0.5, 18.5);
00432       hRHSTE2 = new TH2F("hRHSTE2","hRHSTE2",36,0.5,36.5, 18, 0.5, 18.5);
00433       hStripSTE2 = new TH2F("hStripSTE2","hStripSTE2",36,0.5,36.5, 18, 0.5, 18.5);
00434       hWireSTE2 = new TH2F("hWireSTE2","hWireSTE2",36,0.5,36.5, 18, 0.5, 18.5);
00435       hEffDenominator = new TH2F("hEffDenominator","hEffDenominator",36,0.5,36.5, 18, 0.5, 18.5);
00436       hSEff2 = dbe->book2D("hSEff2","Segment Efficiency 2D",36,0.5,36.5, 18, 0.5, 18.5);
00437       hSEff2->setAxisTitle("Chamber #");
00438       hSEff2->setBinLabel(1,"ME -4/1",2);
00439       hSEff2->setBinLabel(2,"ME -3/2",2);
00440       hSEff2->setBinLabel(3,"ME -3/1",2);
00441       hSEff2->setBinLabel(4,"ME -2/2",2);
00442       hSEff2->setBinLabel(5,"ME -2/1",2);
00443       hSEff2->setBinLabel(6,"ME -1/3",2);
00444       hSEff2->setBinLabel(7,"ME -1/2",2);
00445       hSEff2->setBinLabel(8,"ME -1/1b",2);
00446       hSEff2->setBinLabel(9,"ME -1/1a",2);
00447       hSEff2->setBinLabel(10,"ME +1/1a",2);
00448       hSEff2->setBinLabel(11,"ME +1/1b",2);
00449       hSEff2->setBinLabel(12,"ME +1/2",2);
00450       hSEff2->setBinLabel(13,"ME +1/3",2);
00451       hSEff2->setBinLabel(14,"ME +2/1",2);
00452       hSEff2->setBinLabel(15,"ME +2/2",2);
00453       hSEff2->setBinLabel(16,"ME +3/1",2);
00454       hSEff2->setBinLabel(17,"ME +3/2",2);
00455       hSEff2->setBinLabel(18,"ME +4/1",2);
00456       hRHEff2 = dbe->book2D("hRHEff2","recHit Efficiency 2D",36,0.5,36.5, 18, 0.5, 18.5);
00457       hRHEff2->setAxisTitle("Chamber #");
00458       hRHEff2->setBinLabel(1,"ME -4/1",2);
00459       hRHEff2->setBinLabel(2,"ME -3/2",2);
00460       hRHEff2->setBinLabel(3,"ME -3/1",2);
00461       hRHEff2->setBinLabel(4,"ME -2/2",2);
00462       hRHEff2->setBinLabel(5,"ME -2/1",2);
00463       hRHEff2->setBinLabel(6,"ME -1/3",2);
00464       hRHEff2->setBinLabel(7,"ME -1/2",2);
00465       hRHEff2->setBinLabel(8,"ME -1/1b",2);
00466       hRHEff2->setBinLabel(9,"ME -1/1a",2);
00467       hRHEff2->setBinLabel(10,"ME +1/1a",2);
00468       hRHEff2->setBinLabel(11,"ME +1/1b",2);
00469       hRHEff2->setBinLabel(12,"ME +1/2",2);
00470       hRHEff2->setBinLabel(13,"ME +1/3",2);
00471       hRHEff2->setBinLabel(14,"ME +2/1",2);
00472       hRHEff2->setBinLabel(15,"ME +2/2",2);
00473       hRHEff2->setBinLabel(16,"ME +3/1",2);
00474       hRHEff2->setBinLabel(17,"ME +3/2",2);
00475       hRHEff2->setBinLabel(18,"ME +4/1",2);
00476       hStripReadoutEff2 = dbe->book2D("hStripReadoutEff2","strip readout ratio [(strip+clct+wires)/(clct+wires)] 2D",36,0.5,36.5, 20, 0.5, 20.5);
00477       applyCSClabels(hStripReadoutEff2);
00478       hStripEff2 = dbe->book2D("hStripEff2","strip Efficiency 2D",36,0.5,36.5, 18, 0.5, 18.5);
00479       hStripEff2->setAxisTitle("Chamber #");
00480       hStripEff2->setBinLabel(1,"ME -4/1",2);
00481       hStripEff2->setBinLabel(2,"ME -3/2",2);
00482       hStripEff2->setBinLabel(3,"ME -3/1",2);
00483       hStripEff2->setBinLabel(4,"ME -2/2",2);
00484       hStripEff2->setBinLabel(5,"ME -2/1",2);
00485       hStripEff2->setBinLabel(6,"ME -1/3",2);
00486       hStripEff2->setBinLabel(7,"ME -1/2",2);
00487       hStripEff2->setBinLabel(8,"ME -1/1b",2);
00488       hStripEff2->setBinLabel(9,"ME -1/1a",2);
00489       hStripEff2->setBinLabel(10,"ME +1/1a",2);
00490       hStripEff2->setBinLabel(11,"ME +1/1b",2);
00491       hStripEff2->setBinLabel(12,"ME +1/2",2);
00492       hStripEff2->setBinLabel(13,"ME +1/3",2);
00493       hStripEff2->setBinLabel(14,"ME +2/1",2);
00494       hStripEff2->setBinLabel(15,"ME +2/2",2);
00495       hStripEff2->setBinLabel(16,"ME +3/1",2);
00496       hStripEff2->setBinLabel(17,"ME +3/2",2);
00497       hStripEff2->setBinLabel(18,"ME +4/1",2);
00498       hWireEff2 = dbe->book2D("hWireEff2","wire Efficiency 2D",36,0.5,36.5, 18, 0.5, 18.5);
00499       hWireEff2->setAxisTitle("Chamber #");
00500       hWireEff2->setBinLabel(1,"ME -4/1",2);
00501       hWireEff2->setBinLabel(2,"ME -3/2",2);
00502       hWireEff2->setBinLabel(3,"ME -3/1",2);
00503       hWireEff2->setBinLabel(4,"ME -2/2",2);
00504       hWireEff2->setBinLabel(5,"ME -2/1",2);
00505       hWireEff2->setBinLabel(6,"ME -1/3",2);
00506       hWireEff2->setBinLabel(7,"ME -1/2",2);
00507       hWireEff2->setBinLabel(8,"ME -1/1b",2);
00508       hWireEff2->setBinLabel(9,"ME -1/1a",2);
00509       hWireEff2->setBinLabel(10,"ME +1/1a",2);
00510       hWireEff2->setBinLabel(11,"ME +1/1b",2);
00511       hWireEff2->setBinLabel(12,"ME +1/2",2);
00512       hWireEff2->setBinLabel(13,"ME +1/3",2);
00513       hWireEff2->setBinLabel(14,"ME +2/1",2);
00514       hWireEff2->setBinLabel(15,"ME +2/2",2);
00515       hWireEff2->setBinLabel(16,"ME +3/1",2);
00516       hWireEff2->setBinLabel(17,"ME +3/2",2);
00517       hWireEff2->setBinLabel(18,"ME +4/1",2);
00518       hSensitiveAreaEvt = dbe->book2D("hSensitiveAreaEvt","Events Passing Selection for Efficiency",36,0.5,36.5, 18, 0.5, 18.5);
00519       hSensitiveAreaEvt->setAxisTitle("Chamber #");
00520       hSensitiveAreaEvt->setBinLabel(1,"ME -4/1",2);
00521       hSensitiveAreaEvt->setBinLabel(2,"ME -3/2",2);
00522       hSensitiveAreaEvt->setBinLabel(3,"ME -3/1",2);
00523       hSensitiveAreaEvt->setBinLabel(4,"ME -2/2",2);
00524       hSensitiveAreaEvt->setBinLabel(5,"ME -2/1",2);
00525       hSensitiveAreaEvt->setBinLabel(6,"ME -1/3",2);
00526       hSensitiveAreaEvt->setBinLabel(7,"ME -1/2",2);
00527       hSensitiveAreaEvt->setBinLabel(8,"ME -1/1b",2);
00528       hSensitiveAreaEvt->setBinLabel(9,"ME -1/1a",2);
00529       hSensitiveAreaEvt->setBinLabel(10,"ME +1/1a",2);
00530       hSensitiveAreaEvt->setBinLabel(11,"ME +1/1b",2);
00531       hSensitiveAreaEvt->setBinLabel(12,"ME +1/2",2);
00532       hSensitiveAreaEvt->setBinLabel(13,"ME +1/3",2);
00533       hSensitiveAreaEvt->setBinLabel(14,"ME +2/1",2);
00534       hSensitiveAreaEvt->setBinLabel(15,"ME +2/2",2);
00535       hSensitiveAreaEvt->setBinLabel(16,"ME +3/1",2);
00536       hSensitiveAreaEvt->setBinLabel(17,"ME +3/2",2);
00537       hSensitiveAreaEvt->setBinLabel(18,"ME +4/1",2);
00538 
00539       // BX Monitor for trigger synchronization
00540       dbe->setCurrentFolder("CSC/CSCOfflineMonitor/BXMonitor");
00541       hALCTgetBX = dbe->book1D("hALCTgetBX","ALCT position in ALCT-L1A match window [BX]",7,-0.5,6.5);
00542       hALCTgetBXChamberMeans = dbe->book1D("hALCTgetBXChamberMeans","Chamber Mean ALCT position in ALCT-L1A match window [BX]",60,0,6);
00543       hALCTgetBXSerial = dbe->book2D("hALCTgetBXSerial","ALCT position in ALCT-L1A match window [BX]",601,-0.5,600.5,7,-0.5,6.5);
00544       hALCTgetBXSerial->setAxisTitle("Chamber Serial Number");
00545       hALCTgetBX2DNumerator = new TH2F("hALCTgetBX2DNumerator","ALCT position in ALCT-L1A match window [BX] (sum)",36,0.5,36.5,20,0.5,20.5);
00546       hALCTgetBX2DMeans = dbe->book2D("hALCTgetBX2DMeans","ALCT position in ALCT-L1A match window [BX]",36,0.5,36.5,20,0.5,20.5);
00547       hALCTgetBX2Denominator = dbe->book2D("hALCTgetBX2Denominator","Number of ALCT Digis checked",36,0.5,36.5,20,0.5,20.5);
00548       applyCSClabels(hALCTgetBX2DMeans);
00549       applyCSClabels(hALCTgetBX2Denominator);
00550       hALCTMatch = dbe->book1D("hALCTMatch","ALCT position in ALCT-CLCT match window [BX]",7,-0.5,6.5);
00551       hALCTMatchChamberMeans = dbe->book1D("hALCTMatchChamberMeans","Chamber Mean ALCT position in ALCT-CLCT match window [BX]",60,0,6);
00552       hALCTMatchSerial = dbe->book2D("hALCTMatchSerial","ALCT position in ALCT-CLCT match window [BX]",601,-0.5,600.5,7,-0.5,6.5);
00553       hALCTMatchSerial->setAxisTitle("Chamber Serial Number");
00554       hALCTMatch2DNumerator = new TH2F("hALCTMatch2DNumerator","ALCT position in ALCT-CLCT match window [BX] (sum)",36,0.5,36.5,20,0.5,20.5);
00555       hALCTMatch2DMeans = dbe->book2D("hALCTMatch2DMeans","ALCT position in ALCT-CLCT match window [BX]",36,0.5,36.5,20,0.5,20.5);
00556       hALCTMatch2Denominator = dbe->book2D("hALCTMatch2Denominator","Number of ALCT-CLCT matches checked",36,0.5,36.5,20,0.5,20.5);
00557       applyCSClabels(hALCTMatch2DMeans);
00558       applyCSClabels(hALCTMatch2Denominator);
00559       hCLCTL1A = dbe->book1D("hCLCTL1A","L1A - CLCTpreTrigger at TMB [BX]",10,149.5,159.5);
00560       hCLCTL1AChamberMeans = dbe->book1D("hCLCTL1AChamberMeans","Chamber Mean L1A - CLCTpreTrigger at TMB [BX]",90,150,159);
00561       hCLCTL1ASerial = dbe->book2D("hCLCTL1ASerial","L1A - CLCTpreTrigger at TMB [BX]",601,-0.5,600.5,10,149.5,159.5);
00562       hCLCTL1ASerial->setAxisTitle("Chamber Serial Number");
00563       hCLCTL1A2DNumerator = new TH2F("hCLCTL1A2DNumerator","L1A - CLCTpreTrigger at TMB [BX] (sum)",36,0.5,36.5,20,0.5,20.5);
00564       hCLCTL1A2DMeans = dbe->book2D("hCLCTL1A2DMeans","L1A - CLCTpreTrigger at TMB [BX]",36,0.5,36.5,20,0.5,20.5);
00565       hCLCTL1A2Denominator = dbe->book2D("hCLCTL1A2Denominator","Number of TMB CLCTs checked",36,0.5,36.5,20,0.5,20.5);
00566       applyCSClabels(hCLCTL1A2DMeans);
00567       applyCSClabels(hCLCTL1A2Denominator);
00568 
00569 }
00570 
00572 //  DESTRUCTOR  //
00574 CSCOfflineMonitor::~CSCOfflineMonitor(){
00575 
00576 }
00577 
00578 void CSCOfflineMonitor::endRun( edm::Run const &, edm::EventSetup const & ){
00579   
00580   if (!finalizedHistograms_){
00581     finalize() ;
00582     finalizedHistograms_ = true ;
00583   }
00584 
00585 }
00586 
00587 void CSCOfflineMonitor::endJob(){
00588   
00589   finalize() ;
00590   finalizedHistograms_ = true ;
00591   
00592   bool saveHistos = param.getParameter<bool>("saveHistos");
00593   string outputFileName = param.getParameter<string>("outputFileName");
00594   if(saveHistos){
00595     dbe->save(outputFileName);
00596   }
00597 
00598 }
00599 
00600 
00601 void CSCOfflineMonitor::finalize() {
00602 
00603   hRHEff = dbe->get("CSC/CSCOfflineMonitor/Efficiency/hRHEff");
00604   hSEff = dbe->get("CSC/CSCOfflineMonitor/Efficiency/hSEff");
00605   hSEff2 = dbe->get("CSC/CSCOfflineMonitor/Efficiency/hSEff2");
00606   hRHEff2 = dbe->get("CSC/CSCOfflineMonitor/Efficiency/hRHEff2");
00607   hStripEff2 = dbe->get("CSC/CSCOfflineMonitor/Efficiency/hStripEff2");
00608   hWireEff2 = dbe->get("CSC/CSCOfflineMonitor/Efficiency/hWireEff2");
00609 
00610   hOStripsAndWiresAndCLCT= dbe->get("CSC/CSCOfflineMonitor/Occupancy/hOStripsAndWiresAndCLCT");
00611   hOWiresAndCLCT= dbe->get("CSC/CSCOfflineMonitor/Occupancy/hOWiresAndCLCT");
00612   hStripReadoutEff2 = dbe->get("CSC/CSCOfflineMonitor/Efficiency/hStripReadoutEff2");
00613 
00614   hALCTgetBX2DMeans = dbe->get("CSC/CSCOfflineMonitor/BXMonitor/hALCTgetBX2DMeans");
00615   hALCTMatch2DMeans = dbe->get("CSC/CSCOfflineMonitor/BXMonitor/hALCTMatch2DMeans");
00616   hCLCTL1A2DMeans   = dbe->get("CSC/CSCOfflineMonitor/BXMonitor/hCLCTL1A2DMeans");
00617 
00618   hALCTgetBXSerial = dbe->get("CSC/CSCOfflineMonitor/BXMonitor/hALCTgetBXSerial");
00619   hALCTMatchSerial = dbe->get("CSC/CSCOfflineMonitor/BXMonitor/hALCTMatchSerial");
00620   hCLCTL1ASerial   = dbe->get("CSC/CSCOfflineMonitor/BXMonitor/hCLCTL1ASerial");
00621 
00622   hALCTgetBXChamberMeans = dbe->get("CSC/CSCOfflineMonitor/BXMonitor/hALCTgetBXChamberMeans");
00623   hALCTMatchChamberMeans = dbe->get("CSC/CSCOfflineMonitor/BXMonitor/hALCTMatchChamberMeans");
00624   hCLCTL1AChamberMeans   = dbe->get("CSC/CSCOfflineMonitor/BXMonitor/hCLCTL1AChamberMeans");
00625 
00626   if (hRHEff) histoEfficiency(hRHSTE,hRHEff);
00627   if (hSEff) histoEfficiency(hSSTE,hSEff);
00628   if (hSEff2) hSEff2->getTH2F()->Divide(hSSTE2,hEffDenominator,1.,1.,"B");
00629   if (hRHEff2) hRHEff2->getTH2F()->Divide(hRHSTE2,hEffDenominator,1.,1.,"B");
00630   if (hStripEff2) hStripEff2->getTH2F()->Divide(hStripSTE2,hEffDenominator,1.,1.,"B");
00631   if (hWireEff2) hWireEff2->getTH2F()->Divide(hWireSTE2,hEffDenominator,1.,1.,"B");
00632   if (hStripReadoutEff2) hStripReadoutEff2->getTH2F()->Divide(hOStripsAndWiresAndCLCT->getTH2F(),hOWiresAndCLCT->getTH2F(),1.,1.,"B");
00633   if (hALCTMatch2DMeans){ 
00634     harvestChamberMeans(hALCTMatchChamberMeans, hALCTMatch2DMeans, hALCTMatch2DNumerator,hALCTMatch2Denominator );
00635   }
00636   if (hALCTgetBX2DMeans) {
00637     harvestChamberMeans(hALCTgetBXChamberMeans, hALCTgetBX2DMeans, hALCTgetBX2DNumerator, hALCTgetBX2Denominator );
00638   }
00639   if (hCLCTL1A2DMeans) {
00640     harvestChamberMeans(hCLCTL1AChamberMeans, hCLCTL1A2DMeans, hCLCTL1A2DNumerator, hCLCTL1A2Denominator );
00641   }
00642 
00643   if(hALCTgetBXSerial)  normalize(hALCTgetBXSerial);
00644   if(hALCTMatchSerial)  normalize(hALCTMatchSerial);
00645   if(hCLCTL1ASerial)    normalize(hCLCTL1ASerial);
00646 
00647 
00648 }
00649 
00650 void CSCOfflineMonitor::harvestChamberMeans(MonitorElement* meMean1D, MonitorElement *meMean2D, TH2F *hNum, MonitorElement *meDenom){
00651 
00652 
00653   if (hNum->GetNbinsY()!= meDenom->getNbinsY() || hNum->GetNbinsX()!= meDenom->getNbinsX())
00654     return;
00655   if (meMean2D->getNbinsY()!= meDenom->getNbinsY() || meMean2D->getNbinsX()!= meDenom->getNbinsX())
00656     return;
00657 
00658   float mean;
00659   for (int biny = 0; biny < hNum->GetNbinsY()+1 ; biny++){
00660     for (int binx = 0; binx < hNum->GetNbinsX()+1 ; binx++){
00661       if ( meDenom->getBinContent(binx,biny) > 0){
00662         mean = hNum->GetBinContent(binx,biny)/meDenom->getBinContent(binx,biny);
00663         meMean1D->Fill(mean);
00664         meMean2D->setBinContent(binx,biny,mean);
00665       }
00666     }
00667   }
00668 
00669   return;
00670 }
00671 
00672 void CSCOfflineMonitor::normalize(MonitorElement* me){
00673     
00674   TH2F* h = me->getTH2F();
00675   TH1D* hproj = h->ProjectionX("hproj");
00676 
00677   for (int binx = 0; binx < h->GetNbinsX()+1 ; binx++){
00678     Double_t entries = hproj->GetBinContent(binx);
00679     for (Int_t biny=1;biny <= h->GetNbinsY();biny++) {
00680       Double_t cxy = h->GetBinContent(binx,biny);
00681       if (cxy > 0 && entries>0) h->SetBinContent(binx,biny,cxy/entries);
00682     }
00683   }
00684 
00685 
00686     return;
00687 
00688 }
00689 
00690 
00691 
00693 //  Analysis  //
00695 void CSCOfflineMonitor::analyze(const Event & event, const EventSetup& eventSetup){
00696 
00697   edm::Handle<CSCWireDigiCollection> wires;
00698   edm::Handle<CSCStripDigiCollection> strips;
00699   edm::Handle<CSCALCTDigiCollection> alcts;
00700   edm::Handle<CSCCLCTDigiCollection> clcts;
00701   event.getByLabel(stripDigiTag_, strips);
00702   event.getByLabel(wireDigiTag_, wires);
00703   event.getByLabel(alctDigiTag_, alcts);
00704   event.getByLabel(clctDigiTag_, clcts);
00705 
00706   // Get the CSC Geometry :
00707   ESHandle<CSCGeometry> cscGeom;
00708   eventSetup.get<MuonGeometryRecord>().get(cscGeom);
00709 
00710   // Get the RecHits collection :
00711   Handle<CSCRecHit2DCollection> recHits;
00712   event.getByLabel(cscRecHitTag_,recHits);
00713 
00714   // get CSC segment collection
00715   Handle<CSCSegmentCollection> cscSegments;
00716   event.getByLabel(cscSegTag_, cscSegments);
00717 
00718 
00719   doOccupancies(strips,wires,recHits,cscSegments,clcts);
00720   doStripDigis(strips);
00721   doWireDigis(wires);
00722   doRecHits(recHits,strips,cscGeom);
00723   doSegments(cscSegments,cscGeom);
00724   doResolution(cscSegments,cscGeom);
00725   doPedestalNoise(strips);
00726   doEfficiencies(wires,strips, recHits, cscSegments,cscGeom);
00727   doBXMonitor(alcts, clcts, event, eventSetup);
00728 }
00729 
00730 // ==============================================
00731 //
00732 // look at Occupancies
00733 //
00734 // ==============================================
00735 
00736 void CSCOfflineMonitor::doOccupancies(edm::Handle<CSCStripDigiCollection> strips, edm::Handle<CSCWireDigiCollection> wires,
00737                                       edm::Handle<CSCRecHit2DCollection> recHits, edm::Handle<CSCSegmentCollection> cscSegments,
00738                                       edm::Handle<CSCCLCTDigiCollection> clcts){
00739 
00740   bool clcto[2][4][4][36];
00741   bool wireo[2][4][4][36];
00742   bool stripo[2][4][4][36];
00743   bool rechito[2][4][4][36];
00744   bool segmento[2][4][4][36];
00745 
00746   bool hasWires = false;
00747   bool hasStrips = false;
00748   bool hasRecHits = false;
00749   bool hasSegments = false;
00750 
00751   for (int e = 0; e < 2; e++){
00752     for (int s = 0; s < 4; s++){
00753       for (int r = 0; r < 4; r++){
00754         for (int c = 0; c < 36; c++){
00755           clcto[e][s][r][c] = false;
00756           wireo[e][s][r][c] = false;
00757           stripo[e][s][r][c] = false;
00758           rechito[e][s][r][c] = false;
00759           segmento[e][s][r][c] = false;
00760         }
00761       }
00762     }
00763   }
00764 
00765   //clcts
00766   for (CSCCLCTDigiCollection::DigiRangeIterator j=clcts->begin(); j!=clcts->end(); j++) {
00767     CSCDetId id = (CSCDetId)(*j).first;
00768     int kEndcap  = id.endcap();
00769     int kRing    = id.ring();
00770     int kStation = id.station();
00771     int kChamber = id.chamber();
00772     const CSCCLCTDigiCollection::Range& range =(*j).second;
00773     for (CSCCLCTDigiCollection::const_iterator digiIt = range.first; digiIt!=range.second; ++digiIt){
00774       // Valid digi in the chamber (or in neighbouring chamber) 
00775       if((*digiIt).isValid()){
00776       //Check whether this CLCT came from ME11a
00777         if( kStation ==1 && kRing==1 && (*digiIt).getKeyStrip()>128)
00778           kRing = 4;
00779         clcto[kEndcap-1][kStation-1][kRing-1][kChamber-1] = true;
00780       }
00781     }
00782   }
00783 
00784   //wires
00785   for (CSCWireDigiCollection::DigiRangeIterator wi=wires->begin(); wi!=wires->end(); wi++) {
00786     CSCDetId id = (CSCDetId)(*wi).first;
00787     int kEndcap  = id.endcap();
00788     int kRing    = id.ring();
00789     int kStation = id.station();
00790     int kChamber = id.chamber();
00791     std::vector<CSCWireDigi>::const_iterator wireIt = (*wi).second.first;
00792     std::vector<CSCWireDigi>::const_iterator lastWire = (*wi).second.second;
00793     for( ; wireIt != lastWire; ++wireIt){
00794       if (!wireo[kEndcap-1][kStation-1][kRing-1][kChamber-1]){
00795         wireo[kEndcap-1][kStation-1][kRing-1][kChamber-1] = true;
00796         hOWires->Fill(kChamber,typeIndex(id,2));
00797         hOWireSerial->Fill(chamberSerial(id));
00798         hasWires = true;
00799         if( clcto[kEndcap-1][kStation-1][kRing-1][kChamber-1])
00800           hOWiresAndCLCT->Fill(kChamber,typeIndex(id,2));
00801         //Also check for a CLCT in ME11a if you're in ME11 already
00802         if (kStation==1 && kRing==1 && clcto[kEndcap-1][kStation-1][3][kChamber-1]){
00803           CSCDetId idME11a = CSCDetId(kEndcap, kStation, 4, kChamber);
00804           hOWiresAndCLCT->Fill(kChamber,typeIndex(idME11a,2));
00805         } 
00806       }
00807     }//end for loop
00808   }
00809   
00810   //strips
00811   for (CSCStripDigiCollection::DigiRangeIterator si=strips->begin(); si!=strips->end(); si++) {
00812     CSCDetId id = (CSCDetId)(*si).first;
00813     int kEndcap  = id.endcap();
00814     int kRing    = id.ring();
00815     int kStation = id.station();
00816     int kChamber = id.chamber();
00817     std::vector<CSCStripDigi>::const_iterator stripIt = (*si).second.first;
00818     std::vector<CSCStripDigi>::const_iterator lastStrip = (*si).second.second;
00819     for( ; stripIt != lastStrip; ++stripIt) {
00820       std::vector<int> myADCVals = stripIt->getADCCounts();
00821       bool thisStripFired = false;
00822       float thisPedestal = 0.5*(float)(myADCVals[0]+myADCVals[1]);
00823       float threshold = 13.3 ;
00824       float diff = 0.;
00825       for (unsigned int iCount = 0; iCount < myADCVals.size(); iCount++) {
00826         diff = (float)myADCVals[iCount]-thisPedestal;
00827         if (diff > threshold) { thisStripFired = true; }
00828       }
00829       if (thisStripFired) {
00830         if (!stripo[kEndcap-1][kStation-1][kRing-1][kChamber-1]){
00831           stripo[kEndcap-1][kStation-1][kRing-1][kChamber-1] = true;
00832           hOStrips->Fill(kChamber,typeIndex(id,2));
00833           hOStripSerial->Fill(chamberSerial(id));
00834           hasStrips = true;
00835           if (clcto[kEndcap-1][kStation-1][kRing-1][kChamber-1]){
00836             // check if there is a wire digi in this chamber too
00837             // for ME 1/4 check for a wire in ME 1/1
00838             if(wireo[kEndcap-1][kStation-1][kRing-1][kChamber-1] || (kRing==4 && wireo[kEndcap-1][kStation-1][0][kChamber-1]) ){
00839               hOStripsAndWiresAndCLCT->Fill(kChamber,typeIndex(id,2));
00840             }
00841           }//end clct and wire digi check
00842         }
00843       }//end if (thisStripFired)
00844     }
00845   }
00846 
00847   //rechits
00848   CSCRecHit2DCollection::const_iterator recIt;
00849   for (recIt = recHits->begin(); recIt != recHits->end(); recIt++) {
00850     CSCDetId idrec = (CSCDetId)(*recIt).cscDetId();
00851     int kEndcap  = idrec.endcap();
00852     int kRing    = idrec.ring();
00853     int kStation = idrec.station();
00854     int kChamber = idrec.chamber();
00855     if (!rechito[kEndcap-1][kStation-1][kRing-1][kChamber-1]){
00856       rechito[kEndcap-1][kStation-1][kRing-1][kChamber-1] = true;
00857       hORecHitsSerial->Fill(chamberSerial(idrec));
00858       hORecHits->Fill(kChamber,typeIndex(idrec,2));
00859       hasRecHits = true;
00860     }
00861   }
00862 
00863   //segments
00864   for(CSCSegmentCollection::const_iterator segIt=cscSegments->begin(); segIt != cscSegments->end(); segIt++) {
00865     CSCDetId id  = (CSCDetId)(*segIt).cscDetId();
00866     int kEndcap  = id.endcap();
00867     int kRing    = id.ring();
00868     int kStation = id.station();
00869     int kChamber = id.chamber();
00870     if (!segmento[kEndcap-1][kStation-1][kRing-1][kChamber-1]){
00871       segmento[kEndcap-1][kStation-1][kRing-1][kChamber-1] = true;
00872       hOSegmentsSerial->Fill(chamberSerial(id));
00873       hOSegments->Fill(kChamber,typeIndex(id,2));
00874       hasSegments = true;
00875     }
00876   }
00877 
00878   //Overall CSC Occupancy
00879   hCSCOccupancy->Fill(1);
00880   if (hasWires) hCSCOccupancy->Fill(3);
00881   if (hasStrips) hCSCOccupancy->Fill(5);
00882   if (hasWires && hasStrips) hCSCOccupancy->Fill(7);
00883   if (hasRecHits) hCSCOccupancy->Fill(9);
00884   if (hasSegments) hCSCOccupancy->Fill(11);
00885 
00886 
00887   }
00888 
00889 
00890 // ==============================================
00891 //
00892 // look at WIRE DIGIs
00893 //
00894 // ==============================================
00895 
00896 void CSCOfflineMonitor::doWireDigis(edm::Handle<CSCWireDigiCollection> wires){
00897 
00898   int nWireGroupsTotal = 0;
00899   for (CSCWireDigiCollection::DigiRangeIterator dWDiter=wires->begin(); dWDiter!=wires->end(); dWDiter++) {
00900     CSCDetId id = (CSCDetId)(*dWDiter).first;
00901     std::vector<CSCWireDigi>::const_iterator wireIter = (*dWDiter).second.first;
00902     std::vector<CSCWireDigi>::const_iterator lWire = (*dWDiter).second.second;
00903     for( ; wireIter != lWire; ++wireIter) {
00904       int myWire = wireIter->getWireGroup();
00905       int myTBin = wireIter->getTimeBin();
00906       nWireGroupsTotal++;
00907       hWireTBin[typeIndex(id)-1]->Fill(myTBin);
00908       hWireNumber[typeIndex(id)-1]->Fill(myWire);
00909     }
00910   } // end wire loop
00911 
00912   // this way you can zero suppress but still store info on # events with no digis
00913   if (nWireGroupsTotal == 0) nWireGroupsTotal = -1;
00914   hWirenGroupsTotal->Fill(nWireGroupsTotal);
00915   
00916 }
00917 
00918 
00919 // ==============================================
00920 //
00921 // look at STRIP DIGIs
00922 //
00923 // ==============================================
00924 
00925 void CSCOfflineMonitor::doStripDigis(edm::Handle<CSCStripDigiCollection> strips){
00926 
00927   int nStripsFired = 0;
00928   for (CSCStripDigiCollection::DigiRangeIterator dSDiter=strips->begin(); dSDiter!=strips->end(); dSDiter++) {
00929     CSCDetId id = (CSCDetId)(*dSDiter).first;
00930     std::vector<CSCStripDigi>::const_iterator stripIter = (*dSDiter).second.first;
00931     std::vector<CSCStripDigi>::const_iterator lStrip = (*dSDiter).second.second;
00932     for( ; stripIter != lStrip; ++stripIter) {
00933       int myStrip = stripIter->getStrip();
00934       std::vector<int> myADCVals = stripIter->getADCCounts();
00935       bool thisStripFired = false;
00936       float thisPedestal = 0.5*(float)(myADCVals[0]+myADCVals[1]);
00937       float threshold = 13.3 ;
00938       float diff = 0.;
00939       for (unsigned int iCount = 0; iCount < myADCVals.size(); iCount++) {
00940         diff = (float)myADCVals[iCount]-thisPedestal;
00941         if (diff > threshold) { thisStripFired = true; }
00942       } 
00943       if (thisStripFired) {
00944         nStripsFired++;
00945         hStripNumber[typeIndex(id)-1]->Fill(myStrip);
00946       }
00947     }
00948   } // end strip loop
00949 
00950   // this way you can zero suppress but still store info on # events with no digis
00951   if (nStripsFired == 0) nStripsFired = -1;
00952   hStripNFired->Fill(nStripsFired);
00953   // fill n per event
00954 
00955 }
00956 
00957 
00958 //=======================================================
00959 //
00960 // Look at the Pedestal Noise Distributions
00961 //
00962 //=======================================================
00963 
00964 void CSCOfflineMonitor::doPedestalNoise(edm::Handle<CSCStripDigiCollection> strips){
00965 
00966   for (CSCStripDigiCollection::DigiRangeIterator dPNiter=strips->begin(); dPNiter!=strips->end(); dPNiter++) {
00967     CSCDetId id = (CSCDetId)(*dPNiter).first;
00968     int kStation = id.station();
00969     int kRing = id.ring();
00970     std::vector<CSCStripDigi>::const_iterator pedIt = (*dPNiter).second.first;
00971     std::vector<CSCStripDigi>::const_iterator lStrip = (*dPNiter).second.second;
00972     for( ; pedIt != lStrip; ++pedIt) {
00973       int myStrip = pedIt->getStrip();
00974       std::vector<int> myADCVals = pedIt->getADCCounts();
00975       float TotalADC = getSignal(*strips, id, myStrip);
00976       bool thisStripFired = false;
00977       float thisPedestal = 0.5*(float)(myADCVals[0]+myADCVals[1]);
00978       float thisSignal = (1./6)*(myADCVals[2]+myADCVals[3]+myADCVals[4]+myADCVals[5]+myADCVals[6]+myADCVals[7]);
00979       float threshold = 13.3;
00980       if(kStation == 1 && kRing == 4)
00981         {
00982           kRing = 1;
00983           if(myStrip <= 16) myStrip += 64; // no trapping for any bizarreness
00984         }
00985       if (TotalADC > threshold) { thisStripFired = true;}
00986       if (!thisStripFired){
00987         float ADC = thisSignal - thisPedestal;
00988         hStripPed[typeIndex(id)-1]->Fill(ADC);
00989       }
00990     }
00991   }
00992 
00993 }
00994 
00995 
00996 // ==============================================
00997 //
00998 // look at RECHITs
00999 //
01000 // ==============================================
01001 
01002 void CSCOfflineMonitor::doRecHits(edm::Handle<CSCRecHit2DCollection> recHits,
01003                                   edm::Handle<CSCStripDigiCollection> strips,
01004                                   edm::ESHandle<CSCGeometry> cscGeom){
01005 
01006   // Get the RecHits collection :
01007   int nRecHits = recHits->size();
01008   
01009   // ---------------------
01010   // Loop over rechits 
01011   // ---------------------
01012   // Build iterator for rechits and loop :
01013   CSCRecHit2DCollection::const_iterator dRHIter;
01014   for (dRHIter = recHits->begin(); dRHIter != recHits->end(); dRHIter++) {
01015 
01016     // Find chamber with rechits in CSC 
01017     CSCDetId idrec = (CSCDetId)(*dRHIter).cscDetId();
01018 
01019     // Store rechit as a Local Point:
01020     LocalPoint rhitlocal = (*dRHIter).localPosition();  
01021     //float xreco = rhitlocal.x();
01022     //float yreco = rhitlocal.y();
01023 
01024     // Get the reconstucted strip position and error
01025     float stpos = (*dRHIter).positionWithinStrip();
01026     float sterr = (*dRHIter).errorWithinStrip();
01027 
01029     
01030     int adcsize = dRHIter->nStrips()*dRHIter->nTimeBins();
01031     float rHSumQ = 0;
01032     float sumsides = 0;
01033     for (unsigned int i = 0; i < dRHIter->nStrips(); i++){
01034       for (unsigned int j=0; j<dRHIter->nTimeBins()-1; j++) {
01035         rHSumQ+=dRHIter->adcs(i,j);
01036         if ( i != 1 ) sumsides += dRHIter->adcs(i,j); // skip central strip
01037       }
01038     }   
01039 
01040     float rHratioQ = sumsides/rHSumQ;
01041     if (adcsize != 12) rHratioQ = -99;
01042 
01043     // Get the signal timing of this hit
01044     float rHtime = (*dRHIter).tpeak(); //calculated from cathode SCA bins
01045     float rHtimeAnode = (*dRHIter).wireTime(); // calculated from anode wire bx
01046 
01047     // Get pointer to the layer:
01048     const CSCLayer* csclayer = cscGeom->layer( idrec );
01049 
01050     // Transform hit position from local chamber geometry to global CMS geom
01051     GlobalPoint rhitglobal= csclayer->toGlobal(rhitlocal);
01052     float grecx   =  rhitglobal.x();
01053     float grecy   =  rhitglobal.y();
01054 
01055     // Fill some histograms
01056     int sIndex = idrec.station() + ((idrec.endcap()-1) * 4);
01057     int tIndex = typeIndex(idrec);
01058     hRHSumQ[tIndex-1]->Fill(rHSumQ);
01059     hRHRatioQ[tIndex-1]->Fill(rHratioQ);
01060     hRHstpos[tIndex-1]->Fill(stpos);
01061     hRHsterr[tIndex-1]->Fill(sterr);
01062     hRHTiming[tIndex-1]->Fill(rHtime);
01063     hRHTimingAnode[tIndex-1]->Fill(rHtimeAnode);
01064     hRHGlobal[sIndex-1]->Fill(grecx,grecy);
01065 
01066   } //end rechit loop
01067 
01068   if (nRecHits == 0) nRecHits = -1;
01069   hRHnrechits->Fill(nRecHits);
01070 
01071 }
01072 
01073 
01074 // ==============================================
01075 //
01076 // look at SEGMENTs
01077 //
01078 // ===============================================
01079 
01080 void CSCOfflineMonitor::doSegments(edm::Handle<CSCSegmentCollection> cscSegments,
01081                                    edm::ESHandle<CSCGeometry> cscGeom){
01082 
01083   // get CSC segment collection
01084   int nSegments = cscSegments->size();
01085 
01086   for(CSCSegmentCollection::const_iterator dSiter=cscSegments->begin(); dSiter != cscSegments->end(); dSiter++) {
01087     CSCDetId id  = (CSCDetId)(*dSiter).cscDetId();
01088     float chisq    = (*dSiter).chi2();
01089     int nhits      = (*dSiter).nRecHits();
01090     int nDOF       = 2*nhits-4;
01091     float nChi2    = chisq/nDOF;
01092     double chisqProb = ChiSquaredProbability( (double)chisq, nDOF );
01093     LocalPoint localPos = (*dSiter).localPosition();
01094     LocalVector segDir = (*dSiter).localDirection();
01095 
01096     // prepare to calculate segment times 
01097     float timeCathode = 0;  //average from cathode information alone
01098     float timeAnode = 0;  //average from pruned anode information alone
01099     float timeCombined = 0; //average from cathode hits and pruned anode list
01100     std::vector<float> cathodeTimes;
01101     std::vector<float> anodeTimes;
01102     // Get the CSC recHits that contribute to this segment.
01103     std::vector<CSCRecHit2D> theseRecHits = (*dSiter).specificRecHits();
01104     for ( vector<CSCRecHit2D>::const_iterator iRH = theseRecHits.begin(); iRH != theseRecHits.end(); iRH++) {
01105       if ( !((*iRH).isValid()) ) continue;  // only interested in valid hits
01106       cathodeTimes.push_back((*iRH).tpeak());
01107       anodeTimes.push_back((*iRH).wireTime());
01108     }//end rechit loop
01109     
01110     // Calculate cathode average
01111     for (unsigned int i=0; i<cathodeTimes.size(); i++) 
01112         timeCathode+=cathodeTimes[i]/cathodeTimes.size();
01113     
01114     // Prune the anode list to deal with the late tail 
01115     float anodeMaxDiff;
01116     bool modified = false;
01117     std::vector<float>::iterator anodeMaxHit;
01118     do {
01119       if (anodeTimes.size()==0) continue;
01120       timeAnode=0;
01121       anodeMaxDiff=0;
01122       modified=false;
01123 
01124       // Find the average
01125       for (unsigned int j=0; j<anodeTimes.size(); j++) timeAnode+=anodeTimes[j]/anodeTimes.size();
01126 
01127       // Find the maximum outlier hit
01128       for (unsigned int j=0; j<anodeTimes.size(); j++) {
01129         if (fabs(anodeTimes[j]-timeAnode)>anodeMaxDiff) {
01130           anodeMaxHit=anodeTimes.begin()+j;
01131           anodeMaxDiff=fabs(anodeTimes[j]-timeAnode);
01132         }
01133       }
01134       
01135       // Cut hit if its greater than some time away
01136       if (anodeMaxDiff>26) {
01137         modified=true;
01138         anodeTimes.erase(anodeMaxHit);
01139       }
01140     } while (modified);
01141 
01142     // Calculate combined anode and cathode time average
01143     if(cathodeTimes.size()+anodeTimes.size() >0 )
01144       timeCombined = (timeCathode*cathodeTimes.size() + timeAnode*anodeTimes.size())/(cathodeTimes.size()+anodeTimes.size());
01145 
01146     // global transformation
01147     float globX = 0.;
01148     float globY = 0.;
01149     float globZ = 0.;
01150     float globTOF = 0.;
01151     float globTheta = 0.;
01152     float globPhi   = 0.;
01153     const CSCChamber* cscchamber = cscGeom->chamber(id);
01154     if (cscchamber) {
01155       GlobalPoint globalPosition = cscchamber->toGlobal(localPos);
01156       globX = globalPosition.x();
01157       globY = globalPosition.y();
01158       globZ = globalPosition.z();
01159       globTOF = sqrt(globX*globX+globY*globY+globZ*globZ);
01160       GlobalVector globalDirection = cscchamber->toGlobal(segDir);
01161       globTheta = globalDirection.theta();
01162       globPhi   = globalDirection.phi();
01163     }
01164 
01165     // Fill histos
01166     int tIndex = typeIndex(id);
01167     hSnhitsAll->Fill(nhits);
01168     hSnhits[tIndex-1]->Fill(nhits);
01169     hSChiSqAll->Fill(nChi2);
01170     hSChiSq[tIndex-1]->Fill(nChi2);
01171     hSChiSqProbAll->Fill(chisqProb);
01172     hSChiSqProb[tIndex-1]->Fill(chisqProb);
01173     hSGlobalTheta->Fill(globTheta);
01174     hSGlobalPhi->Fill(globPhi);
01175     hSTimeCathode->Fill(timeCathode);
01176     hSTimeCombined->Fill(timeCombined);
01177     hSTimeVsZ->Fill(globZ, timeCombined);
01178     hSTimeVsTOF->Fill(globTOF, timeCombined);
01179 
01180   } // end segment loop
01181 
01182   if (nSegments == 0) nSegments = -1;
01183   hSnSegments->Fill(nSegments);
01184 
01185 }
01186 
01187 // ==============================================
01188 //
01189 // look at hit Resolution
01190 //
01191 // ==============================================
01192 void CSCOfflineMonitor::doResolution(edm::Handle<CSCSegmentCollection> cscSegments,
01193                                      edm::ESHandle<CSCGeometry> cscGeom){
01194 
01195   for(CSCSegmentCollection::const_iterator dSiter=cscSegments->begin(); dSiter != cscSegments->end(); dSiter++) {
01196     CSCDetId id  = (CSCDetId)(*dSiter).cscDetId();
01197     //
01198     // try to get the CSC recHits that contribute to this segment.
01199     std::vector<CSCRecHit2D> theseRecHits = (*dSiter).specificRecHits();
01200     int nRH = (*dSiter).nRecHits();
01201     int jRH = 0;
01202     CLHEP::HepMatrix sp(6,1);
01203     CLHEP::HepMatrix se(6,1);
01204     for ( vector<CSCRecHit2D>::const_iterator iRH = theseRecHits.begin(); iRH != theseRecHits.end(); iRH++) {
01205       jRH++;
01206       CSCDetId idRH = (CSCDetId)(*iRH).cscDetId();
01207       //int kEndcap  = idRH.endcap();
01208       int kRing    = idRH.ring();
01209       int kStation = idRH.station();
01210       //int kChamber = idRH.chamber();
01211       int kLayer   = idRH.layer();
01212 
01214       int centerid    =  iRH->nStrips()/2 + 1;
01215       int centerStrip =  iRH->channels(centerid - 1);   
01216 
01217       // If this segment has 6 hits, find the position of each hit on the strip in units of stripwidth and store values
01218       if (nRH == 6){
01219         float stpos = (*iRH).positionWithinStrip();
01220         se(kLayer,1) = (*iRH).errorWithinStrip();
01221         // Take into account half-strip staggering of layers (ME1/1 has no staggering)
01222         if (kStation == 1 && (kRing == 1 || kRing == 4)) sp(kLayer,1) = stpos + centerStrip;
01223         else{
01224           if (kLayer == 1 || kLayer == 3 || kLayer == 5) sp(kLayer,1) = stpos + centerStrip;
01225           if (kLayer == 2 || kLayer == 4 || kLayer == 6) sp(kLayer,1) = stpos - 0.5 + centerStrip;
01226         }
01227       }
01228 
01229     }
01230 
01231     float residual = -99;
01232     // Fit all points except layer 3, then compare expected value for layer 3 to reconstructed value
01233     if (nRH == 6){
01234       float expected = fitX(sp,se);
01235       residual = expected - sp(3,1);
01236     }
01237 
01238     hSResid[typeIndex(id)-1]->Fill(residual);
01239 
01240   } // end segment loop
01241 
01242 
01243 
01244 }
01245 
01246 
01247 //-------------------------------------------------------------------------------------
01248 // Fits a straight line to a set of 5 points with errors.  Functions assumes 6 points
01249 // and removes hit in layer 3.  It then returns the expected position value in layer 3
01250 // based on the fit.
01251 //-------------------------------------------------------------------------------------
01252 float CSCOfflineMonitor::fitX(CLHEP::HepMatrix points, CLHEP::HepMatrix errors){
01253 
01254   float S   = 0;
01255   float Sx  = 0;
01256   float Sy  = 0;
01257   float Sxx = 0;
01258   float Sxy = 0;
01259   float sigma2 = 0;
01260 
01261   for (int i=1;i<7;i++){
01262     if (i != 3){
01263       sigma2 = errors(i,1)*errors(i,1);
01264       S = S + (1/sigma2);
01265       Sy = Sy + (points(i,1)/sigma2);
01266       Sx = Sx + ((i)/sigma2);
01267       Sxx = Sxx + (i*i)/sigma2;
01268       Sxy = Sxy + (((i)*points(i,1))/sigma2);
01269     }
01270   }
01271 
01272   float delta = S*Sxx - Sx*Sx;
01273   float intercept = (Sxx*Sy - Sx*Sxy)/delta;
01274   float slope = (S*Sxy - Sx*Sy)/delta;
01275 
01276   return (intercept + slope*3);
01277 
01278 }
01279 
01280 //---------------------------------------------------------------------------------------
01281 // Given a set of digis, the CSCDetId, and the central strip of your choosing, returns
01282 // the avg. Signal-Pedestal for 6 time bin x 5 strip .
01283 //
01284 // Author: P. Jindal
01285 //---------------------------------------------------------------------------------------
01286 
01287 float CSCOfflineMonitor::getSignal(const CSCStripDigiCollection& stripdigis, 
01288                                    CSCDetId idCS, int centerStrip){
01289 
01290   float SigADC[5];
01291   float TotalADC = 0;
01292   SigADC[0] = 0;
01293   SigADC[1] = 0;
01294   SigADC[2] = 0;
01295   SigADC[3] = 0;
01296   SigADC[4] = 0;
01297 
01298  
01299   // Loop over strip digis 
01300   CSCStripDigiCollection::DigiRangeIterator sIt;
01301   
01302   for (sIt = stripdigis.begin(); sIt != stripdigis.end(); sIt++){
01303     CSCDetId id = (CSCDetId)(*sIt).first;
01304     if (id == idCS){
01305 
01306       // First, find the Signal-Pedestal for center strip
01307       vector<CSCStripDigi>::const_iterator digiItr = (*sIt).second.first;
01308       vector<CSCStripDigi>::const_iterator last = (*sIt).second.second;
01309       for ( ; digiItr != last; ++digiItr ) {
01310         int thisStrip = digiItr->getStrip();
01311         if (thisStrip == (centerStrip)){
01312           std::vector<int> myADCVals = digiItr->getADCCounts();
01313           float thisPedestal = 0.5*(float)(myADCVals[0]+myADCVals[1]);
01314           float thisSignal = (myADCVals[2]+myADCVals[3]+myADCVals[4]+myADCVals[5]+myADCVals[6]+myADCVals[7]);
01315           SigADC[0] = thisSignal - 6*thisPedestal;
01316         }
01317      // Now,find the Signal-Pedestal for neighbouring 4 strips
01318         if (thisStrip == (centerStrip+1)){
01319           std::vector<int> myADCVals = digiItr->getADCCounts();
01320           float thisPedestal = 0.5*(float)(myADCVals[0]+myADCVals[1]);
01321           float thisSignal = (myADCVals[2]+myADCVals[3]+myADCVals[4]+myADCVals[5]+myADCVals[6]+myADCVals[7]);
01322           SigADC[1] = thisSignal - 6*thisPedestal;
01323         }
01324         if (thisStrip == (centerStrip+2)){
01325           std::vector<int> myADCVals = digiItr->getADCCounts();
01326           float thisPedestal = 0.5*(float)(myADCVals[0]+myADCVals[1]);
01327           float thisSignal = (myADCVals[2]+myADCVals[3]+myADCVals[4]+myADCVals[5]+myADCVals[6]+myADCVals[7]);
01328           SigADC[2] = thisSignal - 6*thisPedestal;
01329         }
01330         if (thisStrip == (centerStrip-1)){
01331           std::vector<int> myADCVals = digiItr->getADCCounts();
01332           float thisPedestal = 0.5*(float)(myADCVals[0]+myADCVals[1]);
01333           float thisSignal = (myADCVals[2]+myADCVals[3]+myADCVals[4]+myADCVals[5]+myADCVals[6]+myADCVals[7]);
01334           SigADC[3] = thisSignal - 6*thisPedestal;
01335         }
01336         if (thisStrip == (centerStrip-2)){
01337           std::vector<int> myADCVals = digiItr->getADCCounts();
01338           float thisPedestal = 0.5*(float)(myADCVals[0]+myADCVals[1]);
01339           float thisSignal = (myADCVals[2]+myADCVals[3]+myADCVals[4]+myADCVals[5]+myADCVals[6]+myADCVals[7]);
01340           SigADC[4] = thisSignal - 6*thisPedestal;
01341         }
01342       }
01343       TotalADC = 0.2*(SigADC[0]+SigADC[1]+SigADC[2]+SigADC[3]+SigADC[4]);
01344     }
01345   }
01346   return TotalADC;
01347 }
01348 
01349 
01350 
01351 //----------------------------------------------------------------------------
01352 // Calculate basic efficiencies for recHits and Segments
01353 // Author: S. Stoynev
01354 //----------------------------------------------------------------------------
01355 
01356 void CSCOfflineMonitor::doEfficiencies(edm::Handle<CSCWireDigiCollection> wires, edm::Handle<CSCStripDigiCollection> strips,
01357                                        edm::Handle<CSCRecHit2DCollection> recHits, edm::Handle<CSCSegmentCollection> cscSegments,
01358                                        edm::ESHandle<CSCGeometry> cscGeom){
01359 
01360   bool allWires[2][4][4][36][6];
01361   bool allStrips[2][4][4][36][6];
01362   bool AllRecHits[2][4][4][36][6];
01363   bool AllSegments[2][4][4][36];
01364   
01365   //bool MultiSegments[2][4][4][36];
01366   for(int iE = 0;iE<2;iE++){
01367     for(int iS = 0;iS<4;iS++){
01368       for(int iR = 0; iR<4;iR++){
01369         for(int iC =0;iC<36;iC++){
01370           AllSegments[iE][iS][iR][iC] = false;
01371           //MultiSegments[iE][iS][iR][iC] = false;
01372           for(int iL=0;iL<6;iL++){
01373             allWires[iE][iS][iR][iC][iL] = false;
01374             allStrips[iE][iS][iR][iC][iL] = false;
01375             AllRecHits[iE][iS][iR][iC][iL] = false;
01376           }
01377         }
01378       }
01379     }
01380   }
01381   
01382   
01383   // Wires
01384   for (CSCWireDigiCollection::DigiRangeIterator dWDiter=wires->begin(); dWDiter!=wires->end(); dWDiter++) {
01385     CSCDetId idrec = (CSCDetId)(*dWDiter).first;
01386     std::vector<CSCWireDigi>::const_iterator wireIter = (*dWDiter).second.first;
01387     std::vector<CSCWireDigi>::const_iterator lWire = (*dWDiter).second.second;
01388     for( ; wireIter != lWire; ++wireIter) {
01389       allWires[idrec.endcap() -1][idrec.station() -1][idrec.ring() -1][idrec.chamber() -1][idrec.layer() -1] = true;
01390       break;
01391     }
01392   }
01393 
01394   //---- STRIPS
01395   for (CSCStripDigiCollection::DigiRangeIterator dSDiter=strips->begin(); dSDiter!=strips->end(); dSDiter++) {
01396     CSCDetId idrec = (CSCDetId)(*dSDiter).first;
01397     std::vector<CSCStripDigi>::const_iterator stripIter = (*dSDiter).second.first;
01398     std::vector<CSCStripDigi>::const_iterator lStrip = (*dSDiter).second.second;
01399     for( ; stripIter != lStrip; ++stripIter) {
01400       std::vector<int> myADCVals = stripIter->getADCCounts();
01401       bool thisStripFired = false;
01402       float thisPedestal = 0.5*(float)(myADCVals[0]+myADCVals[1]);
01403       float threshold = 13.3 ;
01404       float diff = 0.;
01405       for (unsigned int iCount = 0; iCount < myADCVals.size(); iCount++) {
01406         diff = (float)myADCVals[iCount]-thisPedestal;
01407         if (diff > threshold) {
01408           thisStripFired = true;
01409           break;
01410         }
01411       }
01412       if(thisStripFired){
01413         allStrips[idrec.endcap() -1][idrec.station() -1][idrec.ring() -1][idrec.chamber() -1][idrec.layer() -1] = true;
01414         break;
01415       }
01416     }
01417   }
01418 
01419   // Rechits
01420   for (CSCRecHit2DCollection::const_iterator recEffIt = recHits->begin(); recEffIt != recHits->end(); recEffIt++) {
01421     //CSCDetId idrec = (CSCDetId)(*recIt).cscDetId();
01422     CSCDetId  idrec = (CSCDetId)(*recEffIt).cscDetId();
01423     AllRecHits[idrec.endcap() -1][idrec.station() -1][idrec.ring() -1][idrec.chamber() -1][idrec.layer() -1] = true;
01424 
01425   }
01426 
01427   std::vector <uint> seg_ME2(2,0) ;
01428   std::vector <uint> seg_ME3(2,0) ;
01429   std::vector < pair <CSCDetId, CSCSegment> > theSegments(4);
01430   // Segments
01431   for(CSCSegmentCollection::const_iterator segEffIt=cscSegments->begin(); segEffIt != cscSegments->end(); segEffIt++) {
01432     CSCDetId idseg  = (CSCDetId)(*segEffIt).cscDetId();
01433     //if(AllSegments[idrec.endcap() -1][idrec.station() -1][idrec.ring() -1][idrec.chamber()]){
01434     //MultiSegments[idrec.endcap() -1][idrec.station() -1][idrec.ring() -1][idrec.chamber()] = true;
01435     //}
01436     AllSegments[idseg.endcap() -1][idseg.station() -1][idseg.ring() -1][idseg.chamber() -1] = true;
01437     // "Intrinsic" efficiency measurement relies on "good" segment extrapolation - we need the pre-selection below
01438     // station 2 "good" segment will be used for testing efficiencies in ME1 and ME3
01439     // station 3 "good" segment will be used for testing efficiencies in ME2 and ME4
01440     if(2==idseg.station() || 3==idseg.station()){
01441       uint seg_tmp ; 
01442       if(2==idseg.station()){
01443         ++seg_ME2[idseg.endcap() -1];
01444         seg_tmp = seg_ME2[idseg.endcap() -1];
01445       }
01446       else{
01447         ++seg_ME3[idseg.endcap() -1];
01448         seg_tmp = seg_ME3[idseg.endcap() -1];
01449       }
01450       // is the segment good
01451       if(1== seg_tmp&& 6==(*segEffIt).nRecHits() && (*segEffIt).chi2()/(*segEffIt).degreesOfFreedom()<3.){
01452         pair <CSCDetId, CSCSegment> specSeg = make_pair( (CSCDetId)(*segEffIt).cscDetId(),*segEffIt);
01453         theSegments[2*(idseg.endcap()-1)+(idseg.station() -2)] = specSeg;
01454       }
01455     }
01456     /*
01457     if(2==idseg.station()){
01458         ++seg_ME2[idseg.endcap() -1];
01459        if(1==seg_ME2[idseg.endcap() -1] && 6==(*segEffIt).nRecHits() && (*segEffIt).chi2()/(*segEffIt).degreesOfFreedom()<3.){
01460            pair <CSCDetId, CSCSegment> specSeg = make_pair( (CSCDetId)(*segEffIt).cscDetId(),*segEffIt);
01461            theSegments[2*(idseg.endcap()-1)+(idseg.station() -2)] = specSeg;
01462        }
01463     }
01464     else if(3==idseg.station()){
01465         ++seg_ME3[idseg.endcap() -1];
01466         if(1==seg_ME3[idseg.endcap() -1] && 6==(*segEffIt).nRecHits() && (*segEffIt).chi2()/(*segEffIt).degreesOfFreedom()<3.){
01467          pair <CSCDetId, CSCSegment> specSeg = make_pair( (CSCDetId)(*segEffIt).cscDetId(),*segEffIt);
01468          theSegments[2*(idseg.endcap()-1)+(idseg.station() -2)] = specSeg;
01469        }
01470     }
01471     */
01472     
01473   }
01474   // Simple efficiency calculations
01475   for(int iE = 0;iE<2;iE++){
01476     for(int iS = 0;iS<4;iS++){
01477       for(int iR = 0; iR<4;iR++){
01478         for(int iC =0;iC<36;iC++){
01479           int NumberOfLayers = 0;
01480           for(int iL=0;iL<6;iL++){
01481             if(AllRecHits[iE][iS][iR][iC][iL]){
01482               NumberOfLayers++;
01483             }
01484           }
01485           int bin = 0;
01486           if (iS==0) bin = iR+1+(iE*10);
01487           else bin = (iS+1)*2 + (iR+1) + (iE*10);
01488           if(NumberOfLayers>1){
01489             //if(!(MultiSegments[iE][iS][iR][iC])){
01490             if(AllSegments[iE][iS][iR][iC]){
01491               //---- Efficient segment evenents
01492               hSSTE->Fill(bin);
01493             }
01494             //---- All segment events (normalization)
01495             hSSTE->Fill(20+bin);
01496             //}
01497           }
01498           if(AllSegments[iE][iS][iR][iC]){
01499             if(NumberOfLayers==6){
01500               //---- Efficient rechit events
01501               hRHSTE->Fill(bin);;
01502             }
01503             //---- All rechit events (normalization)
01504             hRHSTE->Fill(20+bin);;
01505           }
01506         }
01507       }
01508     }
01509   }
01510 
01511   // pick a segment only if there are no others in the station
01512   std::vector < pair <CSCDetId, CSCSegment> * > theSeg;
01513   if(1==seg_ME2[0]) theSeg.push_back(&theSegments[0]);
01514   if(1==seg_ME3[0]) theSeg.push_back(&theSegments[1]);
01515   if(1==seg_ME2[1]) theSeg.push_back(&theSegments[2]);
01516   if(1==seg_ME3[1]) theSeg.push_back(&theSegments[3]);
01517 
01518   // Needed for plots
01519   // at the end the chamber types will be numbered as 1 to 18 
01520   // (ME-4/1, -ME3/2, -ME3/1, ..., +ME3/1, +ME3/2, ME+4/1 ) 
01521   std::map <std::string, float> chamberTypes;
01522   chamberTypes["ME1/a"] = 0.5;
01523   chamberTypes["ME1/b"] = 1.5;
01524   chamberTypes["ME1/2"] = 2.5;
01525   chamberTypes["ME1/3"] = 3.5;
01526   chamberTypes["ME2/1"] = 4.5;
01527   chamberTypes["ME2/2"] = 5.5;
01528   chamberTypes["ME3/1"] = 6.5;
01529   chamberTypes["ME3/2"] = 7.5;
01530   chamberTypes["ME4/1"] = 8.5;
01531 
01532   if(theSeg.size()){
01533     std::map <int , GlobalPoint> extrapolatedPoint;
01534     std::map <int , GlobalPoint>::iterator it;
01535     const std::vector<CSCChamber*> ChamberContainer = cscGeom->chambers();
01536     // Pick which chamber with which segment to test
01537     for(unsigned int nCh=0;nCh<ChamberContainer.size();nCh++){
01538       const CSCChamber *cscchamber = ChamberContainer[nCh];
01539       pair <CSCDetId, CSCSegment> * thisSegment = 0;
01540       for(uint iSeg =0;iSeg<theSeg.size();++iSeg ){
01541         if(cscchamber->id().endcap() == theSeg[iSeg]->first.endcap()){ 
01542           if(1==cscchamber->id().station() || 3==cscchamber->id().station() ){
01543             if(2==theSeg[iSeg]->first.station()){
01544               thisSegment = theSeg[iSeg];
01545             }
01546           }
01547           else if (2==cscchamber->id().station() || 4==cscchamber->id().station()){
01548             if(3==theSeg[iSeg]->first.station()){
01549               thisSegment = theSeg[iSeg];
01550             }
01551           }
01552         }
01553       }
01554       // this chamber is to be tested with thisSegment
01555       if(thisSegment){
01556         CSCSegment * seg = &(thisSegment->second);
01557         const CSCChamber *segChamber = cscGeom->chamber(thisSegment->first);
01558         LocalPoint localCenter(0.,0.,0);
01559         GlobalPoint cscchamberCenter =  cscchamber->toGlobal(localCenter);
01560         // try to save some time (extrapolate a segment to a certain position only once)
01561         it = extrapolatedPoint.find(int(cscchamberCenter.z()));
01562         if(it==extrapolatedPoint.end()){
01563           GlobalPoint segPos = segChamber->toGlobal(seg->localPosition());
01564           GlobalVector segDir = segChamber->toGlobal(seg->localDirection());
01565           double paramaterLine = lineParametrization(segPos.z(),cscchamberCenter.z() , segDir.z());
01566           double xExtrapolated = extrapolate1D(segPos.x(),segDir.x(), paramaterLine);
01567           double yExtrapolated = extrapolate1D(segPos.y(),segDir.y(), paramaterLine);
01568           GlobalPoint globP (xExtrapolated, yExtrapolated, cscchamberCenter.z());
01569           extrapolatedPoint[int(cscchamberCenter.z())] = globP;
01570         }
01571         // Where does the extrapolated point lie in the (tested) chamber local frame? Here: 
01572         LocalPoint extrapolatedPointLocal = cscchamber->toLocal(extrapolatedPoint[int(cscchamberCenter.z())]);
01573         const CSCLayer *layer_p = cscchamber->layer(1);//layer 1
01574         const CSCLayerGeometry *layerGeom = layer_p->geometry ();
01575         const std::vector<float> layerBounds = layerGeom->parameters ();
01576         float shiftFromEdge = 15.;//cm
01577         float shiftFromDeadZone = 10.;
01578         // is the extrapolated point within a sensitive region
01579         bool pass = withinSensitiveRegion(extrapolatedPointLocal, layerBounds, 
01580                                           cscchamber->id().station(), cscchamber->id().ring(), 
01581                                           shiftFromEdge, shiftFromDeadZone);
01582         if(pass){// the extrapolation point of the segment lies within sensitive region of that chamber
01583           // how many rechit layers are there in the chamber?
01584           // 0 - maybe the muon died or is deflected at large angle? do not use that case
01585           // 1 - could be noise...
01586           // 2 or more - this is promissing; this is our definition of a reliable signal; use it below
01587           // is other definition better? 
01588           int nRHLayers = 0;
01589           for(int iL =0;iL<6;++iL){
01590             if(AllRecHits[cscchamber->id().endcap()-1]
01591                [cscchamber->id().station()-1]
01592                [cscchamber->id().ring()-1][cscchamber->id().chamber()-1][iL]){
01593               ++nRHLayers;
01594             }
01595           }
01596           //std::cout<<" nRHLayers = "<<nRHLayers<<std::endl;
01597           float verticalScale = chamberTypes[cscchamber->specs()->chamberTypeName()];
01598           if(cscchamberCenter.z()<0){
01599             verticalScale = - verticalScale;
01600           } 
01601           verticalScale +=9.5;
01602           hSensitiveAreaEvt->Fill(float(cscchamber->id().chamber()),verticalScale);
01603           if(nRHLayers>1){// this chamber contains a reliable signal
01604             //chamberTypes[cscchamber->specs()->chamberTypeName()];
01605             // "intrinsic" efficiencies
01606             //std::cout<<" verticalScale = "<<verticalScale<<" chType = "<<cscchamber->specs()->chamberTypeName()<<std::endl;
01607             // this is the denominator forr all efficiencies
01608             hEffDenominator->Fill(float(cscchamber->id().chamber()),verticalScale);
01609             // Segment efficiency
01610             if(AllSegments[cscchamber->id().endcap()-1]
01611                [cscchamber->id().station()-1]
01612                [cscchamber->id().ring()-1][cscchamber->id().chamber()-1]){
01613               hSSTE2->Fill(float(cscchamber->id().chamber()),float(verticalScale));
01614             }
01615           
01616             for(int iL =0;iL<6;++iL){
01617               float weight = 1./6.;
01618               // one shold account for the weight in the efficiency...
01619               // Rechit efficiency
01620               if(AllRecHits[cscchamber->id().endcap()-1]
01621                  [cscchamber->id().station()-1]
01622                  [cscchamber->id().ring()-1][cscchamber->id().chamber()-1][iL]){
01623                 hRHSTE2->Fill(float(cscchamber->id().chamber()),float(verticalScale),weight);
01624               }
01625               // Wire efficiency
01626               if(allWires[cscchamber->id().endcap()-1]
01627                  [cscchamber->id().station()-1]
01628                  [cscchamber->id().ring()-1][cscchamber->id().chamber()-1][iL]){
01629                 // one shold account for the weight in the efficiency...
01630                 hWireSTE2->Fill(float(cscchamber->id().chamber()),float(verticalScale),weight);
01631               }
01632               // Strip efficiency
01633               if(allStrips[cscchamber->id().endcap()-1]
01634                  [cscchamber->id().station()-1]
01635                  [cscchamber->id().ring()-1][cscchamber->id().chamber()-1][iL]){
01636                 // one shold account for the weight in the efficiency...
01637                 hStripSTE2->Fill(float(cscchamber->id().chamber()),float(verticalScale),weight);
01638               }
01639             }
01640           }
01641         }
01642       }
01643     }
01644   }
01645   //
01646 
01647 
01648 }
01649 
01650 // ==============================================
01651 //
01652 // Look at BX level trigger synchronization
01653 //
01654 // ==============================================
01655 
01656 void CSCOfflineMonitor::doBXMonitor(edm::Handle<CSCALCTDigiCollection> alcts, edm::Handle<CSCCLCTDigiCollection> clcts, const edm::Event & event, const EventSetup& eventSetup){
01657 
01658   // Loop over ALCTDigis
01659 
01660   for (CSCALCTDigiCollection::DigiRangeIterator j=alcts->begin(); j!=alcts->end(); j++) {
01661     const CSCDetId& idALCT = (*j).first;
01662     const CSCALCTDigiCollection::Range& range =(*j).second;
01663     for (CSCALCTDigiCollection::const_iterator digiIt = range.first; digiIt!=range.second; ++digiIt){
01664       // Valid digi in the chamber (or in neighbouring chamber)  
01665       if((*digiIt).isValid()){
01666         hALCTgetBX->Fill((*digiIt).getBX());
01667         hALCTgetBXSerial->Fill(chamberSerial(idALCT),(*digiIt).getBX());
01668         hALCTgetBX2DNumerator->Fill(idALCT.chamber(),typeIndex(idALCT,2),(*digiIt).getBX());
01669         hALCTgetBX2Denominator->Fill(idALCT.chamber(),typeIndex(idALCT,2));
01670       }
01671     }
01672   }// end ALCT Digi loop
01673 
01674 
01675   // Loop over raw data to get TMBHeader information
01676   // Taking code from EventFilter/CSCRawToDigis/CSCDCCUnpacker.cc
01677   edm::ESHandle<CSCCrateMap> hcrate;
01678   eventSetup.get<CSCCrateMapRcd>().get(hcrate); 
01679   const CSCCrateMap* pcrate = hcrate.product();
01680 
01681 
01682   // Try to get raw data
01683   edm::Handle<FEDRawDataCollection> rawdata;
01684   if (!(event.getByLabel(FEDRawDataCollectionTag_,rawdata)) ){
01685     edm::LogWarning("CSCOfflineMonitor")<<" raw data with label "<<FEDRawDataCollectionTag_ <<" not available";
01686     return;
01687   }
01688 
01689 
01690 
01691   bool goodEvent = false;
01692   unsigned long dccBinCheckMask = 0x06080016;
01693   unsigned int examinerMask = 0x1FEBF3F6;
01694   unsigned int errorMask = 0x0;
01695 
01696   for (int id=FEDNumbering::MINCSCFEDID;
01697        id<=FEDNumbering::MAXCSCFEDID; ++id) { // loop over DCCs
01700      
01702     const FEDRawData& fedData = rawdata->FEDData(id);
01703     unsigned long length =  fedData.size();
01704    
01705     if (length>=32){ 
01706       CSCDCCExaminer* examiner = NULL;
01707       std::stringstream examiner_out, examiner_err;
01708       goodEvent = true;
01709       examiner = new CSCDCCExaminer();
01710       examiner->output1().redirect(examiner_out);
01711       examiner->output2().redirect(examiner_err);
01712       if( examinerMask&0x40000 ) examiner->crcCFEB(1);
01713       if( examinerMask&0x8000  ) examiner->crcTMB (1);
01714       if( examinerMask&0x0400  ) examiner->crcALCT(1);
01715       examiner->output1().show();
01716       examiner->output2().show();
01717       examiner->setMask(examinerMask);
01718       const short unsigned int *data = (short unsigned int *)fedData.data();
01719  
01720       int res = examiner->check(data,long(fedData.size()/2));
01721       if( res < 0 )   {
01722         goodEvent=false;
01723       } 
01724       else {    
01725         goodEvent=!(examiner->errors()&dccBinCheckMask);
01726       }
01727  
01728                  
01729       if (goodEvent) {
01731  
01732         CSCDCCExaminer * ptrExaminer = examiner;
01733         CSCDCCEventData dccData((short unsigned int *) fedData.data(), ptrExaminer);
01735         const std::vector<CSCDDUEventData> & dduData = dccData.dduData();
01736         
01738         CSCDetId layer(1, 1, 1, 1, 1);
01739         for (unsigned int iDDU=0; iDDU<dduData.size(); ++iDDU) {  // loop over DDUs
01742           if (dduData[iDDU].trailer().errorstat()&errorMask) {
01743             LogTrace("CSCDCCUnpacker|CSCRawToDigi") << "DDU# " << iDDU << " has serious error - no digis unpacked! " <<
01744               std::hex << dduData[iDDU].trailer().errorstat();
01745             continue; // to next iteration of DDU loop
01746           }
01747           
01749           const std::vector<CSCEventData> & cscData = dduData[iDDU].cscData();
01750           
01751           
01752           for (unsigned int iCSC=0; iCSC<cscData.size(); ++iCSC) { // loop over CSCs
01753             
01755             int vmecrate = cscData[iCSC].dmbHeader()->crateID();
01756             int dmb = cscData[iCSC].dmbHeader()->dmbID();
01757             
01758             int icfeb = 0;  
01759             int ilayer = 0; 
01760             
01761              if ((vmecrate>=1)&&(vmecrate<=60) && (dmb>=1)&&(dmb<=10)&&(dmb!=6)) {
01762                layer = pcrate->detId(vmecrate, dmb,icfeb,ilayer );
01763              } 
01764              else{
01765                LogTrace ("CSCOfflineMonitor") << " detID input out of range!!! ";
01766                LogTrace ("CSCOfflineMonitor")
01767                  << " skipping chamber vme= " << vmecrate << " dmb= " << dmb;
01768                continue; // to next iteration of iCSC loop
01769              }
01770 
01771 
01773             int nalct = cscData[iCSC].dmbHeader()->nalct();
01774             bool goodALCT=false;
01775             //if (nalct&&(cscData[iCSC].dataPresent>>6&0x1)==1) {
01776             if (nalct&&cscData[iCSC].alctHeader()) {  
01777               if (cscData[iCSC].alctHeader()->check()){
01778                 goodALCT=true;
01779               }
01780             }
01781             
01783             int nclct = cscData[iCSC].dmbHeader()->nclct();
01784             bool goodTMB=false;
01785             if (nclct&&cscData[iCSC].tmbData()) {
01786               if (cscData[iCSC].tmbHeader()->check()){
01787                 if (cscData[iCSC].clctData()->check()) goodTMB=true; 
01788               }
01789             }
01790             
01791             if (goodTMB && goodALCT) { 
01792               const CSCTMBHeader *tmbHead = cscData[iCSC].tmbHeader();
01793               std::vector<CSCCLCTDigi> clcts = cscData[iCSC].tmbHeader()->CLCTDigis(layer.rawId());
01794               if (clcts.size()==0 || !(clcts[0].isValid()))
01795                 continue;
01796               // Check if the CLCT was in ME11a (ring 4)
01797               if(layer.station()==1 && layer.ring() ==1 && clcts[0].getKeyStrip()>128){
01798                 layer = CSCDetId(layer.endcap(),layer.station(),4, layer.chamber()); 
01799               }
01800               hALCTMatch->Fill(tmbHead->ALCTMatchTime());
01801               hALCTMatchSerial->Fill(chamberSerial(layer),tmbHead->ALCTMatchTime());
01802               // Only fill big 2D display if ALCTMatchTime !=6, since this bin is polluted by the CLCT only triggers
01803               // One will have to look at the serial plots to see if the are a lot of entries here
01804               if(tmbHead->ALCTMatchTime()!=6){
01805                 hALCTMatch2DNumerator->Fill(layer.chamber(),typeIndex(layer,2),tmbHead->ALCTMatchTime());
01806                 hALCTMatch2Denominator->Fill(layer.chamber(),typeIndex(layer,2));             
01807               }
01808 
01809               int TMB_CLCTpre_rel_L1A = tmbHead->BXNCount()-clcts[0].getFullBX();
01810               if (TMB_CLCTpre_rel_L1A > 3563)
01811                 TMB_CLCTpre_rel_L1A = TMB_CLCTpre_rel_L1A - 3564;
01812               if (TMB_CLCTpre_rel_L1A < 0)
01813                 TMB_CLCTpre_rel_L1A = TMB_CLCTpre_rel_L1A + 3564;
01814 
01815               hCLCTL1A->Fill(TMB_CLCTpre_rel_L1A);
01816               hCLCTL1ASerial->Fill(chamberSerial(layer),TMB_CLCTpre_rel_L1A);
01817               hCLCTL1A2DNumerator->Fill(layer.chamber(),typeIndex(layer,2),TMB_CLCTpre_rel_L1A);
01818               hCLCTL1A2Denominator->Fill(layer.chamber(),typeIndex(layer,2));         
01819               
01820             }// end if goodTMB and goodALCT
01821           }// end loop CSCData
01822         }// end loop DDU
01823       }// end if good event
01824       if (examiner!=NULL) delete examiner;
01825     }// end if non-zero fed data
01826   }// end DCC loop for NON-REFERENCE
01827 
01828   return;
01829 
01830 }
01831 
01832 
01833 
01834 void CSCOfflineMonitor::getEfficiency(float bin, float Norm, std::vector<float> &eff){
01835   //---- Efficiency with binomial error
01836   float Efficiency = 0.;
01837   float EffError = 0.;
01838   if(fabs(Norm)>0.000000001){
01839     Efficiency = bin/Norm;
01840     if(bin<Norm){
01841       EffError = sqrt( (1.-Efficiency)*Efficiency/Norm );
01842     }
01843   }
01844   eff[0] = Efficiency;
01845   eff[1] = EffError;
01846 }
01847 
01848 void CSCOfflineMonitor::histoEfficiency(TH1F *readHisto, MonitorElement *writeHisto){
01849   std::vector<float> eff(2);
01850   int Nbins =  readHisto->GetSize()-2;//without underflows and overflows
01851   std::vector<float> bins(Nbins);
01852   std::vector<float> Efficiency(Nbins);
01853   std::vector<float> EffError(Nbins);
01854   float Num = 1;
01855   float Den = 1;
01856   for (int i=0;i<20;i++){
01857     Num = readHisto->GetBinContent(i+1);
01858     Den = readHisto->GetBinContent(i+21);
01859     getEfficiency(Num, Den, eff);
01860     Efficiency[i] = eff[0];
01861     EffError[i] = eff[1];
01862     writeHisto->setBinContent(i+1, Efficiency[i]);
01863     writeHisto->setBinError(i+1, EffError[i]);
01864   }
01865 }
01866 
01867 bool CSCOfflineMonitor::withinSensitiveRegion(LocalPoint localPos, const std::vector<float> layerBounds,
01868                                               int station, int ring, float shiftFromEdge, float shiftFromDeadZone){
01869 //---- check if it is in a good local region (sensitive area - geometrical and HV boundaries excluded) 
01870   bool pass = false;
01871 
01872   float y_center = 0.;
01873   double yUp = layerBounds[3] + y_center;
01874   double yDown = - layerBounds[3] + y_center;
01875   double xBound1Shifted = layerBounds[0] - shiftFromEdge;//
01876   double xBound2Shifted = layerBounds[1] - shiftFromEdge;//
01877   double lineSlope = (yUp - yDown)/(xBound2Shifted-xBound1Shifted);
01878   double lineConst = yUp - lineSlope*xBound2Shifted;
01879   double yBorder =  lineSlope*abs(localPos.x()) + lineConst;
01880       
01881   //bool withinChamberOnly = false;// false = "good region"; true - boundaries only
01882   std::vector <float> deadZoneCenter(6);
01883   float cutZone = shiftFromDeadZone;//cm
01884   //---- hardcoded... not good
01885   if(station>1 && station<5){
01886     if(2==ring){
01887       deadZoneCenter[0]= -162.48 ;
01888       deadZoneCenter[1] = -81.8744;
01889       deadZoneCenter[2] = -21.18165;
01890       deadZoneCenter[3] = 39.51105;
01891       deadZoneCenter[4] = 100.2939;
01892       deadZoneCenter[5] = 160.58;
01893       
01894       if(localPos.y() >yBorder &&
01895          ((localPos.y()> deadZoneCenter[0] + cutZone && localPos.y()< deadZoneCenter[1] - cutZone) ||
01896           (localPos.y()> deadZoneCenter[1] + cutZone && localPos.y()< deadZoneCenter[2] - cutZone) ||
01897           (localPos.y()> deadZoneCenter[2] + cutZone && localPos.y()< deadZoneCenter[3] - cutZone) ||
01898           (localPos.y()> deadZoneCenter[3] + cutZone && localPos.y()< deadZoneCenter[4] - cutZone) ||
01899           (localPos.y()> deadZoneCenter[4] + cutZone && localPos.y()< deadZoneCenter[5] - cutZone))){
01900         pass = true;
01901       }
01902     }
01903     else if(1==ring){
01904       if(2==station){
01905         deadZoneCenter[0]= -95.80 ;
01906         deadZoneCenter[1] = -27.47;
01907         deadZoneCenter[2] = 33.67;
01908         deadZoneCenter[3] = 90.85;
01909         }
01910       else if(3==station){
01911         deadZoneCenter[0]= -89.305 ;
01912         deadZoneCenter[1] = -39.705;
01913         deadZoneCenter[2] = 20.195;
01914         deadZoneCenter[3] = 77.395;
01915       }
01916       else if(4==station){
01917         deadZoneCenter[0]= -75.645;
01918         deadZoneCenter[1] = -26.055;
01919         deadZoneCenter[2] = 23.855;
01920         deadZoneCenter[3] = 70.575;
01921       }
01922       if(localPos.y() >yBorder &&
01923          ((localPos.y()> deadZoneCenter[0] + cutZone && localPos.y()< deadZoneCenter[1] - cutZone) ||
01924           (localPos.y()> deadZoneCenter[1] + cutZone && localPos.y()< deadZoneCenter[2] - cutZone) ||
01925           (localPos.y()> deadZoneCenter[2] + cutZone && localPos.y()< deadZoneCenter[3] - cutZone))){
01926         pass = true;
01927       }
01928     }
01929   }
01930   else if(1==station){
01931     if(3==ring){
01932       deadZoneCenter[0]= -83.155 ;
01933       deadZoneCenter[1] = -22.7401;
01934       deadZoneCenter[2] = 27.86665;
01935       deadZoneCenter[3] = 81.005;
01936       if(localPos.y() > yBorder &&
01937          ((localPos.y()> deadZoneCenter[0] + cutZone && localPos.y()< deadZoneCenter[1] - cutZone) ||
01938           (localPos.y()> deadZoneCenter[1] + cutZone && localPos.y()< deadZoneCenter[2] - cutZone) ||
01939           (localPos.y()> deadZoneCenter[2] + cutZone && localPos.y()< deadZoneCenter[3] - cutZone))){
01940         pass = true;
01941       }
01942     }
01943     else if(2==ring){
01944       deadZoneCenter[0]= -86.285 ;
01945       deadZoneCenter[1] = -32.88305;
01946       deadZoneCenter[2] = 32.867423;
01947       deadZoneCenter[3] = 88.205;
01948       if(localPos.y() > (yBorder) &&
01949          ((localPos.y()> deadZoneCenter[0] + cutZone && localPos.y()< deadZoneCenter[1] - cutZone) ||
01950           (localPos.y()> deadZoneCenter[1] + cutZone && localPos.y()< deadZoneCenter[2] - cutZone) ||
01951           (localPos.y()> deadZoneCenter[2] + cutZone && localPos.y()< deadZoneCenter[3] - cutZone))){
01952         pass = true;
01953       }
01954     }
01955     else{
01956       deadZoneCenter[0]= -81.0;
01957       deadZoneCenter[1] = 81.0;
01958       if(localPos.y() > (yBorder) &&
01959          (localPos.y()> deadZoneCenter[0] + cutZone && localPos.y()< deadZoneCenter[1] - cutZone )){
01960         pass = true;
01961       }
01962     }
01963   }
01964   return pass;
01965 }
01966 
01967 
01968 int CSCOfflineMonitor::typeIndex(CSCDetId id, int flag){
01969   
01970   if (flag == 1){
01971     // linearlized index bases on endcap, station, and ring
01972     int index = 0;
01973     if (id.station() == 1) index = id.ring();
01974     else index = id.station()*2 + id.ring();
01975     if (id.endcap() == 1) index = index + 10;
01976     if (id.endcap() == 2) index = 11 - index;
01977     return index;
01978   }
01979 
01980   else if (flag == 2){
01981     int index = 0;
01982     if (id.station() == 1 && id.ring() != 4) index = id.ring()+1;
01983     if (id.station() == 1 && id.ring() == 4) index = 1; 
01984     if (id.station() != 1) index = id.station()*2 + id.ring();
01985     if (id.endcap() == 1) index = index + 10;
01986     if (id.endcap() == 2) index = 11 - index;
01987     return index;
01988   }
01989 
01990   else return 0;
01991 
01992 }
01993 
01994 int CSCOfflineMonitor::chamberSerial( CSCDetId id ) {
01995   int st = id.station();
01996   int ri = id.ring();
01997   int ch = id.chamber();
01998   int ec = id.endcap();
01999   int kSerial = ch;
02000   if (st == 1 && ri == 1) kSerial = ch;
02001   if (st == 1 && ri == 2) kSerial = ch + 36;
02002   if (st == 1 && ri == 3) kSerial = ch + 72;
02003   if (st == 1 && ri == 4) kSerial = ch;
02004   if (st == 2 && ri == 1) kSerial = ch + 108;
02005   if (st == 2 && ri == 2) kSerial = ch + 126;
02006   if (st == 3 && ri == 1) kSerial = ch + 162;
02007   if (st == 3 && ri == 2) kSerial = ch + 180;
02008   if (st == 4 && ri == 1) kSerial = ch + 216;
02009   if (st == 4 && ri == 2) kSerial = ch + 234;  // one day...
02010   if (ec == 2) kSerial = kSerial + 300;
02011   return kSerial;
02012 }
02013 
02014 
02015 void CSCOfflineMonitor::applyCSClabels( MonitorElement* me ) {
02016   if (me != NULL)
02017    {
02018       me->setAxisTitle("Chamber #");
02019       me->setBinLabel(1,"ME -4/2",2);
02020       me->setBinLabel(2,"ME -4/1",2);
02021       me->setBinLabel(3,"ME -3/2",2);
02022       me->setBinLabel(4,"ME -3/1",2);
02023       me->setBinLabel(5,"ME -2/2",2);
02024       me->setBinLabel(6,"ME -2/1",2);
02025       me->setBinLabel(7,"ME -1/3",2);
02026       me->setBinLabel(8,"ME -1/2",2);
02027       me->setBinLabel(9,"ME -1/1b",2);
02028       me->setBinLabel(10,"ME -1/1a",2);
02029       me->setBinLabel(11,"ME +1/1a",2);
02030       me->setBinLabel(12,"ME +1/1b",2);
02031       me->setBinLabel(13,"ME +1/2",2);
02032       me->setBinLabel(14,"ME +1/3",2);
02033       me->setBinLabel(15,"ME +2/1",2);
02034       me->setBinLabel(16,"ME +2/2",2);
02035       me->setBinLabel(17,"ME +3/1",2);
02036       me->setBinLabel(18,"ME +3/2",2);
02037       me->setBinLabel(19,"ME +4/1",2);
02038       me->setBinLabel(20,"ME +4/2",2);
02039    }
02040 }
02041 
02042 DEFINE_FWK_MODULE(CSCOfflineMonitor);
02043