File indexing completed on 2024-04-06 11:56:28
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0012 #include "DataFormats/DetId/interface/DetId.h"
0013 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
0014 #include "FWCore/Framework/interface/ESHandle.h"
0015 #include "FWCore/Framework/interface/Event.h"
0016 #include "FWCore/Framework/interface/EventSetup.h"
0017 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0018 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0019 #include "FWCore/Utilities/interface/EDMException.h"
0020 #include "FWCore/Utilities/interface/Exception.h"
0021 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
0022 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0023 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0024 #include "SimDataFormats/TrackingHit/interface/PSimHit.h"
0025 #include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
0026
0027
0028 #include "TH1.h"
0029 #include "TH2.h"
0030 #include "TFile.h"
0031
0032
0033 #include <iostream>
0034
0035 class SimAnalyzer : public edm::one::EDAnalyzer<> {
0036 public:
0037
0038 explicit SimAnalyzer(edm::ParameterSet const &theConf);
0039
0040 ~SimAnalyzer();
0041
0042
0043 virtual void analyze(edm::Event const &theEvent, edm::EventSetup const &theSetup);
0044
0045 virtual void beginJob();
0046
0047 private:
0048
0049 double angle(double theAngle);
0050
0051 void closeRootFile();
0052
0053 void initHistograms();
0054
0055
0056 void trackerStatistics(edm::Event const &theEvent, edm::EventSetup const &theSetup);
0057
0058 private:
0059 const edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> tkGeomToken_;
0060 int theEvents;
0061 int theDebugLevel;
0062 double theSearchPhiTIB;
0063 double theSearchPhiTOB;
0064 double theSearchPhiTEC;
0065 double theSearchZTIB;
0066 double theSearchZTOB;
0067
0068
0069 TFile *theFile;
0070 int theCompression;
0071 std::string theFileName;
0072
0073
0074 TH1D *theBarrelSimHitsX;
0075 TH1D *theBarrelSimHitsY;
0076 TH1D *theBarrelSimHitsZ;
0077 TH2D *theBarrelSimHitsYvsX;
0078 TH2D *theBarrelSimHitsXvsZ;
0079 TH2D *theBarrelSimHitsYvsZ;
0080 TH2D *theBarrelSimHitsRvsZ;
0081 TH2D *theBarrelSimHitsPhivsX;
0082 TH2D *theBarrelSimHitsPhivsY;
0083 TH2D *theBarrelSimHitsPhivsZ;
0084
0085
0086 TH1D *theEndcapSimHitsX;
0087 TH1D *theEndcapSimHitsY;
0088 TH1D *theEndcapSimHitsZ;
0089 TH2D *theEndcapSimHitsYvsX;
0090 TH2D *theEndcapSimHitsXvsZ;
0091 TH2D *theEndcapSimHitsYvsZ;
0092 TH2D *theEndcapSimHitsRvsZ;
0093 TH2D *theEndcapSimHitsPhivsX;
0094 TH2D *theEndcapSimHitsPhivsY;
0095 TH2D *theEndcapSimHitsPhivsZ;
0096
0097
0098 TH2D *theSimHitsRvsZ;
0099 TH2D *theSimHitsPhivsZ;
0100 };
0101
0102 SimAnalyzer::SimAnalyzer(edm::ParameterSet const &theConf)
0103 : tkGeomToken_(esConsumes()),
0104 theEvents(0),
0105 theDebugLevel(theConf.getUntrackedParameter<int>("DebugLevel", 0)),
0106 theSearchPhiTIB(theConf.getUntrackedParameter<double>("SearchWindowPhiTIB", 0.05)),
0107 theSearchPhiTOB(theConf.getUntrackedParameter<double>("SearchWindowPhiTOB", 0.05)),
0108 theSearchPhiTEC(theConf.getUntrackedParameter<double>("SearchWindowPhiTEC", 0.05)),
0109 theSearchZTIB(theConf.getUntrackedParameter<double>("SearchWindowZTIB", 1.0)),
0110 theSearchZTOB(theConf.getUntrackedParameter<double>("SearchWindowZTOB", 1.0)),
0111 theFile(),
0112 theCompression(theConf.getUntrackedParameter<int>("ROOTFileCompression", 1)),
0113 theFileName(theConf.getUntrackedParameter<std::string>("ROOTFileName", "test.root")),
0114 theBarrelSimHitsX(0),
0115 theBarrelSimHitsY(0),
0116 theBarrelSimHitsZ(0),
0117 theBarrelSimHitsYvsX(0),
0118 theBarrelSimHitsXvsZ(0),
0119 theBarrelSimHitsYvsZ(0),
0120 theBarrelSimHitsRvsZ(0),
0121 theBarrelSimHitsPhivsX(0),
0122 theBarrelSimHitsPhivsY(0),
0123 theBarrelSimHitsPhivsZ(0),
0124
0125 theEndcapSimHitsX(0),
0126 theEndcapSimHitsY(0),
0127 theEndcapSimHitsZ(0),
0128 theEndcapSimHitsYvsX(0),
0129 theEndcapSimHitsXvsZ(0),
0130 theEndcapSimHitsYvsZ(0),
0131 theEndcapSimHitsRvsZ(0),
0132 theEndcapSimHitsPhivsX(0),
0133 theEndcapSimHitsPhivsY(0),
0134 theEndcapSimHitsPhivsZ(0),
0135
0136 theSimHitsRvsZ(0),
0137 theSimHitsPhivsZ(0) {
0138
0139 edm::LogInfo("SimAnalyzer") << "==========================================================="
0140 << "=== Start configuration ==="
0141 << " theDebugLevel = " << theDebugLevel
0142 << " theSearchPhiTIB = " << theSearchPhiTIB
0143 << " theSearchPhiTOB = " << theSearchPhiTOB
0144 << " theSearchPhiTEC = " << theSearchPhiTEC
0145 << " theSearchZTIB = " << theSearchZTIB
0146 << " theSearchZTOB = " << theSearchZTOB
0147 << " ROOT filename = " << theFileName
0148 << " compression = " << theCompression
0149 << "===========================================================";
0150 }
0151
0152 SimAnalyzer::~SimAnalyzer() {
0153 if (theFile != 0) {
0154
0155 closeRootFile();
0156
0157 delete theFile;
0158 }
0159 }
0160
0161 void SimAnalyzer::analyze(edm::Event const &theEvent, edm::EventSetup const &theSetup) {
0162 LogDebug("SimAnalyzer") << "==========================================================="
0163 << " Private analysis of event #" << theEvent.id().event() << " in run #"
0164 << theEvent.id().run();
0165
0166
0167
0168
0169 theEvents++;
0170
0171 LogDebug("SimAnalyzer") << " Total Event number = " << theEvents;
0172
0173
0174 trackerStatistics(theEvent, theSetup);
0175
0176 LogDebug("SimAnalyzer") << "===========================================================";
0177 }
0178
0179 void SimAnalyzer::beginJob() {
0180 LogDebug("SimAnalyzer") << "==========================================================="
0181 << "=== Start beginJob() ==="
0182 << " creating a CMS Root Tree ...";
0183
0184 theFile = new TFile(theFileName.c_str(), "RECREATE", "CMS ROOT file");
0185
0186
0187 if (theFile) {
0188 theFile->SetCompressionLevel(theCompression);
0189 this->initHistograms();
0190 } else {
0191 throw edm::Exception(edm::errors::LogicError,
0192 "<SimAnalyzer::initSetup()>: ERROR!!! something wrong "
0193 "with the RootFile");
0194 }
0195
0196 LogDebug("SimAnalyzer") << "=== Done beginJob() ==="
0197 << "===========================================================";
0198 }
0199
0200 double SimAnalyzer::angle(double theAngle) { return theAngle += (theAngle >= 0.0) ? 0.0 : 2.0 * M_PI; }
0201
0202 void SimAnalyzer::closeRootFile() {
0203 LogDebug("SimAnalyzer") << " writing all information into a file ";
0204
0205 theFile->Write();
0206 }
0207
0208 void SimAnalyzer::initHistograms() {
0209 LogDebug("SimAnalyzer") << " Start of initialisation monitor histograms ...";
0210
0211
0212 TDirectory *SimHitDir = theFile->mkdir("SimHits");
0213 TDirectory *BarrelDir = SimHitDir->mkdir("Barrel");
0214 TDirectory *EndcapDir = SimHitDir->mkdir("Endcap");
0215
0216
0217 theBarrelSimHitsX = new TH1D("BarrelSimHitsX", "X Position of the SimHits", 200, -100.0, 100.0);
0218 theBarrelSimHitsX->SetDirectory(BarrelDir);
0219 theBarrelSimHitsX->Sumw2();
0220
0221 theBarrelSimHitsY = new TH1D("BarrelSimHitsY", "Y Position of the SimHits", 200, -100.0, 100.0);
0222 theBarrelSimHitsY->SetDirectory(BarrelDir);
0223 theBarrelSimHitsY->Sumw2();
0224
0225 theBarrelSimHitsZ = new TH1D("BarrelSimHitsZ", "Z Position of the SimHits", 240, -120.0, 120.0);
0226 theBarrelSimHitsZ->SetDirectory(BarrelDir);
0227 theBarrelSimHitsZ->Sumw2();
0228
0229 theBarrelSimHitsYvsX =
0230 new TH2D("BarrelSimHitsYvsX", "Y vs X Position of the SimHits", 200, -100.0, 100.0, 200, -100.0, 100.0);
0231 theBarrelSimHitsYvsX->SetDirectory(BarrelDir);
0232 theBarrelSimHitsYvsX->Sumw2();
0233
0234 theBarrelSimHitsXvsZ =
0235 new TH2D("BarrelSimHitsXvsZ", "X vs Z Position of the SimHits", 240, -120.0, 120.0, 200, -100.0, 100.0);
0236 theBarrelSimHitsXvsZ->SetDirectory(BarrelDir);
0237 theBarrelSimHitsXvsZ->Sumw2();
0238
0239 theBarrelSimHitsYvsZ =
0240 new TH2D("BarrelSimHitsYvsZ", "Y vs Z Position of the SimHits", 240, -120.0, 120.0, 200, -100.0, 100.0);
0241 theBarrelSimHitsYvsZ->SetDirectory(BarrelDir);
0242 theBarrelSimHitsYvsZ->Sumw2();
0243
0244 theBarrelSimHitsRvsZ =
0245 new TH2D("BarrelSimHitsRvsZ", "R vs Z Position of the SimHits", 240, -120.0, 120.0, 130, 0.0, 65.0);
0246 theBarrelSimHitsRvsZ->SetDirectory(BarrelDir);
0247 theBarrelSimHitsRvsZ->Sumw2();
0248
0249 theBarrelSimHitsPhivsX =
0250 new TH2D("BarrelSimHitsPhivsX", "Phi [rad] vs X Position of the SimHits", 200, -100.0, 100.0, 70, 0.0, 7.0);
0251 theBarrelSimHitsPhivsX->SetDirectory(BarrelDir);
0252 theBarrelSimHitsPhivsX->Sumw2();
0253
0254 theBarrelSimHitsPhivsY =
0255 new TH2D("BarrelSimHitsPhivsY", "Phi [rad] vs Y Position of the SimHits", 200, -100.0, 100.0, 70, 0.0, 7.0);
0256 theBarrelSimHitsPhivsY->SetDirectory(BarrelDir);
0257 theBarrelSimHitsPhivsY->Sumw2();
0258
0259 theBarrelSimHitsPhivsZ =
0260 new TH2D("BarrelSimHitsPhivsZ", "Phi [rad] vs Z Position of the SimHits", 240, -120.0, 120.0, 70, 0.0, 7.0);
0261 theBarrelSimHitsPhivsZ->SetDirectory(BarrelDir);
0262 theBarrelSimHitsPhivsZ->Sumw2();
0263
0264
0265 theEndcapSimHitsX = new TH1D("EndcapSimHitsX", "X Position of the SimHits", 200, -100.0, 100.0);
0266 theEndcapSimHitsX->SetDirectory(EndcapDir);
0267 theEndcapSimHitsX->Sumw2();
0268
0269 theEndcapSimHitsY = new TH1D("EndcapSimHitsY", "Y Position of the SimHits", 200, -100.0, 100.0);
0270 theEndcapSimHitsY->SetDirectory(EndcapDir);
0271 theEndcapSimHitsY->Sumw2();
0272
0273 theEndcapSimHitsZ = new TH1D("EndcapSimHitsZ", "Z Position of the SimHits", 600, -300.0, 300.0);
0274 theEndcapSimHitsZ->SetDirectory(EndcapDir);
0275 theEndcapSimHitsZ->Sumw2();
0276
0277 theEndcapSimHitsYvsX =
0278 new TH2D("EndcapSimHitsYvsX", "Y vs X Position of the SimHits", 200, -100.0, 100.0, 200, -100.0, 100.0);
0279 theEndcapSimHitsYvsX->SetDirectory(EndcapDir);
0280 theEndcapSimHitsYvsX->Sumw2();
0281
0282 theEndcapSimHitsXvsZ =
0283 new TH2D("EndcapSimHitsXvsZ", "X vs Z Position of the SimHits", 600, -300.0, 300.0, 200, -100.0, 100.0);
0284 theEndcapSimHitsXvsZ->SetDirectory(EndcapDir);
0285 theEndcapSimHitsXvsZ->Sumw2();
0286
0287 theEndcapSimHitsYvsZ =
0288 new TH2D("EndcapSimHitsYvsZ", "Y vs Z Position of the SimHits", 600, -300.0, 300.0, 200, -100.0, 100.0);
0289 theEndcapSimHitsYvsZ->SetDirectory(EndcapDir);
0290 theEndcapSimHitsYvsZ->Sumw2();
0291
0292 theEndcapSimHitsRvsZ =
0293 new TH2D("EndcapSimHitsRvsZ", "R vs Z Position of the SimHits", 600, -300.0, 300.0, 1000, 0.0, 100.0);
0294 theEndcapSimHitsRvsZ->SetDirectory(EndcapDir);
0295 theEndcapSimHitsRvsZ->Sumw2();
0296
0297 theEndcapSimHitsPhivsX =
0298 new TH2D("EndcapSimHitsPhivsX", "Phi [rad] vs X Positon of the SimHits", 200, -100.0, 100.0, 70, 0.0, 7.0);
0299 theEndcapSimHitsPhivsX->SetDirectory(EndcapDir);
0300 theEndcapSimHitsPhivsX->Sumw2();
0301
0302 theEndcapSimHitsPhivsY =
0303 new TH2D("EndcapSimHitsPhivsY", "Phi [rad] vs Y Position of the SimHits", 200, -100.0, 100.0, 70, 0.0, 7.0);
0304 theEndcapSimHitsPhivsY->SetDirectory(EndcapDir);
0305 theEndcapSimHitsPhivsY->Sumw2();
0306
0307 theEndcapSimHitsPhivsZ =
0308 new TH2D("EndcapSimHitsPhivsZ", "Phi [rad] vs Z Position of the SimHits", 600, -300.0, 300.0, 70, 0.0, 7.0);
0309 theEndcapSimHitsPhivsZ->SetDirectory(EndcapDir);
0310 theEndcapSimHitsPhivsZ->Sumw2();
0311
0312
0313 theSimHitsRvsZ = new TH2D("SimHitsRvsZ", "R vs Z Position of the SimHits", 600, -300.0, 300.0, 1000, 0.0, 100.0);
0314 theSimHitsRvsZ->SetDirectory(SimHitDir);
0315 theSimHitsRvsZ->Sumw2();
0316
0317 theSimHitsPhivsZ =
0318 new TH2D("SimHitsPhivsZ", "Phi [rad] vs Z Position of the SimHits", 600, -300.0, 300.0, 700, 0.0, 7.0);
0319 theSimHitsPhivsZ->SetDirectory(SimHitDir);
0320 theSimHitsPhivsZ->Sumw2();
0321 }
0322
0323 void SimAnalyzer::trackerStatistics(edm::Event const &theEvent, edm::EventSetup const &theSetup) {
0324 LogDebug("SimAnalyzer") << "<SimAnalyzer:t:rackerStatistics(edm::Event "
0325 "const& theEvent): filling the histograms ... ";
0326
0327 int theBarrelHits = 0;
0328 int theEndcapHits = 0;
0329
0330
0331 const TrackerGeometry *theTracker = &theSetup.getData(tkGeomToken_);
0332
0333
0334 TrackingGeometry::DetContainer theDetUnits = theTracker->dets();
0335
0336
0337 std::vector<edm::Handle<edm::PSimHitContainer>> theSimHitContainers;
0338
0339
0340 throw cms::Exception("UnsupportedFunction") << "SimAnalyzer::trackerStatistics: "
0341 << "getManyByType has not been supported by the Framework since 2015. "
0342 << "This module has been broken since then. Maybe it should be deleted. "
0343 << "Another possibility is to upgrade to use GetterOfProducts instead.";
0344
0345 LogDebug("SimAnalyzer") << " Geometry node for TrackingGeometry is " << theTracker << "\n I have "
0346 << theTracker->dets().size() << " detectors "
0347 << "\n I have " << theTracker->detTypes().size() << " types "
0348 << "\n theDetUnits has " << theDetUnits.size() << " dets ";
0349
0350
0351 std::vector<PSimHit> theSimHits;
0352 for (int i = 0; i < int(theSimHitContainers.size()); i++) {
0353 theSimHits.insert(theSimHits.end(), theSimHitContainers.at(i)->begin(), theSimHitContainers.at(i)->end());
0354 }
0355
0356
0357 for (std::vector<PSimHit>::const_iterator iHit = theSimHits.begin(); iHit != theSimHits.end(); iHit++) {
0358
0359 DetId theDetUnitId((*iHit).detUnitId());
0360
0361
0362 const GeomDet *theDet = theTracker->idToDet(theDetUnitId);
0363
0364
0365 std::string thePart = "";
0366
0367 LogDebug("SimAnalyzer:SimHitInfo") << " ============================================================ "
0368 << "\n Some Information for this SimHit: "
0369 << "\n"
0370 << *iHit << "\n GlobalPosition = ("
0371 << theDet->surface().toGlobal((*iHit).localPosition()).x() << ","
0372 << theDet->surface().toGlobal((*iHit).localPosition()).y() << ","
0373 << theDet->surface().toGlobal((*iHit).localPosition()).z() << ") "
0374 << "\n R = " << theDet->surface().toGlobal((*iHit).localPosition()).perp()
0375 << "\n phi = " << theDet->surface().toGlobal((*iHit).localPosition()).phi()
0376 << "\n angle(phi) = "
0377 << angle(theDet->surface().toGlobal((*iHit).localPosition()).phi())
0378 << "\n GlobalDirection = ("
0379 << theDet->surface().toGlobal((*iHit).localDirection()).x() << ","
0380 << theDet->surface().toGlobal((*iHit).localDirection()).y() << ","
0381 << theDet->surface().toGlobal((*iHit).localDirection()).z() << ") "
0382 << "\n Total momentum = " << (*iHit).pabs()
0383 << "\n ParticleType = " << (*iHit).particleType()
0384 << "\n detUnitId = " << (*iHit).detUnitId();
0385
0386
0387 switch (theDetUnitId.subdetId()) {
0388 case StripSubdetector::TIB: {
0389 thePart = "TIB";
0390 break;
0391 }
0392 case StripSubdetector::TOB: {
0393 thePart = "TOB";
0394 break;
0395 }
0396 case StripSubdetector::TEC: {
0397 thePart = "TEC";
0398 break;
0399 }
0400 }
0401
0402 if ((thePart == "TIB") || (thePart == "TOB")) {
0403 theBarrelHits++;
0404
0405
0406 theBarrelSimHitsX->Fill(theDet->surface().toGlobal((*iHit).localPosition()).x());
0407 theBarrelSimHitsY->Fill(theDet->surface().toGlobal((*iHit).localPosition()).y());
0408 theBarrelSimHitsZ->Fill(theDet->surface().toGlobal((*iHit).localPosition()).z());
0409 theBarrelSimHitsYvsX->Fill(theDet->surface().toGlobal((*iHit).localPosition()).x(),
0410 theDet->surface().toGlobal((*iHit).localPosition()).y());
0411 theBarrelSimHitsXvsZ->Fill(theDet->surface().toGlobal((*iHit).localPosition()).z(),
0412 theDet->surface().toGlobal((*iHit).localPosition()).x());
0413 theBarrelSimHitsYvsZ->Fill(theDet->surface().toGlobal((*iHit).localPosition()).z(),
0414 theDet->surface().toGlobal((*iHit).localPosition()).y());
0415 theBarrelSimHitsRvsZ->Fill(theDet->surface().toGlobal((*iHit).localPosition()).z(),
0416 theDet->surface().toGlobal((*iHit).localPosition()).perp());
0417 theBarrelSimHitsPhivsX->Fill(theDet->surface().toGlobal((*iHit).localPosition()).x(),
0418 angle(theDet->surface().toGlobal((*iHit).localPosition()).phi()));
0419 theBarrelSimHitsPhivsY->Fill(theDet->surface().toGlobal((*iHit).localPosition()).y(),
0420 angle(theDet->surface().toGlobal((*iHit).localPosition()).phi()));
0421 theBarrelSimHitsPhivsZ->Fill(theDet->surface().toGlobal((*iHit).localPosition()).z(),
0422 angle(theDet->surface().toGlobal((*iHit).localPosition()).phi()));
0423 } else if (thePart == "TEC") {
0424 theEndcapHits++;
0425
0426
0427 theEndcapSimHitsX->Fill(theDet->surface().toGlobal((*iHit).localPosition()).x());
0428 theEndcapSimHitsY->Fill(theDet->surface().toGlobal((*iHit).localPosition()).y());
0429 theEndcapSimHitsZ->Fill(theDet->surface().toGlobal((*iHit).localPosition()).z());
0430 theEndcapSimHitsYvsX->Fill(theDet->surface().toGlobal((*iHit).localPosition()).x(),
0431 theDet->surface().toGlobal((*iHit).localPosition()).y());
0432 theEndcapSimHitsXvsZ->Fill(theDet->surface().toGlobal((*iHit).localPosition()).z(),
0433 theDet->surface().toGlobal((*iHit).localPosition()).x());
0434 theEndcapSimHitsYvsZ->Fill(theDet->surface().toGlobal((*iHit).localPosition()).z(),
0435 theDet->surface().toGlobal((*iHit).localPosition()).y());
0436 theEndcapSimHitsRvsZ->Fill(theDet->surface().toGlobal((*iHit).localPosition()).z(),
0437 theDet->surface().toGlobal((*iHit).localPosition()).perp());
0438 theEndcapSimHitsPhivsX->Fill(theDet->surface().toGlobal((*iHit).localPosition()).x(),
0439 angle(theDet->surface().toGlobal((*iHit).localPosition()).phi()));
0440 theEndcapSimHitsPhivsY->Fill(theDet->surface().toGlobal((*iHit).localPosition()).y(),
0441 angle(theDet->surface().toGlobal((*iHit).localPosition()).phi()));
0442 theEndcapSimHitsPhivsZ->Fill(theDet->surface().toGlobal((*iHit).localPosition()).z(),
0443 angle(theDet->surface().toGlobal((*iHit).localPosition()).phi()));
0444 }
0445
0446
0447 if ((thePart == "TIB") || (thePart == "TOB") || (thePart == "TEC")) {
0448 theSimHitsRvsZ->Fill(theDet->surface().toGlobal((*iHit).localPosition()).z(),
0449 theDet->surface().toGlobal((*iHit).localPosition()).perp());
0450 theSimHitsPhivsZ->Fill(theDet->surface().toGlobal((*iHit).localPosition()).z(),
0451 angle(theDet->surface().toGlobal((*iHit).localPosition()).phi()));
0452 }
0453
0454 }
0455
0456
0457 edm::LogInfo("SimAnalyzer") << " number of SimHits = " << theBarrelHits << "/" << theEndcapHits
0458 << " (Barrel/Endcap) ";
0459 }
0460
0461 #include "FWCore/Framework/interface/MakerMacros.h"
0462 DEFINE_FWK_MODULE(SimAnalyzer);