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 
29  if (pset_.getParameter<std::string>("stripClusterProducer") != "") {
30  theStripClusterLabel = consumes<edmNew::DetSetVector<SiStripCluster> >(edm::InputTag(pset_.getParameter<std::string>("stripClusterProducer")));
31  if (selfUpdateSkipClusters_) theStripClusterMask = consumes<edm::ContainerMask<edmNew::DetSetVector<SiStripCluster>>>(iConfig.getParameter<edm::InputTag>("skipClusters"));
32  }
33  if (pset_.getParameter<std::string>("pixelClusterProducer") != "") {
34  thePixelClusterLabel = consumes<edmNew::DetSetVector<SiPixelCluster> >(edm::InputTag(pset_.getParameter<std::string>("pixelClusterProducer")));
35  if (selfUpdateSkipClusters_) thePixelClusterMask = consumes<edm::ContainerMask<edmNew::DetSetVector<SiPixelCluster>>>(iConfig.getParameter<edm::InputTag>("skipClusters"));
36  }
37 
38  produces<MeasurementTrackerEvent>();
39 }
40 
41 void
43 {
44  edm::ESHandle<MeasurementTracker> measurementTracker;
45  iSetup.get<CkfComponentsRecord>().get(measurementTrackerLabel_, measurementTracker);
46 
47  // create new data structures from templates
48  std::auto_ptr<StMeasurementDetSet> stripData(new StMeasurementDetSet(measurementTracker->stripDetConditions()));
49  std::auto_ptr<PxMeasurementDetSet> pixelData(new PxMeasurementDetSet(measurementTracker->pixelDetConditions()));
50  //std::cout << "Created new strip data @" << &* stripData << std::endl;
51  std::vector<bool> stripClustersToSkip;
52  std::vector<bool> pixelClustersToSkip;
53 
54  // fill them
55  updateStrips(iEvent, *stripData, stripClustersToSkip);
56  updatePixels(iEvent, *pixelData, pixelClustersToSkip);
57 
58  // put into MTE
59  std::auto_ptr<MeasurementTrackerEvent> out(new MeasurementTrackerEvent(*measurementTracker, stripData.release(), pixelData.release(), stripClustersToSkip, pixelClustersToSkip));
60 
61  // put into event
62  iEvent.put(out);
63 }
64 
65 void
66 MeasurementTrackerEventProducer::updatePixels( const edm::Event& event, PxMeasurementDetSet & thePxDets, std::vector<bool> & pixelClustersToSkip ) const
67 {
68  // start by clearinng everything
69  thePxDets.setEmpty();
70 
71  bool switchOffPixelsIfEmpty = (!pset_.existsAs<bool>("switchOffPixelsIfEmpty")) ||
72  (pset_.getParameter<bool>("switchOffPixelsIfEmpty"));
73  std::vector<uint32_t> rawInactiveDetIds;
74  if (!theInactivePixelDetectorLabels.empty()) {
77  if (event.getByToken(tk, detIds)){
78  rawInactiveDetIds.insert(rawInactiveDetIds.end(), detIds->begin(), detIds->end());
79  }else{
80  static std::atomic<bool> iFailedAlready{false};
81  bool expected = false;
82  if (iFailedAlready.compare_exchange_strong(expected,true,std::memory_order_acq_rel)){
83  edm::LogError("MissingProduct")<<"I fail to get the list of inactive pixel modules, because of 4.2/4.4 event content change.";
84  }
85  }
86  }
87  if (!rawInactiveDetIds.empty()) std::sort(rawInactiveDetIds.begin(), rawInactiveDetIds.end());
88  // mark as inactive if in rawInactiveDetIds
89  int i=0, endDet = thePxDets.size();
90  unsigned int idp=0;
91  for ( auto id : rawInactiveDetIds) {
92  if (id==idp) continue; // skip multiple id
93  idp=id;
94  i=thePxDets.find(id,i);
95  assert(i!=endDet && id == thePxDets.id(i));
96  thePxDets.setActiveThisEvent(i,false);
97  }
98  }
99 
100  // Pixel Clusters
101  std::string pixelClusterProducer = pset_.getParameter<std::string>("pixelClusterProducer");
102  if( pixelClusterProducer.empty() ) { //clusters have not been produced
103  if (switchOffPixelsIfEmpty) {
104  thePxDets.setActiveThisEvent(false);
105  }
106  }else{
107 
109  event.getByToken(thePixelClusterLabel, pixelClusters);
110 
111  const edmNew::DetSetVector<SiPixelCluster>* pixelCollection = pixelClusters.product();
112 
113  if (switchOffPixelsIfEmpty && pixelCollection->empty()) {
114  thePxDets.setActiveThisEvent(false);
115  } else {
116 
117  //std::cout <<"updatePixels "<<pixelCollection->dataSize()<<std::endl;
118  pixelClustersToSkip.resize(pixelCollection->dataSize());
119  std::fill(pixelClustersToSkip.begin(),pixelClustersToSkip.end(),false);
120 
123  //and get the collection of pixel ref to skip
124  event.getByToken(thePixelClusterMask,pixelClusterMask);
125  LogDebug("MeasurementTracker")<<"getting pxl refs to skip";
126  if (pixelClusterMask.failedToGet())edm::LogError("MeasurementTracker")<<"not getting the pixel clusters to skip";
127  if (pixelClusterMask->refProd().id()!=pixelClusters.id()){
128  edm::LogError("ProductIdMismatch")<<"The pixel masking does not point to the proper collection of clusters: "<<pixelClusterMask->refProd().id()<<"!="<<pixelClusters.id();
129  }
130  pixelClusterMask->copyMaskTo(pixelClustersToSkip);
131  }
132 
133 
134  // FIXME: should check if lower_bound is better
135  int i = 0, endDet = thePxDets.size();
136  for (edmNew::DetSetVector<SiPixelCluster>::const_iterator it = pixelCollection->begin(), ed = pixelCollection->end(); it != ed; ++it) {
138  unsigned int id = set.id();
139  while ( id != thePxDets.id(i)) {
140  ++i;
141  if (endDet==i) throw "we have a problem!!!!";
142  }
143  // push cluster range in det
144  if ( thePxDets.isActive(i) ) {
145  thePxDets.update(i,set);
146  }
147  }
148  }
149  }
150 
151 }
152 
153 void
154 MeasurementTrackerEventProducer::updateStrips( const edm::Event& event, StMeasurementDetSet & theStDets, std::vector<bool> & stripClustersToSkip ) const
155 {
156  typedef edmNew::DetSet<SiStripCluster> StripDetSet;
157 
158  std::vector<uint32_t> rawInactiveDetIds;
159  getInactiveStrips(event,rawInactiveDetIds);
160 
161  // Strip Clusters
162  std::string stripClusterProducer = pset_.getParameter<std::string>("stripClusterProducer");
163  //first clear all of them
164  theStDets.setEmpty();
165 
166 
167  if( !stripClusterProducer.compare("") ) return; //clusters have not been produced
168 
169  const int endDet = theStDets.size();
170 
171 
172  // mark as inactive if in rawInactiveDetIds
173  int i=0;
174  unsigned int idp=0;
175  for ( auto id : rawInactiveDetIds) {
176  if (id==idp) continue; // skip multiple id
177  idp=id;
178  i=theStDets.find(id,i);
179  assert(i!=endDet && id == theStDets.id(i));
180  theStDets.setActiveThisEvent(i,false);
181  }
182 
183  //========= actually load cluster =============
184  {
186  event.getByToken(theStripClusterLabel, clusterHandle);
187  const edmNew::DetSetVector<SiStripCluster>* clusterCollection = clusterHandle.product();
188 
189 
192  //and get the collection of pixel ref to skip
193  LogDebug("MeasurementTracker")<<"getting strp refs to skip";
194  event.getByToken(theStripClusterMask,stripClusterMask);
195  if (stripClusterMask.failedToGet()) edm::LogError("MeasurementTracker")<<"not getting the strip clusters to skip";
196  if (stripClusterMask->refProd().id()!=clusterHandle.id()){
197  edm::LogError("ProductIdMismatch")<<"The strip masking does not point to the proper collection of clusters: "<<stripClusterMask->refProd().id()<<"!="<<clusterHandle.id();
198  }
199  stripClusterMask->copyMaskTo(stripClustersToSkip);
200  }
201 
202  theStDets.handle() = clusterHandle;
203  int i=0;
204  // cluster and det and in order (both) and unique so let's use set intersection
205  for ( auto j = 0U; j< (*clusterCollection).size(); ++j) {
206  unsigned int id = (*clusterCollection).id(j);
207  while ( id != theStDets.id(i)) { // eventually change to lower_bound
208  ++i;
209  if (endDet==i) throw "we have a problem in strips!!!!";
210  }
211 
212  // push cluster range in det
213  if ( theStDets.isActive(i) )
214  theStDets.update(i,j);
215  }
216  }
217 }
218 
219 void
220 MeasurementTrackerEventProducer::getInactiveStrips(const edm::Event& event,std::vector<uint32_t> & rawInactiveDetIds) const
221 {
222  if (!theInactiveStripDetectorLabels.empty()) {
225  if (event.getByToken(tk, detIds)){
226  rawInactiveDetIds.insert(rawInactiveDetIds.end(), detIds->begin(), detIds->end());
227  }
228  }
229  if (!rawInactiveDetIds.empty()) std::sort(rawInactiveDetIds.begin(), rawInactiveDetIds.end());
230  }
231 
232 }
233 
234 
235 
#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
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:184
ProductID id() const
Definition: HandleBase.cc:15
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:446
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
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)
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 ...
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
bool isActive(int i) const
void getInactiveStrips(const edm::Event &event, std::vector< uint32_t > &rawInactiveDetIds) const
int j
Definition: DBlmapReader.cc:9
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
tuple out
Definition: dbtoconf.py:99
bool failedToGet() const
Definition: HandleBase.h:80
T const * product() const
Definition: Handle.h:81
const T & get() const
Definition: EventSetup.h:55
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:80
int find(unsigned int jd, int i=0) const
edm::Handle< edmNew::DetSetVector< SiStripCluster > > & handle()
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