Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-05-10 03:53:07

0001 // -*- C++ -*-
0002 //
0003 // Package:    CosmicTrackTool/CosmicRateAnalyzer
0004 // Class:      CosmicRateAnalyzer
0005 //
0006 /**\class CosmicRateAnalyzer CosmicRateAnalyzer.cc CosmicTrackTool/CosmicRateAnalyzer/plugins/CosmicRateAnalyzer.cc
0007 
0008  Description :
0009   This Analyzer creates tuple, having necessary infromation for Cosmic Track Rate and Event Rate calculations.
0010   Tuples created by this analyzer also have some kinematic information. This tuple is input to some offline
0011   macros that make Rate plots and Kinematical plots.
0012 
0013 Implementation : Documentation for running this tool is described in twiki :
0014 https://twiki.cern.ch/twiki/bin/view/CMS/TkAlCosmicsRateMonitoring
0015 
0016 */
0017 // Originally created:  Justyna Magdalena Tomaszewska,,,
0018 // Revisited by: Ashutosh Bhardwaj and Kirti Ranjan
0019 // Further Developed by: Sumit Keshri (sumit.keshri@cern.ch) & Saumya (saumya.saumya@cern.ch)
0020 //
0021 //         Created:  Sat, 30 May 2015 20:14:35 GMT
0022 //
0023 
0024 // system include files
0025 #include <memory>
0026 
0027 // user include files
0028 #include "FWCore/Framework/interface/Frameworkfwd.h"
0029 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0030 #include "FWCore/Framework/interface/Event.h"
0031 #include "FWCore/Framework/interface/Run.h"
0032 #include "FWCore/Framework/interface/MakerMacros.h"
0033 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0034 #include "DataFormats/Common/interface/Handle.h"
0035 #include "FWCore/Framework/interface/ESHandle.h"
0036 #include "FWCore/ServiceRegistry/interface/Service.h"
0037 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0038 
0039 #include "DataFormats/TrackReco/interface/Track.h"
0040 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0041 #include "DataFormats/TrackingRecHit/interface/TrackingRecHit.h"
0042 
0043 #include "DataFormats/MuonReco/interface/Muon.h"
0044 #include "DataFormats/MuonReco/interface/MuonFwd.h"
0045 #include "DataFormats/PatCandidates/interface/Muon.h"
0046 
0047 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0048 #include "CondFormats/SiStripObjects/interface/SiStripLatency.h"
0049 #include "CondFormats/DataRecord/interface/SiStripCondDataRecords.h"
0050 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0051 
0052 #include "DataFormats/Provenance/interface/Timestamp.h"
0053 
0054 #include "DataFormats/DetId/interface/DetId.h"
0055 #include "DataFormats/SiStripDetId/interface/SiStripDetId.h"
0056 #include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
0057 
0058 #include "MagneticField/Engine/interface/MagneticField.h"
0059 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
0060 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
0061 #include "DataFormats/SiStripCluster/interface/SiStripCluster.h"
0062 #include "DataFormats/Common/interface/DetSetVectorNew.h"
0063 #include "DataFormats/Common/interface/DetSetVector.h"
0064 
0065 #include <vector>
0066 #include <string>
0067 #include <iostream>
0068 #include <fstream>
0069 #include <iomanip>
0070 #include <TTree.h>
0071 
0072 //
0073 // class declaration
0074 //
0075 class CosmicRateAnalyzer : public edm::one::EDAnalyzer<edm::one::WatchRuns, edm::one::SharedResources> {
0076 public:
0077   explicit CosmicRateAnalyzer(const edm::ParameterSet&);
0078   ~CosmicRateAnalyzer() override;
0079 
0080   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0081 
0082 private:
0083   void beginJob() override;
0084   void analyze(const edm::Event&, const edm::EventSetup&) override;
0085   void endJob() override;
0086 
0087   void beginRun(edm::Run const&, edm::EventSetup const&) override;
0088   void endRun(edm::Run const&, edm::EventSetup const&) override;
0089 
0090   static double stampToReal(edm::Timestamp time) { return time.unixTime() + time.microsecondOffset() * 1e-6; }
0091   void ClearInEventLoop();
0092   void ClearInEndRun();
0093   // ----------member data ---------------------------
0094   const edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> magFieldToken_;
0095   const edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> topoToken_;
0096   const edm::ESGetToken<SiStripLatency, SiStripLatencyRcd> latencyToken_;
0097   edm::EDGetTokenT<reco::TrackCollection> trackTags_;
0098   edm::EDGetTokenT<edmNew::DetSetVector<SiStripCluster> > clustercollectionToken_;
0099   edm::EDGetTokenT<reco::MuonCollection> muonTags_;
0100   edm::RunNumber_t lastrunnum;
0101   double lastruntime, magField;
0102   edm::Service<TFileService> fs;
0103 
0104   unsigned int DetectorID;
0105   TTree* treeEvent;
0106   TTree* treeRun;
0107   TTree* treeCluster;
0108 
0109   //---------  Temporary varibles to store the values till the Run tree is filled  ------//
0110   // a) For track rates
0111   int events;
0112   int track_BPIX;
0113   int track_FPIX;
0114   int track_PIXEL;
0115   int track_TEC;
0116   int track_TECM;
0117   int track_TECP;
0118   int track_TOB;
0119   int track_TIB;
0120   int track_TID;
0121   int track_TIDM;
0122   int track_TIDP;
0123 
0124   // b) For PIXEL Hit Rates by layers
0125   int hit_Total;
0126   int hit_PIX;
0127   int hit_BPIX;
0128   int hit_BPIX_layer1;
0129   int hit_BPIX_layer2;
0130   int hit_BPIX_layer3;
0131   int hit_BPIX_layer4;
0132   int hit_FPIX;
0133   int hit_FPIX_disk1;
0134   int hit_FPIX_disk2;
0135   int hit_FPIX_disk3;
0136   int hit_FPIX_disk1_plus;
0137   int hit_FPIX_disk2_plus;
0138   int hit_FPIX_disk3_plus;
0139   int hit_FPIX_disk1_minus;
0140   int hit_FPIX_disk2_minus;
0141   int hit_FPIX_disk3_minus;
0142 
0143   std::vector<int> v_ntrk;
0144   int ntrk;
0145   int ntrk_runnum;
0146 
0147   //---------- Branch Variables in tree Run ----------//
0148   // a) Track Rate
0149   int number_of_tracks;
0150   int number_of_tracks_PIX;
0151   int number_of_tracks_FPIX;
0152   int number_of_tracks_BPIX;
0153   int number_of_tracks_TEC;
0154   int number_of_tracks_TECP;
0155   int number_of_tracks_TECM;
0156   int number_of_tracks_TOB;
0157   int number_of_tracks_TIB;
0158   int number_of_tracks_TID;
0159   int number_of_tracks_TIDP;
0160   int number_of_tracks_TIDM;
0161   int number_of_events;
0162   edm::RunNumber_t runnum;
0163   double run_time;
0164 
0165   // b) For Hit Rate per PIXEL layer
0166   int number_of_hits_Total;
0167   int number_of_hits_PIX;
0168   int number_of_hits_BPIX;
0169   int number_of_hits_BPIX_layer1;
0170   int number_of_hits_BPIX_layer2;
0171   int number_of_hits_BPIX_layer3;
0172   int number_of_hits_BPIX_layer4;
0173   int number_of_hits_FPIX;
0174   int number_of_hits_FPIX_disk1;
0175   int number_of_hits_FPIX_disk2;
0176   int number_of_hits_FPIX_disk3;
0177   int number_of_hits_FPIX_disk1_plus;
0178   int number_of_hits_FPIX_disk2_plus;
0179   int number_of_hits_FPIX_disk3_plus;
0180   int number_of_hits_FPIX_disk1_minus;
0181   int number_of_hits_FPIX_disk2_minus;
0182   int number_of_hits_FPIX_disk3_minus;
0183 
0184   //---------- Branch Variables in tree Event: Track parameters ----------//
0185   std::vector<double> pt;
0186   std::vector<double> charge;
0187   std::vector<double> chi2;
0188   std::vector<double> chi2_ndof;
0189   std::vector<double> eta;
0190   std::vector<double> theta;
0191   std::vector<double> phi;
0192   std::vector<double> p;
0193   std::vector<double> d0;
0194   std::vector<double> dz;
0195   std::vector<double> nvh;
0196   std::vector<double> DTtime;
0197   std::vector<int> nh_PIXEL;
0198   std::vector<int> nh_BPIX;
0199   std::vector<int> nh_FPIX;
0200   std::vector<int> nh_TIB;
0201   std::vector<int> nh_TOB;
0202   std::vector<int> nh_TID;
0203   std::vector<int> nh_TEC;
0204 
0205   //------ Temporary variables to store Hits per track till the Event tree is filled -------//
0206   //FPIX+/-, BPIX+/-,TEC+/-, TID+/- can also be added similar way in case required
0207   int nHits_PIXEL;
0208 
0209   //------ Variables to keep track of total events and tracks ------//
0210   int nTotalTracks, nTotalEvents;
0211 };
0212 
0213 //
0214 // constants, enums and typedefs
0215 //
0216 
0217 //
0218 // static data member definitions
0219 //
0220 
0221 //
0222 // constructors and destructor
0223 //
0224 CosmicRateAnalyzer::CosmicRateAnalyzer(const edm::ParameterSet& iConfig)
0225     : magFieldToken_(esConsumes()),
0226       topoToken_(esConsumes()),
0227       latencyToken_(esConsumes()),
0228       trackTags_(consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("tracksInputTag"))),
0229       clustercollectionToken_(
0230           consumes<edmNew::DetSetVector<SiStripCluster> >(iConfig.getParameter<edm::InputTag>("tracksInputTag"))),
0231       muonTags_(consumes<reco::MuonCollection>(iConfig.getParameter<edm::InputTag>("muonsInputTag"))) {
0232   //now do what ever initialization is needed
0233   //
0234   usesResource(TFileService::kSharedResource);
0235   treeEvent = fs->make<TTree>("Event", "");
0236   treeRun = fs->make<TTree>("Run", "");
0237   treeCluster = fs->make<TTree>("Cluster", "");
0238 
0239   nTotalTracks = 0;
0240   nTotalEvents = 0;
0241 }
0242 
0243 CosmicRateAnalyzer::~CosmicRateAnalyzer() {
0244   // do anything here that needs to be done at desctruction time
0245   // (e.g. close files, deallocate resources etc.)
0246 }
0247 
0248 //
0249 // member functions
0250 //
0251 void CosmicRateAnalyzer::ClearInEventLoop() {
0252   pt.clear();
0253   charge.clear();
0254   chi2.clear();
0255   chi2_ndof.clear();
0256   eta.clear();
0257   theta.clear();
0258   phi.clear();
0259   p.clear();
0260   d0.clear();
0261   dz.clear();
0262   nvh.clear();
0263   DTtime.clear();
0264   nh_PIXEL.clear();
0265   nh_BPIX.clear();
0266   nh_FPIX.clear();
0267   nh_TIB.clear();
0268   nh_TOB.clear();
0269   nh_TID.clear();
0270   nh_TEC.clear();
0271 }
0272 
0273 // ------------ method called for each event  ------------
0274 void CosmicRateAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0275   using namespace edm;
0276 
0277   using reco::TrackCollection;
0278   edm::Handle<reco::TrackCollection> tracks;
0279   iEvent.getByToken(trackTags_, tracks);
0280 
0281   const TrackerTopology* const tTopo = &iSetup.getData(topoToken_);
0282   const MagneticField* magneticField = &iSetup.getData(magFieldToken_);
0283   magField = magneticField->inTesla(GlobalPoint(0, 0, 0)).mag();
0284   //const SiStripLatency* apvlat = &iSetup.getData(latencyToken_); // unused (for the moment)
0285 
0286   edm::Timestamp ts_begin = iEvent.getRun().beginTime();
0287   double t_begin = stampToReal(ts_begin);
0288   edm::Timestamp ts_end = iEvent.getRun().endTime();
0289   double t_end = stampToReal(ts_end);
0290 
0291   lastruntime = t_end - t_begin;
0292   lastrunnum = iEvent.getRun().run();
0293 
0294   if (!tracks->empty())
0295     v_ntrk.push_back(tracks->size());
0296 
0297   ntrk = 0;
0298   for (TrackCollection::const_iterator itTrack1 = tracks->begin(); itTrack1 != tracks->end(); ++itTrack1) {
0299     pt.push_back(itTrack1->pt());
0300     charge.push_back(itTrack1->charge());
0301     chi2.push_back(itTrack1->chi2());
0302     chi2_ndof.push_back(itTrack1->normalizedChi2());
0303     eta.push_back(itTrack1->eta());
0304     theta.push_back(itTrack1->theta());
0305     phi.push_back(itTrack1->phi());
0306     p.push_back(itTrack1->p());
0307     d0.push_back(itTrack1->d0());
0308     dz.push_back(itTrack1->dz());
0309     nvh.push_back(itTrack1->numberOfValidHits());
0310     nh_BPIX.push_back(itTrack1->hitPattern().numberOfValidPixelBarrelHits());
0311     nh_FPIX.push_back(itTrack1->hitPattern().numberOfValidPixelEndcapHits());
0312     nh_TIB.push_back(itTrack1->hitPattern().numberOfValidStripTIBHits());
0313     nh_TOB.push_back(itTrack1->hitPattern().numberOfValidStripTOBHits());
0314     nh_TID.push_back(itTrack1->hitPattern().numberOfValidStripTIDHits());
0315     nh_TEC.push_back(itTrack1->hitPattern().numberOfValidStripTECHits());
0316 
0317     nHits_PIXEL = 0;
0318 
0319     int nhitinBPIX = 0;
0320     int nhitinFPIX = 0;
0321     int nhitinPIXEL = 0;
0322     int nhitinTEC = 0;
0323     int nhitinTOB = 0;
0324     int nhitinTIB = 0;
0325     int nhitinTID = 0;
0326     int nhitinTECminus = 0;
0327     int nhitinTECplus = 0;
0328     int nhitinTIDminus = 0;
0329     int nhitinTIDplus = 0;
0330 
0331     for (auto const& hit1 : itTrack1->recHits()) {
0332       const DetId detId1(hit1->geographicalId());
0333       const int subdetId1 = detId1.subdetId();
0334       uint32_t detid_db = detId1.rawId();
0335       if (!hit1->isValid())
0336         continue;  // only real hits count as in itTrack1->numberOfValidHits()
0337       hit_Total++;
0338 
0339       ///////////////////////////////////////////////////////////////////////////////////////////////////
0340       //             Hit information in PixelBarrel                                  //
0341       ///////////////////////////////////////////////////////////////////////////////////////////////////
0342       if (PixelSubdetector::PixelBarrel == subdetId1) {
0343         ++nhitinBPIX;   //for cosmic track rate evaluation
0344         ++nhitinPIXEL;  //for cosmic track rate evaluation
0345         ++nHits_PIXEL;  // for PIXEL hits per track in Event Tree
0346         ++hit_PIX;      // for cosmic PIXEL hit rates per layer
0347         ++hit_BPIX;     // for cosmic PIXEL hit rates per layer
0348 
0349         int BPIX_layer = (tTopo->pxbLayer(detid_db));
0350         if (BPIX_layer == 1) {
0351           ++hit_BPIX_layer1;  // for cosmic PIXEL hit rates per layer
0352         } else if (BPIX_layer == 2) {
0353           ++hit_BPIX_layer2;  // for cosmic PIXEL hit rates per layer
0354         } else if (BPIX_layer == 3) {
0355           ++hit_BPIX_layer3;  // for cosmic PIXEL hit rates per layer
0356         } else if (BPIX_layer == 4) {
0357           ++hit_BPIX_layer4;  // for cosmic PIXEL hit rates per layer
0358         } else {
0359           std::cout << "CAUTION : Check Phase! BPIX layer not in {1,2,3}!" << std::endl;
0360           std::cout << "Layer is : " << BPIX_layer << std::endl;
0361         }
0362 
0363       }
0364       ///////////////////////////////////////////////////////////////////////////////////////////////////
0365       //            Hit information in PixelEndcap                                      //
0366       //////////////////////////////////////////////////////////////////////////////////////////////////
0367       else if (PixelSubdetector::PixelEndcap == subdetId1) {
0368         ++nhitinFPIX;
0369         ++nhitinPIXEL;
0370 
0371         ++nHits_PIXEL;
0372         ++hit_PIX;   // for cosmic PIXEL hit rates per layer
0373         ++hit_FPIX;  // for cosmic PIXEL hit rates per layer
0374 
0375         int FPIX_side = (tTopo->pxfSide(detid_db));
0376         int FPIX_disk = (tTopo->pxfDisk(detid_db));
0377 
0378         if (FPIX_disk == 1) {
0379           ++hit_FPIX_disk1;  // for cosmic PIXEL hit rates per layer
0380         } else if (FPIX_disk == 2) {
0381           ++hit_FPIX_disk2;  // for cosmic PIXEL hit rates per layer
0382         } else if (FPIX_disk == 3) {
0383           ++hit_FPIX_disk3;  // for cosmic PIXEL hit rates per layer
0384         } else {
0385           std::cout << "CAUTION : Check Phase! FPIX disk not in {1,2}!" << std::endl;
0386           std::cout << "Disk is : " << FPIX_disk << std::endl;
0387         }
0388 
0389         if (FPIX_disk == 1 && FPIX_side == 1) {
0390           ++hit_FPIX_disk1_minus;  // for cosmic PIXEL hit rates per layer
0391         } else if (FPIX_disk == 1 && FPIX_side == 2) {
0392           ++hit_FPIX_disk1_plus;  // for cosmic PIXEL hit rates per layer
0393         } else if (FPIX_disk == 2 && FPIX_side == 1) {
0394           ++hit_FPIX_disk2_minus;  // for cosmic PIXEL hit rates per layer
0395         } else if (FPIX_disk == 2 && FPIX_side == 2) {
0396           ++hit_FPIX_disk2_plus;  // for cosmic PIXEL hit rates per layer
0397         } else if (FPIX_disk == 3 && FPIX_side == 1) {
0398           ++hit_FPIX_disk3_minus;  // for cosmic PIXEL hit rates per layer
0399         } else if (FPIX_disk == 3 && FPIX_side == 2) {
0400           ++hit_FPIX_disk3_plus;  // for cosmic PIXEL hit rates per layer
0401         } else {
0402           std::cout << "CAUTION : FPIX side not in {1,2}!" << std::endl;
0403         }
0404 
0405       }
0406       //////////////////////////////////////////////////////////////////////////////////////////////////
0407       //            Hit information in TEC                          //
0408       //////////////////////////////////////////////////////////////////////////////////////////////////
0409       else if (SiStripDetId::TEC == subdetId1) {
0410         ++nhitinTEC;
0411 
0412         if (tTopo->tecIsZMinusSide(detId1)) {
0413           ++nhitinTECminus;
0414         } else {
0415           ++nhitinTECplus;
0416         }
0417       }
0418       //////////////////////////////////////////////////////////////////////////////////////////////////
0419       //            Hit information in TOB                                      //
0420       /////////////////////////////////////////////////////////////////////////////////////////////////
0421       else if (SiStripDetId::TOB == subdetId1) {
0422         ++nhitinTOB;
0423       }
0424       //////////////////////////////////////////////////////////////////////////////////////////////////
0425       //            Hit information in TIB                                          //
0426       /////////////////////////////////////////////////////////////////////////////////////////////////
0427       else if (SiStripDetId::TIB == subdetId1) {
0428         ++nhitinTIB;
0429       }
0430       //////////////////////////////////////////////////////////////////////////////////////////////////
0431       //            Hit information in TID                                          //
0432       /////////////////////////////////////////////////////////////////////////////////////////////////
0433       else if (SiStripDetId::TID == subdetId1) {
0434         ++nhitinTID;
0435 
0436         if (tTopo->tidIsZMinusSide(detId1)) {
0437           ++nhitinTIDminus;
0438         } else {
0439           ++nhitinTIDplus;
0440         }
0441       }
0442 
0443     }  // for Loop over Hits
0444 
0445     nh_PIXEL.push_back(nHits_PIXEL);
0446 
0447     if (nhitinBPIX > 0) {
0448       track_BPIX++;
0449     }
0450     if (nhitinFPIX > 0) {
0451       track_FPIX++;
0452     }
0453     if (nhitinPIXEL > 0) {
0454       track_PIXEL++;
0455     }
0456     if (nhitinTEC > 0) {
0457       track_TEC++;
0458     }
0459     if (nhitinTECminus > 0) {
0460       track_TECM++;
0461     }
0462     if (nhitinTECplus > 0) {
0463       track_TECP++;
0464     }
0465     if (nhitinTOB > 0) {
0466       track_TOB++;
0467     }
0468     if (nhitinTIB > 0) {
0469       track_TIB++;
0470     }
0471     if (nhitinTID > 0) {
0472       track_TID++;
0473     }
0474     if (nhitinTIDminus > 0) {
0475       track_TIDM++;
0476     }
0477     if (nhitinTIDplus > 0) {
0478       track_TIDP++;
0479     }
0480 
0481     ntrk++;
0482     ntrk_runnum++;
0483     nTotalTracks++;
0484   }  // for Loop over TrackCollection
0485   events++;
0486 
0487   Handle<edmNew::DetSetVector<SiStripCluster> > cluster;
0488   iEvent.getByToken(clustercollectionToken_, cluster);
0489 
0490   for (edmNew::DetSetVector<SiStripCluster>::const_iterator det = cluster->begin(); det != cluster->end(); ++det) {
0491     DetectorID = (det->detId());
0492     treeCluster->Fill();
0493   }
0494 
0495   edm::Handle<reco::MuonCollection> muH;
0496   iEvent.getByToken(muonTags_, muH);
0497   const reco::MuonCollection& muonsT0 = *(muH.product());
0498   float time = -9999.;
0499   for (unsigned int i = 0; i < muonsT0.size(); i++) {
0500     //DT time
0501     reco::MuonTime mt0 = muonsT0[i].time();
0502     time = mt0.timeAtIpInOut;
0503     DTtime.push_back(time);
0504   }
0505 
0506   treeEvent->Fill();
0507   ClearInEventLoop();
0508   nTotalEvents++;
0509 
0510 }  //Event Loop
0511 
0512 // ------------ method called once each job just before starting event loop  ------------
0513 void CosmicRateAnalyzer::beginJob() {
0514   //--- Event tree ---//
0515   treeEvent->Branch("pt", &pt);
0516   treeEvent->Branch("charge", &charge);
0517   treeEvent->Branch("chi2", &chi2);
0518   treeEvent->Branch("chi2_ndof", &chi2_ndof);
0519   treeEvent->Branch("eta", &eta);
0520   treeEvent->Branch("theta", &theta);
0521   treeEvent->Branch("phi", &phi);
0522   treeEvent->Branch("p", &p);
0523   treeEvent->Branch("d0", &d0);
0524   treeEvent->Branch("dz", &dz);
0525   treeEvent->Branch("nvh", &nvh);
0526   treeEvent->Branch("ntrk", &ntrk);
0527   treeEvent->Branch("nHitsPIXEL", &nh_PIXEL);
0528   treeEvent->Branch("nHitsBPIX", &nh_BPIX);
0529   treeEvent->Branch("nHitsFPIX", &nh_FPIX);
0530   treeEvent->Branch("nHitsTIB", &nh_TIB);
0531   treeEvent->Branch("nHitsTOB", &nh_TOB);
0532   treeEvent->Branch("nHitsTID", &nh_TID);
0533   treeEvent->Branch("nHitsTEC", &nh_TEC);
0534   treeEvent->Branch("DTtime", &DTtime);
0535   treeEvent->Branch("magField", &magField);
0536 
0537   //--- Run tree ---//
0538   treeRun->Branch("run_time", &run_time);
0539   treeRun->Branch("runnum", &runnum);
0540   // a) For track Rate Calculation
0541   treeRun->Branch("number_of_events", &number_of_events);
0542   treeRun->Branch("number_of_tracks", &number_of_tracks);
0543   treeRun->Branch("number_of_tracks_PIX", &number_of_tracks_PIX);
0544   treeRun->Branch("number_of_tracks_FPIX", &number_of_tracks_FPIX);
0545   treeRun->Branch("number_of_tracks_BPIX", &number_of_tracks_BPIX);
0546   treeRun->Branch("number_of_tracks_TID", &number_of_tracks_TID);
0547   treeRun->Branch("number_of_tracks_TIDM", &number_of_tracks_TIDM);
0548   treeRun->Branch("number_of_tracks_TIDP", &number_of_tracks_TIDP);
0549   treeRun->Branch("number_of_tracks_TIB", &number_of_tracks_TIB);
0550   treeRun->Branch("number_of_tracks_TEC", &number_of_tracks_TEC);
0551   treeRun->Branch("number_of_tracks_TECP", &number_of_tracks_TECP);
0552   treeRun->Branch("number_of_tracks_TECM", &number_of_tracks_TECM);
0553   treeRun->Branch("number_of_tracks_TOB", &number_of_tracks_TOB);
0554   // a) For PIXEL Hit Rate Calculation
0555   treeRun->Branch("number_of_hits_Total", &number_of_hits_Total);
0556   treeRun->Branch("number_of_hits_PIX", &number_of_hits_PIX);
0557   treeRun->Branch("number_of_hits_BPIX", &number_of_hits_BPIX);
0558   treeRun->Branch("number_of_hits_BPIX_layer1", &number_of_hits_BPIX_layer1);
0559   treeRun->Branch("number_of_hits_BPIX_layer2", &number_of_hits_BPIX_layer2);
0560   treeRun->Branch("number_of_hits_BPIX_layer3", &number_of_hits_BPIX_layer3);
0561   treeRun->Branch("number_of_hits_BPIX_layer4", &number_of_hits_BPIX_layer4);
0562   treeRun->Branch("number_of_hits_FPIX", &number_of_hits_FPIX);
0563   treeRun->Branch("number_of_hits_FPIX_disk1", &number_of_hits_FPIX_disk1);
0564   treeRun->Branch("number_of_hits_FPIX_disk2", &number_of_hits_FPIX_disk2);
0565   treeRun->Branch("number_of_hits_FPIX_disk3", &number_of_hits_FPIX_disk3);
0566   treeRun->Branch("number_of_hits_FPIX_disk1_plus", &number_of_hits_FPIX_disk1_plus);
0567   treeRun->Branch("number_of_hits_FPIX_disk1_minus", &number_of_hits_FPIX_disk1_minus);
0568   treeRun->Branch("number_of_hits_FPIX_disk2_plus", &number_of_hits_FPIX_disk2_plus);
0569   treeRun->Branch("number_of_hits_FPIX_disk2_minus", &number_of_hits_FPIX_disk2_minus);
0570   treeRun->Branch("number_of_hits_FPIX_disk3_plus", &number_of_hits_FPIX_disk3_plus);
0571   treeRun->Branch("number_of_hits_FPIX_disk3_minus", &number_of_hits_FPIX_disk3_minus);
0572 
0573   //--- Cluster tree ---//
0574   treeCluster->Branch("DetID", &DetectorID);
0575 }
0576 
0577 // ------------ method called once each job just after ending the event loop  ------------
0578 void CosmicRateAnalyzer::endJob() {
0579   std::cout << "Total Events: " << nTotalEvents << std::endl;
0580   std::cout << "TotalTracks: " << nTotalTracks << std::endl;
0581 }
0582 
0583 // ------------ method called when starting to processes a run  ------------
0584 void CosmicRateAnalyzer::beginRun(edm::Run const&, edm::EventSetup const&) {
0585   lastruntime = 0.0;
0586   lastrunnum = 0.0;
0587   ntrk_runnum = 0.0;
0588   events = 0.0;
0589   // a) for Track rate
0590   track_BPIX = 0.0;
0591   track_FPIX = 0.0;
0592   track_PIXEL = 0.0;
0593   track_TEC = 0.0;
0594   track_TECM = 0.0;
0595   track_TECP = 0.0;
0596   track_TOB = 0.0;
0597   track_TIB = 0.0;
0598   track_TID = 0.0;
0599   track_TIDM = 0.0;
0600   track_TIDP = 0.0;
0601 
0602   // b) for PIXEL hit rate
0603   hit_Total = 0.0;
0604   hit_PIX = 0.0;
0605   hit_BPIX = 0.0;
0606   hit_BPIX_layer1 = 0.0;
0607   hit_BPIX_layer2 = 0.0;
0608   hit_BPIX_layer3 = 0.0;
0609   hit_BPIX_layer4 = 0.0;
0610   hit_FPIX = 0.0;
0611   hit_FPIX_disk1 = 0.0;
0612   hit_FPIX_disk2 = 0.0;
0613   hit_FPIX_disk3 = 0.0;
0614   hit_FPIX_disk1_plus = 0.0;
0615   hit_FPIX_disk1_minus = 0.0;
0616   hit_FPIX_disk2_plus = 0.0;
0617   hit_FPIX_disk2_minus = 0.0;
0618   hit_FPIX_disk3_plus = 0.0;
0619   hit_FPIX_disk3_minus = 0.0;
0620 }
0621 
0622 // ------------ method called when ending the processing of a run  ------------
0623 
0624 void CosmicRateAnalyzer::endRun(edm::Run const&, edm::EventSetup const&) {
0625   number_of_tracks = ntrk_runnum;
0626   run_time = lastruntime;
0627   runnum = lastrunnum;
0628   // a) for Track Rate
0629   number_of_tracks_PIX = track_PIXEL;
0630   number_of_tracks_FPIX = track_FPIX;
0631   number_of_tracks_BPIX = track_BPIX;
0632   number_of_tracks_TEC = track_TEC;
0633   number_of_tracks_TECM = track_TECM;
0634   number_of_tracks_TECP = track_TECP;
0635   number_of_tracks_TOB = track_TOB;
0636   number_of_tracks_TIB = track_TIB;
0637   number_of_tracks_TID = track_TID;
0638   number_of_tracks_TIDM = track_TIDM;
0639   number_of_tracks_TIDP = track_TIDP;
0640   number_of_events = events;
0641   // b) for PIXEL Hit Rate
0642   number_of_hits_Total = hit_Total;
0643   number_of_hits_PIX = hit_PIX;
0644   number_of_hits_BPIX = hit_BPIX;
0645   number_of_hits_BPIX_layer1 = hit_BPIX_layer1;
0646   number_of_hits_BPIX_layer2 = hit_BPIX_layer2;
0647   number_of_hits_BPIX_layer3 = hit_BPIX_layer3;
0648   number_of_hits_BPIX_layer4 = hit_BPIX_layer4;
0649   number_of_hits_FPIX = hit_FPIX;
0650   number_of_hits_FPIX_disk1 = hit_FPIX_disk1;
0651   number_of_hits_FPIX_disk2 = hit_FPIX_disk2;
0652   number_of_hits_FPIX_disk3 = hit_FPIX_disk3;
0653   number_of_hits_FPIX_disk1_plus = hit_FPIX_disk1_plus;
0654   number_of_hits_FPIX_disk1_minus = hit_FPIX_disk1_minus;
0655   number_of_hits_FPIX_disk2_plus = hit_FPIX_disk2_plus;
0656   number_of_hits_FPIX_disk2_minus = hit_FPIX_disk2_minus;
0657   number_of_hits_FPIX_disk3_plus = hit_FPIX_disk3_plus;
0658   number_of_hits_FPIX_disk3_minus = hit_FPIX_disk3_minus;
0659 
0660   treeRun->Fill();
0661 }
0662 
0663 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0664 void CosmicRateAnalyzer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0665   edm::ParameterSetDescription desc;
0666   desc.setComment("Create tuple with all variables required to calculate cosmic event and track rates.");
0667   desc.add<edm::InputTag>("tracksInputTag", edm::InputTag("ALCARECOTkAlCosmicsCTF0T"));
0668   desc.add<edm::InputTag>("muonsInputTag", edm::InputTag("muons1Leg"));
0669   descriptions.add("cosmicRateAnalyzer", desc);
0670 }
0671 
0672 //define this as a plug-in
0673 DEFINE_FWK_MODULE(CosmicRateAnalyzer);