00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "DQM/DTMonitorModule/src/DTLocalTriggerLutTask.h"
00011
00012
00013 #include "FWCore/Framework/interface/EventSetup.h"
00014
00015
00016 #include "DataFormats/L1DTTrackFinder/interface/L1MuDTChambPhContainer.h"
00017 #include "DQM/DTMonitorModule/interface/DTTrigGeomUtils.h"
00018
00019
00020 #include "DataFormats/GeometryVector/interface/Pi.h"
00021 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00022 #include "Geometry/DTGeometry/interface/DTGeometry.h"
00023 #include "Geometry/DTGeometry/interface/DTLayer.h"
00024 #include "Geometry/DTGeometry/interface/DTTopology.h"
00025
00026
00027 #include"TH1.h"
00028 #include"TAxis.h"
00029
00030 #include <sstream>
00031 #include <iostream>
00032 #include <math.h>
00033
00034
00035 using namespace edm;
00036 using namespace std;
00037
00038 DTLocalTriggerLutTask::DTLocalTriggerLutTask(const edm::ParameterSet& ps) : trigGeomUtils(0) {
00039
00040 LogTrace("DTDQM|DTMonitorModule|DTLocalTriggerLutTask") << "[DTLocalTriggerLutTask]: Constructor"<<endl;
00041
00042 dccInputTag = ps.getUntrackedParameter<InputTag>("inputTagDCC");
00043 segInputTag = ps.getUntrackedParameter<InputTag>("inputTagSEG");
00044
00045 overUnderIn = ps.getUntrackedParameter<bool>("rebinOutFlowsInGraph");
00046 detailedAnalysis = ps.getUntrackedParameter<bool>("detailedAnalysis");
00047 theGeomLabel = ps.getUntrackedParameter<string>("geomLabel");
00048
00049 if (detailedAnalysis){
00050 nPhiBins = 401;
00051 rangePhi = 10.025;
00052 nPhibBins = 401;
00053 rangePhiB = 10.025;
00054 } else {
00055 nPhiBins = 51;
00056 rangePhi = 5.1;
00057 nPhibBins = 51;
00058 rangePhiB = 10.2;
00059 }
00060
00061 baseFolder = "DT/03-LocalTrigger-DCC/";
00062 parameters = ps;
00063 dbe = edm::Service<DQMStore>().operator->();
00064
00065 }
00066
00067
00068 DTLocalTriggerLutTask::~DTLocalTriggerLutTask() {
00069
00070 LogTrace("DTDQM|DTMonitorModule|DTLocalTriggerLutTask") << "[DTLocalTriggerLutTask]: analyzed " << nEvents << " events" << endl;
00071 if (trigGeomUtils) { delete trigGeomUtils; }
00072
00073 }
00074
00075
00076 void DTLocalTriggerLutTask::beginJob(){
00077
00078 LogTrace("DTDQM|DTMonitorModule|DTLocalTriggerLutTask") << "[DTLocalTriggerLutTask]: BeginJob" << endl;
00079 nEvents = 0;
00080 nLumis = 0;
00081
00082 }
00083
00084 void DTLocalTriggerLutTask::bookHistos(DTChamberId chId) {
00085
00086 stringstream wheel; wheel << chId.wheel();
00087 stringstream sector; sector << chId.sector();
00088 stringstream station; station << chId.station();
00089
00090 dbe->setCurrentFolder(topFolder() + "Wheel" + wheel.str() + "/Sector" + sector.str() +
00091 "/Station" + station.str() + "/Segment");
00092
00093 string chTag = "_W" + wheel.str() + "_Sec" + sector.str() + "_St" + station.str();
00094 std::map<std::string, MonitorElement*> &chambMap = chHistos[chId.rawId()];
00095
00096 string hName = "DCC_PhiResidual";
00097 chambMap[hName] = dbe->book1D(hName+chTag,"Trigger local position - Segment local position (correlated triggers)",nPhiBins,-rangePhi,rangePhi);
00098 hName = "DCC_PhibResidual";
00099 chambMap[hName] =dbe->book1D(hName+chTag,"Trigger local direction - Segment local direction (correlated triggers)",nPhibBins,-rangePhiB,rangePhiB);
00100
00101 if (detailedAnalysis) {
00102
00103 hName = "DCC_PhitkvsPhitrig";
00104 chambMap[hName] = dbe->book2D(hName+chTag,"Local position: segment vs trigger",100,-500.,500.,100,-500.,500.);
00105 hName = "DCC_PhibtkvsPhibtrig";
00106 chambMap[hName] =dbe->book2D(hName+chTag,"Local direction : segment vs trigger",200,-40.,40.,200,-40.,40.);
00107 hName = "DCC_PhibResidualvsTkPos";
00108 chambMap[hName] =dbe->book2D(hName+chTag,"Local direction residual vs Segment Position",100,-500.,500.,200,-10.,10.);
00109 hName = "DCC_PhiResidualvsTkPos";
00110 chambMap[hName] =dbe->book2D(hName+chTag,"Local Position residual vs Segment Position",100,-500.,500.,200,-10.,10.);
00111
00112 }
00113
00114 }
00115
00116
00117
00118 void DTLocalTriggerLutTask::beginRun(const edm::Run& run, const edm::EventSetup& context) {
00119
00120 LogTrace("DTDQM|DTMonitorModule|DTLocalTriggerLutTask") << "[DTLocalTriggerLutTask]: BeginRun" << endl;
00121
00122 context.get<MuonGeometryRecord>().get(theGeomLabel,muonGeom);
00123 trigGeomUtils = new DTTrigGeomUtils(muonGeom);
00124
00125 std::vector<DTChamber*>::const_iterator chambIt = muonGeom->chambers().begin();
00126 std::vector<DTChamber*>::const_iterator chambEnd = muonGeom->chambers().end();
00127
00128 for (; chambIt!=chambEnd; ++chambIt)
00129 bookHistos((*chambIt)->id());
00130
00131 }
00132
00133
00134 void DTLocalTriggerLutTask::beginLuminosityBlock(const LuminosityBlock& lumiSeg, const EventSetup& context) {
00135
00136 nLumis++;
00137 LogTrace("DTDQM|DTMonitorModule|DTLocalTriggerLutTask") << "[DTLocalTriggerLutTask]: Begin of LS transition" << endl;
00138
00139 if(nLumis%parameters.getUntrackedParameter<int>("ResetCycle") == 0) {
00140
00141 LogTrace("DTDQM|DTMonitorModule|DTLocalTriggerLutTask") << "[DTLocalTriggerLutTask]: Cleaning histos" << endl;
00142 map<uint32_t, map<string, MonitorElement*> > ::const_iterator chambIt = chHistos.begin();
00143 map<uint32_t, map<string, MonitorElement*> > ::const_iterator chambEnd = chHistos.end();
00144
00145 for(; chambIt!=chambEnd; ++chambIt) {
00146 map<string, MonitorElement*> ::const_iterator histoIt = chambIt->second.begin();
00147 map<string, MonitorElement*> ::const_iterator histoEnd = chambIt->second.end();
00148 for(; histoIt!=histoEnd; ++ histoIt) {
00149 histoIt->second->Reset();
00150 }
00151 }
00152
00153 }
00154
00155 }
00156
00157
00158 void DTLocalTriggerLutTask::endJob(){
00159
00160 LogVerbatim("DTDQM|DTMonitorModule|DTLocalTriggerLutTask") << "[DTLocalTriggerLutTask]: analyzed " << nEvents << " events" << endl;
00161 dbe->rmdir(topFolder());
00162
00163 }
00164
00165
00166 void DTLocalTriggerLutTask::analyze(const edm::Event& e, const edm::EventSetup& c){
00167
00168 nEvents++;
00169
00170 edm::Handle<L1MuDTChambPhContainer> trigHandle;
00171 e.getByLabel(dccInputTag,trigHandle);
00172 vector<L1MuDTChambPhDigi>* trigs = trigHandle->getContainer();
00173 searchDccBest(trigs);
00174
00175 Handle<DTRecSegment4DCollection> segments4D;
00176 e.getByLabel(segInputTag,segments4D);
00177 DTRecSegment4DCollection::id_iterator chamberId;
00178
00179
00180 vector<const DTRecSegment4D*> best4DSegments;
00181
00182 for (chamberId = segments4D->id_begin(); chamberId != segments4D->id_end(); ++chamberId){
00183
00184 DTRecSegment4DCollection::range rangeInCh = segments4D->get(*chamberId);
00185 DTRecSegment4DCollection::const_iterator trackIt = rangeInCh.first;
00186 DTRecSegment4DCollection::const_iterator trackEnd = rangeInCh.second;
00187
00188 const DTRecSegment4D* tmpBest = 0;
00189 int tmpdof = 0;
00190 int dof = 0;
00191
00192 for (; trackIt!=trackEnd; ++trackIt){
00193
00194 if(trackIt->hasPhi()) {
00195 dof = trackIt->phiSegment()->degreesOfFreedom();
00196 if (dof>tmpdof) {
00197 tmpBest = &(*trackIt);
00198 tmpdof = dof;
00199 }
00200 }
00201
00202 }
00203
00204 if (tmpBest) best4DSegments.push_back(tmpBest);
00205
00206 }
00207
00208 vector<const DTRecSegment4D*>::const_iterator bestTrackIt = best4DSegments.begin();
00209 vector<const DTRecSegment4D*>::const_iterator bestTrackEnd = best4DSegments.end();
00210
00211 for (; bestTrackIt!=bestTrackEnd; ++bestTrackIt) {
00212
00213 if((*bestTrackIt)->hasPhi()) {
00214
00215 DTChamberId chId = (*bestTrackIt)->chamberId();
00216 int nHitsPhi = (*bestTrackIt)->phiSegment()->degreesOfFreedom()+2;
00217
00218 int wheel = chId.wheel();
00219 int station = chId.station();
00220 int scsector = 0;
00221 float trackPosPhi, trackPosEta, trackDirPhi, trackDirEta;
00222 trigGeomUtils->computeSCCoordinates((*bestTrackIt),scsector,trackPosPhi,trackDirPhi,trackPosEta,trackDirEta);
00223
00224 map<string, MonitorElement*> &chMap = chHistos[chId.rawId()];
00225
00226 if (trigQualBest[wheel+3][station][scsector] > 3 &&
00227 trigQualBest[wheel+3][station][scsector] < 7 &&
00228 nHitsPhi>=7 ) {
00229
00230 float trigPos = trigGeomUtils->trigPos(trigBest[wheel+3][station][scsector]);
00231 float trigDir = trigGeomUtils->trigDir(trigBest[wheel+3][station][scsector]);
00232 trigGeomUtils->trigToSeg(station,trigPos,trackDirPhi);
00233
00234 double deltaPos = trigPos-trackPosPhi;
00235 deltaPos = overUnderIn ? max(min(deltaPos,rangePhi-0.01),-rangePhi+0.01) : deltaPos;
00236 double deltaDir = trigDir-trackDirPhi;
00237 deltaDir = overUnderIn ? max(min(deltaDir,rangePhiB-0.01),-rangePhiB+0.01) : deltaDir;
00238 chMap.find("DCC_PhiResidual")->second->Fill(deltaPos);
00239 chMap.find("DCC_PhibResidual")->second->Fill(deltaDir);
00240
00241 if (detailedAnalysis){
00242 chMap.find("DCC_PhitkvsPhitrig")->second->Fill(trigPos,trackPosPhi);
00243 chMap.find("DCC_PhibtkvsPhibtrig")->second->Fill(trigDir,trackDirPhi);
00244 chMap.find("DCC_PhibResidualvsTkPos")->second->Fill(trackPosPhi,trigDir-trackDirPhi);
00245 chMap.find("DCC_PhiResidualvsTkPos")->second->Fill(trackPosPhi,trigPos-trackPosPhi);
00246 }
00247
00248 }
00249
00250 }
00251 }
00252
00253 }
00254
00255 void DTLocalTriggerLutTask::searchDccBest( std::vector<L1MuDTChambPhDigi>* trigs ){
00256
00257 string histoType ;
00258 string histoTag ;
00259
00260
00261
00262 for (int st=0;st<=4;++st)
00263 for (int wh=0;wh<=5;++wh)
00264 for (int sec=0;sec<=12;++sec)
00265 trigQualBest[wh][st][sec] = -1;
00266
00267 vector<L1MuDTChambPhDigi>::const_iterator trigIt = trigs->begin();
00268 vector<L1MuDTChambPhDigi>::const_iterator trigEnd = trigs->end();
00269 for(; trigIt!=trigEnd; ++trigIt) {
00270
00271 int wh = trigIt->whNum();
00272 int sec = trigIt->scNum() + 1;
00273 int st = trigIt->stNum();
00274 int qual = trigIt->code();
00275
00276 if(qual>trigQualBest[wh+3][st][sec] && qual<7) {
00277 trigQualBest[wh+3][st][sec]=qual;
00278 trigBest[wh+3][st][sec] = &(*trigIt);
00279 }
00280
00281 }
00282 }