Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-08-13 05:00:11

0001 
0002 #ifndef LaserAlignment_LaserAlignment_H
0003 #define LaserAlignment_LaserAlignment_H
0004 
0005 /** \class LaserAlignment
0006  *  Main reconstruction module for the Laser Alignment System
0007  *
0008  *  $Date: 2012/12/26 20:34:44 $
0009  *  $Revision: 1.32 $
0010  *  \author Maarten Thomas
0011  *  \author Jan Olzem
0012  */
0013 
0014 #include <sstream>
0015 #include <iostream>
0016 #include <cmath>
0017 
0018 #include "FWCore/Framework/interface/Event.h"
0019 #include "FWCore/Framework/interface/one/EDProducer.h"
0020 #include "FWCore/Framework/interface/ESHandle.h"
0021 #include "FWCore/Framework/interface/EventSetup.h"
0022 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0023 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0024 #include "FWCore/ServiceRegistry/interface/Service.h"
0025 
0026 #include "DataFormats/Common/interface/DetSetVector.h"
0027 #include "DataFormats/SiStripDigi/interface/SiStripDigi.h"
0028 #include "DataFormats/SiStripDigi/interface/SiStripRawDigi.h"
0029 #include "DataFormats/DetId/interface/DetId.h"
0030 #include "DataFormats/SiStripDetId/interface/SiStripDetId.h"
0031 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
0032 
0033 #include "DataFormats/GeometryCommonDetAlgo/interface/ErrorFrameTransformer.h"
0034 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
0035 #include "DataFormats/Alignment/interface/SiStripLaserRecHit2D.h"
0036 #include "DataFormats/Alignment/interface/TkLasBeam.h"
0037 
0038 #include "CondFormats/SiStripObjects/interface/SiStripPedestals.h"
0039 #include "CondFormats/DataRecord/interface/SiStripPedestalsRcd.h"
0040 #include "CondFormats/Alignment/interface/DetectorGlobalPosition.h"
0041 #include "CondFormats/AlignmentRecord/interface/GlobalPositionRcd.h"
0042 
0043 #include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetUnit.h"
0044 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeomBuilderFromGeometricDet.h"
0045 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0046 #include "Geometry/CommonTopologies/interface/StripTopology.h"
0047 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0048 #include "Geometry/GeometryAligner/interface/GeometryAligner.h"
0049 
0050 #include "Alignment/TrackerAlignment/interface/AlignableTracker.h"
0051 
0052 #include "Alignment/LaserAlignment/interface/LASGlobalData.h"
0053 #include "Alignment/LaserAlignment/interface/LASGlobalLoop.h"
0054 #include "Alignment/LaserAlignment/interface/LASModuleProfile.h"
0055 #include "Alignment/LaserAlignment/interface/LASProfileJudge.h"
0056 #include "Alignment/LaserAlignment/interface/LASBarrelAlgorithm.h"
0057 #include "Alignment/LaserAlignment/interface/LASAlignmentTubeAlgorithm.h"
0058 #include "Alignment/LaserAlignment/interface/LASEndcapAlgorithm.h"
0059 #include "Alignment/LaserAlignment/interface/LASPeakFinder.h"
0060 #include "Alignment/LaserAlignment/interface/LASCoordinateSet.h"
0061 #include "Alignment/LaserAlignment/interface/LASGeometryUpdater.h"
0062 #include "Alignment/LaserAlignment/interface/LASConstants.h"
0063 
0064 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0065 
0066 #include "TH1.h"
0067 #include "TFile.h"
0068 #include "TF1.h"
0069 
0070 ///
0071 ///
0072 ///
0073 class LaserAlignment : public edm::one::EDProducer<edm::EndRunProducer> {
0074 public:
0075   explicit LaserAlignment(edm::ParameterSet const& theConf);
0076   ~LaserAlignment() override;
0077   void beginJob() override;
0078   void produce(edm::Event&, edm::EventSetup const&) override;
0079   void endJob() override;
0080   void endRunProduce(edm::Run&, const edm::EventSetup&) override;
0081 
0082   /// for debugging & testing only, will disappear..
0083   void testRoutine(void);
0084 
0085 private:
0086   /// fill profiles from SiStrip(Raw)Digi container
0087   void fillDataProfiles(edm::Event const&, edm::EventSetup const&);
0088 
0089   /// fill pedestals from dbase
0090   void fillPedestalProfiles(edm::ESHandle<SiStripPedestals>&);
0091 
0092   /// decide whether TEC or AT beams have fired
0093   bool isTECBeam(void);
0094   bool isATBeam(void);
0095 
0096   /// returns the nominal beam position (strips) in TOB for the profileJudge
0097   double getTIBTOBNominalBeamOffset(unsigned int, unsigned int, unsigned int);
0098 
0099   /// returns the nominal beam position (strips) in TEC (AT) for the profileJudge
0100   double getTEC2TECNominalBeamOffset(unsigned int, unsigned int, unsigned int);
0101 
0102   /// fill hard coded detIds
0103   void fillDetectorId(void);
0104 
0105   /// convert an angle in the [-pi,pi] range to the [0,2*pi] range
0106   double ConvertAngle(double);
0107 
0108   /// fills a LASGlobalData<LASCoordinateSet> with nominal module positions
0109   void CalculateNominalCoordinates(void);
0110 
0111   /// for debugging only, will disappear
0112   void DumpPosFileSet(LASGlobalData<LASCoordinateSet>&);
0113 
0114   /// for debugging only, will disappear
0115   void DumpStripFileSet(LASGlobalData<std::pair<float, float> >&);
0116 
0117   /// for debugging only, will disappear
0118   void DumpHitmaps(LASGlobalData<int>&);
0119 
0120   /// apply endcap correction to masked modules in TEC
0121   void ApplyEndcapMaskingCorrections(LASGlobalData<LASCoordinateSet>&,
0122                                      LASGlobalData<LASCoordinateSet>&,
0123                                      LASEndcapAlignmentParameterSet&);
0124 
0125   /// same for alignment tube modules
0126   void ApplyATMaskingCorrections(LASGlobalData<LASCoordinateSet>&,
0127                                  LASGlobalData<LASCoordinateSet>&,
0128                                  LASBarrelAlignmentParameterSet&);
0129 
0130   /// Tokens for ESconsumes
0131   const edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> topoToken_;
0132   const edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> geomToken_;
0133   const edm::ESGetToken<GeometricDet, IdealGeometryRecord> geomDetToken_;
0134   const edm::ESGetToken<PTrackerParameters, PTrackerParametersRcd> ptpToken_;
0135   const edm::ESGetToken<PTrackerAdditionalParametersPerDet, PTrackerAdditionalParametersPerDetRcd> ptitpToken_;
0136   const edm::ESGetToken<Alignments, GlobalPositionRcd> gprToken_;
0137   const edm::ESGetToken<SiStripPedestals, SiStripPedestalsRcd> stripPedestalsToken_;
0138 
0139   /// counter for the total number of events processed
0140   int theEvents;
0141 
0142   /// config switch
0143   bool theDoPedestalSubtraction;
0144 
0145   /// config switch
0146   bool theUseMinuitAlgorithm;
0147 
0148   /// config switch
0149   bool theApplyBeamKinkCorrections;
0150 
0151   /// config parameter
0152   double peakFinderThreshold;
0153 
0154   /// config switch
0155   bool enableJudgeZeroFilter;
0156 
0157   /// config parameters for the LASProfileJudge
0158   unsigned int judgeOverdriveThreshold;
0159 
0160   /// config switch
0161   bool updateFromInputGeometry;
0162 
0163   /// config switch
0164   bool misalignedByRefGeometry;
0165 
0166   /// config switch
0167   bool theStoreToDB;
0168 
0169   // digi producer
0170   std::vector<edm::ParameterSet> theDigiProducersList;
0171 
0172   /// config switch
0173   bool theSaveHistograms;
0174 
0175   /// config parameter (histograms file compression level)
0176   int theCompression;
0177 
0178   /// config parameter (histograms file output name)
0179   std::string theFileName;
0180 
0181   /// config parameters
0182   std::vector<unsigned int> theMaskTecModules;
0183   std::vector<unsigned int> theMaskAtModules;
0184 
0185   /// config switch
0186   bool theSetNominalStrips;
0187 
0188   // this object can judge if
0189   // a LASModuleProfile is usable for position measurement
0190   LASProfileJudge judge;
0191 
0192   // colection of constants
0193   LASConstants theLasConstants;
0194 
0195   // the detector ids for all the modules
0196   LASGlobalData<unsigned int> detectorId;
0197 
0198   // the detector ids for the doubly hit modules in the TECs
0199   std::vector<unsigned int> tecDoubleHitDetId;
0200 
0201   // all the 474 profiles for the pedestals
0202   LASGlobalData<LASModuleProfile> pedestalProfiles;
0203 
0204   /// data profiles for the current event
0205   LASGlobalData<LASModuleProfile> currentDataProfiles;
0206 
0207   // summed data profiles
0208   LASGlobalData<LASModuleProfile> collectedDataProfiles;
0209 
0210   // 474 names for retrieving data from the branches
0211   LASGlobalData<std::string> theProfileNames;
0212 
0213   // number of accepted profiles for each module
0214   LASGlobalData<int> numberOfAcceptedProfiles;
0215 
0216   // hit map for the current event (int=0,1)
0217   // which is needed for branching into AT or TEC mode
0218   LASGlobalData<int> isAcceptedProfile;
0219 
0220   // histograms for the summed profiles;
0221   // these are needed for the fitting procedure (done by ROOT)
0222   LASGlobalData<TH1D*> summedHistograms;
0223 
0224   // container for nominal module positions
0225   LASGlobalData<LASCoordinateSet> nominalCoordinates;
0226 
0227   // a class for easy looping over LASGlobalData objects,
0228   // avoids nested for-statements
0229   LASGlobalLoop moduleLoop;
0230 
0231   /// Tree stuff
0232   TFile* theFile;
0233   TDirectory* singleModulesDir;
0234 
0235   /// tracker geometry;
0236   edm::ESHandle<GeometricDet> gD;
0237   edm::ESHandle<TrackerGeometry> theTrackerGeometry;
0238   edm::ESHandle<Alignments> theGlobalPositionRcd;
0239 
0240   AlignableTracker* theAlignableTracker;
0241 
0242   std::string theAlignRecordName, theErrorRecordName;
0243 
0244   bool firstEvent_;
0245 };
0246 #endif