test
CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MeasurementTrackerEventProducer.cc
Go to the documentation of this file.
2 
5 
9 
11  measurementTrackerLabel_(iConfig.getParameter<std::string>("measurementTracker")),
12  pset_(iConfig)
13 {
14  std::vector<edm::InputTag> inactivePixelDetectorTags(iConfig.getParameter<std::vector<edm::InputTag> >("inactivePixelDetectorLabels"));
15  for (auto &t : inactivePixelDetectorTags) theInactivePixelDetectorLabels.push_back(consumes<DetIdCollection>(t));
16 
17  std::vector<edm::InputTag> inactiveStripDetectorTags(iConfig.getParameter<std::vector<edm::InputTag> >("inactiveStripDetectorLabels"));
18  for (auto &t : inactiveStripDetectorTags) theInactiveStripDetectorLabels.push_back(consumes<DetIdCollection>(t));
19 
20  //the measurement tracking is set to skip clusters, the other option is set from outside
21  selfUpdateSkipClusters_=iConfig.exists("skipClusters");
23  {
24  edm::InputTag skip=iConfig.getParameter<edm::InputTag>("skipClusters");
25  if (skip==edm::InputTag("")) selfUpdateSkipClusters_=false;
26  }
27  LogDebug("MeasurementTracker")<<"skipping clusters: "<<selfUpdateSkipClusters_;
28  isPhase2 = false;
29 
30  if (pset_.getParameter<std::string>("stripClusterProducer") != "") {
31  theStripClusterLabel = consumes<edmNew::DetSetVector<SiStripCluster> >(edm::InputTag(pset_.getParameter<std::string>("stripClusterProducer")));
32  if (selfUpdateSkipClusters_) theStripClusterMask = consumes<edm::ContainerMask<edmNew::DetSetVector<SiStripCluster>>>(iConfig.getParameter<edm::InputTag>("skipClusters"));
33  }
34  if (pset_.getParameter<std::string>("pixelClusterProducer") != "") {
35  thePixelClusterLabel = consumes<edmNew::DetSetVector<SiPixelCluster> >(edm::InputTag(pset_.getParameter<std::string>("pixelClusterProducer")));
36  if (selfUpdateSkipClusters_) thePixelClusterMask = consumes<edm::ContainerMask<edmNew::DetSetVector<SiPixelCluster>>>(iConfig.getParameter<edm::InputTag>("skipClusters"));
37  }
38  if (pset_.existsAs<std::string>("Phase2TrackerCluster1DProducer")) {
39  thePh2OTClusterLabel = consumes<edmNew::DetSetVector<Phase2TrackerCluster1D> >(edm::InputTag(pset_.getParameter<std::string>("Phase2TrackerCluster1DProducer")));
40  isPhase2 = true;
41  }
42 
43  produces<MeasurementTrackerEvent>();
44 }
45 
46 void
48 {
50  iSetup.get<CkfComponentsRecord>().get(measurementTrackerLabel_, measurementTracker);
51 
52  // create new data structures from templates
53  auto stripData = std::make_unique<StMeasurementDetSet>(measurementTracker->stripDetConditions());
54  auto pixelData= std::make_unique<PxMeasurementDetSet>(measurementTracker->pixelDetConditions());
55  auto phase2OTData = std::make_unique<Phase2OTMeasurementDetSet>(measurementTracker->phase2DetConditions());
56  std::vector<bool> stripClustersToSkip;
57  std::vector<bool> pixelClustersToSkip;
58  std::vector<bool> phase2ClustersToSkip;
59  // fill them
60  updateStrips(iEvent, *stripData, stripClustersToSkip);
61  updatePixels(iEvent, *pixelData, pixelClustersToSkip);
62  updatePhase2OT(iEvent, *phase2OTData);
63  updateStacks(iEvent, *phase2OTData);
64 
65  // put into MTE
66  // put into event
67  iEvent.put(std::move(
68  std::make_unique<MeasurementTrackerEvent>(*measurementTracker,
69  stripData.release(), pixelData.release(), phase2OTData.release(),
70  stripClustersToSkip, pixelClustersToSkip, phase2ClustersToSkip)
71  ));
72 }
73 
74 void
75 MeasurementTrackerEventProducer::updatePixels( const edm::Event& event, PxMeasurementDetSet & thePxDets, std::vector<bool> & pixelClustersToSkip ) const
76 {
77  // start by clearinng everything
78  thePxDets.setEmpty();
79 
80  bool switchOffPixelsIfEmpty = pset_.getParameter<bool>("switchOffPixelsIfEmpty");
81  std::vector<uint32_t> rawInactiveDetIds;
82  if (!theInactivePixelDetectorLabels.empty()) {
85  if (event.getByToken(tk, detIds)){
86  rawInactiveDetIds.insert(rawInactiveDetIds.end(), detIds->begin(), detIds->end());
87  }else{
88  static std::atomic<bool> iFailedAlready{false};
89  bool expected = false;
90  if (iFailedAlready.compare_exchange_strong(expected,true,std::memory_order_acq_rel)){
91  edm::LogError("MissingProduct")<<"I fail to get the list of inactive pixel modules, because of 4.2/4.4 event content change.";
92  }
93  }
94  }
95  if (!rawInactiveDetIds.empty()) std::sort(rawInactiveDetIds.begin(), rawInactiveDetIds.end());
96  // mark as inactive if in rawInactiveDetIds
97  int i=0, endDet = thePxDets.size();
98  unsigned int idp=0;
99  for ( auto id : rawInactiveDetIds) {
100  if (id==idp) continue; // skip multiple id
101  idp=id;
102  i=thePxDets.find(id,i);
103  assert(i!=endDet && id == thePxDets.id(i));
104  thePxDets.setActiveThisEvent(i,false);
105  }
106  }
107 
108  // Pixel Clusters
110  if( pixelClusterProducer.empty() ) { //clusters have not been produced
111  if (switchOffPixelsIfEmpty) {
112  thePxDets.setActiveThisEvent(false);
113  }
114  }else{
115 
117  event.getByToken(thePixelClusterLabel, pixelClusters);
118 
119  const edmNew::DetSetVector<SiPixelCluster>* pixelCollection = pixelClusters.product();
120 
121 
122  if (switchOffPixelsIfEmpty && pixelCollection->empty()) {
123  thePxDets.setActiveThisEvent(false);
124  } else {
125 
126  //std::cout <<"updatePixels "<<pixelCollection->dataSize()<<std::endl;
127  pixelClustersToSkip.resize(pixelCollection->dataSize());
128  std::fill(pixelClustersToSkip.begin(),pixelClustersToSkip.end(),false);
129 
132  //and get the collection of pixel ref to skip
133  event.getByToken(thePixelClusterMask,pixelClusterMask);
134  LogDebug("MeasurementTracker")<<"getting pxl refs to skip";
135  if (pixelClusterMask.failedToGet())edm::LogError("MeasurementTracker")<<"not getting the pixel clusters to skip";
136  if (pixelClusterMask->refProd().id()!=pixelClusters.id()){
137  edm::LogError("ProductIdMismatch")<<"The pixel masking does not point to the proper collection of clusters: "<<pixelClusterMask->refProd().id()<<"!="<<pixelClusters.id();
138  }
139  pixelClusterMask->copyMaskTo(pixelClustersToSkip);
140  }
141 
142 
143  // FIXME: should check if lower_bound is better
144  int i = 0, endDet = thePxDets.size();
145  for (edmNew::DetSetVector<SiPixelCluster>::const_iterator it = pixelCollection->begin(), ed = pixelCollection->end(); it != ed; ++it) {
147  unsigned int id = set.id();
148  while ( id != thePxDets.id(i)) {
149  ++i;
150  if (endDet==i) throw "we have a problem!!!!";
151  }
152  // push cluster range in det
153  if ( thePxDets.isActive(i) ) {
154  thePxDets.update(i,set);
155  }
156  }
157  }
158  }
159 
160 }
161 
162 void
163 MeasurementTrackerEventProducer::updateStrips( const edm::Event& event, StMeasurementDetSet & theStDets, std::vector<bool> & stripClustersToSkip ) const
164 {
165  typedef edmNew::DetSet<SiStripCluster> StripDetSet;
166 
167  std::vector<uint32_t> rawInactiveDetIds;
168  getInactiveStrips(event,rawInactiveDetIds);
169 
170  // Strip Clusters
172  //first clear all of them
173  theStDets.setEmpty();
174 
175 
176  if( !stripClusterProducer.compare("") ) return; //clusters have not been produced
177 
178  const int endDet = theStDets.size();
179 
180 
181  // mark as inactive if in rawInactiveDetIds
182  int i=0;
183  unsigned int idp=0;
184  for ( auto id : rawInactiveDetIds) {
185  if (id==idp) continue; // skip multiple id
186  idp=id;
187  i=theStDets.find(id,i);
188  assert(i!=endDet && id == theStDets.id(i));
189  theStDets.setActiveThisEvent(i,false);
190  }
191 
192  //========= actually load cluster =============
193  {
195  event.getByToken(theStripClusterLabel, clusterHandle);
196  const edmNew::DetSetVector<SiStripCluster>* clusterCollection = clusterHandle.product();
197 
198 
201  //and get the collection of pixel ref to skip
202  LogDebug("MeasurementTracker")<<"getting strp refs to skip";
203  event.getByToken(theStripClusterMask,stripClusterMask);
204  if (stripClusterMask.failedToGet()) edm::LogError("MeasurementTracker")<<"not getting the strip clusters to skip";
205  if (stripClusterMask->refProd().id()!=clusterHandle.id()){
206  edm::LogError("ProductIdMismatch")<<"The strip masking does not point to the proper collection of clusters: "<<stripClusterMask->refProd().id()<<"!="<<clusterHandle.id();
207  }
208  stripClusterMask->copyMaskTo(stripClustersToSkip);
209  }
210 
211  theStDets.handle() = clusterHandle;
212  int i=0;
213  // cluster and det and in order (both) and unique so let's use set intersection
214  for ( auto j = 0U; j< (*clusterCollection).size(); ++j) {
215  unsigned int id = (*clusterCollection).id(j);
216  while ( id != theStDets.id(i)) { // eventually change to lower_bound
217  ++i;
218  if (endDet==i) throw "we have a problem in strips!!!!";
219  }
220 
221  // push cluster range in det
222  if ( theStDets.isActive(i) )
223  theStDets.update(i,j);
224  }
225  }
226 }
227 
228 //FIXME: just a temporary solution for phase2!
229 void
231 
232 
233  // Phase2OT Clusters
234  if ( isPhase2 ) {
235 
236  std::string phase2ClusterProducer = pset_.getParameter<std::string>("Phase2TrackerCluster1DProducer");
237  if( phase2ClusterProducer.empty() ) { //clusters have not been produced
238  thePh2OTDets.setActiveThisEvent(false);
239  } else {
240 
242  event.getByToken(thePh2OTClusterLabel, phase2OTClusters);
243  const edmNew::DetSetVector<Phase2TrackerCluster1D>* phase2OTCollection = phase2OTClusters.product();
244 
245  int i = 0, endDet = thePh2OTDets.size();
246  for (edmNew::DetSetVector<Phase2TrackerCluster1D>::const_iterator it = phase2OTCollection->begin(), ed = phase2OTCollection->end(); it != ed; ++it) {
247 
249  unsigned int id = set.id();
250  while ( id != thePh2OTDets.id(i)) {
251  ++i;
252  if (endDet==i) throw "we have a problem!!!!";
253  }
254  // push cluster range in det
255  if ( thePh2OTDets.isActive(i) ) {
256  thePh2OTDets.update(i,set);
257  }
258  }
259  }
260 
261  }
262  return;
263 }
264 
265 void
266 MeasurementTrackerEventProducer::getInactiveStrips(const edm::Event& event,std::vector<uint32_t> & rawInactiveDetIds) const
267 {
268  if (!theInactiveStripDetectorLabels.empty()) {
271  if (event.getByToken(tk, detIds)){
272  rawInactiveDetIds.insert(rawInactiveDetIds.end(), detIds->begin(), detIds->end());
273  }
274  }
275  if (!rawInactiveDetIds.empty()) std::sort(rawInactiveDetIds.begin(), rawInactiveDetIds.end());
276  }
277 
278 }
279 
280 
281 
#define LogDebug(id)
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
const_iterator end(bool update=false) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
size_type dataSize() const
std::vector< edm::EDGetTokenT< DetIdCollection > > theInactiveStripDetectorLabels
string fill
Definition: lumiContext.py:319
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:186
ProductID id() const
Definition: HandleBase.cc:15
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
assert(m_qm.get())
MeasurementTrackerEventProducer(const edm::ParameterSet &iConfig)
bool exists(std::string const &parameterName) const
checks if a parameter exists
void updateStrips(const edm::Event &, StMeasurementDetSet &theStDets, std::vector< bool > &stripClustersToSkip) const
void update(int i, const StripDetset &detSet)
edm::EDGetTokenT< edmNew::DetSetVector< Phase2TrackerCluster1D > > thePh2OTClusterLabel
const edm::Handle< edmNew::DetSetVector< SiPixelCluster > > & handle() const
void updatePixels(const edm::Event &, PxMeasurementDetSet &thePxDets, std::vector< bool > &pixelClustersToSkip) const
unsigned int id(int i) const
unsigned int id(int i) const
int find(unsigned int jd, int i=0) const
int iEvent
Definition: GenABIO.cc:230
void setActiveThisEvent(int i, bool active)
Turn on/off the module for reconstruction for one events. This per-event flag is cleared by any call ...
void updatePhase2OT(const edm::Event &, Phase2OTMeasurementDetSet &thePh2OTDets) const
const edm::Handle< edmNew::DetSetVector< Phase2TrackerCluster1D > > & handle() const
bool isActive(int i) const
def move
Definition: eostools.py:510
void getInactiveStrips(const edm::Event &event, std::vector< uint32_t > &rawInactiveDetIds) const
int j
Definition: DBlmapReader.cc:9
void updateStacks(const edm::Event &, Phase2OTMeasurementDetSet &theStDets) const
void update(int i, const PixelDetSet &detSet)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
virtual void produce(edm::Event &, const edm::EventSetup &) override
bool failedToGet() const
Definition: HandleBase.h:79
T const * product() const
Definition: Handle.h:81
const T & get() const
Definition: EventSetup.h:56
edm::EDGetTokenT< edm::ContainerMask< edmNew::DetSetVector< SiPixelCluster > > > thePixelClusterMask
bool isActive(int i) const
void setActiveThisEvent(bool active)
edm::EDGetTokenT< edmNew::DetSetVector< SiStripCluster > > theStripClusterLabel
id_type id() const
Definition: DetSetNew.h:81
int find(unsigned int jd, int i=0) const
void setActiveThisEvent(bool active)
edm::Handle< edmNew::DetSetVector< SiStripCluster > > & handle()
unsigned int id(int i) const
void update(int i, const Phase2DetSet &detSet)
edm::EDGetTokenT< edmNew::DetSetVector< SiPixelCluster > > thePixelClusterLabel
edm::EDGetTokenT< edm::ContainerMask< edmNew::DetSetVector< SiStripCluster > > > theStripClusterMask
const_iterator begin(bool update=false) const
std::vector< edm::EDGetTokenT< DetIdCollection > > theInactivePixelDetectorLabels