Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "DTVDriftSegmentCalibration.h"
00011
00012 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00013 #include "FWCore/Framework/interface/EventSetup.h"
00014 #include "FWCore/Framework/interface/Event.h"
00015 #include "FWCore/Framework/interface/ESHandle.h"
00016 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00017 #include "FWCore/Utilities/interface/InputTag.h"
00018
00019 #include "Geometry/DTGeometry/interface/DTGeometry.h"
00020 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00021 #include "DataFormats/DTRecHit/interface/DTRecSegment4DCollection.h"
00022 #include "CondFormats/DTObjects/interface/DTMtime.h"
00023
00024 #include "CalibMuon/DTCalibration/interface/DTCalibDBUtils.h"
00025 #include "CalibMuon/DTCalibration/interface/DTSegmentSelector.h"
00026
00027 #include <string>
00028 #include <sstream>
00029 #include "TFile.h"
00030 #include "TH1F.h"
00031 #include "TH2F.h"
00032
00033 using namespace std;
00034 using namespace edm;
00035
00036 DTVDriftSegmentCalibration::DTVDriftSegmentCalibration(const ParameterSet& pset):
00037 select_(pset),
00038 theRecHits4DLabel_(pset.getParameter<InputTag>("recHits4DLabel")),
00039
00040 theCalibChamber_(pset.getUntrackedParameter<string>("calibChamber", "All")) {
00041
00042 LogVerbatim("Calibration") << "[DTVDriftSegmentCalibration] Constructor called!";
00043
00044
00045 string rootFileName = pset.getUntrackedParameter<string>("rootFileName","DTVDriftHistos.root");
00046 rootFile_ = new TFile(rootFileName.c_str(), "RECREATE");
00047 rootFile_->cd();
00048 }
00049
00050 void DTVDriftSegmentCalibration::beginJob(){
00051 TH1::SetDefaultSumw2(true);
00052 }
00053
00054 void DTVDriftSegmentCalibration::beginRun(const edm::Run& run, const edm::EventSetup& setup) {}
00055
00056 DTVDriftSegmentCalibration::~DTVDriftSegmentCalibration(){
00057 rootFile_->Close();
00058 LogVerbatim("Calibration") << "[DTVDriftSegmentCalibration] Destructor called!";
00059 }
00060
00061 void DTVDriftSegmentCalibration::analyze(const Event & event, const EventSetup& eventSetup) {
00062 rootFile_->cd();
00063
00064
00065 ESHandle<DTGeometry> dtGeom;
00066 eventSetup.get<MuonGeometryRecord>().get(dtGeom);
00067
00068
00069 Handle<DTRecSegment4DCollection> all4DSegments;
00070 event.getByLabel(theRecHits4DLabel_, all4DSegments);
00071
00072 DTChamberId chosenChamberId;
00073 if(theCalibChamber_ != "All") {
00074 stringstream linestr;
00075 int selWheel, selStation, selSector;
00076 linestr << theCalibChamber_;
00077 linestr >> selWheel >> selStation >> selSector;
00078 chosenChamberId = DTChamberId(selWheel, selStation, selSector);
00079 LogVerbatim("Calibration") << " Chosen chamber: " << chosenChamberId << endl;
00080 }
00081
00082 DTRecSegment4DCollection::id_iterator chamberIdIt;
00083 for(chamberIdIt = all4DSegments->id_begin(); chamberIdIt != all4DSegments->id_end(); ++chamberIdIt){
00084
00085
00086 if((theCalibChamber_ != "All") && ((*chamberIdIt) != chosenChamberId)) continue;
00087
00088
00089 if(theVDriftHistoMapTH1F_.find(*chamberIdIt) == theVDriftHistoMapTH1F_.end()){
00090 LogTrace("Calibration") << " Booking histos for Chamber: " << *chamberIdIt;
00091 bookHistos(*chamberIdIt);
00092 }
00093
00094
00095 const DTChamber* chamber = dtGeom->chamber(*chamberIdIt);
00096
00097 DTRecSegment4DCollection::range range = all4DSegments->get((*chamberIdIt));
00098
00099 for(DTRecSegment4DCollection::const_iterator segment = range.first;
00100 segment != range.second; ++segment){
00101
00102
00103 LogTrace("Calibration") << "Segment local pos (in chamber RF): " << (*segment).localPosition()
00104 << "\nSegment global pos: " << chamber->toGlobal((*segment).localPosition());
00105
00106 if( !select_(*segment, event, eventSetup) ) continue;
00107
00108
00109 if( (*segment).hasPhi() ) {
00110
00111 double segmentVDrift = segment->phiSegment()->vDrift();
00112 if( segmentVDrift != 0.00 ){
00113 (theVDriftHistoMapTH1F_[*chamberIdIt])[0]->Fill(segmentVDrift);
00114 (theVDriftHistoMapTH2F_[*chamberIdIt])[0]->Fill(segment->localPosition().x(),segmentVDrift);
00115 (theVDriftHistoMapTH2F_[*chamberIdIt])[1]->Fill(segment->localPosition().y(),segmentVDrift);
00116 }
00117 }
00118
00119 if( (*segment).hasZed() ){
00120
00121 double segmentVDrift = segment->zSegment()->vDrift();
00122 if( segmentVDrift != 0.00 ){
00123 (theVDriftHistoMapTH1F_[*chamberIdIt])[1]->Fill(segmentVDrift);
00124 }
00125 }
00126 }
00127 }
00128 }
00129
00130 void DTVDriftSegmentCalibration::endJob() {
00131 rootFile_->cd();
00132
00133 LogVerbatim("Calibration") << "[DTVDriftSegmentCalibration] Writing histos to file!" << endl;
00134
00135 for(ChamberHistosMapTH1F::const_iterator itChHistos = theVDriftHistoMapTH1F_.begin(); itChHistos != theVDriftHistoMapTH1F_.end(); ++itChHistos){
00136 vector<TH1F*>::const_iterator itHistTH1F = (*itChHistos).second.begin();
00137 vector<TH1F*>::const_iterator itHistTH1F_end = (*itChHistos).second.end();
00138 for(; itHistTH1F != itHistTH1F_end; ++itHistTH1F) (*itHistTH1F)->Write();
00139
00140 vector<TH2F*>::const_iterator itHistTH2F = theVDriftHistoMapTH2F_[(*itChHistos).first].begin();
00141 vector<TH2F*>::const_iterator itHistTH2F_end = theVDriftHistoMapTH2F_[(*itChHistos).first].end();
00142 for(; itHistTH2F != itHistTH2F_end; ++itHistTH2F) (*itHistTH2F)->Write();
00143 }
00144
00145
00146
00147
00148 }
00149
00150
00151 void DTVDriftSegmentCalibration::bookHistos(DTChamberId chId) {
00152
00153
00154 stringstream wheel; wheel << chId.wheel();
00155 stringstream station; station << chId.station();
00156 stringstream sector; sector << chId.sector();
00157
00158 string chHistoName =
00159 "_W" + wheel.str() +
00160 "_St" + station.str() +
00161 "_Sec" + sector.str();
00162
00163 vector<TH1F*> histosTH1F;
00164 histosTH1F.push_back(new TH1F(("hRPhiVDriftCorr" + chHistoName).c_str(), "v-drift corr. from Phi segments", 200, -0.4, 0.4));
00165 if(chId.station() != 4) histosTH1F.push_back(new TH1F(("hRZVDriftCorr" + chHistoName).c_str(), "v-drift corr. from Z segments", 200, -0.4, 0.4));
00166
00167 vector<TH2F*> histosTH2F;
00168 histosTH2F.push_back(new TH2F(("hRPhiVDriftCorrVsSegmPosX" + chHistoName).c_str(), "v-drift corr. vs. segment x position", 250, -125., 125., 200, -0.4, 0.4));
00169 histosTH2F.push_back(new TH2F(("hRPhiVDriftCorrVsSegmPosY" + chHistoName).c_str(), "v-drift corr. vs. segment y position", 250, -125., 125., 200, -0.4, 0.4));
00170
00171
00172 theVDriftHistoMapTH1F_[chId] = histosTH1F;
00173 theVDriftHistoMapTH2F_[chId] = histosTH2F;
00174 }