CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
AlignmentPrescaler.cc
Go to the documentation of this file.
2 
16 
19 
26 
27 #include "Riostream.h"
28 
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 }
40 
42  //
43 }
44 
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 }
69 
71 
72  delete tpresc_;
73  fpresc_->Close();
74  delete fpresc_;
75  delete myrand_;
76 }
77 
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
241 
242 
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
272 
273 // ========= MODULE DEF ==============
ClusterRef cluster() const
type
Definition: HCALResponse.h:22
unsigned int layer() const
layer id
Definition: TOBDetId.h:39
AlignmentPrescaler(const edm::ParameterSet &iConfig)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
int layerFromId(const DetId &id) const
unsigned int layer() const
layer id
Definition: PXBDetId.h:35
unsigned int side() const
positive or negative id
Definition: TECDetId.h:47
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
edm::InputTag srcQualityMap_
int iEvent
Definition: GenABIO.cc:243
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
ClusterRef cluster() const
std::string prescfilename_
std::string presctreename_
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
unsigned int disk() const
disk id
Definition: PXFDetId.h:43
Definition: DetId.h:20
unsigned int side() const
positive or negative id
Definition: TIDDetId.h:45
ClusterRef cluster() const
Definition: SiPixelRecHit.h:41
bool isValid() const
unsigned int wheel() const
wheel id
Definition: TECDetId.h:52
unsigned int layer() const
layer id
Definition: TIBDetId.h:41
unsigned int side() const
positive or negative id
Definition: PXFDetId.h:38
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup)
tuple cout
Definition: gather_cfg.py:121
DetId geographicalId() const
unsigned int wheel() const
wheel id
Definition: TIDDetId.h:50
Our base class.
Definition: SiPixelRecHit.h:22