CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
AlignmentPrescaler Class Reference

#include <AlignmentPrescaler.h>

Inheritance diagram for AlignmentPrescaler:
edm::EDProducer edm::ProducerBase edm::ProductRegistryHelper

Public Member Functions

 AlignmentPrescaler (const edm::ParameterSet &iConfig)
 
void beginJob ()
 
void endJob ()
 
virtual void produce (edm::Event &iEvent, const edm::EventSetup &iSetup)
 
 ~AlignmentPrescaler ()
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
virtual ~EDProducer ()
 
- Public Member Functions inherited from edm::ProducerBase
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
boost::function< void(const
BranchDescription &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 

Private Member Functions

int layerFromId (const DetId &id) const
 

Private Attributes

unsigned int detid_
 
TFile * fpresc_
 
float hitPrescFactor_
 
TRandom3 * myrand_
 
float overlapPrescFactor_
 
std::string prescfilename_
 
std::string presctreename_
 
edm::InputTag src_
 
edm::InputTag srcQualityMap_
 
int totnhitspxl_
 
TTree * tpresc_
 

Additional Inherited Members

- Public Types inherited from edm::EDProducer
typedef EDProducer ModuleType
 
typedef WorkerT< EDProducerWorkerType
 
- Public Types inherited from edm::ProducerBase
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 
- Static Public Member Functions inherited from edm::EDProducer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDProducer
CurrentProcessingContext const * currentContext () const
 
- Protected Member Functions inherited from edm::ProducerBase
template<class TProducer , class TMethod >
void callWhenNewProductsRegistered (TProducer *iProd, TMethod iMethod)
 

Detailed Description

Definition at line 23 of file AlignmentPrescaler.h.

Constructor & Destructor Documentation

AlignmentPrescaler::AlignmentPrescaler ( const edm::ParameterSet iConfig)

Definition at line 29 of file AlignmentPrescaler.cc.

29  :
30  src_(iConfig.getParameter<edm::InputTag>("src")),
31  srcQualityMap_(iConfig.getParameter<edm::InputTag>("assomap")),
32  prescfilename_(iConfig.getParameter<std::string>("PrescFileName")),
33  presctreename_(iConfig.getParameter<std::string>("PrescTreeName"))
34 {
35  // issue the produce<>
36  produces<AliClusterValueMap>();
37  produces<AliTrackTakenClusterValueMap>();
38 
39 }
T getParameter(std::string const &) const
edm::InputTag srcQualityMap_
std::string prescfilename_
std::string presctreename_
AlignmentPrescaler::~AlignmentPrescaler ( )

Definition at line 41 of file AlignmentPrescaler.cc.

41  {
42  //
43 }

Member Function Documentation

void AlignmentPrescaler::beginJob ( void  )
virtual

Reimplemented from edm::EDProducer.

Definition at line 45 of file AlignmentPrescaler.cc.

References gather_cfg::cout, detid_, fpresc_, hitPrescFactor_, myrand_, overlapPrescFactor_, prescfilename_, presctreename_, and tpresc_.

45  {
46  //
47  std::cout<<"in AlignmentPrescaler::beginJob"<<std::flush;
48  fpresc_=new TFile(prescfilename_.c_str(),"READ");
49  tpresc_=(TTree*)fpresc_->Get(presctreename_.c_str());
50  tpresc_->BuildIndex("DetId");
51  tpresc_->SetBranchStatus("*",0);
52  tpresc_->SetBranchStatus("DetId",1);
53  tpresc_->SetBranchStatus("PrescaleFactor",1);
54  tpresc_->SetBranchStatus("PrescaleFactorOverlap",1);
55  cout<<" Branches activated "<<std::flush;
56  detid_=0;
57  hitPrescFactor_=99.0;
59 
60  tpresc_->SetBranchAddress("DetId",&detid_);
61  tpresc_->SetBranchAddress("PrescaleFactor",&hitPrescFactor_);
62  tpresc_->SetBranchAddress("PrescaleFactorOverlap",&overlapPrescFactor_);
63  cout<<" addressed "<<std::flush;
64  myrand_=new TRandom3();
65  // myrand_->SetSeed();
66  cout<<" ok "<<std::endl;
67 
68 }
std::string prescfilename_
std::string presctreename_
tuple cout
Definition: gather_cfg.py:121
void AlignmentPrescaler::endJob ( void  )
virtual

Reimplemented from edm::EDProducer.

Definition at line 70 of file AlignmentPrescaler.cc.

References fpresc_, myrand_, and tpresc_.

70  {
71 
72  delete tpresc_;
73  fpresc_->Close();
74  delete fpresc_;
75  delete myrand_;
76 }
int AlignmentPrescaler::layerFromId ( const DetId id) const
private

Definition at line 243 of file AlignmentPrescaler.cc.

References PXFDetId::disk(), PXBDetId::layer(), TOBDetId::layer(), TIBDetId::layer(), PixelSubdetector::PixelBarrel, PixelSubdetector::PixelEndcap, PXFDetId::side(), TIDDetId::side(), TECDetId::side(), StripSubdetector::TEC, StripSubdetector::TIB, StripSubdetector::TID, StripSubdetector::TOB, TIDDetId::wheel(), and TECDetId::wheel().

244 {
245  if ( uint32_t(id.subdetId())==PixelSubdetector::PixelBarrel ) {
246  PXBDetId tobId(id);
247  return tobId.layer();
248  }
249  else if ( uint32_t(id.subdetId())==PixelSubdetector::PixelEndcap ) {
250  PXFDetId tobId(id);
251  return tobId.disk() + (3*(tobId.side()-1));
252  }
253  else if ( id.subdetId()==StripSubdetector::TIB ) {
254  TIBDetId tibId(id);
255  return tibId.layer();
256  }
257  else if ( id.subdetId()==StripSubdetector::TOB ) {
258  TOBDetId tobId(id);
259  return tobId.layer();
260  }
261  else if ( id.subdetId()==StripSubdetector::TEC ) {
262  TECDetId tobId(id);
263  return tobId.wheel() + (9*(tobId.side()-1));
264  }
265  else if ( id.subdetId()==StripSubdetector::TID ) {
266  TIDDetId tobId(id);
267  return tobId.wheel() + (3*(tobId.side()-1));
268  }
269  return -1;
270 
271 }//end layerfromId
void AlignmentPrescaler::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
virtual

Implements edm::EDProducer.

Definition at line 78 of file AlignmentPrescaler.cc.

References SiStripRecHit1D::cluster(), SiPixelRecHit::cluster(), SiStripRecHit2D::cluster(), gather_cfg::cout, edm::helper::Filler< Map >::fill(), TrackingRecHit::geographicalId(), edm::Event::getByLabel(), hitPrescFactor_, edm::helper::Filler< Map >::insert(), TrackingRecHit::isValid(), myrand_, overlapPrescFactor_, edm::Event::put(), DetId::rawId(), findQualityFiles::rr, src_, srcQualityMap_, DetId::subdetId(), and tpresc_.

Referenced by JSONExport.JsonExport::export(), HTMLExport.HTMLExport::export(), and HTMLExport.HTMLExportStatic::export().

78  {
79  // std::cout<<"\n\n#################\n### Starting the AlignmentPrescaler::produce ; Event: "<<iEvent.id().run() <<", "<<iEvent.id().event()<<std::endl;
81  iEvent.getByLabel(src_, Tracks);
82 
83  //take HitAssomap
85  iEvent.getByLabel(srcQualityMap_, hMap);
86  AliClusterValueMap InValMap=*hMap;
87 
88  //prepare the output of the ValueMap flagging tracks
89  std::vector<int> trackflags(Tracks->size(),0);
90 
91 
92  //int npxlhits=0;
93 
94  //loop on tracks
95  for(std::vector<reco::Track>::const_iterator ittrk = Tracks->begin(), edtrk = Tracks->end(); ittrk != edtrk; ++ittrk){
96  //loop on tracking rechits
97  // std::cout << "Loop on hits of track #" << (ittrk - Tracks->begin()) << std::endl;
98  int nhit=0;
99  int ntakenhits=0;
100  bool firstTakenHit=false;
101 
102  for (trackingRecHit_iterator ith = ittrk->recHitsBegin(), edh = ittrk->recHitsEnd(); ith != edh; ++ith) {
103  const TrackingRecHit *hit = ith->get(); // ith is an iterator on edm::Ref to rechit
104  if(! hit->isValid()){
105  nhit++;
106  continue;
107  }
108  uint32_t tmpdetid = hit->geographicalId().rawId();
109  tpresc_->GetEntryWithIndex(tmpdetid);
110 
111 
112  //-------------
113  //decide whether to take this hit or not
114  bool takeit=false;
115  int subdetId=hit->geographicalId().subdetId();
116 
117 
118  //check first if the cluster is also in the overlap asso map
119  bool isOverlapHit=false;
120  // bool first=true;
121  //ugly...
122  const SiPixelRecHit* pixelhit= dynamic_cast<const SiPixelRecHit*>(hit);
123  const SiStripRecHit1D* stripHit1D = dynamic_cast<const SiStripRecHit1D*>(hit);
124  const SiStripRecHit2D* stripHit2D = dynamic_cast<const SiStripRecHit2D*>(hit);
125 
126  AlignmentClusterFlag tmpflag(hit->geographicalId());
127  int stripType=0;
128  if(subdetId>2){// SST case
129  const std::type_info &type = typeid(*hit);
130  if (type == typeid(SiStripRecHit1D)) stripType=1;
131  else if (type == typeid(SiStripRecHit2D)) stripType=2;
132  else stripType=3;
133 
134  if(stripType==1) {
135  // const SiStripRecHit1D* stripHit1D = dynamic_cast<const SiStripRecHit1D*>(hit);
136 
137  if(stripHit1D!=0){
138  SiStripRecHit1D::ClusterRef stripclust(stripHit1D->cluster());
139  tmpflag=InValMap[stripclust];
140  tmpflag.SetDetId(hit->geographicalId());
141  if(tmpflag.isOverlap())isOverlapHit=true;
142  // std::cout<<"~*~*~* Prescale (1D) for module "<<tmpflag.detId().rawId()<<"("<<InValMap[stripclust].detId().rawId() <<") is "<<hitPrescFactor_<<std::flush;
143  // if(tmpflag.isOverlap())cout<<" (it is Overlap)"<<endl;
144  // else cout<<endl;
145 
146  }//end if striphit1D!=0
147  }
148  else if (stripType==2) {
149  //const SiStripRecHit2D* stripHit2D = dynamic_cast<const SiStripRecHit2D*>(hit);
150  if(stripHit2D!=0){
151  SiStripRecHit2D::ClusterRef stripclust(stripHit2D->cluster());
152  tmpflag=InValMap[stripclust];
153  tmpflag.SetDetId(hit->geographicalId());
154  if(tmpflag.isOverlap())isOverlapHit=true;
155  // std::cout<<"~*~*~* Prescale (2D) for module "<<tmpflag.detId().rawId()<<"("<<InValMap[stripclust].detId().rawId() <<") is "<<hitPrescFactor_<<std::flush;
156  // if(tmpflag.isOverlap())cout<<" (it is Overlap)"<<endl;
157  // else cout<<endl;
158 
159  }//end if striphit2D!=0
160  }
161  }//end if is a strip hit
162  else{
163  // const SiPixelRecHit* pixelhit= dynamic_cast<const SiPixelRecHit*>(hit);
164  if(pixelhit!=0){
165  //npxlhits++;
166  SiPixelClusterRefNew pixclust(pixelhit->cluster());
167  tmpflag=InValMap[pixclust];
168  tmpflag.SetDetId(hit->geographicalId());
169  if(tmpflag.isOverlap())isOverlapHit=true;
170  }
171  }//end else is a pixel hit
172  // tmpflag.SetDetId(hit->geographicalId());
173 
174  if( isOverlapHit ){
175  //cout<<" DetId="<<tmpdetid<<" is Overlap! "<<flush;
176  takeit=(float(myrand_->Rndm())<=overlapPrescFactor_);
177  }
178  if( !takeit ){
179  float rr=float(myrand_->Rndm());
180  takeit=(rr<=hitPrescFactor_);
181  }
182  if(takeit){//HIT TAKEN !
183  //cout<<" DetId="<<tmpdetid<<" taken!"<<flush;
184  tmpflag.SetTakenFlag();
185 
186  if(subdetId>2){
187  if(stripType==1){
188  SiStripRecHit1D::ClusterRef stripclust(stripHit1D->cluster());
189  InValMap[stripclust]=tmpflag;//.SetTakenFlag();
190  }
191  else if(stripType==2){
192  SiStripRecHit1D::ClusterRef stripclust(stripHit2D->cluster());
193  InValMap[stripclust]=tmpflag;//.SetTakenFlag();
194  }
195  else std::cout<<"Unknown type of strip hit"<<std::endl;
196  }
197  else{
198  SiPixelClusterRefNew pixclust(pixelhit->cluster());
199  InValMap[pixclust]=tmpflag;//.SetTakenFlag();
200  }
201 
202  if(!firstTakenHit){
203  firstTakenHit=true;
204  //std::cout<<"Index of the track iterator is "<< ittrk-Tracks->begin() <<endl;
205 
206  }
207  ntakenhits++;
208  }//end if take this hit
209  //cout<<endl;
210 
211  nhit++;
212  //cout<<endl;
213  }//end loop on RecHits
214  trackflags[ittrk-Tracks->begin()]=ntakenhits;
215 
216  }//end loop on tracks
217 
218 
219 
220  // totnhitspxl_+=ntakenhits;
221  //cout<<"AlignmentPrescaler::produce says that in this event "<<ntakenhits<<" pixel clusters were taken (out of "<<npxlhits<<" total pixel hits."<<endl;
222 
223 
224 
225  //save the asso map, tracks...
226  // prepare output
227  std::auto_ptr<AliClusterValueMap> OutVM( new AliClusterValueMap);
228  *OutVM=InValMap;
229 
230  iEvent.put(OutVM);
231 
232 
233  std::auto_ptr<AliTrackTakenClusterValueMap> trkVM( new AliTrackTakenClusterValueMap);
234  AliTrackTakenClusterValueMap::Filler trkmapfiller(*trkVM);
235  trkmapfiller.insert(Tracks,trackflags.begin(),trackflags.end() );
236  trkmapfiller.fill();
237  iEvent.put(trkVM);
238 
239 
240 }//end produce
ClusterRef cluster() const
type
Definition: HCALResponse.h:22
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
edm::InputTag srcQualityMap_
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
ClusterRef cluster() const
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:39
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
ClusterRef cluster() const
Definition: SiPixelRecHit.h:41
bool isValid() const
tuple cout
Definition: gather_cfg.py:121
DetId geographicalId() const
Our base class.
Definition: SiPixelRecHit.h:22

Member Data Documentation

unsigned int AlignmentPrescaler::detid_
private

Definition at line 46 of file AlignmentPrescaler.h.

Referenced by beginJob().

TFile* AlignmentPrescaler::fpresc_
private

Definition at line 39 of file AlignmentPrescaler.h.

Referenced by beginJob(), and endJob().

float AlignmentPrescaler::hitPrescFactor_
private

Definition at line 47 of file AlignmentPrescaler.h.

Referenced by beginJob(), and produce().

TRandom3* AlignmentPrescaler::myrand_
private

Definition at line 41 of file AlignmentPrescaler.h.

Referenced by beginJob(), endJob(), and produce().

float AlignmentPrescaler::overlapPrescFactor_
private

Definition at line 47 of file AlignmentPrescaler.h.

Referenced by beginJob(), and produce().

std::string AlignmentPrescaler::prescfilename_
private

Definition at line 36 of file AlignmentPrescaler.h.

Referenced by beginJob().

std::string AlignmentPrescaler::presctreename_
private

Definition at line 37 of file AlignmentPrescaler.h.

Referenced by beginJob().

edm::InputTag AlignmentPrescaler::src_
private

Definition at line 33 of file AlignmentPrescaler.h.

Referenced by produce().

edm::InputTag AlignmentPrescaler::srcQualityMap_
private

Definition at line 34 of file AlignmentPrescaler.h.

Referenced by produce().

int AlignmentPrescaler::totnhitspxl_
private

Definition at line 48 of file AlignmentPrescaler.h.

TTree* AlignmentPrescaler::tpresc_
private

Definition at line 40 of file AlignmentPrescaler.h.

Referenced by beginJob(), endJob(), and produce().