Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-15 08:47:19

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     int countHit = 0;
0331 
0332     for (auto const& hit1 : itTrack1->recHits()) {
0333       const DetId detId1(hit1->geographicalId());
0334       const int subdetId1 = detId1.subdetId();
0335       uint32_t detid_db = detId1.rawId();
0336       if (!hit1->isValid())
0337         continue;  // only real hits count as in itTrack1->numberOfValidHits()
0338       hit_Total++;
0339 
0340       ///////////////////////////////////////////////////////////////////////////////////////////////////
0341       //             Hit information in PixelBarrel                                  //
0342       ///////////////////////////////////////////////////////////////////////////////////////////////////
0343       if (PixelSubdetector::PixelBarrel == subdetId1) {
0344         ++nhitinBPIX;   //for cosmic track rate evaluation
0345         ++nhitinPIXEL;  //for cosmic track rate evaluation
0346         ++nHits_PIXEL;  // for PIXEL hits per track in Event Tree
0347         ++hit_PIX;      // for cosmic PIXEL hit rates per layer
0348         ++hit_BPIX;     // for cosmic PIXEL hit rates per layer
0349 
0350         int BPIX_layer = (tTopo->pxbLayer(detid_db));
0351         if (BPIX_layer == 1) {
0352           ++hit_BPIX_layer1;  // for cosmic PIXEL hit rates per layer
0353         } else if (BPIX_layer == 2) {
0354           ++hit_BPIX_layer2;  // for cosmic PIXEL hit rates per layer
0355         } else if (BPIX_layer == 3) {
0356           ++hit_BPIX_layer3;  // for cosmic PIXEL hit rates per layer
0357         } else if (BPIX_layer == 4) {
0358           ++hit_BPIX_layer4;  // for cosmic PIXEL hit rates per layer
0359         } else {
0360           std::cout << "CAUTION : Check Phase! BPIX layer not in {1,2,3}!" << std::endl;
0361           std::cout << "Layer is : " << BPIX_layer << std::endl;
0362         }
0363 
0364       }
0365       ///////////////////////////////////////////////////////////////////////////////////////////////////
0366       //            Hit information in PixelEndcap                                      //
0367       //////////////////////////////////////////////////////////////////////////////////////////////////
0368       else if (PixelSubdetector::PixelEndcap == subdetId1) {
0369         ++nhitinFPIX;
0370         ++nhitinPIXEL;
0371 
0372         ++nHits_PIXEL;
0373         ++hit_PIX;   // for cosmic PIXEL hit rates per layer
0374         ++hit_FPIX;  // for cosmic PIXEL hit rates per layer
0375 
0376         int FPIX_side = (tTopo->pxfSide(detid_db));
0377         int FPIX_disk = (tTopo->pxfDisk(detid_db));
0378 
0379         if (FPIX_disk == 1) {
0380           ++hit_FPIX_disk1;  // for cosmic PIXEL hit rates per layer
0381         } else if (FPIX_disk == 2) {
0382           ++hit_FPIX_disk2;  // for cosmic PIXEL hit rates per layer
0383         } else if (FPIX_disk == 3) {
0384           ++hit_FPIX_disk3;  // for cosmic PIXEL hit rates per layer
0385         } else {
0386           std::cout << "CAUTION : Check Phase! FPIX disk not in {1,2}!" << std::endl;
0387           std::cout << "Disk is : " << FPIX_disk << std::endl;
0388         }
0389 
0390         if (FPIX_disk == 1 && FPIX_side == 1) {
0391           ++hit_FPIX_disk1_minus;  // for cosmic PIXEL hit rates per layer
0392         } else if (FPIX_disk == 1 && FPIX_side == 2) {
0393           ++hit_FPIX_disk1_plus;  // for cosmic PIXEL hit rates per layer
0394         } else if (FPIX_disk == 2 && FPIX_side == 1) {
0395           ++hit_FPIX_disk2_minus;  // for cosmic PIXEL hit rates per layer
0396         } else if (FPIX_disk == 2 && FPIX_side == 2) {
0397           ++hit_FPIX_disk2_plus;  // for cosmic PIXEL hit rates per layer
0398         } else if (FPIX_disk == 3 && FPIX_side == 1) {
0399           ++hit_FPIX_disk3_minus;  // for cosmic PIXEL hit rates per layer
0400         } else if (FPIX_disk == 3 && FPIX_side == 2) {
0401           ++hit_FPIX_disk3_plus;  // for cosmic PIXEL hit rates per layer
0402         } else {
0403           std::cout << "CAUTION : FPIX side not in {1,2}!" << std::endl;
0404         }
0405 
0406       }
0407       //////////////////////////////////////////////////////////////////////////////////////////////////
0408       //            Hit information in TEC                          //
0409       //////////////////////////////////////////////////////////////////////////////////////////////////
0410       else if (SiStripDetId::TEC == subdetId1) {
0411         ++nhitinTEC;
0412 
0413         if (tTopo->tecIsZMinusSide(detId1)) {
0414           ++nhitinTECminus;
0415         } else {
0416           ++nhitinTECplus;
0417         }
0418       }
0419       //////////////////////////////////////////////////////////////////////////////////////////////////
0420       //            Hit information in TOB                                      //
0421       /////////////////////////////////////////////////////////////////////////////////////////////////
0422       else if (SiStripDetId::TOB == subdetId1) {
0423         ++nhitinTOB;
0424       }
0425       //////////////////////////////////////////////////////////////////////////////////////////////////
0426       //            Hit information in TIB                                          //
0427       /////////////////////////////////////////////////////////////////////////////////////////////////
0428       else if (SiStripDetId::TIB == subdetId1) {
0429         ++nhitinTIB;
0430       }
0431       //////////////////////////////////////////////////////////////////////////////////////////////////
0432       //            Hit information in TID                                          //
0433       /////////////////////////////////////////////////////////////////////////////////////////////////
0434       else if (SiStripDetId::TID == subdetId1) {
0435         ++nhitinTID;
0436 
0437         if (tTopo->tidIsZMinusSide(detId1)) {
0438           ++nhitinTIDminus;
0439         } else {
0440           ++nhitinTIDplus;
0441         }
0442       }
0443 
0444       countHit++;
0445     }  // for Loop over Hits
0446 
0447     nh_PIXEL.push_back(nHits_PIXEL);
0448 
0449     if (nhitinBPIX > 0) {
0450       track_BPIX++;
0451     }
0452     if (nhitinFPIX > 0) {
0453       track_FPIX++;
0454     }
0455     if (nhitinPIXEL > 0) {
0456       track_PIXEL++;
0457     }
0458     if (nhitinTEC > 0) {
0459       track_TEC++;
0460     }
0461     if (nhitinTECminus > 0) {
0462       track_TECM++;
0463     }
0464     if (nhitinTECplus > 0) {
0465       track_TECP++;
0466     }
0467     if (nhitinTOB > 0) {
0468       track_TOB++;
0469     }
0470     if (nhitinTIB > 0) {
0471       track_TIB++;
0472     }
0473     if (nhitinTID > 0) {
0474       track_TID++;
0475     }
0476     if (nhitinTIDminus > 0) {
0477       track_TIDM++;
0478     }
0479     if (nhitinTIDplus > 0) {
0480       track_TIDP++;
0481     }
0482 
0483     ntrk++;
0484     ntrk_runnum++;
0485     nTotalTracks++;
0486   }  // for Loop over TrackCollection
0487   events++;
0488 
0489   Handle<edmNew::DetSetVector<SiStripCluster> > cluster;
0490   iEvent.getByToken(clustercollectionToken_, cluster);
0491 
0492   for (edmNew::DetSetVector<SiStripCluster>::const_iterator det = cluster->begin(); det != cluster->end(); ++det) {
0493     DetectorID = (det->detId());
0494     treeCluster->Fill();
0495   }
0496 
0497   edm::Handle<reco::MuonCollection> muH;
0498   iEvent.getByToken(muonTags_, muH);
0499   const reco::MuonCollection& muonsT0 = *(muH.product());
0500   float time = -9999.;
0501   for (unsigned int i = 0; i < muonsT0.size(); i++) {
0502     //DT time
0503     reco::MuonTime mt0 = muonsT0[i].time();
0504     time = mt0.timeAtIpInOut;
0505     DTtime.push_back(time);
0506   }
0507 
0508   treeEvent->Fill();
0509   ClearInEventLoop();
0510   nTotalEvents++;
0511 
0512 }  //Event Loop
0513 
0514 // ------------ method called once each job just before starting event loop  ------------
0515 void CosmicRateAnalyzer::beginJob() {
0516   //--- Event tree ---//
0517   treeEvent->Branch("pt", &pt);
0518   treeEvent->Branch("charge", &charge);
0519   treeEvent->Branch("chi2", &chi2);
0520   treeEvent->Branch("chi2_ndof", &chi2_ndof);
0521   treeEvent->Branch("eta", &eta);
0522   treeEvent->Branch("theta", &theta);
0523   treeEvent->Branch("phi", &phi);
0524   treeEvent->Branch("p", &p);
0525   treeEvent->Branch("d0", &d0);
0526   treeEvent->Branch("dz", &dz);
0527   treeEvent->Branch("nvh", &nvh);
0528   treeEvent->Branch("ntrk", &ntrk);
0529   treeEvent->Branch("nHitsPIXEL", &nh_PIXEL);
0530   treeEvent->Branch("nHitsBPIX", &nh_BPIX);
0531   treeEvent->Branch("nHitsFPIX", &nh_FPIX);
0532   treeEvent->Branch("nHitsTIB", &nh_TIB);
0533   treeEvent->Branch("nHitsTOB", &nh_TOB);
0534   treeEvent->Branch("nHitsTID", &nh_TID);
0535   treeEvent->Branch("nHitsTEC", &nh_TEC);
0536   treeEvent->Branch("DTtime", &DTtime);
0537   treeEvent->Branch("magField", &magField);
0538 
0539   //--- Run tree ---//
0540   treeRun->Branch("run_time", &run_time);
0541   treeRun->Branch("runnum", &runnum);
0542   // a) For track Rate Calculation
0543   treeRun->Branch("number_of_events", &number_of_events);
0544   treeRun->Branch("number_of_tracks", &number_of_tracks);
0545   treeRun->Branch("number_of_tracks_PIX", &number_of_tracks_PIX);
0546   treeRun->Branch("number_of_tracks_FPIX", &number_of_tracks_FPIX);
0547   treeRun->Branch("number_of_tracks_BPIX", &number_of_tracks_BPIX);
0548   treeRun->Branch("number_of_tracks_TID", &number_of_tracks_TID);
0549   treeRun->Branch("number_of_tracks_TIDM", &number_of_tracks_TIDM);
0550   treeRun->Branch("number_of_tracks_TIDP", &number_of_tracks_TIDP);
0551   treeRun->Branch("number_of_tracks_TIB", &number_of_tracks_TIB);
0552   treeRun->Branch("number_of_tracks_TEC", &number_of_tracks_TEC);
0553   treeRun->Branch("number_of_tracks_TECP", &number_of_tracks_TECP);
0554   treeRun->Branch("number_of_tracks_TECM", &number_of_tracks_TECM);
0555   treeRun->Branch("number_of_tracks_TOB", &number_of_tracks_TOB);
0556   // a) For PIXEL Hit Rate Calculation
0557   treeRun->Branch("number_of_hits_Total", &number_of_hits_Total);
0558   treeRun->Branch("number_of_hits_PIX", &number_of_hits_PIX);
0559   treeRun->Branch("number_of_hits_BPIX", &number_of_hits_BPIX);
0560   treeRun->Branch("number_of_hits_BPIX_layer1", &number_of_hits_BPIX_layer1);
0561   treeRun->Branch("number_of_hits_BPIX_layer2", &number_of_hits_BPIX_layer2);
0562   treeRun->Branch("number_of_hits_BPIX_layer3", &number_of_hits_BPIX_layer3);
0563   treeRun->Branch("number_of_hits_BPIX_layer4", &number_of_hits_BPIX_layer4);
0564   treeRun->Branch("number_of_hits_FPIX", &number_of_hits_FPIX);
0565   treeRun->Branch("number_of_hits_FPIX_disk1", &number_of_hits_FPIX_disk1);
0566   treeRun->Branch("number_of_hits_FPIX_disk2", &number_of_hits_FPIX_disk2);
0567   treeRun->Branch("number_of_hits_FPIX_disk3", &number_of_hits_FPIX_disk3);
0568   treeRun->Branch("number_of_hits_FPIX_disk1_plus", &number_of_hits_FPIX_disk1_plus);
0569   treeRun->Branch("number_of_hits_FPIX_disk1_minus", &number_of_hits_FPIX_disk1_minus);
0570   treeRun->Branch("number_of_hits_FPIX_disk2_plus", &number_of_hits_FPIX_disk2_plus);
0571   treeRun->Branch("number_of_hits_FPIX_disk2_minus", &number_of_hits_FPIX_disk2_minus);
0572   treeRun->Branch("number_of_hits_FPIX_disk3_plus", &number_of_hits_FPIX_disk3_plus);
0573   treeRun->Branch("number_of_hits_FPIX_disk3_minus", &number_of_hits_FPIX_disk3_minus);
0574 
0575   //--- Cluster tree ---//
0576   treeCluster->Branch("DetID", &DetectorID);
0577 }
0578 
0579 // ------------ method called once each job just after ending the event loop  ------------
0580 void CosmicRateAnalyzer::endJob() {
0581   std::cout << "Total Events: " << nTotalEvents << std::endl;
0582   std::cout << "TotalTracks: " << nTotalTracks << std::endl;
0583 }
0584 
0585 // ------------ method called when starting to processes a run  ------------
0586 void CosmicRateAnalyzer::beginRun(edm::Run const&, edm::EventSetup const&) {
0587   lastruntime = 0.0;
0588   lastrunnum = 0.0;
0589   ntrk_runnum = 0.0;
0590   events = 0.0;
0591   // a) for Track rate
0592   track_BPIX = 0.0;
0593   track_FPIX = 0.0;
0594   track_PIXEL = 0.0;
0595   track_TEC = 0.0;
0596   track_TECM = 0.0;
0597   track_TECP = 0.0;
0598   track_TOB = 0.0;
0599   track_TIB = 0.0;
0600   track_TID = 0.0;
0601   track_TIDM = 0.0;
0602   track_TIDP = 0.0;
0603 
0604   // b) for PIXEL hit rate
0605   hit_Total = 0.0;
0606   hit_PIX = 0.0;
0607   hit_BPIX = 0.0;
0608   hit_BPIX_layer1 = 0.0;
0609   hit_BPIX_layer2 = 0.0;
0610   hit_BPIX_layer3 = 0.0;
0611   hit_BPIX_layer4 = 0.0;
0612   hit_FPIX = 0.0;
0613   hit_FPIX_disk1 = 0.0;
0614   hit_FPIX_disk2 = 0.0;
0615   hit_FPIX_disk3 = 0.0;
0616   hit_FPIX_disk1_plus = 0.0;
0617   hit_FPIX_disk1_minus = 0.0;
0618   hit_FPIX_disk2_plus = 0.0;
0619   hit_FPIX_disk2_minus = 0.0;
0620   hit_FPIX_disk3_plus = 0.0;
0621   hit_FPIX_disk3_minus = 0.0;
0622 }
0623 
0624 // ------------ method called when ending the processing of a run  ------------
0625 
0626 void CosmicRateAnalyzer::endRun(edm::Run const&, edm::EventSetup const&) {
0627   number_of_tracks = ntrk_runnum;
0628   run_time = lastruntime;
0629   runnum = lastrunnum;
0630   // a) for Track Rate
0631   number_of_tracks_PIX = track_PIXEL;
0632   number_of_tracks_FPIX = track_FPIX;
0633   number_of_tracks_BPIX = track_BPIX;
0634   number_of_tracks_TEC = track_TEC;
0635   number_of_tracks_TECM = track_TECM;
0636   number_of_tracks_TECP = track_TECP;
0637   number_of_tracks_TOB = track_TOB;
0638   number_of_tracks_TIB = track_TIB;
0639   number_of_tracks_TID = track_TID;
0640   number_of_tracks_TIDM = track_TIDM;
0641   number_of_tracks_TIDP = track_TIDP;
0642   number_of_events = events;
0643   // b) for PIXEL Hit Rate
0644   number_of_hits_Total = hit_Total;
0645   number_of_hits_PIX = hit_PIX;
0646   number_of_hits_BPIX = hit_BPIX;
0647   number_of_hits_BPIX_layer1 = hit_BPIX_layer1;
0648   number_of_hits_BPIX_layer2 = hit_BPIX_layer2;
0649   number_of_hits_BPIX_layer3 = hit_BPIX_layer3;
0650   number_of_hits_BPIX_layer4 = hit_BPIX_layer4;
0651   number_of_hits_FPIX = hit_FPIX;
0652   number_of_hits_FPIX_disk1 = hit_FPIX_disk1;
0653   number_of_hits_FPIX_disk2 = hit_FPIX_disk2;
0654   number_of_hits_FPIX_disk3 = hit_FPIX_disk3;
0655   number_of_hits_FPIX_disk1_plus = hit_FPIX_disk1_plus;
0656   number_of_hits_FPIX_disk1_minus = hit_FPIX_disk1_minus;
0657   number_of_hits_FPIX_disk2_plus = hit_FPIX_disk2_plus;
0658   number_of_hits_FPIX_disk2_minus = hit_FPIX_disk2_minus;
0659   number_of_hits_FPIX_disk3_plus = hit_FPIX_disk3_plus;
0660   number_of_hits_FPIX_disk3_minus = hit_FPIX_disk3_minus;
0661 
0662   treeRun->Fill();
0663 }
0664 
0665 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0666 void CosmicRateAnalyzer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0667   edm::ParameterSetDescription desc;
0668   desc.setComment("Create tuple with all variables required to calculate cosmic event and track rates.");
0669   desc.add<edm::InputTag>("tracksInputTag", edm::InputTag("ALCARECOTkAlCosmicsCTF0T"));
0670   desc.add<edm::InputTag>("muonsInputTag", edm::InputTag("muons1Leg"));
0671   descriptions.add("cosmicRateAnalyzer", desc);
0672 }
0673 
0674 //define this as a plug-in
0675 DEFINE_FWK_MODULE(CosmicRateAnalyzer);