Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-07 04:34:31

0001 #include "Alignment/LaserAlignment/interface/LASGlobalData.h"
0002 #include "Alignment/LaserAlignment/interface/LASGlobalLoop.h"
0003 #include "DataFormats/Common/interface/DetSetVector.h"
0004 #include "FWCore/Framework/interface/Event.h"
0005 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007 
0008 // Forward declarations
0009 class TFile;
0010 class TTree;
0011 
0012 class RawDataConverter : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
0013 public:
0014   explicit RawDataConverter(const edm::ParameterSet&);
0015   ~RawDataConverter() override = default;
0016 
0017 private:
0018   enum DigiType { ZeroSuppressed, VirginRaw, ProcessedRaw, Unknown };
0019   void beginJob() override;
0020   void beginRun(edm::Run const&, edm::EventSetup const&) override;
0021   void analyze(const edm::Event&, const edm::EventSetup&) override;
0022   void endRun(edm::Run const&, edm::EventSetup const&) override {}
0023   void endJob() override;
0024 
0025   void fillDetectorId(void);
0026   void ClearData(void);
0027   DigiType GetValidLabels(
0028       const edm::Event&
0029           iEvent);  // Check what kind of file is being processed and get valid module and instance labels returns the type of Digis that was found
0030 
0031   template <class T>
0032   void GetDigis(const edm::Event&);  // Copy the Digis into the local container (theData)
0033 
0034   std::vector<std::string> theDigiModuleLabels;
0035   std::vector<std::string> theProductInstanceLabels;
0036 
0037   std::string CurrentModuleLabel;
0038   std::string CurrentInstanceLabel;
0039 
0040   TFile* theOutputFile;
0041   TTree* theOutputTree;
0042   LASGlobalData<std::vector<float> > theData;
0043 
0044   int latency;
0045   int eventnumber;
0046   int runnumber;
0047   int lumiBlock;
0048   LASGlobalData<int> detectorId;
0049 };
0050 
0051 // Copy the Digis into the local container (theData)
0052 // Currently this has only been implemented and tested for SiStripDigis
0053 // SiStripRawDigis and SiStripProcessedRawDigis will need some changes to work (this is the final goal)
0054 template <class Digitype>
0055 void RawDataConverter::GetDigis(const edm::Event& iEvent) {
0056   LogDebug("RawDataConverter") << "Fill ZeroSuppressed Digis into the Tree";
0057 
0058   // Get the DetSetVector for the SiStripDigis
0059   // This is a vector with all the modules, each module containing zero or more strips with signal (Digis)
0060   edm::Handle<edm::DetSetVector<Digitype> > detSetVector;  // Handle for holding the DetSetVector
0061   iEvent.getByLabel(CurrentModuleLabel, CurrentInstanceLabel, detSetVector);
0062   if (!detSetVector.isValid())
0063     throw std::runtime_error("Could not find the Digis");
0064 
0065   // set everything in the local container to zero
0066   ClearData();
0067 
0068   // Fill the Digis into the Raw Data Container
0069 
0070   LASGlobalLoop loop;              // loop helper
0071   int det, ring, beam, disk, pos;  // and its variables
0072 
0073   // loop over TEC+- (internal) modules
0074   det = 0;
0075   ring = 0;
0076   beam = 0;
0077   disk = 0;
0078   do {
0079     // Find the module in the DetSetVector and get a pointer (iterator) to it
0080     typename edm::DetSetVector<Digitype>::const_iterator theModule =
0081         detSetVector->find(detectorId.GetTECEntry(det, ring, beam, disk));
0082 
0083     if (theModule != detSetVector->end()) {
0084       // loop over all the Digis in this Module
0085       typename edm::DetSet<Digitype>::const_iterator theDigi;
0086       for (theDigi = theModule->data.begin(); theDigi != theModule->data.end(); ++theDigi) {
0087         // fill the number of adc counts into the local container
0088         if (theDigi->channel() < 512)
0089           theData.GetTECEntry(det, ring, beam, disk).at(theDigi->channel()) = theDigi->adc();
0090       }
0091     }
0092   } while (loop.TECLoop(det, ring, beam, disk));
0093 
0094   // loop TIB/TOB
0095   det = 2;
0096   beam = 0;
0097   pos = 0;  // <- set det = 2 (TIB)
0098   do {
0099     // Find the module in the DetSetVector and get a pointer (iterator) to it
0100     typename edm::DetSetVector<Digitype>::const_iterator theModule =
0101         detSetVector->find(detectorId.GetTIBTOBEntry(det, beam, pos));
0102 
0103     if (theModule != detSetVector->end()) {
0104       // loop over all the Digis in this Module
0105       typename edm::DetSet<Digitype>::const_iterator theDigi;
0106       for (theDigi = theModule->data.begin(); theDigi != theModule->data.end(); ++theDigi) {
0107         // fill the number of adc counts into the local container
0108         if (theDigi->channel() < 512)
0109           theData.GetTIBTOBEntry(det, beam, pos).at(theDigi->channel()) = theDigi->adc();
0110       }
0111     }
0112   } while (loop.TIBTOBLoop(det, beam, pos));
0113 
0114   // loop TEC (AT)
0115   det = 0;
0116   beam = 0;
0117   disk = 0;
0118   do {
0119     // Find the module in the DetSetVector and get a pointer (iterator) to it
0120     typename edm::DetSetVector<Digitype>::const_iterator theModule =
0121         detSetVector->find(detectorId.GetTEC2TECEntry(det, beam, disk));
0122 
0123     if (theModule != detSetVector->end()) {
0124       // loop over all the Digis in this Module
0125       typename edm::DetSet<Digitype>::const_iterator theDigi;
0126       for (theDigi = theModule->data.begin(); theDigi != theModule->data.end(); ++theDigi) {
0127         // fill the number of adc counts into the local container
0128         if (theDigi->channel() < 512)
0129           theData.GetTEC2TECEntry(det, beam, disk).at(theDigi->channel()) = theDigi->adc();
0130       }
0131     }
0132   } while (loop.TEC2TECLoop(det, beam, disk));
0133 }