Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:57:29

0001 /// \file
0002 ///
0003 /// $Date: 2007/12/06 01:55:18 $
0004 /// $Revision: 1.2 $
0005 ///
0006 /// $Author: ratnik $
0007 /// \author Frederic Ronga - CERN-PH-CMG
0008 
0009 #include <string>
0010 #include <iostream>
0011 #include <sstream>
0012 
0013 // Framework
0014 #include "FWCore/Utilities/interface/Exception.h"
0015 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0016 
0017 // Alignment
0018 #include "Alignment/TrackerAlignment/interface/TrackerScenarioBuilder.h"
0019 #include "Alignment/TrackerAlignment/interface/AlignableTracker.h"
0020 
0021 //__________________________________________________________________________________________________
0022 TrackerScenarioBuilder::TrackerScenarioBuilder(AlignableTracker* alignable)
0023     : MisalignmentScenarioBuilder(alignable->objectIdProvider().geometry()), theAlignableTracker(alignable) {
0024   if (!theAlignableTracker) {
0025     throw cms::Exception("TypeMismatch") << "Pointer to AlignableTracker is empty.\n";
0026   }
0027 
0028   // Fill what is needed for possiblyPartOf(..):
0029   theSubdets.push_back(stripOffModule(align::TPBModule));  // Take care, order matters: 1st pixel, 2nd strip.
0030   theSubdets.push_back(stripOffModule(align::TPEModule));
0031   theFirstStripIndex = theSubdets.size();
0032   theSubdets.push_back(stripOffModule(align::TIBModule));
0033   theSubdets.push_back(stripOffModule(align::TIDModule));
0034   theSubdets.push_back(stripOffModule(align::TOBModule));
0035   theSubdets.push_back(stripOffModule(align::TECModule));
0036 }
0037 
0038 //__________________________________________________________________________________________________
0039 void TrackerScenarioBuilder::applyScenario(const edm::ParameterSet& scenario) {
0040   // Apply the scenario to all main components of tracker.
0041   theModifierCounter = 0;
0042 
0043   // Seed is set at top-level, and is mandatory
0044   if (this->hasParameter_("seed", scenario))
0045     theModifier.setSeed(static_cast<long>(scenario.getParameter<int>("seed")));
0046   else
0047     throw cms::Exception("BadConfig") << "No generator seed defined!";
0048 
0049   // misalignment applied recursively ('subStructures("Tracker")' contains only tracker itself)
0050   this->decodeMovements_(scenario, theAlignableTracker->subStructures("Tracker"));
0051 
0052   edm::LogInfo("TrackerScenarioBuilder") << "Applied modifications to " << theModifierCounter << " alignables";
0053 }
0054 
0055 //__________________________________________________________________________________________________
0056 bool TrackerScenarioBuilder::isTopLevel_(const std::string& parameterSetName) const {
0057   // Get root name (strip last character [s])
0058   std::string root = this->rootName_(parameterSetName);
0059 
0060   if (root == "Tracker")
0061     return true;
0062 
0063   return false;
0064 }
0065 
0066 //__________________________________________________________________________________________________
0067 bool TrackerScenarioBuilder::possiblyPartOf(const std::string& subStruct, const std::string& largeStr) const {
0068   // string::find(s) != nPos => 's' is contained in string!
0069   const std::string::size_type nPos = std::string::npos;
0070 
0071   // First check whether anything from pixel in strip.
0072   if (largeStr.find("Strip") != nPos) {
0073     if (subStruct.find("Pixel") != nPos)
0074       return false;
0075     for (unsigned int iPix = 0; iPix < theFirstStripIndex; ++iPix) {
0076       if (subStruct.find(theSubdets[iPix]) != nPos)
0077         return false;
0078     }
0079   }
0080 
0081   // Now check whether anything from strip in pixel.
0082   if (largeStr.find("Pixel") != nPos) {
0083     if (subStruct.find("Strip") != nPos)
0084       return false;
0085     for (unsigned int iStrip = theFirstStripIndex; iStrip < theSubdets.size(); ++iStrip) {
0086       if (subStruct.find(theSubdets[iStrip]) != nPos)
0087         return false;
0088     }
0089   }
0090 
0091   // Finally check for any different detector parts, e.g. TIDEndcap/TIBString gives false.
0092   for (unsigned int iSub = 0; iSub < theSubdets.size(); ++iSub) {
0093     for (unsigned int iLarge = 0; iLarge < theSubdets.size(); ++iLarge) {
0094       if (iLarge == iSub)
0095         continue;
0096       if (largeStr.find(theSubdets[iLarge]) != nPos && subStruct.find(theSubdets[iSub]) != nPos) {
0097         return false;
0098       }
0099     }
0100   }
0101 
0102   // It seems like a possible combination:
0103   return true;
0104 }
0105 
0106 //__________________________________________________________________________________________________
0107 std::string TrackerScenarioBuilder::stripOffModule(const align::StructureType& type) const {
0108   const std::string module{"Module"};
0109   std::string name{theAlignableTracker->objectIdProvider().typeToName(type)};
0110   auto start = name.find(module);
0111   if (start == std::string::npos) {
0112     throw cms::Exception("LogicError") << "[TrackerScenarioBuilder] '" << name << "' is not a module type";
0113   }
0114   name.replace(start, module.length(), "");
0115   return name;
0116 }