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 Types | Private Attributes
TkAlCaSkimTreeMerger Class Reference
Inheritance diagram for TkAlCaSkimTreeMerger:
edm::EDAnalyzer edm::EDConsumerBase

Public Member Functions

void analyze (const edm::Event &, const edm::EventSetup &) override
 
void beginJob () override
 
void endJob () override
 
 TkAlCaSkimTreeMerger (const edm::ParameterSet &iConfig)
 
 ~TkAlCaSkimTreeMerger ()
 
- Public Member Functions inherited from edm::EDAnalyzer
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzer ()
 
ModuleDescription const & moduleDescription () const
 
std::string workerType () const
 
virtual ~EDAnalyzer ()
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesDependentUpon (const std::string &iProcessName, std::vector< const char * > &oModuleLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Private Types

typedef std::map< uint32_t,
uint32_t > 
DetHitMap
 

Private Attributes

TChain * ch_
 
std::string filelist_
 
std::string firstfilename_
 
TTree * firsttree_
 
DetHitMap hitmap_
 
int maxhits_
 
edm::ParameterSet maxhitsSet_
 
int maxPXBhits_
 
int maxPXFhits_
 
int maxTEChits_
 
int maxTIBhits_
 
int maxTIDhits_
 
int maxTOBhits_
 
TStopwatch myclock
 
TTree * out_
 
std::string outfilename_
 
DetHitMap overlapmap_
 
std::string treename_
 

Additional Inherited Members

- Public Types inherited from edm::EDAnalyzer
typedef EDAnalyzer ModuleType
 
- Static Public Member Functions inherited from edm::EDAnalyzer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Definition at line 25 of file TkAlCaSkimTreeMerger.cc.

Member Typedef Documentation

typedef std::map<uint32_t,uint32_t> TkAlCaSkimTreeMerger::DetHitMap
private

Definition at line 44 of file TkAlCaSkimTreeMerger.cc.

Constructor & Destructor Documentation

TkAlCaSkimTreeMerger::TkAlCaSkimTreeMerger ( const edm::ParameterSet iConfig)

Definition at line 62 of file TkAlCaSkimTreeMerger.cc.

References ch_, gather_cfg::cout, firsttree_, edm::ParameterSet::getParameter(), maxhits_, maxhitsSet_, maxPXBhits_, maxPXFhits_, maxTEChits_, maxTIBhits_, maxTIDhits_, maxTOBhits_, and out_.

62  :
63  filelist_(iConfig.getParameter<std::string>("FileList")),
64  treename_(iConfig.getParameter<std::string>("TreeName")),
65  outfilename_(iConfig.getParameter<std::string>("OutputFile")),
66  // maxhits_(iConfig.getParameter<vint>("NhitsMaxLimit"))
67  maxhits_(iConfig.getParameter<int32_t>("NhitsMaxLimit")),
68  maxhitsSet_(iConfig.getParameter<edm::ParameterSet>("NhitsMaxSet"))
69 {
70  maxPXBhits_=maxhitsSet_.getParameter<int32_t>("PXBmaxhits");
71  maxPXFhits_=maxhitsSet_.getParameter<int32_t>("PXFmaxhits");
72  maxTIBhits_=maxhitsSet_.getParameter<int32_t>("TIBmaxhits");
73  maxTIDhits_=maxhitsSet_.getParameter<int32_t>("TIDmaxhits");
74  maxTOBhits_=maxhitsSet_.getParameter<int32_t>("TOBmaxhits");
75  maxTEChits_=maxhitsSet_.getParameter<int32_t>("TECmaxhits");
76  //anything you want to do for initializing
77  std::cout<<"\n\n*** MAX N HITS = "<<maxhits_<<std::endl<<std::endl;
78  out_=0;
79  firsttree_=0;
80  ch_=0;
81 }
T getParameter(std::string const &) const
edm::ParameterSet maxhitsSet_
tuple cout
Definition: gather_cfg.py:121
TkAlCaSkimTreeMerger::~TkAlCaSkimTreeMerger ( )

Definition at line 84 of file TkAlCaSkimTreeMerger.cc.

References ch_, and gather_cfg::cout.

84  {
85  //default destructor
86  // delete out_;
87  // delete firsttree_;
88 
89  delete ch_;
90  std::cout<<"finished."<<std::endl;
91 }
tuple cout
Definition: gather_cfg.py:121

Member Function Documentation

void TkAlCaSkimTreeMerger::analyze ( const edm::Event ,
const edm::EventSetup  
)
overridevirtual

Implements edm::EDAnalyzer.

Definition at line 183 of file TkAlCaSkimTreeMerger.cc.

183  {
184  // std::cout<<firsttree_->GetEntries()<<std::endl;
185 }//end analyze
void TkAlCaSkimTreeMerger::beginJob ( void  )
overridevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 94 of file TkAlCaSkimTreeMerger.cc.

References ch_, gather_cfg::cout, filelist_, lut2db_cfg::filename, plotBeamSpotDB::first, firstfilename_, hitmap_, recoMuon::in, myclock, overlapmap_, AlCaHLTBitMon_QueryRunRegistry::string, and treename_.

94  {
95 
96  myclock.Start();
97 
98  //prepare the chain
99  ch_=new TChain(treename_.c_str());
100  std::cout<<"The chain contains "<<ch_->GetNtrees()<<" trees"<<std::endl;
101 
102  //load the trees into the chain
103  std::ifstream flist(filelist_.c_str(),std::ios::in);
105  std::string firstfilename;
106  bool first=true;
107  while(!flist.eof()){
108  filename="";
109  flist>>filename;
110  if(filename.empty())continue;
111  //std::cout<<"Adding "<<filename<<std::endl;
112  ch_->Add(filename.c_str());
113  if(first){
115  first=false;
116  }
117 
118  }
119  std::cout<<"Now the chain contains "<<ch_->GetNtrees()<<" trees ("<<ch_->GetEntries()<<" entries)"<<std::endl;
120 
121 
122  unsigned int id_ch=0;
123  uint32_t nhits_ch=0,noverlaps_ch=0;
124  ch_->SetBranchAddress("DetId", &id_ch);
125  ch_->SetBranchAddress("Nhits", &nhits_ch);
126  ch_->SetBranchAddress("Noverlaps",&noverlaps_ch);
127 
128  ch_->SetBranchStatus("SubDet",0);
129  ch_->SetBranchStatus("Layer",0);
130  ch_->SetBranchStatus("is2D",0);
131  ch_->SetBranchStatus("isStereo",0);
132  ch_->SetBranchStatus("posX",0);
133  ch_->SetBranchStatus("posY",0);
134  ch_->SetBranchStatus("posZ",0);
135  ch_->SetBranchStatus("posR",0);
136  ch_->SetBranchStatus("posEta",0);
137  ch_->SetBranchStatus("posPhi",0);//now only id, nhits and noverlaps are on...
138 
139 
140  int totnhits(0),totnoverlaps(0);
141 
142 
143  //look if you find this detid in the map
144  DetHitMap::iterator mapiter;
145  DetHitMap::iterator overlapiter;
146 
147  for(int ent=0;ent<ch_->GetEntries();++ent){
148  // for(int ent=0;ent<100;++ent){
149  ch_->GetEntry(ent);
150  totnhits+=nhits_ch;
151  totnoverlaps+=noverlaps_ch;
152 
153  mapiter= hitmap_.find(id_ch);
154  if(mapiter!=hitmap_.end() ){//present, increase its value
155  hitmap_[id_ch]=hitmap_[id_ch]+nhits_ch;
156  }
157  else{//not present, let's add this key to the map with value=1
158  hitmap_.insert(std::pair<uint32_t, uint32_t>(id_ch, nhits_ch));
159  }
160  //do the same for overlaps
161  overlapiter= overlapmap_.find(id_ch);
162  if(overlapiter!=overlapmap_.end() ){
163  overlapmap_[id_ch]=overlapmap_[id_ch]+noverlaps_ch;
164  }
165  else{
166  overlapmap_.insert(std::pair<uint32_t, uint32_t>(id_ch, noverlaps_ch));
167  }
168 
169  }//end loop on ent - entries in the chain
170 
171 
172  std::cout<<"Nhits in the chain: "<<totnhits<<std::endl;
173  std::cout<<"NOverlaps in the chain: "<<totnoverlaps<<std::endl;
174 
175 
176  myclock.Stop();
177  std::cout<<"Finished beginJob after "<<myclock.RealTime()<<" s (real time) / "<<myclock.CpuTime()<<" s (cpu time)"<<std::endl;
178  myclock.Continue();
179 }//end beginJob
tuple filename
Definition: lut2db_cfg.py:20
tuple cout
Definition: gather_cfg.py:121
void TkAlCaSkimTreeMerger::endJob ( void  )
overridevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 188 of file TkAlCaSkimTreeMerger.cc.

References gather_cfg::cout, firstfilename_, firsttree_, hitmap_, maxhits_, maxPXBhits_, maxPXFhits_, maxTEChits_, maxTIBhits_, maxTIDhits_, maxTOBhits_, mod(), myclock, out_, getDQMSummary::outfile, outfilename_, overlapmap_, and treename_.

188  {
189 
190 
191  //address variables in the first tree and in the chain
192  TFile *firstfile=new TFile(firstfilename_.c_str(),"READ");
193  firsttree_=(TTree*)firstfile->Get(treename_.c_str());
194  std::cout<<"the first tree has "<<firsttree_->GetEntries() <<" entries"<<std::endl;
195  unsigned int id=0;
196  uint32_t nhits=0,noverlaps=0;
197  float posX(-99999.0),posY(-77777.0),posZ(-88888.0);
198  float posEta(-6666.0),posPhi(-5555.0),posR(-4444.0);
199  int subdet=0;
200  unsigned int layer=0;
201  // bool is2D=false,isStereo=false;
202  firsttree_->SetBranchAddress("DetId", &id);
203  firsttree_->SetBranchAddress("Nhits", &nhits);
204  firsttree_->SetBranchAddress("Noverlaps",&noverlaps);
205  firsttree_->SetBranchAddress("SubDet", &subdet);
206  firsttree_->SetBranchAddress("Layer", &layer);
207  // firsttree_->SetBranchAddress("is2D" , &is2D);
208  // firsttree_->SetBranchAddress("isStereo", &isStereo);
209  firsttree_->SetBranchAddress("posX", &posX);
210  firsttree_->SetBranchAddress("posY", &posY);
211  firsttree_->SetBranchAddress("posZ", &posZ);
212  firsttree_->SetBranchAddress("posR", &posR);
213  firsttree_->SetBranchAddress("posEta", &posEta);
214  firsttree_->SetBranchAddress("posPhi", &posPhi);
215 
216 
217  //create and book the output
218 
219 
220  TFile *outfile=new TFile(outfilename_.c_str(),"RECREATE");
221  out_=new TTree(treename_.c_str(),"AlignmentHitMapsTOTAL");
222  unsigned int id_out=0;
223  uint32_t nhits_out=0,noverlaps_out=0;
224  float posX_out(-99999.0),posY_out(-77777.0),posZ_out(-88888.0);
225  float posEta_out(-6666.0),posPhi_out(-5555.0),posR_out(-4444.0);
226  int subdet_out=0;
227  unsigned int layer_out=0;
228  bool is2D_out=false,isStereo_out=false;
229  float prescfact_out=1.0;
230  float prescfact_overlap_out=1.0;
231 
232  out_->Branch("DetId", &id_out , "DetId/i");
233  out_->Branch("Nhits", &nhits_out , "Nhits/i");
234  out_->Branch("Noverlaps",&noverlaps_out,"Noverlaps/i");
235  out_->Branch("SubDet", &subdet_out, "SubDet/I");
236  out_->Branch("Layer", &layer_out, "Layer/i");
237  out_->Branch("is2D" , &is2D_out, "is2D/B");
238  out_->Branch("isStereo", &isStereo_out, "isStereo/B");
239  out_->Branch("posX", &posX_out, "posX/F");
240  out_->Branch("posY", &posY_out, "posY/F");
241  out_->Branch("posZ", &posZ_out, "posZ/F");
242  out_->Branch("posR", &posR_out, "posR/F");
243  out_->Branch("posEta", &posEta_out, "posEta/F");
244  out_->Branch("posPhi", &posPhi_out, "posPhi/F");
245  out_->Branch("PrescaleFactor",&prescfact_out,"PrescaleFact/F");
246  out_->Branch("PrescaleFactorOverlap",&prescfact_overlap_out,"PrescaleFactOverlap/F");
247 
248 
249  //look if you find this detid in the map
250  DetHitMap::iterator mapiter;
251 
252  for(int mod=0;mod<firsttree_->GetEntries();mod++){
253  //for(int mod=0;mod<100;++mod){
254  // nhits_out=0;
255  // noverlaps_out=0;
256 
257  firsttree_->GetEntry(mod);
258  nhits_out=hitmap_[id];
259  noverlaps_out=overlapmap_[id];
260  // if(mod<25)std::cout<<"Nhits 1st tree: "<<nhits<<"\tTotal nhits chain: "<<nhits_out<<std::endl;
261  id_out=id;
262  subdet_out=subdet;
263  layer_out=layer;
264  posX_out=posX;
265  posY_out=posY;
266  posZ_out=posZ;
267  posR_out=posR;
268  posEta_out=posEta;
269  posPhi_out=posPhi;
270 
271  //calculate prescaling factor
272  int subdetmax=-1;
273  if(subdet_out==1)subdetmax=maxPXBhits_;
274  else if(subdet_out==2)subdetmax=maxPXFhits_;
275  else if(subdet_out==3)subdetmax=maxTIBhits_;
276  else if(subdet_out==4)subdetmax=maxTIDhits_;
277  else if(subdet_out==5)subdetmax=maxTOBhits_;
278  else if(subdet_out==6)subdetmax=maxTEChits_;
279  else subdetmax=-9999;
280 
281  if(maxhits_>-1){
282  if(int(nhits_out)>maxhits_){
283  prescfact_out=float(maxhits_)/float(nhits_out);
284  }
285  if(int(noverlaps_out)>maxhits_){
286  prescfact_overlap_out=float(maxhits_)/float(noverlaps_out);
287  }
288  }
289  else if(subdetmax>0){//calculate different prescaling factors for each subdet
290  if(int(nhits_out)>subdetmax){
291  prescfact_out=float(subdetmax/nhits_out);
292  }
293  if(int(noverlaps_out)>subdetmax){
294  prescfact_overlap_out=float(subdetmax)/float(noverlaps_out);
295  }
296  }
297  else{
298  prescfact_out=1.0;
299  prescfact_overlap_out=1.0;
300  }
301  out_->Fill();
302 
303  }//end loop on mod - first tree modules
304 
305 
306  myclock.Stop();
307  std::cout<<"Finished endJob after "<<myclock.RealTime()<<" s (real time) / "<<myclock.CpuTime()<<" s (cpu time)"<<std::endl;
308  std::cout<<"Ending the tree merging."<<std::endl;
309  out_->Write();
310  std::cout<<"Deleting..."<<std::flush;
311  delete firstfile;
312  delete outfile;
313 
314 
315 }//end endJob
tuple cout
Definition: gather_cfg.py:121
T mod(const T &a, const T &b)
Definition: ecalDccMap.h:4

Member Data Documentation

TChain* TkAlCaSkimTreeMerger::ch_
private

Definition at line 37 of file TkAlCaSkimTreeMerger.cc.

Referenced by beginJob(), TkAlCaSkimTreeMerger(), and ~TkAlCaSkimTreeMerger().

std::string TkAlCaSkimTreeMerger::filelist_
private

Definition at line 38 of file TkAlCaSkimTreeMerger.cc.

Referenced by beginJob().

std::string TkAlCaSkimTreeMerger::firstfilename_
private

Definition at line 39 of file TkAlCaSkimTreeMerger.cc.

Referenced by beginJob(), and endJob().

TTree* TkAlCaSkimTreeMerger::firsttree_
private

Definition at line 36 of file TkAlCaSkimTreeMerger.cc.

Referenced by endJob(), and TkAlCaSkimTreeMerger().

DetHitMap TkAlCaSkimTreeMerger::hitmap_
private

Definition at line 45 of file TkAlCaSkimTreeMerger.cc.

Referenced by beginJob(), and endJob().

int TkAlCaSkimTreeMerger::maxhits_
private

Definition at line 47 of file TkAlCaSkimTreeMerger.cc.

Referenced by endJob(), and TkAlCaSkimTreeMerger().

edm::ParameterSet TkAlCaSkimTreeMerger::maxhitsSet_
private

Definition at line 48 of file TkAlCaSkimTreeMerger.cc.

Referenced by TkAlCaSkimTreeMerger().

int TkAlCaSkimTreeMerger::maxPXBhits_
private

Definition at line 49 of file TkAlCaSkimTreeMerger.cc.

Referenced by endJob(), and TkAlCaSkimTreeMerger().

int TkAlCaSkimTreeMerger::maxPXFhits_
private

Definition at line 49 of file TkAlCaSkimTreeMerger.cc.

Referenced by endJob(), and TkAlCaSkimTreeMerger().

int TkAlCaSkimTreeMerger::maxTEChits_
private

Definition at line 49 of file TkAlCaSkimTreeMerger.cc.

Referenced by endJob(), and TkAlCaSkimTreeMerger().

int TkAlCaSkimTreeMerger::maxTIBhits_
private

Definition at line 49 of file TkAlCaSkimTreeMerger.cc.

Referenced by endJob(), and TkAlCaSkimTreeMerger().

int TkAlCaSkimTreeMerger::maxTIDhits_
private

Definition at line 49 of file TkAlCaSkimTreeMerger.cc.

Referenced by endJob(), and TkAlCaSkimTreeMerger().

int TkAlCaSkimTreeMerger::maxTOBhits_
private

Definition at line 49 of file TkAlCaSkimTreeMerger.cc.

Referenced by endJob(), and TkAlCaSkimTreeMerger().

TStopwatch TkAlCaSkimTreeMerger::myclock
private

Definition at line 52 of file TkAlCaSkimTreeMerger.cc.

Referenced by beginJob(), and endJob().

TTree* TkAlCaSkimTreeMerger::out_
private

Definition at line 35 of file TkAlCaSkimTreeMerger.cc.

Referenced by endJob(), and TkAlCaSkimTreeMerger().

std::string TkAlCaSkimTreeMerger::outfilename_
private

Definition at line 41 of file TkAlCaSkimTreeMerger.cc.

Referenced by endJob().

DetHitMap TkAlCaSkimTreeMerger::overlapmap_
private

Definition at line 46 of file TkAlCaSkimTreeMerger.cc.

Referenced by beginJob(), and endJob().

std::string TkAlCaSkimTreeMerger::treename_
private

Definition at line 40 of file TkAlCaSkimTreeMerger.cc.

Referenced by beginJob(), and endJob().